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 * Implementation of the AFS system operations exported by the
16 * --------------------- Required definitions ---------------------
18 #include <afsconfig.h>
19 #include <afs/param.h>
24 #include "uss_fs.h" /*Interface to this module */
25 #include <sys/types.h>
27 #include <sys/socket.h>
29 #include <sys/ioccom.h>
31 #include <netinet/in.h>
41 #include <afs/venus.h>
42 #include "uss_common.h"
46 * ---------------------- Private definitions ---------------------
52 * ------------------------ Private globals -----------------------
54 static struct ViceIoctl blob; /*Param-passing area */
55 static struct ViceIoctl *blobP = &blob; /*Ptr to above */
58 /*------------------------------------------------------------------------
62 * Is the given pathname in AFS?
65 * a_path : Pathname to examine.
68 * 0 if the pathname is NOT in AFS,
72 * Nothing interesting.
76 *------------------------------------------------------------------------*/
80 register char *a_path;
84 static char rn[] = "uss_fs:InAFS";
85 register afs_int32 code;
89 blob.out_size = USS_FS_MAX_SIZE;
90 blob.out = uss_fs_OutBuff;
92 code = pioctl(a_path, VIOC_FILE_CELL_NAME, blobP, 1);
94 if ((errno == EINVAL) || (errno == ENOENT))
102 /*------------------------------------------------------------------------
103 * static ParentAndComponent
106 * Calculate the parent directory of the given pathname, along
107 * with the final component.
110 * char *a_path : Pathname to ancestorize.
111 * char *a_parentBuff : Ptr to parent buffer to use.
112 * char **a_componentPP : Ptr to the final component.
116 * Ptr to the buffer containing the parent dir name.
119 * Nothing interesting.
123 *------------------------------------------------------------------------*/
126 ParentAndComponent(a_path, a_parentBuff, a_componentPP)
129 char **a_componentPP;
131 { /*ParentAndComponent */
133 static char rn[] = "uss_fs:Parent";
137 * Copy over the original pathname, then find the location of the
138 * rightmost slash. If there is one, we chop off the string at
139 * point. Otherwise, it is a single pathname component whose
140 * parent must be the current working directory. In this case,
141 * we cheat and return ``.''.
143 strcpy(a_parentBuff, a_path);
144 rightSlashP = (char *)strrchr(a_parentBuff, '/');
147 *a_componentPP = rightSlashP + 1;
149 strcpy(a_parentBuff, ".");
150 *a_componentPP = a_path;
153 return (a_parentBuff);
155 } /*ParentAndComponent */
158 /*------------------------------------------------------------------------
159 * static CarefulPioctl
162 * Execute a pioctl(), but be careful to refresh the Cache Manager's
163 * volume mapping in case we get an ENODEV the first time.
166 * char *a_path : pioctl() pathname argument.
167 * int a_opcode : pioctl() opcode.
168 * struct ViceIoctl *a_blobP : pioctl() blob pointer.
169 * int a_sl : pioctl() symlink info.
172 * Whatever the pioctl() returned, either the after the first
173 * call if we didn't get an ENODEV, or the results of the second
177 * Nothing interesting.
181 *------------------------------------------------------------------------*/
184 CarefulPioctl(a_path, a_opcode, a_blobP, a_sl)
187 struct ViceIoctl *a_blobP;
192 static char rn[] = "uss_fs:CarefulPioctl";
193 register afs_int32 code;
196 * Call the pioctl() the first time, return if things worked
200 printf("%s: First pioctl call\n", rn);
201 #endif /* USS_FS_DB */
202 code = pioctl(a_path, a_opcode, a_blobP, a_sl);
205 printf("%s: First pioctl call fails, errno is %d\n", rn, errno);
206 #endif /* USS_FS_DB */
207 if ((code == 0) || (code && (errno != ENODEV)))
211 * Hmm, it's possible out volume mappings are stale. Let's
212 * bring them up to date, then try again.
215 printf("%s: First pioctl got a NODEV\n", rn);
216 #endif /* USS_FS_DB */
217 code = uss_fs_CkBackups();
218 code = pioctl(a_path, a_opcode, a_blobP, a_sl);
224 /*------------------------------------------------------------------------
225 * EXPORTED uss_fs_GetACL
228 * Nothing interesting.
232 *------------------------------------------------------------------------*/
235 uss_fs_GetACL(a_dirPath, a_aclBuff, a_aclBuffBytes)
238 afs_int32 a_aclBuffBytes;
242 static char rn[] = "uss_fs_GetACL"; /*Routine name */
243 register afs_int32 code; /*pioctl() result */
247 blob.out = a_aclBuff;
248 blob.out_size = a_aclBuffBytes;
251 printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in,
252 blob.in_size, blob.out, blob.out_size);
253 #endif /* USS_FS_DB */
255 code = CarefulPioctl(a_dirPath, VIOCGETAL, blobP, 1);
259 printf("%s: pioctl() failed, errno %d\n", rn, errno);
260 #endif /* USS_FS_DB */
267 /*------------------------------------------------------------------------
268 * EXPORTED uss_fs_SetACL
271 * Nothing interesting.
275 *------------------------------------------------------------------------*/
278 uss_fs_SetACL(a_dirPath, a_aclBuff, a_aclBuffBytes)
281 afs_int32 a_aclBuffBytes;
285 static char rn[] = "uss_fs_SetACL"; /*Routine name */
286 register afs_int32 code; /*pioctl() result */
289 blob.in_size = a_aclBuffBytes;
294 printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in,
295 blob.in_size, blob.out, blob.out_size);
296 printf("%s: ACL value for dir '%s' is '%s'\n", rn, a_dirPath, a_aclBuff);
297 #endif /* USS_FS_DB */
299 code = CarefulPioctl(a_dirPath, VIOCSETAL, blobP, 1);
303 printf("%s: pioctl() failed, errno %d", rn, errno);
304 #endif /* USS_FS_DB */
311 /*------------------------------------------------------------------------
312 * EXPORTED uss_fs_GetVolStat
315 * Nothing interesting.
319 *------------------------------------------------------------------------*/
322 uss_fs_GetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes)
325 afs_int32 a_volStatBuffBytes;
327 { /*uss_fs_GetVolStat */
329 static char rn[] = "uss_fs_GetVolStat"; /*Routine name */
330 register afs_int32 code; /*pioctl() result */
334 blob.out = a_volStatBuff;
335 blob.out_size = a_volStatBuffBytes;
338 printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in,
339 blob.in_size, blob.out, blob.out_size);
340 #endif /* USS_FS_DB */
342 code = CarefulPioctl(a_mountpoint, VIOCGETVOLSTAT, blobP, 1);
346 printf("%s: pioctl() failed, errno %d", rn, errno);
347 #endif /* USS_FS_DB */
351 } /*uss_fs_GetVolStat */
354 /*------------------------------------------------------------------------
355 * EXPORTED uss_fs_SetVolStat
358 * Nothing interesting.
362 *------------------------------------------------------------------------*/
365 uss_fs_SetVolStat(a_mountpoint, a_volStatBuff, a_volStatBuffBytes)
368 afs_int32 a_volStatBuffBytes;
370 { /*uss_fs_SetVolStat */
372 static char rn[] = "uss_fs_SetVolStat"; /*Routine name */
373 register afs_int32 code; /*pioctl() result */
375 blob.in = a_volStatBuff;
376 blob.in_size = a_volStatBuffBytes;
377 blob.out = a_volStatBuff;
378 blob.out_size = USS_FS_MAX_SIZE;
381 printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in,
382 blob.in_size, blob.out, blob.out_size);
383 #endif /* USS_FS_DB */
385 code = CarefulPioctl(a_mountpoint, VIOCSETVOLSTAT, blobP, 1);
389 printf("%s: pioctl() failed, errno %d", rn, errno);
390 #endif /* USS_FS_DB */
394 } /*uss_fs_SetVolStat */
397 /*------------------------------------------------------------------------
398 * EXPORTED uss_fs_CkBackups
401 * We are NOT careful here, since it's OK to get ENODEVs.
405 *------------------------------------------------------------------------*/
409 { /*uss_fs_CkBackups */
411 static char rn[] = "uss_fs_CkBackups"; /*Routine name */
412 register afs_int32 code; /*pioctl() result */
420 printf("%s: in 0x%x (%d bytes), out 0x%x, (%d bytes)\n", rn, blob.in,
421 blob.in_size, blob.out, blob.out_size);
422 #endif /* USS_FS_DB */
424 code = pioctl(NULL, /*No pathname needed here */
425 VIOCCKBACK, /*CheckBackups */
427 1); /*Symlink disposition */
430 printf("%s: pioctl() failed, errno %d", rn, errno);
431 #endif /* USS_FS_DB */
435 } /*uss_fs_CkBackups */
438 /*------------------------------------------------------------------------
439 * EXPORTED uss_fs_MkMountPoint
442 * Uses uss_fs_OutBuff to construct the mountpoint contents.
446 *------------------------------------------------------------------------*/
449 uss_fs_MkMountPoint(a_volname, a_cellname, a_rw, a_mountpoint)
455 { /*uss_fs_MkMountPoint */
456 extern int local_Cell;
457 static char rn[] = "uss_fs_MkMountPoint"; /*Routine name */
458 register afs_int32 code; /*pioctl() result */
459 char *tp; /*Temporary */
463 ("%s: a_volname='%s', a_cellname='%s', a_rw=%d, a_mountpoint='%s'\n",
464 rn, a_volname, a_cellname, a_rw, a_mountpoint);
465 #endif /* USS_FS_DB */
468 * Make sure the parent directory is in AFS.
470 if (!InAFS(ParentAndComponent(a_mountpoint, uss_fs_OutBuff, &tp))) {
471 printf("%s: Mountpoints must be created within AFS\n", rn);
476 * Build the contents of the mountpoint we'll create. It's safe to
477 * use the uss_fs_OutBuff for this construction. Note: the last
478 * char, by convention, is a dot.
481 sprintf(uss_fs_OutBuff, "%s%s.", (a_rw ? "%" : "#"), a_volname);
483 sprintf(uss_fs_OutBuff, "%s%s:%s.", (a_rw ? "%" : "#"), a_cellname,
488 * Now, create the symlink with the above value.
490 code = symlink(uss_fs_OutBuff, a_mountpoint);
493 printf("%s: Mountpoint creation (symlink) failed, errno is %d\n", rn,
495 #endif /* USS_FS_DB */
499 } /*uss_fs_MkMountPoint */
502 /*------------------------------------------------------------------------
503 * EXPORTED uss_fs_RmMountPoint
506 * Nothing interesting.
510 *------------------------------------------------------------------------*/
513 uss_fs_RmMountPoint(a_mountpoint)
516 { /*uss_fs_RmMountPoint */
518 static char rn[] = "uss_fs_RmMountPoint"; /*Routine name */
519 register afs_int32 code; /*pioctl() result */
520 char *parentDirP; /*Ptr to parent */
521 char *componentP; /*Ptr to last component */
524 * Get the parent & final component names.
526 parentDirP = ParentAndComponent(a_mountpoint, uss_fs_InBuff, &componentP);
528 blob.in = componentP;
529 blob.in_size = strlen(componentP) + 1;
530 blob.out = uss_fs_OutBuff;
531 blob.out_size = USS_FS_MAX_SIZE;
534 printf("%s: AFS_STAT_MT_PT, in 0x%x (%d bytes), out 0x%x, (%d bytes)\n",
535 rn, blob.in, blob.in_size, blob.out, blob.out_size);
536 #endif /* USS_FS_DB */
538 code = CarefulPioctl(parentDirP, VIOC_AFS_STAT_MT_PT, blobP, 1);
541 printf("%s: STAT_MT_PT pioctl() failed, errno %d", rn, errno);
542 #endif /* USS_FS_DB */
544 printf("%s: '%s' is not a mountpoint\n", rn, a_mountpoint);
549 * Now that we know we have a proper mountpoint, nuke it.
551 blob.in = componentP;
552 blob.in_size = strlen(componentP) + 1;
559 ("%s: AFS_DELETE_MT_PT, in 0x%x (%d bytes), out 0x%x, (%d bytes)\n",
560 rn, blob.in, blob.in_size, blob.out, blob.out_size);
561 #endif /* USS_FS_DB */
563 code = pioctl(parentDirP, VIOC_AFS_DELETE_MT_PT, blobP, 1);
566 printf("%s: DELETE_MT_PT pioctl() failed, errno %d", rn, errno);
567 #endif /* USS_FS_DB */
570 printf("\t[Dry run - mount point '%s' NOT removed]\n", componentP);
574 } /*uss_fs_RmMountPoint */
577 #include <afs/auth.h>
579 struct ktc_token token;
580 struct ktc_principal service;
581 struct ktc_principal client;
586 * Build a list of tokens, delete the bad ones (the ones to remove from the
587 * permissions list,) destroy all tokens, and then re-register the good ones.
588 * Ugly, but it works.
590 uss_fs_UnlogToken(celln)
593 unsigned count = 0, index, index2;
594 afs_int32 code = 0, cnt = 0;
595 struct ktc_principal serviceName;
596 struct tokenInfo *tokenInfoP, *tp;
599 code = ktc_ListTokens(count, &count, &serviceName);
604 (struct tokenInfo *)malloc((sizeof(struct tokenInfo) * count));
605 for (code = index = index2 = 0; (!code) && (index < count); index++) {
606 tp = tokenInfoP + index;
607 code = ktc_ListTokens(index2, &index2, &tp->service);
610 ktc_GetToken(&tp->service, &tp->token,
611 sizeof(struct ktc_token), &tp->client);
613 tp->deleted = (!strcmp(celln, tp->client.cell) ? 1 : 0);
619 if (code = ktc_ForgetAllTokens()) {
620 printf("uss_fs_UnlogToken: could not discard tickets, code %d\n",
624 for (code = index = 0; index < count; index++) {
625 tp = tokenInfoP + index;
626 if (!(tp->deleted)) {
627 code = ktc_SetToken(&tp->service, &tp->token, &tp->client, 0);
630 ("uss_fs_UnlogToken: Couldn't re-register token, code = %d\n",