2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * This file contains routines common to both the client and the server-
12 * primarily an interface routine to the pioctl call
13 * and a routine for setting the primary flag in the token structure in
14 * order to create a new PAG while doing the SET TOKEN. In addition there are
15 * debugging routines of interest to both the client and server processes
18 #include "apache_afs_utils.h"
19 #include "apache_afs_utils.h"
22 * do_pioctl does the actual call to pioctl (or equivalent for that platform)
23 * sets up the ViceIoctl buffer with all the parameters required
24 * NOTE: in_buffer and out_buffer may point to the same memory buffer
27 do_pioctl(char *in_buffer, int in_size, char *out_buffer, int out_size,
28 int opcode, char *path, int followSymLinks)
32 iob.in_size = in_size;
34 iob.out_size = out_size;
36 #ifdef AFS_USR_SUN5_ENV
37 return syscall(AFS_SYSCALL, AFSCALL_PIOCTL, path, _VICEIOCTL(opcode),
38 &iob, followSymLinks);
39 #else /* AFS_USR_SUN5_ENV */
40 return lpioctl(path, _VICEIOCTL(opcode), &iob, followSymLinks);
41 #endif /* AFS_USR_SUN5_ENV */
51 * Return 1 if we have a token, 0 if we don't
60 memcpy((void *)temp, (void *)&i, sizeof(afs_int32));
62 do_pioctl(temp, sizeof(afs_int32), temp, sizeof(temp), VIOCGETTOK,
72 * flipPrimary sets the primary cell longword -
73 * enabling a SETPAG if the same buffer is used with VICESETTOK
75 flipPrimary(char *tokenBuf)
78 char *temp = tokenBuf;
80 /* skip over the secret token */
81 memcpy(&i, temp, sizeof(afs_int32));
82 temp += (i + sizeof(afs_int32));
84 /* skip over the clear token */
85 memcpy(&i, temp, sizeof(afs_int32));
86 temp += (i + sizeof(afs_int32));
88 /* set the primary flag */
89 memcpy(&i, temp, sizeof(afs_int32));
91 memcpy(temp, &i, sizeof(afs_int32));
92 temp += sizeof(afs_int32);
96 /* get the current AFS pag for the calling process */
102 afs_uint32 h, l, ret;
104 if (getgroups(sizeof groups / sizeof groups[0], groups) < 2)
107 g0 = groups[0] & 0xffff;
108 g1 = groups[1] & 0xffff;
111 if (g0 < 0xc000 && g1 < 0xc000) {
112 l = ((g0 & 0x3fff) << 14) | (g1 & 0x3fff);
114 h = (g1 >> 14) + h + h + h;
115 ret = ((h << 28) | l);
116 /* Additional testing */
117 if (((ret >> 24) & 0xff) == 'A')
125 /* Returns the AFS pag number, if any, otherwise return -1 */
131 assert(sizeof(afs_uint32) == 4);
132 assert(sizeof(afs_int32) == 4);
135 if (pag == 0 || pag == -1)
138 /* high order byte is always 'A'; actual pag value is low 24 bits */
139 return (pag & 0xFFFFFF);
143 * Write out the formatted string to the error log if the specified level
144 * is greater than or equal to the global afsDebugLevel which is set by
145 * the directive SetAFSDebugLevel in the httpd.conf file
149 afsLogError(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
167 sprintf(reason, a, b, c, d, e, f, g, h, i, j, k, l, m, n);
168 /* LOG_REASON(reason,r->uri,r); */
169 strcat(reason, "\n");
170 fprintf(stderr, reason);
174 /* the following are debug utilities */
177 hexDump(char *tbuffer, int len)
181 char *temp = tbuffer;
183 fprintf(stderr, "HEXDUMP:\n");
184 for (i = 0; i < len; i++) {
187 fprintf(stderr, "%x", byte);
189 fprintf(stderr, "\n");
193 * debugging utility to see if the group id changes - if SETPAG worked
194 * call this before and after the routine to dosetpag and verify results
201 gid_t grouplist[NGROUPS_MAX];
203 numGroups = getgroups(NGROUPS_MAX, &grouplist[0]);
204 if (numGroups == -1) {
205 perror("getgroups:");
208 for (i = 0; i < numGroups; i++) {
209 fprintf(stderr, "grouplist[%d]=%d\n", i, grouplist[i]);
215 * prints clear token fields, cell name and primary flag to stdout
219 parseToken(char *buf)
226 afs_int32 AuthHandle;
227 char HandShakeKey[8];
229 afs_int32 BeginTimestamp;
230 afs_int32 EndTimestamp;
236 memcpy(&len, tp, sizeof(afs_int32)); /* get size of secret token */
237 tp += (sizeof(afs_int32) + len); /* skip secret token */
239 memcpy(&len, tp, sizeof(afs_int32)); /* get size of clear token */
240 if (len != sizeof(struct ClearToken)) {
242 "weblog:parseToken: error getting length of ClearToken\n");
246 tp += sizeof(afs_int32); /* skip length of cleartoken */
247 memcpy(&clearToken, tp, sizeof(struct ClearToken)); /* copy cleartoken */
249 tp += len; /* skip clear token itself */
251 memcpy(&len, tp, sizeof(afs_int32)); /* copy the primary flag */
252 tp += sizeof(afs_int32); /* skip primary flag */
254 /* tp now points to the cell name */
255 strcpy(cellName, tp);
257 fprintf(stderr, "CellName:%s\n", cellName);
258 fprintf(stderr, "Primary Flag (Hex):%x\n", len);
260 "ClearToken Fields:-\nAuthHandle=%d\n"
261 "ViceId=%d\nBeginTimestamp=%d\nEndTimestamp=%d\n",
262 clearToken.AuthHandle, clearToken.ViceId,
263 clearToken.BeginTimestamp, clearToken.EndTimestamp);