aix51-pag-header-20090320
[openafs.git] / src / auth / ktc.c
index 805ef25..165e3fc 100644 (file)
@@ -40,6 +40,7 @@ RCSID
 #include <unistd.h>
 #endif
 #include <stdio.h>
+#include <stdlib.h>
 #include <afs/stds.h>
 #include <afs/pthread_glock.h>
 #include <sys/types.h>
@@ -49,18 +50,15 @@ RCSID
 #include <errno.h>
 #include <sys/ioctl.h>
 #include <netinet/in.h>
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <afs/vice.h>
 #ifdef AFS_AIX_ENV
 #include <sys/lockf.h>
 #ifdef AFS_AIX51_ENV
 #include <sys/cred.h>
+#ifdef HAVE_SYS_PAG_H
+#include <sys/pag.h>
+#endif
 #endif
 #endif
 #ifdef HAVE_UNISTD_H
@@ -69,6 +67,7 @@ RCSID
 #include "auth.h"
 #include <afs/venus.h>
 #include <afs/afsutil.h>
+#include <afs/sys_prototypes.h>
 
 #endif /* defined(UKERNEL) */
 
@@ -131,10 +130,16 @@ static struct flock fileUlock = { F_UNLCK, 0, 0, 0, 0 };
 /* the following routines aren't static anymore on behalf of the kerberos IV
  * compatibility library built in subtree krb.
  */
-int afs_tf_init(), afs_tf_get_pname(), afs_tf_get_pinst(), afs_tf_get_cred();
-int afs_tf_save_cred(), afs_tf_close(), afs_tf_create();
-int afs_tf_dest_tkt();
-static void ktc_LocalCell();
+int afs_tf_init(char *, int);
+int afs_tf_get_pname(char *);
+int afs_tf_get_pinst(char *);
+int afs_tf_get_cred(struct ktc_principal *, struct ktc_token *);
+int afs_tf_save_cred(struct ktc_principal *, struct ktc_token *, 
+                    struct ktc_principal *);
+int afs_tf_close(void);
+int afs_tf_create(char *, char *);
+int afs_tf_dest_tkt(void);
+static void ktc_LocalCell(void);
 #endif /* AFS_KERBEROS_ENV */
 
 #ifdef AFS_DUX40_ENV
