Make ktc_curpag generally available
[openafs.git] / src / auth / ktc.c
index 5395d82..3c4a2ff 100644 (file)
@@ -16,8 +16,6 @@
 #include <afs/param.h>
 #endif
 
-RCSID
-    ("$Header$");
 
 #if defined(UKERNEL)
 #include "afs/sysincludes.h"
@@ -29,6 +27,7 @@ RCSID
 #include "afs/venus.h"
 #include "afs/pthread_glock.h"
 #include "afs/dirpath.h"
+#include <ctype.h>
 
 #if !defined(min)
 #define min(a,b) ((a)<(b)?(a):(b))
@@ -921,6 +920,57 @@ ktc_OldPioctl(void)
     return rc;
 }
 
+afs_uint32
+ktc_curpag(void)
+{
+    int code;
+    struct ViceIoctl iob;
+    afs_int32 pag;
+
+    /* now setup for the pioctl */
+    iob.in = NULL;
+    iob.in_size = 0;
+    iob.out = &pag;
+    iob.out_size = sizeof(afs_int32);
+
+    code = PIOCTL(0, VIOC_GETPAG, &iob, 0);
+    if (code < 0) {
+#if defined(AFS_AIX52_ENV)
+       code = getpagvalue("afs");
+       if (code < 0 && errno == EINVAL)
+           code = 0;
+       return code;
+#elif defined(AFS_AIX51_ENV)
+       return -1;
+#else
+       gid_t groups[NGROUPS_MAX];
+       afs_uint32 g0, g1;
+       afs_uint32 h, l, ret;
+
+       if (getgroups(sizeof groups / sizeof groups[0], groups) < 2)
+           return 0;
+
+       g0 = groups[0] & 0xffff;
+       g1 = groups[1] & 0xffff;
+       g0 -= 0x3f00;
+       g1 -= 0x3f00;
+       if (g0 < 0xc000 && g1 < 0xc000) {
+           l = ((g0 & 0x3fff) << 14) | (g1 & 0x3fff);
+           h = (g0 >> 14);
+           h = (g1 >> 14) + h + h + h;
+           ret = ((h << 28) | l);
+           /* Additional testing */
+           if (((ret >> 24) & 0xff) == 'A')
+               return ret;
+           else
+               return -1;
+       }
+       return -1;
+#endif
+    }
+    return pag;
+}
+
 
 #ifdef AFS_KERBEROS_ENV
  /*
@@ -1614,57 +1664,6 @@ afs_tf_dest_tkt(void)
     return 0;
 }
 
-afs_uint32
-ktc_curpag(void)
-{
-    int code;
-    struct ViceIoctl iob;
-    afs_int32 pag;
-
-    /* now setup for the pioctl */
-    iob.in = NULL;
-    iob.in_size = 0;
-    iob.out = &pag;
-    iob.out_size = sizeof(afs_int32);
-
-    code = PIOCTL(0, VIOC_GETPAG, &iob, 0);
-    if (code < 0) {
-#if defined(AFS_AIX52_ENV)
-       code = getpagvalue("afs");
-       if (code < 0 && errno == EINVAL)
-           code = 0;
-       return code;
-#elif defined(AFS_AIX51_ENV)
-       return -1;
-#else
-       gid_t groups[NGROUPS_MAX];
-       afs_uint32 g0, g1;
-       afs_uint32 h, l, ret;
-       
-       if (getgroups(sizeof groups / sizeof groups[0], groups) < 2)
-           return 0;
-       
-       g0 = groups[0] & 0xffff;
-       g1 = groups[1] & 0xffff;
-       g0 -= 0x3f00;
-       g1 -= 0x3f00;
-       if (g0 < 0xc000 && g1 < 0xc000) {
-           l = ((g0 & 0x3fff) << 14) | (g1 & 0x3fff);
-           h = (g0 >> 14);
-           h = (g1 >> 14) + h + h + h;
-           ret = ((h << 28) | l);
-           /* Additional testing */
-           if (((ret >> 24) & 0xff) == 'A')
-               return ret;
-           else
-               return -1;
-       }
-       return -1;
-#endif
-    }
-    return pag;
-}
-
 int
 ktc_newpag(void)
 {
@@ -1688,8 +1687,8 @@ ktc_newpag(void)
        sprintf(fname, "%s%d", prefix, getuid());
        sprintf(fname5, "%s%d", prefix5, getuid());
     } else {
-       sprintf(fname, "%sp%lu", prefix, afs_cast_uint32(pag));
-       sprintf(fname5, "%sp%lud", prefix5, (long unsigned int) pag);
+       sprintf(fname, "%sp%lu", prefix, afs_printable_uint32_lu(pag));
+       sprintf(fname5, "%sp%lud", prefix5, afs_printable_uint32_lu(pag));
     }
     ktc_set_tkt_string(fname);