int k_afs_cell_of_file(const char *path, char *cell, int len) { struct ViceIoctl parms; parms.in = NULL; parms.in_size = 0; parms.out = cell; parms.out_size = len; return k_pioctl(rk_UNCONST(path), VIOC_FILE_CELL_NAME, &parms, 1); }
int kafs_settoken_rxkad(const char *cell, struct ClearToken *ct, void *ticket, size_t ticket_len) { struct ViceIoctl parms; char buf[2048], *t; int32_t sizeof_x; t = buf; /* * length of secret token followed by secret token */ sizeof_x = ticket_len; memcpy(t, &sizeof_x, sizeof(sizeof_x)); t += sizeof(sizeof_x); memcpy(t, ticket, sizeof_x); t += sizeof_x; /* * length of clear token followed by clear token */ sizeof_x = sizeof(*ct); memcpy(t, &sizeof_x, sizeof(sizeof_x)); t += sizeof(sizeof_x); memcpy(t, ct, sizeof_x); t += sizeof_x; /* * do *not* mark as primary cell */ sizeof_x = 0; memcpy(t, &sizeof_x, sizeof(sizeof_x)); t += sizeof(sizeof_x); /* * follow with cell name */ sizeof_x = strlen(cell) + 1; memcpy(t, cell, sizeof_x); t += sizeof_x; /* * Build argument block */ parms.in = buf; parms.in_size = t - buf; parms.out = 0; parms.out_size = 0; return k_pioctl(0, VIOCSETTOK, &parms, 0); }
static void display_tokens(int do_verbose) { uint32_t i; unsigned char t[4096]; struct ViceIoctl parms; parms.in = (void *)&i; parms.in_size = sizeof(i); parms.out = (void *)t; parms.out_size = sizeof(t); for (i = 0;; i++) { int32_t size_secret_tok, size_public_tok; unsigned char *cell; struct ClearToken ct; unsigned char *r = t; struct timeval tv; char buf1[20], buf2[20]; if(k_pioctl(NULL, VIOCGETTOK, &parms, 0) < 0) { if(errno == EDOM) break; continue; } if(parms.out_size > sizeof(t)) continue; if(parms.out_size < sizeof(size_secret_tok)) continue; t[min(parms.out_size,sizeof(t)-1)] = 0; memcpy(&size_secret_tok, r, sizeof(size_secret_tok)); /* dont bother about the secret token */ r += size_secret_tok + sizeof(size_secret_tok); if (parms.out_size < (r - t) + sizeof(size_public_tok)) continue; memcpy(&size_public_tok, r, sizeof(size_public_tok)); r += sizeof(size_public_tok); if (parms.out_size < (r - t) + size_public_tok + sizeof(int32_t)) continue; memcpy(&ct, r, size_public_tok); r += size_public_tok; /* there is a int32_t with length of cellname, but we dont read it */ r += sizeof(int32_t); cell = r; gettimeofday (&tv, NULL); strlcpy (buf1, printable_time(ct.BeginTimestamp), sizeof(buf1)); if (do_verbose || tv.tv_sec < ct.EndTimestamp) strlcpy (buf2, printable_time(ct.EndTimestamp), sizeof(buf2)); else strlcpy (buf2, N_(">>> Expired <<<", ""), sizeof(buf2)); printf("%s %s ", buf1, buf2); if ((ct.EndTimestamp - ct.BeginTimestamp) & 1) printf(N_("User's (AFS ID %d) tokens for %s", ""), ct.ViceId, cell); else printf(N_("Tokens for %s", ""), cell); if (do_verbose) printf(" (%d)", ct.AuthHandle); putchar('\n'); } }
static void afs_setacl(char *path, char *user, char *rights) { struct Acl *acl; struct AclEntry *position; struct ViceIoctl a_params; int i; int newrights=0; int foundit=0; char *ptr; char acltext[MAXSIZE]; char tmpstr[MAXSIZE]; if((acl=afs_getacl(path))==NULL) exit(1); if(!strcmp(rights,"read")) newrights=PRSFS_READ | PRSFS_LOOKUP; else if(!strcmp(rights,"write")) newrights=PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK; else if(!strcmp(rights,"mail")) newrights=PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP; else if(!strcmp(rights,"all")) newrights=PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER; else { ptr=rights; while(*ptr!=0) { if(*ptr=='r') newrights|=PRSFS_READ; if(*ptr=='l') newrights|=PRSFS_LOOKUP; if(*ptr=='i') newrights|=PRSFS_INSERT; if(*ptr=='d') newrights|=PRSFS_DELETE; if(*ptr=='w') newrights|=PRSFS_WRITE; if(*ptr=='k') newrights|=PRSFS_LOCK; if(*ptr=='a') newrights|=PRSFS_ADMINISTER; ptr++; } } position=acl->pos; for(i=0; i<acl->NumPositiveEntries; i++) { if(!strncmp(user, position->name, 100)) { position->RightsMask=newrights; foundit=1; } if(position->next) position=position->next; } if(!foundit) { if (position) { position->next=malloc(sizeof(struct AclEntry)); position=position->next; } else { acl->pos = malloc(sizeof(struct AclEntry)); position = acl->pos; } if(position==NULL) { printf("fs: Out of memory\n"); exit(1); } acl->NumPositiveEntries++; position->next=NULL; strlcpy(position->name, user, sizeof(position->name)); position->RightsMask=newrights; } acltext[0] = 0; for(position=acl->pos; position && acl->NumPositiveEntries; position = position->next) { if (position->RightsMask) { snprintf(tmpstr, sizeof(tmpstr), "%s %d\n", position->name, position->RightsMask); strlcat(acltext, tmpstr, sizeof(acltext)); } else acl->NumPositiveEntries--; } for(position=acl->neg; position && acl->NumNegativeEntries; position = position->next) { if (position->RightsMask) { snprintf(tmpstr, sizeof(tmpstr), "%s %d\n", position->name, position->RightsMask); strlcat(acltext, tmpstr, sizeof(acltext)); } else acl->NumNegativeEntries--; } strlcpy (tmpstr, acltext, sizeof(tmpstr)); snprintf(acltext, sizeof(acltext), "%d\n%d\n%s", acl->NumPositiveEntries, acl->NumNegativeEntries, tmpstr); a_params.in_size=strlen(acltext); a_params.out_size=0; a_params.in=acltext; a_params.out=0; if(k_pioctl(path,VIOCSETAL,&a_params,1)==-1) { fserr(PROGNAME, errno, path); return; } /* XXX free(oldacl); and its contents */ }
static int lstat_file (const char *file, struct stat *sb) { #ifdef KRB4 if (do_the_afs_dance && k_hasafs() && strcmp(file, ".") && strcmp(file, "..") && strcmp(file, "/")) { struct ViceIoctl a_params; char *dir, *last; char *path_bkp; static ino_t ino_counter = 0, ino_last = 0; int ret; const int maxsize = 2048; path_bkp = strdup (file); if (path_bkp == NULL) return -1; a_params.out = malloc (maxsize); if (a_params.out == NULL) { free (path_bkp); return -1; } /* If path contains more than the filename alone - split it */ last = strrchr (path_bkp, '/'); if (last != NULL) { if(last[1] == '\0') /* if path ended in /, replace with `.' */ a_params.in = "."; else a_params.in = last + 1; while(last > path_bkp && *--last == '/'); if(*last != '/' || last != path_bkp) { *++last = '\0'; dir = path_bkp; } else /* we got to the start, so this must be the root dir */ dir = "/"; } else { /* file is relative to cdir */ dir = "."; a_params.in = path_bkp; } a_params.in_size = strlen (a_params.in) + 1; a_params.out_size = maxsize; ret = k_pioctl (dir, VIOC_AFS_STAT_MT_PT, &a_params, 0); free (a_params.out); if (ret < 0) { free (path_bkp); if (errno != EINVAL) return ret; else /* if we get EINVAL this is probably not a mountpoint */ return lstat (file, sb); } /* * wow this was a mountpoint, lets cook the struct stat * use . as a prototype */ ret = lstat (dir, sb); free (path_bkp); if (ret < 0) return ret; if (ino_last == sb->st_ino) ino_counter++; else { ino_last = sb->st_ino; ino_counter = 0; } sb->st_ino += ino_counter; sb->st_nlink = 3; return 0; } #endif /* KRB4 */ return lstat (file, sb); }