@@ -254,11 +259,10 @@ static struct {
  * now. */
 
 static int
-NewSetToken(aserver, atoken, aclient, flags)
-     struct ktc_principal *aserver;
-     struct ktc_principal *aclient;
-     struct ktc_token *atoken;
-     afs_int32 flags;
+NewSetToken(struct ktc_principal *aserver, 
+           struct ktc_token *atoken, 
+           struct ktc_principal *aclient, 
+            afs_int32 flags)
 {
     TRY_KERNEL(KTC_SETTOKEN_OP, aserver, aclient, atoken,
               sizeof(struct ktc_token));
@@ -270,10 +274,8 @@ NewSetToken(aserver, atoken, aclient, flags)
 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
 
 static int
-OldSetToken(aserver, atoken, aclient, flags)
-     struct ktc_principal *aserver, *aclient;
-     struct ktc_token *atoken;
-     afs_int32 flags;
+OldSetToken(struct ktc_principal *aserver, struct ktc_token *atoken, 
+           struct ktc_principal *aclient, afs_int32 flags)
 {
     struct ViceIoctl iob;
     char tbuffer[MAXPIOCTLTOKENLEN];
@@ -489,14 +491,13 @@ ktc_SetToken(struct ktc_principal *aserver,
 /* get token, given server we need and token buffer.  aclient will eventually
  * be set to our identity to the server.
  */
-ktc_GetToken(aserver, atoken, atokenLen, aclient)
-     struct ktc_principal *aserver, *aclient;
-     int atokenLen;
-     struct ktc_token *atoken;
+int
+ktc_GetToken(struct ktc_principal *aserver, struct ktc_token *atoken, 
+            int atokenLen, struct ktc_principal *aclient)
 {
     struct ViceIoctl iob;
     char tbuffer[MAXPIOCTLTOKENLEN];
-    register afs_int32 code;
+    register afs_int32 code = 0;
     int index;
     char *stp, *cellp;         /* secret token ptr */
     struct ClearToken ct;
@@ -504,7 +505,9 @@ ktc_GetToken(aserver, atoken, atokenLen, aclient)
     afs_int32 temp;
     int maxLen;                        /* biggest ticket we can copy */
     int tktLen;                        /* server ticket length */
+#ifdef AFS_KERBEROS_ENV
     char found = 0;
+#endif
 
     LOCK_GLOBAL_MUTEX;
 #ifndef NO_AFS_CLIENT
@@ -542,8 +545,8 @@ ktc_GetToken(aserver, atoken, atokenLen, aclient)
                    found = 1;
            } else {
                char tmpstring[MAXHOSTCHARS];
-               afs_tf_get_pname(&tmpstring);
-               afs_tf_get_pinst(&tmpstring);
+               afs_tf_get_pname(tmpstring);
+               afs_tf_get_pinst(tmpstring);
                found = 1;
            }
        }
@@ -673,8 +676,8 @@ ktc_GetToken(aserver, atoken, atokenLen, aclient)
  * NOT IMPLEMENTED YET!
  */
 #ifndef NO_AFS_CLIENT
-ktc_ForgetToken(aserver)
-     struct ktc_principal *aserver;
+int
+ktc_ForgetToken(struct ktc_principal *aserver)
 {
     int rc;
 
@@ -698,7 +701,7 @@ ktc_ListTokens(int aprevIndex,
 {
     struct ViceIoctl iob;
     char tbuffer[MAXPIOCTLTOKENLEN];
-    register afs_int32 code;
+    register afs_int32 code = 0 ;
     register char *tp;
     afs_int32 temp, index;
 
@@ -903,7 +906,8 @@ ktc_ForgetAllTokens(void)
 /* ktc_OldPioctl - returns a boolean true if the kernel supports only the old
  * pioctl interface for delivering AFS tickets to the cache manager. */
 
-ktc_OldPioctl()
+int
+ktc_OldPioctl(void)
 {
     int rc;
     LOCK_GLOBAL_MUTEX;
@@ -953,12 +957,13 @@ ktc_OldPioctl()
  *     c. In tf_close, be sure it gets reinitialized to a negative
  *        number. 
  */
-static fd = -1;
-static curpos;                 /* Position in tfbfr */
-static lastpos;                        /* End of tfbfr */
+static int fd = -1;
+static int curpos;                     /* Position in tfbfr */
+static int lastpos;                    /* End of tfbfr */
 static char tfbfr[BUFSIZ];     /* Buffer for ticket data */
 
-static tf_gets(), tf_read();
+static int tf_gets(char *, int);
+static int tf_read(char *, int);
 
 /*
  * This file contains routines for manipulating the ticket cache file.
@@ -1023,8 +1028,8 @@ static tf_gets(), tf_read();
  * TKT_FIL_LCK  - couldn't lock the file, even after a retry
  */
 
-afs_tf_init(tf_name, rw)
-     char *tf_name;
+int
+afs_tf_init(char *tf_name, int rw)
 {
     int wflag;
     int me;
@@ -1117,8 +1122,8 @@ afs_tf_init(tf_name, rw)
  * was longer than MAXKTCNAMELEN, TKT_FIL_FMT is returned. 
  */
 
-afs_tf_get_pname(p)
-     char *p;
+int
+afs_tf_get_pname(char *p)
 {
     if (fd < 0) {
        return TKT_FIL_INI;
@@ -1138,8 +1143,8 @@ afs_tf_get_pname(p)
  * instance may be null. 
  */
 
-afs_tf_get_pinst(inst)
-     char *inst;
+int
+afs_tf_get_pinst(char *inst)
 {
     if (fd < 0) {
        return TKT_FIL_INI;
@@ -1160,9 +1165,8 @@ afs_tf_get_pinst(inst)
  * EOF          - end of file encountered
  */
 
-afs_tf_get_cred(principal, token)
-     struct ktc_principal *principal;
-     struct ktc_token *token;
+int
+afs_tf_get_cred(struct ktc_principal *principal, struct ktc_token *token)
 {
     int k_errno;
     int kvno, lifetime;
@@ -1220,7 +1224,8 @@ afs_tf_get_cred(principal, token)
  * The return value is not defined.
  */
 
-afs_tf_close()
+int
+afs_tf_close(void)
 {
     if (!(fd < 0)) {
 #if defined(AFS_AIX_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_SUN5_ENV)
@@ -1232,6 +1237,7 @@ afs_tf_close()
        fd = -1;                /* see declaration of fd above */
     }
     memset(tfbfr, 0, sizeof(tfbfr));
+    return 0;
 }
 
 /*
@@ -1252,11 +1258,10 @@ afs_tf_close()
  *             file is seriously ill.
  */
 
-static
-tf_gets(s, n)
-     register char *s;
+static int
+tf_gets(register char *s, int n)
 {
-    register count;
+    register int count;
 
     if (fd < 0) {
        return TKT_FIL_INI;
@@ -1288,12 +1293,10 @@ tf_gets(s, n)
  * 0           on end of file or read error
  */
 
-static
-tf_read(s, n)
-     register char *s;
-     register n;
+static int
+tf_read(register char *s, register int n)
 {
-    register count;
+    register int count;
 
     for (count = n; count > 0; --count) {
        if (curpos >= sizeof(tfbfr)) {
@@ -1308,8 +1311,6 @@ tf_read(s, n)
     return n;
 }
 
-char *tkt_string();
-
 /*
  * afs_tf_save_cred() appends an incoming ticket to the end of the ticket
  * file.  You must call afs_tf_init() before calling afs_tf_save_cred().
@@ -1321,10 +1322,10 @@ char *tkt_string();
  * called previously, and KFAILURE for anything else that went wrong.
  */
 
-afs_tf_save_cred(aserver, atoken, aclient)
-     struct ktc_principal *aserver;
-     struct ktc_principal *aclient;
-     struct ktc_token *atoken; /* Token */
+int
+afs_tf_save_cred(struct ktc_principal *aserver, 
+                struct ktc_token *atoken, 
+                struct ktc_principal *aclient)
 {
     char realm[MAXKTCREALMLEN + 1];
     char junk[MAXKTCNAMELEN];
@@ -1423,8 +1424,6 @@ afs_tf_save_cred(aserver, atoken, aclient)
  * <mit-copyright.h>.
  */
 
-char *getenv();
-
 /*
  * This routine is used to generate the name of the file that holds
  * the user's cache of server tickets and associated session keys.
@@ -1454,7 +1453,7 @@ ktc_tkt_string_uid(afs_uint32 uid)
 
     LOCK_GLOBAL_MUTEX;
     if (!*krb_ticket_string) {
-       if (env = getenv("KRBTKFILE")) {
+       if ((env = getenv("KRBTKFILE"))) {
            (void)strncpy(krb_ticket_string, env,
                          sizeof(krb_ticket_string) - 1);
            krb_ticket_string[sizeof(krb_ticket_string) - 1] = '\0';
@@ -1497,9 +1496,8 @@ ktc_set_tkt_string(char * val)
  * success, or KFAILURE if something goes wrong.
  */
 
-afs_tf_create(pname, pinst)
-     char *pname;
-     char *pinst;
+int
+afs_tf_create(char *pname, char *pinst)
 {
     int tktfile;
     int me, metoo;
@@ -1576,7 +1574,8 @@ afs_tf_create(pname, pinst)
  * failure.
  */
 
-afs_tf_dest_tkt()
+int
+afs_tf_dest_tkt(void)
 {
     char *file = ktc_tkt_string();
     int i, fd;
@@ -1616,14 +1615,13 @@ afs_tf_dest_tkt()
 }
 
 static afs_uint32
-curpag()
+curpag(void)
 {
 #if defined(AFS_AIX51_ENV)
-    afs_int32 pag;
-
-    if (get_pag(PAG_AFS, &pag) < 0 || pag == 0)
-        pag = NOPAG;
-    return pag;
+    int code = getpagvalue("afs");
+    if (code < 0 && errno == EINVAL)
+       code = 0;
+    return code;
 #else
     gid_t groups[NGROUPS_MAX];
     afs_uint32 g0, g1;
@@ -1651,8 +1649,8 @@ curpag()
 #endif
 }
 
-
-ktc_newpag()
+int
+ktc_newpag(void)
 {
     extern char **environ;
 
@@ -1671,7 +1669,7 @@ ktc_newpag()
     if (pag == -1) {
        sprintf(fname, "%s%d", prefix, getuid());
     } else {
-       sprintf(fname, "%sp%ld", prefix, pag);
+       sprintf(fname, "%sp%lu", prefix, afs_cast_uint32(pag));
     }
     ktc_set_tkt_string(fname);
 
@@ -1679,7 +1677,7 @@ ktc_newpag()
        numenv++;
     newenv = (char **)malloc((numenv + 2) * sizeof(char *));
 
-    for (senv = environ, denv = newenv; *senv; *senv++) {
+    for (senv = environ, denv = newenv; *senv; senv++) {
        if (strncmp(*senv, "KRBTKFILE=", 10) != 0)
            *denv++ = *senv;
     }
@@ -1690,6 +1688,7 @@ ktc_newpag()
     *++denv = 0;
     environ = newenv;
     UNLOCK_GLOBAL_MUTEX;
+    return 0;
 }
 
 /*
@@ -1697,7 +1696,7 @@ ktc_newpag()
  * find out what the local cell is.
  */
 static void
-ktc_LocalCell()
+ktc_LocalCell(void)
 {
     int code;
     struct afsconf_dir *conf;