#include <afs/vice.h>
#ifdef AFS_AIX_ENV
#include <sys/lockf.h>
+#ifdef AFS_AIX51_ENV
+#include <sys/cred.h>
+#endif
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
/* For malloc() */
#include <stdlib.h>
-
+#include "ktc.h"
#ifdef notdef
/* AFS_KERBEROS_ENV is now conditionally defined in the Makefile */
int afs_tf_save_cred(), afs_tf_close(), afs_tf_create();
int afs_tf_dest_tkt();
static void ktc_LocalCell();
-char *ktc_tkt_string();
#endif /* AFS_KERBEROS_ENV */
#ifdef AFS_DUX40_ENV
return 0;
}
-
-ktc_SetToken(aserver, atoken, aclient, flags)
- struct ktc_principal *aserver;
- struct ktc_principal *aclient;
- struct ktc_token *atoken;
- afs_int32 flags;
+int
+ktc_SetToken(struct ktc_principal *aserver,
+ struct ktc_token *atoken,
+ struct ktc_principal *aclient,
+ afs_int32 flags)
{
int ncode, ocode;
- LOCK_GLOBAL_MUTEX
+ LOCK_GLOBAL_MUTEX;
#ifdef AFS_KERBEROS_ENV
- if (!lcell[0])
+ if (!lcell[0])
ktc_LocalCell();
if ( /*!strcmp(aclient->cell, lcell) && this would only store local creds */
}
afs_tf_close();
#ifdef NO_AFS_CLIENT
- UNLOCK_GLOBAL_MUTEX return ncode;
+ UNLOCK_GLOBAL_MUTEX;
+ return ncode;
#endif /* NO_AFS_CLIENT */
}
#endif
} else
ocode = 0;
if (ncode && ocode) {
- UNLOCK_GLOBAL_MUTEX if (ocode == -1)
+ UNLOCK_GLOBAL_MUTEX;
+ if (ocode == -1)
ocode = errno;
else if (ocode == KTC_PIOCTLFAIL)
ocode = errno;
return KTC_PIOCTLFAIL;
}
#endif /* NO_AFS_CLIENT */
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
/* get token, given server we need and token buffer. aclient will eventually
int tktLen; /* server ticket length */
char found = 0;
- LOCK_GLOBAL_MUTEX
+ LOCK_GLOBAL_MUTEX;
#ifndef NO_AFS_CLIENT
- TRY_KERNEL(KTC_GETTOKEN_OP, aserver, aclient, atoken, atokenLen);
+ TRY_KERNEL(KTC_GETTOKEN_OP, aserver, aclient, atoken, atokenLen);
#endif /* NO_AFS_CLIENT */
#ifdef AFS_KERBEROS_ENV
min(atokenLen, sizeof(struct ktc_token)));
if (aclient)
*aclient = local_tokens[i].client;
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
#ifdef AFS_KERBEROS_ENV
if (!afs_tf_init(ktc_tkt_string(), R_TKT_FIL)) {
min(atokenLen, sizeof(struct ktc_token)));
afs_tf_close();
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
}
}
afs_tf_close();
#endif
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
#ifndef NO_AFS_CLIENT
for (index = 0; index < 200; index++) { /* sanity check in case pioctl fails */
if (code) {
/* failed to retrieve specified token */
if (code < 0 && errno == EDOM) {
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
} else {
/* token retrieved; parse buffer */
/* get size of clear token and verify */
memcpy(&temp, tp, sizeof(afs_int32));
if (temp != sizeof(struct ClearToken)) {
- UNLOCK_GLOBAL_MUTEX return KTC_ERROR;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_ERROR;
}
tp += sizeof(afs_int32);
maxLen =
atokenLen - sizeof(struct ktc_token) + MAXKTCTICKETLEN;
if (maxLen < tktLen) {
- UNLOCK_GLOBAL_MUTEX return KTC_TOOBIG;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_TOOBIG;
}
/* set return values */
sprintf(aclient->name, "Unix UID %d", ct.ViceId);
}
}
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
}
}
#endif /* NO_AFS_CLIENT */
- UNLOCK_GLOBAL_MUTEX if ((code < 0) && (errno == EINVAL))
+ UNLOCK_GLOBAL_MUTEX;
+ if ((code < 0) && (errno == EINVAL))
return KTC_NOPIOCTL;
return KTC_PIOCTLFAIL; /* probable cause */
}
{
int rc;
- LOCK_GLOBAL_MUTEX TRY_KERNEL(KTC_FORGETTOKEN_OP, aserver, 0, 0, 0);
+ LOCK_GLOBAL_MUTEX;
+ TRY_KERNEL(KTC_FORGETTOKEN_OP, aserver, 0, 0, 0);
rc = ktc_ForgetAllTokens(); /* bogus, but better */
- UNLOCK_GLOBAL_MUTEX return rc;
+ UNLOCK_GLOBAL_MUTEX;
+ return rc;
}
#endif /* NO_AFS_CLIENT */
* next rock in (*aindex). (*aserver) is set to the relevant ticket on
* success. */
-ktc_ListTokens(aprevIndex, aindex, aserver)
- int aprevIndex, *aindex;
- struct ktc_principal *aserver;
+int
+ktc_ListTokens(int aprevIndex,
+ int *aindex,
+ struct ktc_principal *aserver)
{
struct ViceIoctl iob;
char tbuffer[MAXPIOCTLTOKENLEN];
memset(tbuffer, 0, sizeof(tbuffer));
- LOCK_GLOBAL_MUTEX
+ LOCK_GLOBAL_MUTEX;
#ifndef NO_AFS_CLIENT
- TRY_KERNEL(KTC_LISTTOKENS_OP, aserver, aprevIndex, aindex, 0);
+ TRY_KERNEL(KTC_LISTTOKENS_OP, aserver, aprevIndex, aindex, 0);
#endif /* NO_AFS_CLIENT */
index = aprevIndex;
if (afs_tf_init(ktc_tkt_string(), R_TKT_FIL)
|| afs_tf_get_pname(tbuffer) || afs_tf_get_pinst(tbuffer)) {
afs_tf_close();
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
for (i = 214; i < index; i++) {
if (afs_tf_get_cred(&cprincipal, &ctoken)) {
afs_tf_close();
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
}
again:
if (afs_tf_get_cred(&cprincipal, &ctoken)) {
afs_tf_close();
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
index++;
*aserver = cprincipal;
*aindex = index;
afs_tf_close();
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
#endif
if (local_tokens[index - 123].valid) {
*aserver = local_tokens[index - 123].server;
*aindex = index + 1;
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
index++;
}
- UNLOCK_GLOBAL_MUTEX
+ UNLOCK_GLOBAL_MUTEX;
#ifdef AFS_KERBEROS_ENV
- return ktc_ListTokens(214, aindex, aserver);
+ return ktc_ListTokens(214, aindex, aserver);
#else
- return KTC_NOENT;
+ return KTC_NOENT;
#endif
}
if (index < 123) {
int rc;
rc = ktc_ListTokens(123, aindex, aserver);
- UNLOCK_GLOBAL_MUTEX return rc;
+ UNLOCK_GLOBAL_MUTEX;
+ return rc;
} else {
- UNLOCK_GLOBAL_MUTEX return KTC_NOENT;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_NOENT;
}
}
if (code == 0)
index++;
}
if (code < 0) {
- UNLOCK_GLOBAL_MUTEX if (errno == EINVAL)
+ UNLOCK_GLOBAL_MUTEX;
+ if (errno == EINVAL)
return KTC_NOPIOCTL;
return KTC_PIOCTLFAIL;
}
tp += temp; /* skip ticket for now */
memcpy(&temp, tp, sizeof(afs_int32)); /* get size of clear token */
if (temp != sizeof(struct ClearToken)) {
- UNLOCK_GLOBAL_MUTEX return KTC_ERROR;
+ UNLOCK_GLOBAL_MUTEX;
+ return KTC_ERROR;
}
tp += sizeof(afs_int32); /* skip length */
tp += temp; /* skip clear token itself */
aserver->instance[0] = 0;
strcpy(aserver->name, "afs");
#endif /* NO_AFS_CLIENT */
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
/* discard all tokens from this user's cache */
static int
-NewForgetAll()
+NewForgetAll(void)
{
#ifndef NO_AFS_CLIENT
TRY_KERNEL(KTC_FORGETALLTOKENS_OP, 0, 0, 0, 0);
}
static int
-OldForgetAll()
+OldForgetAll(void)
{
struct ViceIoctl iob;
register afs_int32 code;
}
int
-ktc_ForgetAllTokens()
+ktc_ForgetAllTokens(void)
{
int ncode, ocode;
- LOCK_GLOBAL_MUTEX
+ LOCK_GLOBAL_MUTEX;
#ifdef AFS_KERBEROS_ENV
- (void) afs_tf_dest_tkt();
+ (void)afs_tf_dest_tkt();
#endif
ncode = NewForgetAll();
ocode = errno;
else if (ocode == KTC_PIOCTLFAIL)
ocode = errno;
- UNLOCK_GLOBAL_MUTEX if (ocode == EINVAL)
+ UNLOCK_GLOBAL_MUTEX;
+ if (ocode == EINVAL)
return KTC_NOPIOCTL;
return KTC_PIOCTLFAIL;
}
- UNLOCK_GLOBAL_MUTEX return 0;
+ UNLOCK_GLOBAL_MUTEX;
+ return 0;
}
/* ktc_OldPioctl - returns a boolean true if the kernel supports only the old
ktc_OldPioctl()
{
int rc;
- LOCK_GLOBAL_MUTEX
+ LOCK_GLOBAL_MUTEX;
#ifdef KERNEL_KTC_COMPAT
- CHECK_KERNEL;
+ CHECK_KERNEL;
rc = (kernelKTC != 1); /* old style interface */
#else
- rc = 1;
+ rc = 1;
#endif
- UNLOCK_GLOBAL_MUTEX return rc;
+ UNLOCK_GLOBAL_MUTEX;
+ return rc;
}
static char krb_ticket_string[4096] = "";
char *
-ktc_tkt_string()
+ktc_tkt_string(void)
+{
+ return ktc_tkt_string_uid(getuid());
+}
+
+char *
+ktc_tkt_string_uid(afs_uint32 uid)
{
char *env;
- LOCK_GLOBAL_MUTEX if (!*krb_ticket_string) {
+ LOCK_GLOBAL_MUTEX;
+ if (!*krb_ticket_string) {
if (env = getenv("KRBTKFILE")) {
(void)strncpy(krb_ticket_string, env,
sizeof(krb_ticket_string) - 1);
} else {
/* 32 bits of signed integer will always fit in 11 characters
* (including the sign), so no need to worry about overflow */
- (void)sprintf(krb_ticket_string, "%s%d", TKT_ROOT, getuid());
+ (void)sprintf(krb_ticket_string, "%s%d", TKT_ROOT, uid);
}
}
- UNLOCK_GLOBAL_MUTEX return krb_ticket_string;
+ UNLOCK_GLOBAL_MUTEX;
+ return krb_ticket_string;
}
/*
*/
void
-ktc_set_tkt_string(val)
- char *val;
+ktc_set_tkt_string(char * val)
{
- LOCK_GLOBAL_MUTEX(void) strncpy(krb_ticket_string, val,
- sizeof(krb_ticket_string) - 1);
+ LOCK_GLOBAL_MUTEX;
+ (void)strncpy(krb_ticket_string, val, sizeof(krb_ticket_string) - 1);
krb_ticket_string[sizeof(krb_ticket_string) - 1] = '\0';
- UNLOCK_GLOBAL_MUTEX return;
+ UNLOCK_GLOBAL_MUTEX;
+ return;
}
/*
static afs_uint32
curpag()
{
+#if defined(AFS_AIX51_ENV)
+ afs_int32 pag;
+
+ if (get_pag(PAG_AFS, &pag) < 0 || pag == 0)
+ pag = NOPAG;
+ return pag;
+#else
gid_t groups[NGROUPS_MAX];
afs_uint32 g0, g1;
afs_uint32 h, l, ret;
return -1;
}
return -1;
+#endif
}
int numenv;
char **newenv, **senv, **denv;
- LOCK_GLOBAL_MUTEX if (stat("/ticket", &sbuf) == -1) {
+ LOCK_GLOBAL_MUTEX;
+ if (stat("/ticket", &sbuf) == -1) {
prefix = "/tmp/tkt";
}
strcat(*denv, fname);
*++denv = 0;
environ = newenv;
-UNLOCK_GLOBAL_MUTEX}
+ UNLOCK_GLOBAL_MUTEX;
+}
/*
* BLETCH! We have to invoke the entire afsconf package just to