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 /* Returns the AFS pag number, if any, otherwise return -1 */
102 assert(sizeof(afs_uint32
) == 4);
103 assert(sizeof(afs_int32
) == 4);
106 if (pag
== 0 || pag
== -1)
109 /* high order byte is always 'A'; actual pag value is low 24 bits */
110 return (pag
& 0xFFFFFF);
114 * Write out the formatted string to the error log if the specified level
115 * is greater than or equal to the global afsDebugLevel which is set by
116 * the directive SetAFSDebugLevel in the httpd.conf file
120 afsLogError(a
, b
, c
, d
, e
, f
, g
, h
, i
, j
, k
, l
, m
, n
)
138 sprintf(reason
, a
, b
, c
, d
, e
, f
, g
, h
, i
, j
, k
, l
, m
, n
);
139 /* LOG_REASON(reason,r->uri,r); */
140 strcat(reason
, "\n");
141 fprintf(stderr
, reason
);
145 /* the following are debug utilities */
148 hexDump(char *tbuffer
, int len
)
152 char *temp
= tbuffer
;
154 fprintf(stderr
, "HEXDUMP:\n");
155 for (i
= 0; i
< len
; i
++) {
158 fprintf(stderr
, "%x", byte
);
160 fprintf(stderr
, "\n");
164 * debugging utility to see if the group id changes - if SETPAG worked
165 * call this before and after the routine to dosetpag and verify results
172 gid_t grouplist
[NGROUPS_MAX
];
174 numGroups
= getgroups(NGROUPS_MAX
, &grouplist
[0]);
175 if (numGroups
== -1) {
176 perror("getgroups:");
179 for (i
= 0; i
< numGroups
; i
++) {
180 fprintf(stderr
, "grouplist[%d]=%d\n", i
, grouplist
[i
]);
186 * prints clear token fields, cell name and primary flag to stdout
190 parseToken(char *buf
)
197 afs_int32 AuthHandle
;
198 char HandShakeKey
[8];
200 afs_int32 BeginTimestamp
;
201 afs_int32 EndTimestamp
;
207 memcpy(&len
, tp
, sizeof(afs_int32
)); /* get size of secret token */
208 tp
+= (sizeof(afs_int32
) + len
); /* skip secret token */
210 memcpy(&len
, tp
, sizeof(afs_int32
)); /* get size of clear token */
211 if (len
!= sizeof(struct ClearToken
)) {
213 "weblog:parseToken: error getting length of ClearToken\n");
217 tp
+= sizeof(afs_int32
); /* skip length of cleartoken */
218 memcpy(&clearToken
, tp
, sizeof(struct ClearToken
)); /* copy cleartoken */
220 tp
+= len
; /* skip clear token itself */
222 memcpy(&len
, tp
, sizeof(afs_int32
)); /* copy the primary flag */
223 tp
+= sizeof(afs_int32
); /* skip primary flag */
225 /* tp now points to the cell name */
226 strcpy(cellName
, tp
);
228 fprintf(stderr
, "CellName:%s\n", cellName
);
229 fprintf(stderr
, "Primary Flag (Hex):%x\n", len
);
231 "ClearToken Fields:-\nAuthHandle=%d\n"
232 "ViceId=%d\nBeginTimestamp=%d\nEndTimestamp=%d\n",
233 clearToken
.AuthHandle
, clearToken
.ViceId
,
234 clearToken
.BeginTimestamp
, clearToken
.EndTimestamp
);