#define BUFSIZ 4096
#endif
-#ifdef AFS_HPUX_ENV
-#include <unistd.h>
-#endif
#if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV)
static struct flock fileWlock = { F_WRLCK, 0, 0, 0, 0, 0 };
static struct flock fileRlock = { F_RDLCK, 0, 0, 0, 0, 0 };
#ifdef AFS_DUX40_ENV
#define PIOCTL afs_pioctl
#elif defined(UKERNEL)
-#define PIOCTL(A,B,C,D) call_syscall(AFSCALL_PIOCTL,A,B,C,D)
+#define PIOCTL(A,B,C,D) (errno = (call_syscall(AFSCALL_PIOCTL,A,B,C,D)), errno?-1:0)
#else
#define PIOCTL pioctl
#endif
struct ktc_principal server;
struct ktc_principal client;
struct ktc_token token;
-} local_tokens[MAXLOCALTOKENS] = { {
-0}, {
-0}, {
-0}, {
-0}};
+} local_tokens[MAXLOCALTOKENS];
+
+static int
+GetToken(struct ktc_principal *aserver, struct ktc_token *atoken,
+ int atokenLen, struct ktc_principal *alicnet, afs_int32 *aviceid);
#define MAXPIOCTLTOKENLEN \
memset(&server, 0, sizeof(server));
strcpy(server.name, "afs");
- strcpy(server.cell, token->cell);
+ if (strlcpy(server.cell, token->cell, sizeof(server.cell))
+ >= sizeof(server.cell)) {
+ free(rxkadToken);
+ return KTC_INVAL;
+ }
code = ktc_SetToken(&server, rxkadToken, &client, flags);
free(rxkadToken);
return code;
*/
if (code == -1 && errno == EINVAL) {
struct ktc_principal server;
- struct ktc_principal client;
struct ktc_tokenUnion token;
struct ktc_token *ktcToken; /* too huge for the stack */
+ afs_int32 viceid;
memset(&server, 0, sizeof(server));
ktcToken = malloc(sizeof(struct ktc_token));
memset(ktcToken, 0, sizeof(struct ktc_token));
strcpy(server.name, "afs");
- strcpy(server.cell, cellName);
- code = ktc_GetToken(&server, ktcToken, sizeof(struct ktc_token),
- &client);
+
+ if (cellName != NULL)
+ strcpy(server.cell, cellName);
+
+ code = GetToken(&server, ktcToken, sizeof(struct ktc_token),
+ NULL /*client*/, &viceid);
if (code == 0) {
*tokenSet = token_buildTokenJar(cellName);
token.at_type = AFSTOKEN_UNION_KAD;
= ktcToken->ticketLen;
token.ktc_tokenUnion_u.at_kad.rk_ticket.rk_ticket_val
= ktcToken->ticket;
+ token.ktc_tokenUnion_u.at_kad.rk_viceid = viceid;
token_addToken(*tokenSet, &token);
ktc_GetToken(struct ktc_principal *aserver, struct ktc_token *atoken,
int atokenLen, struct ktc_principal *aclient)
{
+ return GetToken(aserver, atoken, atokenLen, aclient, NULL);
+}
+
+static int
+GetToken(struct ktc_principal *aserver, struct ktc_token *atoken,
+ int atokenLen, struct ktc_principal *aclient, afs_int32 *aviceid)
+{
struct ViceIoctl iob;
char tbuffer[MAXPIOCTLTOKENLEN];
afs_int32 code = 0;
#ifdef AFS_KERBEROS_ENV
char found = 0;
#endif
+ if (aviceid) {
+ *aviceid = 0;
+ }
LOCK_GLOBAL_MUTEX;
sizeof(struct ktc_encryptionKey));
atoken->ticketLen = tktLen;
- if (aclient) {
- strcpy(aclient->cell, cellp);
- aclient->instance[0] = 0;
+ if (aclient || aviceid) {
+ if (aclient) {
+ strlcpy(aclient->cell, cellp, sizeof(aclient->cell));
+ aclient->instance[0] = 0;
+ }
if ((atoken->kvno == 999) || /* old style bcrypt ticket */
(ct.BeginTimestamp && /* new w/ prserver lookup */
(((ct.EndTimestamp - ct.BeginTimestamp) & 1) == 1))) {
- sprintf(aclient->name, "AFS ID %d", ct.ViceId);
- } else {
+ if (aclient) {
+ sprintf(aclient->name, "AFS ID %d", ct.ViceId);
+ }
+ if (aviceid) {
+ *aviceid = ct.ViceId;
+ }
+ } else if (aclient) {
sprintf(aclient->name, "Unix UID %d", ct.ViceId);
}
}
tp += temp; /* skip clear token itself */
tp += sizeof(afs_int32); /* skip primary flag */
/* tp now points to the cell name */
- strcpy(aserver->cell, tp);
+ strlcpy(aserver->cell, tp, sizeof(aserver->cell));
aserver->instance[0] = 0;
strcpy(aserver->name, "afs");
#endif /* NO_AFS_CLIENT */
*/
#if 0
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <sys/file.h>
#include <krb.h>
#endif
for (senv = environ, numenv = 0; *senv; senv++)
numenv++;
- newenv = (char **)malloc((numenv + 2) * sizeof(char *));
+ newenv = malloc((numenv + 2) * sizeof(char *));
for (senv = environ, denv = newenv; *senv; senv++) {
if (strncmp(*senv, "KRBTKFILE=", 10) != 0 &&