| File: | venus/fs.c |
| Location: | line 3834, column 5 |
| Description: | Value stored to 'ts' is never read |
| 1 | /* |
| 2 | * Copyright 2000, International Business Machines Corporation and others. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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 |
| 8 | */ |
| 9 | |
| 10 | #include <afsconfig.h> |
| 11 | #include <afs/param.h> |
| 12 | #include <afs/stds.h> |
| 13 | |
| 14 | #include <roken.h> |
| 15 | |
| 16 | #include <ctype.h> |
| 17 | |
| 18 | #include <afs/afs_consts.h> |
| 19 | #include <afs/afs_args.h> |
| 20 | #include <rx/xdr.h> |
| 21 | #include <afs/vice.h> |
| 22 | #include <afs/venus.h> |
| 23 | #include <afs/com_err.h> |
| 24 | #include <afs/afs_consts.h> |
| 25 | |
| 26 | #undef VIRTUE |
| 27 | #undef VICE |
| 28 | #include "afs/prs_fs.h" |
| 29 | #include <afs/afsint.h> |
| 30 | #include <afs/cellconfig.h> |
| 31 | #include <ubik.h> |
| 32 | #include <rx/rxkad.h> |
| 33 | #include <rx/rx_globals.h> |
| 34 | #include <afs/vldbint.h> |
| 35 | #include <afs/volser.h> |
| 36 | #include <afs/vlserver.h> |
| 37 | #include <afs/cmd.h> |
| 38 | #include <afs/com_err.h> |
| 39 | #include <afs/ptclient.h> |
| 40 | #include <afs/ptuser.h> |
| 41 | #include <afs/afsutil.h> |
| 42 | #include <afs/sys_prototypes.h> |
| 43 | |
| 44 | #define MAXNAME100 100 |
| 45 | #define MAXINSIZE1300 1300 /* pioctl complains if data is larger than this */ |
| 46 | #define VMSGSIZE128 128 /* size of msg buf in volume hdr */ |
| 47 | |
| 48 | static char space[AFS_PIOCTL_MAXSIZE2048]; |
| 49 | static char tspace[1024]; |
| 50 | static struct ubik_client *uclient; |
| 51 | |
| 52 | static int GetClientAddrsCmd(struct cmd_syndesc *, void *); |
| 53 | static int SetClientAddrsCmd(struct cmd_syndesc *, void *); |
| 54 | static int FlushMountCmd(struct cmd_syndesc *, void *); |
| 55 | static int RxStatProcCmd(struct cmd_syndesc *, void *); |
| 56 | static int RxStatPeerCmd(struct cmd_syndesc *, void *); |
| 57 | static int GetFidCmd(struct cmd_syndesc *, void *); |
| 58 | static int UuidCmd(struct cmd_syndesc *, void *); |
| 59 | |
| 60 | static char pn[] = "fs"; |
| 61 | static int rxInitDone = 0; |
| 62 | |
| 63 | struct AclEntry; |
| 64 | struct Acl; |
| 65 | static void ZapList(struct AclEntry *); |
| 66 | static int PruneList(struct AclEntry **, int); |
| 67 | static int CleanAcl(struct Acl *, char *); |
| 68 | static int SetVolCmd(struct cmd_syndesc *as, void *arock); |
| 69 | static int GetCellName(char *, struct afsconf_cell *); |
| 70 | static int VLDBInit(int, struct afsconf_cell *); |
| 71 | static void Die(int, char *); |
| 72 | |
| 73 | /* |
| 74 | * Character to use between name and rights in printed representation for |
| 75 | * DFS ACL's. |
| 76 | */ |
| 77 | #define DFS_SEPARATOR' ' ' ' |
| 78 | |
| 79 | typedef char sec_rgy_name_t[1025]; /* A DCE definition */ |
| 80 | |
| 81 | struct Acl { |
| 82 | int dfs; /* Originally true if a dfs acl; now also the type |
| 83 | * of the acl (1, 2, or 3, corresponding to object, |
| 84 | * initial dir, or initial object). */ |
| 85 | sec_rgy_name_t cell; /* DFS cell name */ |
| 86 | int nplus; |
| 87 | int nminus; |
| 88 | struct AclEntry *pluslist; |
| 89 | struct AclEntry *minuslist; |
| 90 | }; |
| 91 | |
| 92 | struct AclEntry { |
| 93 | struct AclEntry *next; |
| 94 | char name[MAXNAME100]; |
| 95 | afs_int32 rights; |
| 96 | }; |
| 97 | |
| 98 | struct vcxstat2 { |
| 99 | afs_int32 callerAccess; |
| 100 | afs_int32 cbExpires; |
| 101 | afs_int32 anyAccess; |
| 102 | char mvstat; |
| 103 | }; |
| 104 | |
| 105 | static void |
| 106 | ZapAcl(struct Acl *acl) |
| 107 | { |
| 108 | if (!acl) |
| 109 | return; |
| 110 | ZapList(acl->pluslist); |
| 111 | ZapList(acl->minuslist); |
| 112 | free(acl); |
| 113 | } |
| 114 | |
| 115 | static int |
| 116 | foldcmp(char *a, char *b) |
| 117 | { |
| 118 | char t, u; |
| 119 | while (1) { |
| 120 | t = *a++; |
| 121 | u = *b++; |
| 122 | if (t >= 'A' && t <= 'Z') |
| 123 | t += 0x20; |
| 124 | if (u >= 'A' && u <= 'Z') |
| 125 | u += 0x20; |
| 126 | if (t != u) |
| 127 | return 1; |
| 128 | if (t == 0) |
| 129 | return 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Mods for the AFS/DFS protocol translator. |
| 135 | * |
| 136 | * DFS rights. It's ugly to put these definitions here, but they |
| 137 | * *cannot* change, because they're part of the wire protocol. |
| 138 | * In any event, the protocol translator will guarantee these |
| 139 | * assignments for AFS cache managers. |
| 140 | */ |
| 141 | #define DFS_READ0x01 0x01 |
| 142 | #define DFS_WRITE0x02 0x02 |
| 143 | #define DFS_EXECUTE0x04 0x04 |
| 144 | #define DFS_CONTROL0x08 0x08 |
| 145 | #define DFS_INSERT0x10 0x10 |
| 146 | #define DFS_DELETE0x20 0x20 |
| 147 | |
| 148 | /* the application definable ones (backwards from AFS) */ |
| 149 | #define DFS_USR00x80000000 0x80000000 /* "A" bit */ |
| 150 | #define DFS_USR10x40000000 0x40000000 /* "B" bit */ |
| 151 | #define DFS_USR20x20000000 0x20000000 /* "C" bit */ |
| 152 | #define DFS_USR30x10000000 0x10000000 /* "D" bit */ |
| 153 | #define DFS_USR40x08000000 0x08000000 /* "E" bit */ |
| 154 | #define DFS_USR50x04000000 0x04000000 /* "F" bit */ |
| 155 | #define DFS_USR60x02000000 0x02000000 /* "G" bit */ |
| 156 | #define DFS_USR70x01000000 0x01000000 /* "H" bit */ |
| 157 | #define DFS_USRALL(0x80000000 | 0x40000000 | 0x20000000 | 0x10000000 | 0x08000000 | 0x04000000 | 0x02000000 | 0x01000000) (DFS_USR00x80000000 | DFS_USR10x40000000 | DFS_USR20x20000000 | DFS_USR30x10000000 |\ |
| 158 | DFS_USR40x08000000 | DFS_USR50x04000000 | DFS_USR60x02000000 | DFS_USR70x01000000) |
| 159 | |
| 160 | /* |
| 161 | * Offset of -id switch in command structure for various commands. |
| 162 | * The -if switch is the next switch always. |
| 163 | */ |
| 164 | static int parm_setacl_id, parm_copyacl_id, parm_listacl_id; |
| 165 | |
| 166 | /* |
| 167 | * Determine whether either the -id or -if switches are present, and |
| 168 | * return 0, 1 or 2, as appropriate. Abort if both switches are present. |
| 169 | */ |
| 170 | /* int id; Offset of -id switch; -if is next switch */ |
| 171 | static int |
| 172 | getidf(struct cmd_syndesc *as, int id) |
| 173 | { |
| 174 | int idf = 0; |
| 175 | |
| 176 | if (as->parms[id].items) { |
| 177 | idf |= 1; |
| 178 | } |
| 179 | if (as->parms[id + 1].items) { |
| 180 | idf |= 2; |
| 181 | } |
| 182 | if (idf == 3) { |
| 183 | fprintf(stderr__stderrp, |
| 184 | "%s: you may specify either -id or -if, but not both switches\n", |
| 185 | pn); |
| 186 | exit(1); |
| 187 | } |
| 188 | return idf; |
| 189 | } |
| 190 | |
| 191 | static int |
| 192 | PRights(afs_int32 arights, int dfs) |
| 193 | { |
| 194 | if (!dfs) { |
| 195 | if (arights & PRSFS_READ1) |
| 196 | printf("r"); |
| 197 | if (arights & PRSFS_LOOKUP8) |
| 198 | printf("l"); |
| 199 | if (arights & PRSFS_INSERT4) |
| 200 | printf("i"); |
| 201 | if (arights & PRSFS_DELETE16) |
| 202 | printf("d"); |
| 203 | if (arights & PRSFS_WRITE2) |
| 204 | printf("w"); |
| 205 | if (arights & PRSFS_LOCK32) |
| 206 | printf("k"); |
| 207 | if (arights & PRSFS_ADMINISTER64) |
| 208 | printf("a"); |
| 209 | if (arights & PRSFS_USR00x01000000) |
| 210 | printf("A"); |
| 211 | if (arights & PRSFS_USR10x02000000) |
| 212 | printf("B"); |
| 213 | if (arights & PRSFS_USR20x04000000) |
| 214 | printf("C"); |
| 215 | if (arights & PRSFS_USR30x08000000) |
| 216 | printf("D"); |
| 217 | if (arights & PRSFS_USR40x10000000) |
| 218 | printf("E"); |
| 219 | if (arights & PRSFS_USR50x20000000) |
| 220 | printf("F"); |
| 221 | if (arights & PRSFS_USR60x40000000) |
| 222 | printf("G"); |
| 223 | if (arights & PRSFS_USR70x80000000) |
| 224 | printf("H"); |
| 225 | } else { |
| 226 | if (arights & DFS_READ0x01) |
| 227 | printf("r"); |
| 228 | else |
| 229 | printf("-"); |
| 230 | if (arights & DFS_WRITE0x02) |
| 231 | printf("w"); |
| 232 | else |
| 233 | printf("-"); |
| 234 | if (arights & DFS_EXECUTE0x04) |
| 235 | printf("x"); |
| 236 | else |
| 237 | printf("-"); |
| 238 | if (arights & DFS_CONTROL0x08) |
| 239 | printf("c"); |
| 240 | else |
| 241 | printf("-"); |
| 242 | if (arights & DFS_INSERT0x10) |
| 243 | printf("i"); |
| 244 | else |
| 245 | printf("-"); |
| 246 | if (arights & DFS_DELETE0x20) |
| 247 | printf("d"); |
| 248 | else |
| 249 | printf("-"); |
| 250 | if (arights & (DFS_USRALL(0x80000000 | 0x40000000 | 0x20000000 | 0x10000000 | 0x08000000 | 0x04000000 | 0x02000000 | 0x01000000))) |
| 251 | printf("+"); |
| 252 | if (arights & DFS_USR00x80000000) |
| 253 | printf("A"); |
| 254 | if (arights & DFS_USR10x40000000) |
| 255 | printf("B"); |
| 256 | if (arights & DFS_USR20x20000000) |
| 257 | printf("C"); |
| 258 | if (arights & DFS_USR30x10000000) |
| 259 | printf("D"); |
| 260 | if (arights & DFS_USR40x08000000) |
| 261 | printf("E"); |
| 262 | if (arights & DFS_USR50x04000000) |
| 263 | printf("F"); |
| 264 | if (arights & DFS_USR60x02000000) |
| 265 | printf("G"); |
| 266 | if (arights & DFS_USR70x01000000) |
| 267 | printf("H"); |
| 268 | } |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */ |
| 273 | static int |
| 274 | InAFS(char *apath) |
| 275 | { |
| 276 | struct ViceIoctl blob; |
| 277 | afs_int32 code; |
| 278 | |
| 279 | blob.in_size = 0; |
| 280 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 281 | blob.out = space; |
| 282 | |
| 283 | code = pioctl(apath, VIOC_FILE_CELL_NAME((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((30))))), &blob, 1); |
| 284 | if (code) { |
| 285 | if ((errno(* __error()) == EINVAL22) || (errno(* __error()) == ENOENT2)) |
| 286 | return 0; |
| 287 | } |
| 288 | return 1; |
| 289 | } |
| 290 | |
| 291 | /* return a static pointer to a buffer */ |
| 292 | static char * |
| 293 | Parent(char *apath) |
| 294 | { |
| 295 | char *tp; |
| 296 | strlcpy(tspace, apath, sizeof(tspace)); |
| 297 | tp = strrchr(tspace, '/'); |
| 298 | if (tp == (char *)tspace) |
| 299 | tp++; |
| 300 | else if (tp == (char *)NULL((void *)0)) { |
| 301 | tp = (char *)tspace; |
| 302 | *(tp++) = '.'; |
| 303 | } |
| 304 | *tp = '\0'; |
| 305 | return tspace; |
| 306 | } |
| 307 | |
| 308 | /* added relative add resp. delete */ |
| 309 | /* (so old add really means to set) */ |
| 310 | enum rtype { add, destroy, deny, reladd, reldel }; |
| 311 | |
| 312 | static afs_int32 |
| 313 | Convert(char *arights, int dfs, enum rtype *rtypep) |
| 314 | { |
| 315 | afs_int32 mode; |
| 316 | char tc; |
| 317 | char *tcp; /* to walk through the rights string */ |
| 318 | |
| 319 | *rtypep = add; /* add rights, by default */ |
| 320 | |
| 321 | /* analyze last character of string */ |
| 322 | tcp = arights + strlen(arights); |
| 323 | if ( tcp-- > arights ) { /* assure non-empty string */ |
| 324 | if ( *tcp == '+' ) |
| 325 | *rtypep = reladd; /* '+' indicates more rights */ |
| 326 | else if ( *tcp == '-' ) |
| 327 | *rtypep = reldel; /* '-' indicates less rights */ |
| 328 | else if ( *tcp == '=' ) |
| 329 | *rtypep = add; /* '=' also allows old behaviour */ |
| 330 | else |
| 331 | tcp++; /* back to original null byte */ |
| 332 | *tcp = '\0'; /* do not disturb old strcmp-s */ |
| 333 | } |
| 334 | |
| 335 | if (dfs) { |
| 336 | if (!strcmp(arights, "null")) { |
| 337 | *rtypep = deny; |
| 338 | return 0; |
| 339 | } |
| 340 | if (!strcmp(arights, "read")) |
| 341 | return DFS_READ0x01 | DFS_EXECUTE0x04; |
| 342 | if (!strcmp(arights, "write")) |
| 343 | return DFS_READ0x01 | DFS_EXECUTE0x04 | DFS_INSERT0x10 | DFS_DELETE0x20 | |
| 344 | DFS_WRITE0x02; |
| 345 | if (!strcmp(arights, "all")) |
| 346 | return DFS_READ0x01 | DFS_EXECUTE0x04 | DFS_INSERT0x10 | DFS_DELETE0x20 | |
| 347 | DFS_WRITE0x02 | DFS_CONTROL0x08; |
| 348 | } else { |
| 349 | if (!strcmp(arights, "read")) |
| 350 | return PRSFS_READ1 | PRSFS_LOOKUP8; |
| 351 | if (!strcmp(arights, "write")) |
| 352 | return PRSFS_READ1 | PRSFS_LOOKUP8 | PRSFS_INSERT4 | PRSFS_DELETE16 | |
| 353 | PRSFS_WRITE2 | PRSFS_LOCK32; |
| 354 | if (!strcmp(arights, "mail")) |
| 355 | return PRSFS_INSERT4 | PRSFS_LOCK32 | PRSFS_LOOKUP8; |
| 356 | if (!strcmp(arights, "all")) |
| 357 | return PRSFS_READ1 | PRSFS_LOOKUP8 | PRSFS_INSERT4 | PRSFS_DELETE16 | |
| 358 | PRSFS_WRITE2 | PRSFS_LOCK32 | PRSFS_ADMINISTER64; |
| 359 | } |
| 360 | if (!strcmp(arights, "none")) { |
| 361 | *rtypep = destroy; /* Remove entire entry */ |
| 362 | return 0; |
| 363 | } |
| 364 | mode = 0; |
| 365 | tcp = arights; |
| 366 | while ((tc = *tcp++ )) { |
| 367 | if (dfs) { |
| 368 | if (tc == '-') |
| 369 | continue; |
| 370 | else if (tc == 'r') |
| 371 | mode |= DFS_READ0x01; |
| 372 | else if (tc == 'w') |
| 373 | mode |= DFS_WRITE0x02; |
| 374 | else if (tc == 'x') |
| 375 | mode |= DFS_EXECUTE0x04; |
| 376 | else if (tc == 'c') |
| 377 | mode |= DFS_CONTROL0x08; |
| 378 | else if (tc == 'i') |
| 379 | mode |= DFS_INSERT0x10; |
| 380 | else if (tc == 'd') |
| 381 | mode |= DFS_DELETE0x20; |
| 382 | else if (tc == 'A') |
| 383 | mode |= DFS_USR00x80000000; |
| 384 | else if (tc == 'B') |
| 385 | mode |= DFS_USR10x40000000; |
| 386 | else if (tc == 'C') |
| 387 | mode |= DFS_USR20x20000000; |
| 388 | else if (tc == 'D') |
| 389 | mode |= DFS_USR30x10000000; |
| 390 | else if (tc == 'E') |
| 391 | mode |= DFS_USR40x08000000; |
| 392 | else if (tc == 'F') |
| 393 | mode |= DFS_USR50x04000000; |
| 394 | else if (tc == 'G') |
| 395 | mode |= DFS_USR60x02000000; |
| 396 | else if (tc == 'H') |
| 397 | mode |= DFS_USR70x01000000; |
| 398 | else { |
| 399 | fprintf(stderr__stderrp, "%s: illegal DFS rights character '%c'.\n", |
| 400 | pn, tc); |
| 401 | exit(1); |
| 402 | } |
| 403 | } else { |
| 404 | if (tc == 'r') |
| 405 | mode |= PRSFS_READ1; |
| 406 | else if (tc == 'l') |
| 407 | mode |= PRSFS_LOOKUP8; |
| 408 | else if (tc == 'i') |
| 409 | mode |= PRSFS_INSERT4; |
| 410 | else if (tc == 'd') |
| 411 | mode |= PRSFS_DELETE16; |
| 412 | else if (tc == 'w') |
| 413 | mode |= PRSFS_WRITE2; |
| 414 | else if (tc == 'k') |
| 415 | mode |= PRSFS_LOCK32; |
| 416 | else if (tc == 'a') |
| 417 | mode |= PRSFS_ADMINISTER64; |
| 418 | else if (tc == 'A') |
| 419 | mode |= PRSFS_USR00x01000000; |
| 420 | else if (tc == 'B') |
| 421 | mode |= PRSFS_USR10x02000000; |
| 422 | else if (tc == 'C') |
| 423 | mode |= PRSFS_USR20x04000000; |
| 424 | else if (tc == 'D') |
| 425 | mode |= PRSFS_USR30x08000000; |
| 426 | else if (tc == 'E') |
| 427 | mode |= PRSFS_USR40x10000000; |
| 428 | else if (tc == 'F') |
| 429 | mode |= PRSFS_USR50x20000000; |
| 430 | else if (tc == 'G') |
| 431 | mode |= PRSFS_USR60x40000000; |
| 432 | else if (tc == 'H') |
| 433 | mode |= PRSFS_USR70x80000000; |
| 434 | else { |
| 435 | fprintf(stderr__stderrp, "%s: illegal rights character '%c'.\n", pn, |
| 436 | tc); |
| 437 | exit(1); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | return mode; |
| 442 | } |
| 443 | |
| 444 | static struct AclEntry * |
| 445 | FindList(struct AclEntry *alist, char *aname) |
| 446 | { |
| 447 | while (alist) { |
| 448 | if (!foldcmp(alist->name, aname)) |
| 449 | return alist; |
| 450 | alist = alist->next; |
| 451 | } |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | /* if no parm specified in a particular slot, set parm to be "." instead */ |
| 456 | static void |
| 457 | SetDotDefault(struct cmd_item **aitemp) |
| 458 | { |
| 459 | struct cmd_item *ti; |
| 460 | if (*aitemp) |
| 461 | return; /* already has value */ |
| 462 | /* otherwise, allocate an item representing "." */ |
| 463 | ti = (struct cmd_item *)malloc(sizeof(struct cmd_item)); |
| 464 | assert(ti)do{if (!(ti)) AssertionFailed("fs.c", 464);}while(0); |
| 465 | ti->next = (struct cmd_item *)0; |
| 466 | ti->data = (char *)malloc(2); |
| 467 | assert(ti->data)do{if (!(ti->data)) AssertionFailed("fs.c", 467);}while(0); |
| 468 | strcpy(ti->data, "."); |
| 469 | *aitemp = ti; |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights, |
| 474 | enum rtype *artypep) |
| 475 | { |
| 476 | struct AclEntry *tlist; |
| 477 | tlist = (plus ? al->pluslist : al->minuslist); |
| 478 | tlist = FindList(tlist, aname); |
| 479 | if (tlist) { |
| 480 | /* Found the item already in the list. |
| 481 | * modify rights in case of reladd and reladd only, |
| 482 | * use standard - add, ie. set - otherwise |
| 483 | */ |
| 484 | if ( artypep == NULL((void *)0) ) |
| 485 | tlist->rights = arights; |
| 486 | else if ( *artypep == reladd ) |
| 487 | tlist->rights |= arights; |
| 488 | else if ( *artypep == reldel ) |
| 489 | tlist->rights &= ~arights; |
| 490 | else |
| 491 | tlist->rights = arights; |
| 492 | |
| 493 | if (plus) |
| 494 | al->nplus -= PruneList(&al->pluslist, al->dfs); |
| 495 | else |
| 496 | al->nminus -= PruneList(&al->minuslist, al->dfs); |
| 497 | return; |
| 498 | } |
| 499 | if ( artypep != NULL((void *)0) && *artypep == reldel ) |
| 500 | return; /* can't reduce non-existing rights */ |
| 501 | |
| 502 | /* Otherwise we make a new item and plug in the new data. */ |
| 503 | tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry)); |
| 504 | assert(tlist)do{if (!(tlist)) AssertionFailed("fs.c", 504);}while(0); |
| 505 | strcpy(tlist->name, aname); |
| 506 | tlist->rights = arights; |
| 507 | if (plus) { |
| 508 | tlist->next = al->pluslist; |
| 509 | al->pluslist = tlist; |
| 510 | al->nplus++; |
| 511 | if (arights == 0 || arights == -1) |
| 512 | al->nplus -= PruneList(&al->pluslist, al->dfs); |
| 513 | } else { |
| 514 | tlist->next = al->minuslist; |
| 515 | al->minuslist = tlist; |
| 516 | al->nminus++; |
| 517 | if (arights == 0) |
| 518 | al->nminus -= PruneList(&al->minuslist, al->dfs); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | ZapList(struct AclEntry *alist) |
| 524 | { |
| 525 | struct AclEntry *tp, *np; |
| 526 | for (tp = alist; tp; tp = np) { |
| 527 | np = tp->next; |
| 528 | free(tp); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | static int |
| 533 | PruneList(struct AclEntry **ae, int dfs) |
| 534 | { |
| 535 | struct AclEntry **lp; |
| 536 | struct AclEntry *te, *ne; |
| 537 | afs_int32 ctr; |
| 538 | ctr = 0; |
| 539 | lp = ae; |
| 540 | for (te = *ae; te; te = ne) { |
| 541 | if ((!dfs && te->rights == 0) || te->rights == -1) { |
| 542 | *lp = te->next; |
| 543 | ne = te->next; |
| 544 | free(te); |
| 545 | ctr++; |
| 546 | } else { |
| 547 | ne = te->next; |
| 548 | lp = &te->next; |
| 549 | } |
| 550 | } |
| 551 | return ctr; |
| 552 | } |
| 553 | |
| 554 | static char * |
| 555 | SkipLine(char *astr) |
| 556 | { |
| 557 | while (*astr != '\n') |
| 558 | astr++; |
| 559 | astr++; |
| 560 | return astr; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * Create an empty acl, taking into account whether the acl pointed |
| 565 | * to by astr is an AFS or DFS acl. Only parse this minimally, so we |
| 566 | * can recover from problems caused by bogus ACL's (in that case, always |
| 567 | * assume that the acl is AFS: for DFS, the user can always resort to |
| 568 | * acl_edit, but for AFS there may be no other way out). |
| 569 | */ |
| 570 | static struct Acl * |
| 571 | EmptyAcl(char *astr) |
| 572 | { |
| 573 | struct Acl *tp; |
| 574 | int junk; |
| 575 | |
| 576 | tp = (struct Acl *)malloc(sizeof(struct Acl)); |
| 577 | assert(tp)do{if (!(tp)) AssertionFailed("fs.c", 577);}while(0); |
| 578 | tp->nplus = tp->nminus = 0; |
| 579 | tp->pluslist = tp->minuslist = 0; |
| 580 | tp->dfs = 0; |
| 581 | sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell); |
| 582 | return tp; |
| 583 | } |
| 584 | |
| 585 | static struct Acl * |
| 586 | ParseAcl(char *astr) |
| 587 | { |
| 588 | int nplus, nminus, i, trights; |
| 589 | char tname[MAXNAME100]; |
| 590 | struct AclEntry *first, *last, *tl; |
| 591 | struct Acl *ta; |
| 592 | |
| 593 | ta = (struct Acl *)malloc(sizeof(struct Acl)); |
| 594 | assert(ta)do{if (!(ta)) AssertionFailed("fs.c", 594);}while(0); |
| 595 | ta->dfs = 0; |
| 596 | sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell); |
| 597 | astr = SkipLine(astr); |
| 598 | sscanf(astr, "%d", &ta->nminus); |
| 599 | astr = SkipLine(astr); |
| 600 | |
| 601 | nplus = ta->nplus; |
| 602 | nminus = ta->nminus; |
| 603 | |
| 604 | last = 0; |
| 605 | first = 0; |
| 606 | for (i = 0; i < nplus; i++) { |
| 607 | sscanf(astr, "%100s %d", tname, &trights); |
| 608 | astr = SkipLine(astr); |
| 609 | tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); |
| 610 | assert(tl)do{if (!(tl)) AssertionFailed("fs.c", 610);}while(0); |
| 611 | if (!first) |
| 612 | first = tl; |
| 613 | strcpy(tl->name, tname); |
| 614 | tl->rights = trights; |
| 615 | tl->next = 0; |
| 616 | if (last) |
| 617 | last->next = tl; |
| 618 | last = tl; |
| 619 | } |
| 620 | ta->pluslist = first; |
| 621 | |
| 622 | last = 0; |
| 623 | first = 0; |
| 624 | for (i = 0; i < nminus; i++) { |
| 625 | sscanf(astr, "%100s %d", tname, &trights); |
| 626 | astr = SkipLine(astr); |
| 627 | tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); |
| 628 | assert(tl)do{if (!(tl)) AssertionFailed("fs.c", 628);}while(0); |
| 629 | if (!first) |
| 630 | first = tl; |
| 631 | strcpy(tl->name, tname); |
| 632 | tl->rights = trights; |
| 633 | tl->next = 0; |
| 634 | if (last) |
| 635 | last->next = tl; |
| 636 | last = tl; |
| 637 | } |
| 638 | ta->minuslist = first; |
| 639 | |
| 640 | return ta; |
| 641 | } |
| 642 | |
| 643 | static int |
| 644 | PrintStatus(VolumeStatus * status, char *name, char *offmsg) |
| 645 | { |
| 646 | printf("Volume status for vid = %u named %s\n", status->Vid, name); |
| 647 | if (*offmsg != 0) |
| 648 | printf("Current offline message is %s\n", offmsg); |
| 649 | printf("Current disk quota is "); |
| 650 | if (status->MaxQuota != 0) |
| 651 | printf("%d\n", status->MaxQuota); |
| 652 | else |
| 653 | printf("unlimited\n"); |
| 654 | printf("Current blocks used are %d\n", status->BlocksInUse); |
| 655 | printf("The partition has %d blocks available out of %d\n\n", |
| 656 | status->PartBlocksAvail, status->PartMaxBlocks); |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static const char power_letter[] = { |
| 661 | 'K', /* kibi */ |
| 662 | 'M', /* mebi */ |
| 663 | 'G', /* gibi */ |
| 664 | 'T', /* tebi */ |
| 665 | 'P', /* pebi */ |
| 666 | }; |
| 667 | |
| 668 | static void |
| 669 | HumanPrintSpace(afs_int32 int_space) |
| 670 | { |
| 671 | int exponent = 0; |
| 672 | int exponent_max = sizeof(power_letter) - 1; |
| 673 | float space = int_space; |
| 674 | |
| 675 | while (space >= 1024 && exponent < exponent_max) { |
| 676 | exponent++; |
| 677 | space /= 1024; |
| 678 | } |
| 679 | printf("%9.1f%c", space, power_letter[exponent]); |
| 680 | } |
| 681 | |
| 682 | static int |
| 683 | QuickPrintStatus(VolumeStatus * status, char *name, int human) |
| 684 | { |
| 685 | double QuotaUsed = 0.0; |
| 686 | double PartUsed = 0.0; |
| 687 | int WARN = 0; |
| 688 | printf("%-25.25s", name); |
| 689 | |
| 690 | if (status->MaxQuota != 0) { |
| 691 | if (human) { |
| 692 | printf(" "); |
| 693 | HumanPrintSpace(status->MaxQuota); |
| 694 | printf(" "); |
| 695 | HumanPrintSpace(status->BlocksInUse); |
| 696 | } |
| 697 | else |
| 698 | printf(" %10d %10d", status->MaxQuota, status->BlocksInUse); |
| 699 | QuotaUsed = |
| 700 | ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0); |
| 701 | } else { |
| 702 | printf(" no limit "); |
| 703 | if (human) |
| 704 | HumanPrintSpace(status->BlocksInUse); |
| 705 | else |
| 706 | printf("%10d", status->BlocksInUse); |
| 707 | } |
| 708 | if (QuotaUsed > 90.0) { |
| 709 | printf("%5.0f%%<<", QuotaUsed); |
| 710 | WARN = 1; |
| 711 | } else |
| 712 | printf("%5.0f%% ", QuotaUsed); |
| 713 | PartUsed = |
| 714 | (100.0 - |
| 715 | ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) * |
| 716 | 100.0)); |
| 717 | if (PartUsed > 97.0) { |
| 718 | printf("%9.0f%%<<", PartUsed); |
| 719 | WARN = 1; |
| 720 | } else |
| 721 | printf("%9.0f%% ", PartUsed); |
| 722 | if (WARN) { |
| 723 | printf(" <<WARNING\n"); |
| 724 | } else |
| 725 | printf("\n"); |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int |
| 730 | QuickPrintSpace(VolumeStatus * status, char *name, int human) |
| 731 | { |
| 732 | double PartUsed = 0.0; |
| 733 | int WARN = 0; |
| 734 | printf("%-25.25s", name); |
| 735 | |
| 736 | if (human) { |
| 737 | HumanPrintSpace(status->PartMaxBlocks); |
| 738 | HumanPrintSpace(status->PartMaxBlocks - status->PartBlocksAvail); |
| 739 | HumanPrintSpace(status->PartBlocksAvail); |
| 740 | } |
| 741 | else |
| 742 | printf("%10d%10d%10d", status->PartMaxBlocks, |
| 743 | status->PartMaxBlocks - status->PartBlocksAvail, |
| 744 | status->PartBlocksAvail); |
| 745 | |
| 746 | PartUsed = |
| 747 | (100.0 - |
| 748 | ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) * |
| 749 | 100.0)); |
| 750 | if (PartUsed > 90.0) { |
| 751 | printf(" %4.0f%%<<", PartUsed); |
| 752 | WARN = 1; |
| 753 | } else |
| 754 | printf(" %4.0f%% ", PartUsed); |
| 755 | if (WARN) { |
| 756 | printf(" <<WARNING\n"); |
| 757 | } else |
| 758 | printf("\n"); |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static char * |
| 763 | AclToString(struct Acl *acl) |
| 764 | { |
| 765 | static char mydata[AFS_PIOCTL_MAXSIZE2048]; |
| 766 | char tstring[AFS_PIOCTL_MAXSIZE2048]; |
| 767 | char dfsstring[30]; |
| 768 | struct AclEntry *tp; |
| 769 | |
| 770 | if (acl->dfs) |
| 771 | sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell); |
| 772 | else |
| 773 | dfsstring[0] = '\0'; |
| 774 | sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus); |
| 775 | for (tp = acl->pluslist; tp; tp = tp->next) { |
| 776 | sprintf(tstring, "%s %d\n", tp->name, tp->rights); |
| 777 | strcat(mydata, tstring); |
| 778 | } |
| 779 | for (tp = acl->minuslist; tp; tp = tp->next) { |
| 780 | sprintf(tstring, "%s %d\n", tp->name, tp->rights); |
| 781 | strcat(mydata, tstring); |
| 782 | } |
| 783 | return mydata; |
| 784 | } |
| 785 | |
| 786 | static int |
| 787 | SetACLCmd(struct cmd_syndesc *as, void *arock) |
| 788 | { |
| 789 | afs_int32 code; |
| 790 | struct ViceIoctl blob; |
| 791 | struct Acl *ta = 0; |
| 792 | struct cmd_item *ti, *ui; |
| 793 | int plusp; |
| 794 | afs_int32 rights; |
| 795 | int clear; |
| 796 | int idf = getidf(as, parm_setacl_id); |
| 797 | int error = 0; |
| 798 | |
| 799 | if (as->parms[2].items) |
| 800 | clear = 1; |
| 801 | else |
| 802 | clear = 0; |
| 803 | plusp = !(as->parms[3].items); |
| 804 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 805 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 806 | blob.in_size = idf; |
| 807 | blob.in = blob.out = space; |
| 808 | code = pioctl(ti->data, VIOCGETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 809 | if (code) { |
| 810 | Die(errno(* __error()), ti->data); |
| 811 | error = 1; |
| 812 | continue; |
| 813 | } |
| 814 | |
| 815 | if (ta) |
| 816 | ZapAcl(ta); |
| 817 | ta = ParseAcl(space); |
| 818 | if (!plusp && ta->dfs) { |
| 819 | fprintf(stderr__stderrp, |
| 820 | "%s: %s: you may not use the -negative switch with DFS acl's.\n%s", |
| 821 | pn, ti->data, |
| 822 | "(you may specify \"null\" to revoke all rights, however)\n"); |
| 823 | error = 1; |
| 824 | continue; |
| 825 | } |
| 826 | |
| 827 | if (ta) |
| 828 | ZapAcl(ta); |
| 829 | if (clear) |
| 830 | ta = EmptyAcl(space); |
| 831 | else |
| 832 | ta = ParseAcl(space); |
| 833 | CleanAcl(ta, ti->data); |
| 834 | for (ui = as->parms[1].items; ui; ui = ui->next->next) { |
| 835 | enum rtype rtype; |
| 836 | if (!ui->next) { |
| 837 | fprintf(stderr__stderrp, |
| 838 | "%s: Missing second half of user/access pair.\n", pn); |
| 839 | ZapAcl(ta); |
| 840 | return 1; |
| 841 | } |
| 842 | rights = Convert(ui->next->data, ta->dfs, &rtype); |
| 843 | if (rtype == destroy && !ta->dfs) { |
| 844 | struct AclEntry *tlist; |
| 845 | |
| 846 | tlist = (plusp ? ta->pluslist : ta->minuslist); |
| 847 | if (!FindList(tlist, ui->data)) |
| 848 | continue; |
| 849 | } |
| 850 | if (rtype == deny && !ta->dfs) |
| 851 | plusp = 0; |
| 852 | if (rtype == destroy && ta->dfs) |
| 853 | rights = -1; |
| 854 | ChangeList(ta, plusp, ui->data, rights, &rtype); |
| 855 | } |
| 856 | blob.in = AclToString(ta); |
| 857 | blob.out_size = 0; |
| 858 | blob.in_size = 1 + strlen(blob.in); |
| 859 | code = pioctl(ti->data, VIOCSETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((1))))), &blob, 1); |
| 860 | if (code) { |
| 861 | if (errno(* __error()) == EINVAL22) { |
| 862 | if (ta->dfs) { |
| 863 | static char *fsenv = 0; |
| 864 | if (!fsenv) { |
| 865 | fsenv = (char *)getenv("FS_EXPERT"); |
| 866 | } |
| 867 | fprintf(stderr__stderrp, |
| 868 | "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", |
| 869 | pn); |
| 870 | if (!fsenv) { |
| 871 | fprintf(stderr__stderrp, |
| 872 | "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
| 873 | "\nPossible reasons for this include:\n\n", |
| 874 | " -You may have specified an inappropriate combination of rights.\n", |
| 875 | " For example, some DFS-supported filesystems may not allow you to\n", |
| 876 | " drop the \"c\" right from \"user_obj\".\n\n", |
| 877 | " -A mask_obj may be required (it is likely required by the underlying\n", |
| 878 | " filesystem if you try to set anything other than the basic \"user_obj\"\n", |
| 879 | " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n", |
| 880 | " does not automatically create or update the mask_obj. Try setting\n", |
| 881 | " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n", |
| 882 | " users or groups. You can do this with a single command, such as\n", |
| 883 | " \"fs sa mask_obj all user:somename read\"\n\n", |
| 884 | " -A specified user or group may not exist.\n\n", |
| 885 | " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n", |
| 886 | " This is probably not allowed by the underlying file system.\n\n", |
| 887 | " -If you add a user or group to a DFS ACL, remember that it must be\n", |
| 888 | " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n", |
| 889 | " may be local requirements on the format of the user or group name.\n", |
| 890 | " Check with your cell administrator.\n\n", |
| 891 | " -Or numerous other possibilities. It would be great if we could be more\n", |
| 892 | " precise about the actual problem, but for various reasons, this is\n", |
| 893 | " impractical via this interface. If you can't figure it out, you\n", |
| 894 | " might try logging into a DCE-equipped machine and use acl_edit (or\n", |
| 895 | " whatever is provided). You may get better results. Good luck!\n\n", |
| 896 | " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n"); |
| 897 | } |
| 898 | } else { |
| 899 | fprintf(stderr__stderrp, |
| 900 | "%s: Invalid argument, possible reasons include:\n", |
| 901 | pn); |
| 902 | fprintf(stderr__stderrp, "\t-File not in AFS\n"); |
| 903 | fprintf(stderr__stderrp, |
| 904 | "\t-Too many users on access control list\n"); |
| 905 | fprintf(stderr__stderrp, |
| 906 | "\t-Tried to add non-existent user to access control list\n"); |
| 907 | } |
| 908 | } else { |
| 909 | Die(errno(* __error()), ti->data); |
| 910 | } |
| 911 | error = 1; |
| 912 | } |
| 913 | } |
| 914 | if (ta) |
| 915 | ZapAcl(ta); |
| 916 | return error; |
| 917 | } |
| 918 | |
| 919 | |
| 920 | static int |
| 921 | CopyACLCmd(struct cmd_syndesc *as, void *arock) |
| 922 | { |
| 923 | afs_int32 code; |
| 924 | struct ViceIoctl blob; |
| 925 | struct Acl *fa, *ta = 0; |
| 926 | struct AclEntry *tp; |
| 927 | struct cmd_item *ti; |
| 928 | int clear; |
| 929 | int idf = getidf(as, parm_copyacl_id); |
| 930 | int error = 0; |
| 931 | |
| 932 | if (as->parms[2].items) |
| 933 | clear = 1; |
| 934 | else |
| 935 | clear = 0; |
| 936 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 937 | blob.in_size = idf; |
| 938 | blob.in = blob.out = space; |
| 939 | code = pioctl(as->parms[0].items->data, VIOCGETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 940 | if (code) { |
| 941 | Die(errno(* __error()), as->parms[0].items->data); |
| 942 | return 1; |
| 943 | } |
| 944 | fa = ParseAcl(space); |
| 945 | CleanAcl(fa, as->parms[0].items->data); |
| 946 | for (ti = as->parms[1].items; ti; ti = ti->next) { |
| 947 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 948 | blob.in_size = idf; |
| 949 | blob.in = blob.out = space; |
| 950 | code = pioctl(ti->data, VIOCGETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 951 | if (code) { |
| 952 | Die(errno(* __error()), ti->data); |
| 953 | error = 1; |
| 954 | continue; |
| 955 | } |
| 956 | |
| 957 | if (ta) |
| 958 | ZapAcl(ta); |
| 959 | if (clear) |
| 960 | ta = EmptyAcl(space); |
| 961 | else |
| 962 | ta = ParseAcl(space); |
| 963 | CleanAcl(ta, ti->data); |
| 964 | if (ta->dfs != fa->dfs) { |
| 965 | fprintf(stderr__stderrp, |
| 966 | "%s: incompatible file system types: acl not copied to %s; aborted\n", |
| 967 | pn, ti->data); |
| 968 | error = 1; |
| 969 | continue; |
| 970 | } |
| 971 | if (ta->dfs) { |
| 972 | if (!clear && strcmp(ta->cell, fa->cell) != 0) { |
| 973 | fprintf(stderr__stderrp, |
| 974 | "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", |
| 975 | pn, ti->data); |
| 976 | error = 1; |
| 977 | continue; |
| 978 | } |
| 979 | strcpy(ta->cell, fa->cell); |
| 980 | } |
| 981 | /* NULL rtype for standard handling */ |
| 982 | for (tp = fa->pluslist; tp; tp = tp->next) |
| 983 | ChangeList(ta, 1, tp->name, tp->rights, NULL((void *)0)); |
| 984 | for (tp = fa->minuslist; tp; tp = tp->next) |
| 985 | ChangeList(ta, 0, tp->name, tp->rights, NULL((void *)0)); |
| 986 | blob.in = AclToString(ta); |
| 987 | blob.out_size = 0; |
| 988 | blob.in_size = 1 + strlen(blob.in); |
| 989 | code = pioctl(ti->data, VIOCSETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((1))))), &blob, 1); |
| 990 | if (code) { |
| 991 | if (errno(* __error()) == EINVAL22) { |
| 992 | fprintf(stderr__stderrp, |
| 993 | "%s: Invalid argument, possible reasons include:\n", |
| 994 | pn); |
| 995 | fprintf(stderr__stderrp, "\t-File not in AFS\n"); |
| 996 | } else { |
| 997 | Die(errno(* __error()), ti->data); |
| 998 | } |
| 999 | error = 1; |
| 1000 | } |
| 1001 | } |
| 1002 | if (ta) |
| 1003 | ZapAcl(ta); |
| 1004 | ZapAcl(fa); |
| 1005 | return error; |
| 1006 | } |
| 1007 | |
| 1008 | /* pioctl() call to get the cellname of a pathname */ |
| 1009 | static afs_int32 |
| 1010 | GetCell(char *fname, char *cellname) |
| 1011 | { |
| 1012 | afs_int32 code; |
| 1013 | struct ViceIoctl blob; |
| 1014 | |
| 1015 | blob.in_size = 0; |
| 1016 | blob.out_size = MAXCELLCHARS64; |
| 1017 | blob.out = cellname; |
| 1018 | |
| 1019 | code = pioctl(fname, VIOC_FILE_CELL_NAME((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((30))))), &blob, 1); |
| 1020 | return code ? errno(* __error()) : 0; |
| 1021 | } |
| 1022 | |
| 1023 | /* Check if a username is valid: If it contains only digits (or a |
| 1024 | * negative sign), then it might be bad. We then query the ptserver |
| 1025 | * to see. |
| 1026 | */ |
| 1027 | static int |
| 1028 | BadName(char *aname, char *fname) |
| 1029 | { |
| 1030 | afs_int32 tc, code, id; |
| 1031 | char *nm; |
| 1032 | char cell[MAXCELLCHARS64]; |
| 1033 | |
| 1034 | for (nm = aname; (tc = *nm); nm++) { |
| 1035 | /* all must be '-' or digit to be bad */ |
| 1036 | if (tc != '-' && (tc < '0' || tc > '9')) |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | /* Go to the PRDB and see if this all number username is valid */ |
| 1041 | code = GetCell(fname, cell); |
| 1042 | if (code) |
| 1043 | return 0; |
| 1044 | |
| 1045 | pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID), cell); |
| 1046 | code = pr_SNameToId(aname, &id); |
| 1047 | pr_End(); |
| 1048 | |
| 1049 | /* 1=>Not-valid; 0=>Valid */ |
| 1050 | return ((!code && (id == ANONYMOUSID32766)) ? 1 : 0); |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | /* clean up an access control list of its bad entries; return 1 if we made |
| 1055 | any changes to the list, and 0 otherwise */ |
| 1056 | static int |
| 1057 | CleanAcl(struct Acl *aa, char *fname) |
| 1058 | { |
| 1059 | struct AclEntry *te, **le, *ne; |
| 1060 | int changes; |
| 1061 | |
| 1062 | /* Don't correct DFS ACL's for now */ |
| 1063 | if (aa->dfs) |
| 1064 | return 0; |
| 1065 | |
| 1066 | /* prune out bad entries */ |
| 1067 | changes = 0; /* count deleted entries */ |
| 1068 | le = &aa->pluslist; |
| 1069 | for (te = aa->pluslist; te; te = ne) { |
| 1070 | ne = te->next; |
| 1071 | if (BadName(te->name, fname)) { |
| 1072 | /* zap this dude */ |
| 1073 | *le = te->next; |
| 1074 | aa->nplus--; |
| 1075 | free(te); |
| 1076 | changes++; |
| 1077 | } else { |
| 1078 | le = &te->next; |
| 1079 | } |
| 1080 | } |
| 1081 | le = &aa->minuslist; |
| 1082 | for (te = aa->minuslist; te; te = ne) { |
| 1083 | ne = te->next; |
| 1084 | if (BadName(te->name, fname)) { |
| 1085 | /* zap this dude */ |
| 1086 | *le = te->next; |
| 1087 | aa->nminus--; |
| 1088 | free(te); |
| 1089 | changes++; |
| 1090 | } else { |
| 1091 | le = &te->next; |
| 1092 | } |
| 1093 | } |
| 1094 | return changes; |
| 1095 | } |
| 1096 | |
| 1097 | |
| 1098 | /* clean up an acl to not have bogus entries */ |
| 1099 | static int |
| 1100 | CleanACLCmd(struct cmd_syndesc *as, void *arock) |
| 1101 | { |
| 1102 | afs_int32 code; |
| 1103 | struct Acl *ta = 0; |
| 1104 | struct ViceIoctl blob; |
| 1105 | int changes; |
| 1106 | struct cmd_item *ti; |
| 1107 | struct AclEntry *te; |
| 1108 | int error = 0; |
| 1109 | |
| 1110 | SetDotDefault(&as->parms[0].items); |
| 1111 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1112 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1113 | blob.in_size = 0; |
| 1114 | blob.out = space; |
| 1115 | code = pioctl(ti->data, VIOCGETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 1116 | if (code) { |
| 1117 | Die(errno(* __error()), ti->data); |
| 1118 | error = 1; |
| 1119 | continue; |
| 1120 | } |
| 1121 | |
| 1122 | if (ta) |
| 1123 | ZapAcl(ta); |
| 1124 | ta = ParseAcl(space); |
| 1125 | if (ta->dfs) { |
| 1126 | fprintf(stderr__stderrp, |
| 1127 | "%s: cleanacl is not supported for DFS access lists.\n", |
| 1128 | pn); |
| 1129 | error = 1; |
| 1130 | continue; |
| 1131 | } |
| 1132 | |
| 1133 | changes = CleanAcl(ta, ti->data); |
| 1134 | |
| 1135 | if (changes) { |
| 1136 | /* now set the acl */ |
| 1137 | blob.in = AclToString(ta); |
| 1138 | blob.in_size = strlen(blob.in) + 1; |
| 1139 | blob.out_size = 0; |
| 1140 | code = pioctl(ti->data, VIOCSETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((1))))), &blob, 1); |
| 1141 | if (code) { |
| 1142 | if (errno(* __error()) == EINVAL22) { |
| 1143 | fprintf(stderr__stderrp, |
| 1144 | "%s: Invalid argument, possible reasons include\n", |
| 1145 | pn); |
| 1146 | fprintf(stderr__stderrp, "%s: File not in vice or\n", pn); |
| 1147 | fprintf(stderr__stderrp, |
| 1148 | "%s: Too many users on access control list or\n", |
| 1149 | pn); |
| 1150 | } else { |
| 1151 | Die(errno(* __error()), ti->data); |
| 1152 | } |
| 1153 | error = 1; |
| 1154 | continue; |
| 1155 | } |
| 1156 | |
| 1157 | /* now list the updated acl */ |
| 1158 | printf("Access list for %s is now\n", ti->data); |
| 1159 | if (ta->nplus > 0) { |
| 1160 | if (!ta->dfs) |
| 1161 | printf("Normal rights:\n"); |
| 1162 | for (te = ta->pluslist; te; te = te->next) { |
| 1163 | printf(" %s ", te->name); |
| 1164 | PRights(te->rights, ta->dfs); |
| 1165 | printf("\n"); |
| 1166 | } |
| 1167 | } |
| 1168 | if (ta->nminus > 0) { |
| 1169 | printf("Negative rights:\n"); |
| 1170 | for (te = ta->minuslist; te; te = te->next) { |
| 1171 | printf(" %s ", te->name); |
| 1172 | PRights(te->rights, ta->dfs); |
| 1173 | printf("\n"); |
| 1174 | } |
| 1175 | } |
| 1176 | if (ti->next) |
| 1177 | printf("\n"); |
| 1178 | } else |
| 1179 | printf("Access list for %s is fine.\n", ti->data); |
| 1180 | } |
| 1181 | if (ta) |
| 1182 | ZapAcl(ta); |
| 1183 | return error; |
| 1184 | } |
| 1185 | |
| 1186 | static int |
| 1187 | ListACLCmd(struct cmd_syndesc *as, void *arock) |
| 1188 | { |
| 1189 | afs_int32 code; |
| 1190 | struct Acl *ta; |
| 1191 | struct ViceIoctl blob; |
| 1192 | struct AclEntry *te; |
| 1193 | struct cmd_item *ti; |
| 1194 | int idf = getidf(as, parm_listacl_id); |
| 1195 | int error = 0; |
| 1196 | |
| 1197 | SetDotDefault(&as->parms[0].items); |
| 1198 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1199 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1200 | blob.in_size = idf; |
| 1201 | blob.in = blob.out = space; |
| 1202 | code = pioctl(ti->data, VIOCGETAL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 1203 | if (code) { |
| 1204 | Die(errno(* __error()), ti->data); |
| 1205 | error = 1; |
| 1206 | continue; |
| 1207 | } |
| 1208 | ta = ParseAcl(space); |
| 1209 | if (as->parms[3].items) { /* -cmd */ |
| 1210 | printf("fs setacl -dir %s -acl ", ti->data); |
| 1211 | if (ta->nplus > 0) { |
| 1212 | for (te = ta->pluslist; te; te = te->next) { |
| 1213 | printf(" %s ", te->name); |
| 1214 | PRights(te->rights, ta->dfs); |
| 1215 | } |
| 1216 | } |
| 1217 | printf("\n"); |
| 1218 | if (ta->nminus > 0) { |
| 1219 | printf("fs setacl -dir %s -acl ", ti->data); |
| 1220 | for (te = ta->minuslist; te; te = te->next) { |
| 1221 | printf(" %s ", te->name); |
| 1222 | PRights(te->rights, ta->dfs); |
| 1223 | } |
| 1224 | printf(" -negative\n"); |
| 1225 | } |
| 1226 | } else { |
| 1227 | switch (ta->dfs) { |
| 1228 | case 0: |
| 1229 | printf("Access list for %s is\n", ti->data); |
| 1230 | break; |
| 1231 | case 1: |
| 1232 | printf("DFS access list for %s is\n", ti->data); |
| 1233 | break; |
| 1234 | case 2: |
| 1235 | printf("DFS initial directory access list of %s is\n", ti->data); |
| 1236 | break; |
| 1237 | case 3: |
| 1238 | printf("DFS initial file access list of %s is\n", ti->data); |
| 1239 | break; |
| 1240 | } |
| 1241 | if (ta->dfs) { |
| 1242 | printf(" Default cell = %s\n", ta->cell); |
| 1243 | } |
| 1244 | if (ta->nplus > 0) { |
| 1245 | if (!ta->dfs) |
| 1246 | printf("Normal rights:\n"); |
| 1247 | for (te = ta->pluslist; te; te = te->next) { |
| 1248 | printf(" %s ", te->name); |
| 1249 | PRights(te->rights, ta->dfs); |
| 1250 | printf("\n"); |
| 1251 | } |
| 1252 | } |
| 1253 | if (ta->nminus > 0) { |
| 1254 | printf("Negative rights:\n"); |
| 1255 | for (te = ta->minuslist; te; te = te->next) { |
| 1256 | printf(" %s ", te->name); |
| 1257 | PRights(te->rights, ta->dfs); |
| 1258 | printf("\n"); |
| 1259 | } |
| 1260 | } |
| 1261 | if (ti->next) |
| 1262 | printf("\n"); |
| 1263 | } |
| 1264 | ZapAcl(ta); |
| 1265 | } |
| 1266 | return error; |
| 1267 | } |
| 1268 | |
| 1269 | static int |
| 1270 | GetCallerAccess(struct cmd_syndesc *as, void *arock) |
| 1271 | { |
| 1272 | struct cmd_item *ti; |
| 1273 | int error = 0; |
| 1274 | |
| 1275 | SetDotDefault(&as->parms[0].items); |
| 1276 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1277 | afs_int32 code; |
| 1278 | struct ViceIoctl blob; |
| 1279 | struct vcxstat2 stat; |
| 1280 | blob.out_size = sizeof(struct vcxstat2); |
| 1281 | blob.in_size = 0; |
| 1282 | blob.out = (void *)&stat; |
| 1283 | code = pioctl(ti->data, VIOC_GETVCXSTATUS2((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((69))))), &blob, 1); |
| 1284 | if (code) { |
| 1285 | Die(errno(* __error()), ti->data); |
| 1286 | error = 1; |
| 1287 | continue; |
| 1288 | } |
| 1289 | printf("Callers access to %s is ", ti->data); |
| 1290 | PRights(stat.callerAccess, 0); |
| 1291 | printf("\n"); |
| 1292 | } |
| 1293 | return error; |
| 1294 | } |
| 1295 | |
| 1296 | static int |
| 1297 | FlushVolumeCmd(struct cmd_syndesc *as, void *arock) |
| 1298 | { |
| 1299 | afs_int32 code; |
| 1300 | struct ViceIoctl blob; |
| 1301 | struct cmd_item *ti; |
| 1302 | int error = 0; |
| 1303 | |
| 1304 | SetDotDefault(&as->parms[0].items); |
| 1305 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1306 | blob.in_size = blob.out_size = 0; |
| 1307 | code = pioctl(ti->data, VIOC_FLUSHVOLUME((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((37))))), &blob, 0); |
| 1308 | if (code) { |
| 1309 | fprintf(stderr__stderrp, "Error flushing volume "); |
| 1310 | perror(ti->data); |
| 1311 | error = 1; |
| 1312 | continue; |
| 1313 | } |
| 1314 | } |
| 1315 | return error; |
| 1316 | } |
| 1317 | |
| 1318 | /* |
| 1319 | * The Windows version of UuidCmd displays the UUID. |
| 1320 | * When the UNIX version is updated to do the same |
| 1321 | * be sure to replace the CMD_REQUIRED flag with |
| 1322 | * CMD_OPTIONAL in the cmd_AddParam(-generate) call |
| 1323 | */ |
| 1324 | static int |
| 1325 | UuidCmd(struct cmd_syndesc *as, void *arock) |
| 1326 | { |
| 1327 | afs_int32 code; |
| 1328 | struct ViceIoctl blob; |
| 1329 | |
| 1330 | blob.in_size = 0; |
| 1331 | blob.out_size = 0; |
| 1332 | |
| 1333 | if (as->parms[0].items) { |
| 1334 | if (geteuid()) { |
| 1335 | fprintf (stderr__stderrp, "Permission denied: requires root access.\n"); |
| 1336 | return EACCES13; |
| 1337 | } |
| 1338 | |
| 1339 | /* generate new UUID */ |
| 1340 | code = pioctl(0, VIOC_NEWUUID((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((9))))), &blob, 1); |
| 1341 | |
| 1342 | if (code) { |
| 1343 | Die(errno(* __error()), 0); |
| 1344 | return 1; |
| 1345 | } |
| 1346 | |
| 1347 | printf("New uuid generated.\n"); |
| 1348 | } else { |
| 1349 | /* This will never execute */ |
| 1350 | printf("Please add the '-generate' option to generate a new UUID.\n"); |
| 1351 | } |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | #if defined(AFS_CACHE_BYPASS) |
| 1356 | /* |
| 1357 | * Set cache-bypass threshold. Files larger than this size will not be cached. |
| 1358 | * With a threshold of 0, the cache is always bypassed. With a threshold of -1, |
| 1359 | * cache bypass is disabled. |
| 1360 | */ |
| 1361 | |
| 1362 | static int |
| 1363 | BypassThresholdCmd(struct cmd_syndesc *as, void *arock) |
| 1364 | { |
| 1365 | afs_int32 code; |
| 1366 | struct ViceIoctl blob; |
| 1367 | afs_int32 threshold_i, threshold_o; |
| 1368 | char *tp; |
| 1369 | |
| 1370 | /* if new threshold supplied, then set and confirm, else, |
| 1371 | * get current threshold and print |
| 1372 | */ |
| 1373 | |
| 1374 | if(as->parms[0].items) { |
| 1375 | int digit, ix, len; |
| 1376 | |
| 1377 | tp = as->parms[0].items->data; |
| 1378 | len = strlen(tp); |
| 1379 | |
| 1380 | if (!strcmp(tp,"-1")) { |
| 1381 | threshold_i = -1; |
| 1382 | } else { |
| 1383 | digit = 1; |
| 1384 | for(ix = 0; ix < len; ++ix) { |
| 1385 | if(!isdigit(tp[0])__isctype((tp[0]), 0x00000400L)) { |
| 1386 | digit = 0; |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | if (digit == 0) { |
| 1391 | fprintf(stderr__stderrp, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp); |
| 1392 | return EINVAL22; |
| 1393 | } |
| 1394 | threshold_i = atoi(tp); |
| 1395 | if(ix > 9 && threshold_i < 2147483647) |
| 1396 | threshold_i = 2147483647; |
| 1397 | } |
| 1398 | blob.in = (char *) &threshold_i; |
| 1399 | blob.in_size = sizeof(threshold_i); |
| 1400 | } else { |
| 1401 | blob.in = NULL((void *)0); |
| 1402 | blob.in_size = 0; |
| 1403 | } |
| 1404 | |
| 1405 | blob.out = (char *) &threshold_o; |
| 1406 | blob.out_size = sizeof(threshold_o); |
| 1407 | code = pioctl(0, VIOC_SETBYPASS_THRESH, &blob, 1); |
| 1408 | if (code) { |
| 1409 | Die(errno(* __error()), NULL((void *)0)); |
| 1410 | return 1; |
| 1411 | } else { |
| 1412 | printf("Cache bypass threshold %d", threshold_o); |
| 1413 | if(threshold_o == -1) |
| 1414 | printf(" (disabled)"); |
| 1415 | printf("\n"); |
| 1416 | } |
| 1417 | |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | #endif |
| 1422 | |
| 1423 | static int |
| 1424 | FlushCmd(struct cmd_syndesc *as, void *arock) |
| 1425 | { |
| 1426 | afs_int32 code; |
| 1427 | struct ViceIoctl blob; |
| 1428 | struct cmd_item *ti; |
| 1429 | int error = 0; |
| 1430 | |
| 1431 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1432 | blob.in_size = blob.out_size = 0; |
| 1433 | code = pioctl(ti->data, VIOCFLUSH((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((6))))), &blob, 0); |
| 1434 | if (code) { |
| 1435 | if (errno(* __error()) == EMFILE24) { |
| 1436 | fprintf(stderr__stderrp, "%s: Can't flush active file %s\n", pn, |
| 1437 | ti->data); |
| 1438 | } else { |
| 1439 | fprintf(stderr__stderrp, "%s: Error flushing file ", pn); |
| 1440 | perror(ti->data); |
| 1441 | } |
| 1442 | error = 1; |
| 1443 | continue; |
| 1444 | } |
| 1445 | } |
| 1446 | return error; |
| 1447 | } |
| 1448 | |
| 1449 | /* all this command does is repackage its args and call SetVolCmd */ |
| 1450 | static int |
| 1451 | SetQuotaCmd(struct cmd_syndesc *as, void *arock) |
| 1452 | { |
| 1453 | struct cmd_syndesc ts; |
| 1454 | |
| 1455 | /* copy useful stuff from our command slot; we may later have to reorder */ |
| 1456 | memcpy(&ts, as, sizeof(ts)); /* copy whole thing */ |
| 1457 | return SetVolCmd(&ts, arock); |
| 1458 | } |
| 1459 | |
| 1460 | static int |
| 1461 | SetVolCmd(struct cmd_syndesc *as, void *arock) |
| 1462 | { |
| 1463 | afs_int32 code; |
| 1464 | struct ViceIoctl blob; |
| 1465 | struct cmd_item *ti; |
| 1466 | struct VolumeStatus *status; |
| 1467 | char *offmsg, *input; |
| 1468 | int error = 0; |
| 1469 | |
| 1470 | SetDotDefault(&as->parms[0].items); |
| 1471 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1472 | /* once per file */ |
| 1473 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1474 | blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */ |
| 1475 | blob.out = space; |
| 1476 | blob.in = space; |
| 1477 | status = (VolumeStatus *) space; |
| 1478 | status->MinQuota = status->MaxQuota = -1; |
| 1479 | offmsg = NULL((void *)0); |
| 1480 | if (as->parms[1].items) { |
| 1481 | code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota); |
| 1482 | if (code) { |
| 1483 | fprintf(stderr__stderrp, "%s: bad integer specified for quota.\n", pn); |
| 1484 | error = 1; |
| 1485 | continue; |
| 1486 | } |
| 1487 | } |
| 1488 | if (as->parms[2].items) |
| 1489 | offmsg = as->parms[2].items->data; |
| 1490 | input = (char *)status + sizeof(*status); |
| 1491 | *(input++) = '\0'; /* never set name: this call doesn't change vldb */ |
| 1492 | if (offmsg) { |
| 1493 | if (strlen(offmsg) >= VMSGSIZE128) { |
| 1494 | fprintf(stderr__stderrp, |
| 1495 | "%s: message must be shorter than %d characters\n", |
| 1496 | pn, VMSGSIZE128); |
| 1497 | error = 1; |
| 1498 | continue; |
| 1499 | } |
| 1500 | strcpy(input, offmsg); |
| 1501 | blob.in_size += strlen(offmsg); |
| 1502 | input += strlen(offmsg) + 1; |
| 1503 | } else |
| 1504 | *(input++) = '\0'; |
| 1505 | *(input++) = '\0'; /* Pad for old style volume "motd" */ |
| 1506 | code = pioctl(ti->data, VIOCSETVOLSTAT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((5))))), &blob, 1); |
| 1507 | if (code) { |
| 1508 | Die(errno(* __error()), ti->data); |
| 1509 | error = 1; |
| 1510 | } |
| 1511 | } |
| 1512 | return error; |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * Why is VenusFid declared in the kernel-only section of afs.h, |
| 1517 | * if it's the exported interface of the cache manager? |
| 1518 | */ |
| 1519 | struct VenusFid { |
| 1520 | afs_int32 Cell; |
| 1521 | AFSFid Fid; |
| 1522 | }; |
| 1523 | |
| 1524 | static int |
| 1525 | ExamineCmd(struct cmd_syndesc *as, void *arock) |
| 1526 | { |
| 1527 | afs_int32 code; |
| 1528 | struct ViceIoctl blob; |
| 1529 | struct cmd_item *ti; |
| 1530 | struct VolumeStatus *status; |
| 1531 | char *name, *offmsg; |
| 1532 | int error = 0; |
| 1533 | |
| 1534 | SetDotDefault(&as->parms[0].items); |
| 1535 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1536 | struct VenusFid vfid; |
| 1537 | |
| 1538 | /* once per file */ |
| 1539 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1540 | blob.in_size = 0; |
| 1541 | blob.out = space; |
| 1542 | code = pioctl(ti->data, VIOCGETVOLSTAT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((4))))), &blob, 1); |
| 1543 | if (code) { |
| 1544 | Die(errno(* __error()), ti->data); |
| 1545 | error = 1; |
| 1546 | continue; |
| 1547 | } |
| 1548 | status = (VolumeStatus *) space; |
| 1549 | name = (char *)status + sizeof(*status); |
| 1550 | offmsg = name + strlen(name) + 1; |
| 1551 | |
| 1552 | blob.out_size = sizeof(struct VenusFid); |
| 1553 | blob.out = (char *) &vfid; |
| 1554 | if (0 == pioctl(ti->data, VIOCGETFID((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((22))))), &blob, 1)) { |
| 1555 | printf("File %s (%u.%u.%u) contained in volume %u\n", |
| 1556 | ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique, |
| 1557 | vfid.Fid.Volume); |
| 1558 | } |
| 1559 | |
| 1560 | PrintStatus(status, name, offmsg); |
| 1561 | } |
| 1562 | return error; |
| 1563 | } |
| 1564 | |
| 1565 | static int |
| 1566 | ListQuotaCmd(struct cmd_syndesc *as, void *arock) |
| 1567 | { |
| 1568 | afs_int32 code; |
| 1569 | struct ViceIoctl blob; |
| 1570 | struct cmd_item *ti; |
| 1571 | struct VolumeStatus *status; |
| 1572 | char *name; |
| 1573 | int error = 0; |
| 1574 | int human = 0; |
| 1575 | |
| 1576 | if (as->parms[1].items) |
| 1577 | human = 1; |
| 1578 | |
| 1579 | printf("%-25s%-11s%-11s%-7s%-11s\n", "Volume Name", " Quota", |
| 1580 | " Used", " %Used", " Partition"); |
| 1581 | SetDotDefault(&as->parms[0].items); |
| 1582 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1583 | /* once per file */ |
| 1584 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1585 | blob.in_size = 0; |
| 1586 | blob.out = space; |
| 1587 | code = pioctl(ti->data, VIOCGETVOLSTAT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((4))))), &blob, 1); |
| 1588 | if (code) { |
| 1589 | Die(errno(* __error()), ti->data); |
| 1590 | error = 1; |
| 1591 | continue; |
| 1592 | } |
| 1593 | status = (VolumeStatus *) space; |
| 1594 | name = (char *)status + sizeof(*status); |
| 1595 | QuickPrintStatus(status, name, human); |
| 1596 | } |
| 1597 | return error; |
| 1598 | } |
| 1599 | |
| 1600 | static int |
| 1601 | WhereIsCmd(struct cmd_syndesc *as, void *arock) |
| 1602 | { |
| 1603 | afs_int32 code; |
| 1604 | struct ViceIoctl blob; |
| 1605 | struct cmd_item *ti; |
| 1606 | int j; |
| 1607 | afs_int32 *hosts; |
| 1608 | char *tp; |
| 1609 | int error = 0; |
| 1610 | |
| 1611 | SetDotDefault(&as->parms[0].items); |
| 1612 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1613 | /* once per file */ |
| 1614 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1615 | blob.in_size = 0; |
| 1616 | blob.out = space; |
| 1617 | memset(space, 0, sizeof(space)); |
| 1618 | code = pioctl(ti->data, VIOCWHEREIS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((14))))), &blob, 1); |
| 1619 | if (code) { |
| 1620 | Die(errno(* __error()), ti->data); |
| 1621 | error = 1; |
| 1622 | continue; |
| 1623 | } |
| 1624 | hosts = (afs_int32 *) space; |
| 1625 | printf("File %s is on host%s ", ti->data, |
| 1626 | (hosts[0] && !hosts[1]) ? "" : "s"); |
| 1627 | for (j = 0; j < AFS_MAXHOSTS13; j++) { |
| 1628 | if (hosts[j] == 0) |
| 1629 | break; |
| 1630 | tp = hostutil_GetNameByINet(hosts[j]); |
| 1631 | printf("%s ", tp); |
| 1632 | } |
| 1633 | printf("\n"); |
| 1634 | } |
| 1635 | return error; |
| 1636 | } |
| 1637 | |
| 1638 | |
| 1639 | static int |
| 1640 | DiskFreeCmd(struct cmd_syndesc *as, void *arock) |
| 1641 | { |
| 1642 | afs_int32 code; |
| 1643 | struct ViceIoctl blob; |
| 1644 | struct cmd_item *ti; |
| 1645 | char *name; |
| 1646 | struct VolumeStatus *status; |
| 1647 | int error = 0; |
| 1648 | int human = 0; |
| 1649 | |
| 1650 | if (as->parms[1].items) |
| 1651 | human = 1; |
| 1652 | |
| 1653 | printf("%-25s%10s%10s%10s%6s\n", "Volume Name", |
| 1654 | human ? "total" : "kbytes", "used", "avail", "%used"); |
| 1655 | SetDotDefault(&as->parms[0].items); |
| 1656 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1657 | /* once per file */ |
| 1658 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1659 | blob.in_size = 0; |
| 1660 | blob.out = space; |
| 1661 | code = pioctl(ti->data, VIOCGETVOLSTAT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((4))))), &blob, 1); |
| 1662 | if (code) { |
| 1663 | Die(errno(* __error()), ti->data); |
| 1664 | error = 1; |
| 1665 | continue; |
| 1666 | } |
| 1667 | status = (VolumeStatus *) space; |
| 1668 | name = (char *)status + sizeof(*status); |
| 1669 | QuickPrintSpace(status, name, human); |
| 1670 | } |
| 1671 | return error; |
| 1672 | } |
| 1673 | |
| 1674 | static int |
| 1675 | QuotaCmd(struct cmd_syndesc *as, void *arock) |
| 1676 | { |
| 1677 | afs_int32 code; |
| 1678 | struct ViceIoctl blob; |
| 1679 | struct cmd_item *ti; |
| 1680 | double quotaPct; |
| 1681 | struct VolumeStatus *status; |
| 1682 | int error = 0; |
| 1683 | |
| 1684 | SetDotDefault(&as->parms[0].items); |
| 1685 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1686 | /* once per file */ |
| 1687 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1688 | blob.in_size = 0; |
| 1689 | blob.out = space; |
| 1690 | code = pioctl(ti->data, VIOCGETVOLSTAT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((4))))), &blob, 1); |
| 1691 | if (code) { |
| 1692 | Die(errno(* __error()), ti->data); |
| 1693 | error = 1; |
| 1694 | continue; |
| 1695 | } |
| 1696 | status = (VolumeStatus *) space; |
| 1697 | if (status->MaxQuota) |
| 1698 | quotaPct = |
| 1699 | ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0); |
| 1700 | else |
| 1701 | quotaPct = 0.0; |
| 1702 | printf("%2.0f%% of quota used.\n", quotaPct); |
| 1703 | } |
| 1704 | return error; |
| 1705 | } |
| 1706 | |
| 1707 | static int |
| 1708 | GetLastComponent(const char *data, char **outdir, char **outbase, |
| 1709 | int *thru_symlink) |
| 1710 | { |
| 1711 | char orig_name[1024]; /*Original name, may be modified */ |
| 1712 | char true_name[1024]; /*``True'' dirname (e.g., symlink target) */ |
| 1713 | char *lastSlash; |
| 1714 | struct stat statbuff; /*Buffer for status info */ |
| 1715 | int link_chars_read; /*Num chars read in readlink() */ |
| 1716 | char *dirname = NULL((void *)0); |
| 1717 | char *basename = NULL((void *)0); |
| 1718 | |
| 1719 | if (thru_symlink) |
| 1720 | *thru_symlink = 0; |
| 1721 | |
| 1722 | snprintf(orig_name, sizeof(orig_name), "%s%s", |
| 1723 | (data[0] == '/') ? "" : "./", data); |
| 1724 | |
| 1725 | if (lstat(orig_name, &statbuff) < 0) { |
| 1726 | /* if lstat fails, we should still try the pioctl, since it |
| 1727 | * may work (for example, lstat will fail, but pioctl will |
| 1728 | * work if the volume of offline (returning ENODEV). */ |
| 1729 | statbuff.st_mode = S_IFDIR0040000; /* lie like pros */ |
| 1730 | } |
| 1731 | |
| 1732 | /* |
| 1733 | * The lstat succeeded. If the given file is a symlink, substitute |
| 1734 | * the file name with the link name. |
| 1735 | */ |
| 1736 | if ((statbuff.st_mode & S_IFMT0170000) == S_IFLNK0120000) { |
| 1737 | if (thru_symlink) |
| 1738 | *thru_symlink = 1; |
| 1739 | |
| 1740 | /* Read name of resolved file */ |
| 1741 | link_chars_read = readlink(orig_name, true_name, 1024); |
| 1742 | if (link_chars_read <= 0) { |
| 1743 | fprintf(stderr__stderrp, |
| 1744 | "%s: Can't read target name for '%s' symbolic link!\n", |
| 1745 | pn, orig_name); |
| 1746 | goto out; |
| 1747 | } |
| 1748 | |
| 1749 | /* Add a trailing null to what was read, bump the length. */ |
| 1750 | true_name[link_chars_read++] = 0; |
| 1751 | |
| 1752 | /* |
| 1753 | * If the symlink is an absolute pathname, we're fine. Otherwise, we |
| 1754 | * have to create a full pathname using the original name and the |
| 1755 | * relative symlink name. Find the rightmost slash in the original |
| 1756 | * name (we know there is one) and splice in the symlink value. |
| 1757 | */ |
| 1758 | if (true_name[0] != '/') { |
| 1759 | lastSlash = strrchr(orig_name, '/'); |
| 1760 | strcpy(++lastSlash, true_name); |
| 1761 | strcpy(true_name, orig_name); |
| 1762 | } |
| 1763 | } else { |
| 1764 | strcpy(true_name, orig_name); |
| 1765 | } |
| 1766 | |
| 1767 | /* Find rightmost slash, if any. */ |
| 1768 | lastSlash = strrchr(true_name, '/'); |
| 1769 | if (lastSlash == true_name) { |
| 1770 | dirname = strdup("/"); |
| 1771 | basename = strdup(lastSlash+1); |
| 1772 | } else if (lastSlash != NULL((void *)0)) { |
| 1773 | /* |
| 1774 | * Found it. Designate everything before it as the parent directory, |
| 1775 | * everything after it as the final component. |
| 1776 | */ |
| 1777 | *lastSlash = '\0'; |
| 1778 | dirname = strdup(true_name); |
| 1779 | basename = strdup(lastSlash+1); |
| 1780 | } else { |
| 1781 | /* |
| 1782 | * No slash appears in the given file name. Set parent_dir to the current |
| 1783 | * directory, and the last component as the given name. |
| 1784 | */ |
| 1785 | dirname = strdup("."); |
| 1786 | basename = strdup(true_name); |
| 1787 | } |
| 1788 | |
| 1789 | if (strcmp(basename, ".") == 0 |
| 1790 | || strcmp(basename, "..") == 0) { |
| 1791 | fprintf(stderr__stderrp, |
| 1792 | "%s: you may not use '.' or '..' as the last component\n", pn); |
| 1793 | fprintf(stderr__stderrp, "%s: of a name in this fs command.\n", pn); |
| 1794 | goto out; |
| 1795 | } |
| 1796 | |
| 1797 | *outdir = dirname; |
| 1798 | *outbase = basename; |
| 1799 | |
| 1800 | return 0; |
| 1801 | |
| 1802 | out: |
| 1803 | if (outdir) |
| 1804 | free(outdir); |
| 1805 | if (outbase) |
| 1806 | free(outbase); |
| 1807 | return -1; |
| 1808 | } |
| 1809 | |
| 1810 | |
| 1811 | static int |
| 1812 | ListMountCmd(struct cmd_syndesc *as, void *arock) |
| 1813 | { |
| 1814 | afs_int32 code; |
| 1815 | struct ViceIoctl blob; |
| 1816 | struct cmd_item *ti; |
| 1817 | char *last_component; |
| 1818 | char *parent_dir; |
| 1819 | int thru_symlink = 0; |
| 1820 | int error = 0; |
| 1821 | |
| 1822 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1823 | if (GetLastComponent(ti->data, &parent_dir, |
| 1824 | &last_component, &thru_symlink) != 0) { |
| 1825 | error = 1; |
| 1826 | continue; |
| 1827 | } |
| 1828 | |
| 1829 | blob.in = last_component; |
| 1830 | blob.in_size = strlen(last_component) + 1; |
| 1831 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1832 | blob.out = space; |
| 1833 | memset(space, 0, AFS_PIOCTL_MAXSIZE2048); |
| 1834 | |
| 1835 | code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((29))))), &blob, 1); |
| 1836 | free(last_component); |
| 1837 | free(parent_dir); |
| 1838 | |
| 1839 | if (code == 0) { |
| 1840 | printf("'%s' is a %smount point for volume '%s'\n", ti->data, |
| 1841 | (thru_symlink ? "symbolic link, leading to a " : ""), |
| 1842 | space); |
| 1843 | } else { |
| 1844 | if (errno(* __error()) == EINVAL22) { |
| 1845 | fprintf(stderr__stderrp, "'%s' is not a mount point.\n", ti->data); |
| 1846 | } else { |
| 1847 | Die(errno(* __error()), (ti->data ? ti->data : parent_dir)); |
| 1848 | } |
| 1849 | error = 1; |
| 1850 | } |
| 1851 | } |
| 1852 | return error; |
| 1853 | } |
| 1854 | |
| 1855 | static int |
| 1856 | MakeMountCmd(struct cmd_syndesc *as, void *arock) |
| 1857 | { |
| 1858 | afs_int32 code; |
| 1859 | char *cellName, *volName, *tmpName; |
| 1860 | struct afsconf_cell info; |
| 1861 | struct vldbentry vldbEntry; |
| 1862 | struct ViceIoctl blob; |
| 1863 | |
| 1864 | /* |
| 1865 | |
| 1866 | defect #3069 |
| 1867 | |
| 1868 | if (as->parms[5].items && !as->parms[2].items) { |
| 1869 | fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn); |
| 1870 | return 1; |
| 1871 | } |
| 1872 | */ |
| 1873 | |
| 1874 | if (as->parms[2].items) /* cell name specified */ |
| 1875 | cellName = as->parms[2].items->data; |
| 1876 | else |
| 1877 | cellName = NULL((void *)0); |
| 1878 | volName = as->parms[1].items->data; |
| 1879 | |
| 1880 | if (strlen(volName) >= 64) { |
| 1881 | fprintf(stderr__stderrp, |
| 1882 | "%s: volume name too long (length must be < 64 characters)\n", |
| 1883 | pn); |
| 1884 | return 1; |
| 1885 | } |
| 1886 | |
| 1887 | /* Check for a cellname in the volume specification, and complain |
| 1888 | * if it doesn't match what was specified with -cell */ |
| 1889 | if ((tmpName = strchr(volName, ':'))) { |
| 1890 | *tmpName = '\0'; |
| 1891 | if (cellName) { |
| 1892 | if (strcasecmp(cellName, volName)) { |
| 1893 | fprintf(stderr__stderrp, "%s: cellnames do not match.\n", pn); |
| 1894 | return 1; |
| 1895 | } |
| 1896 | } |
| 1897 | cellName = volName; |
| 1898 | volName = ++tmpName; |
| 1899 | } |
| 1900 | |
| 1901 | if (!InAFS(Parent(as->parms[0].items->data))) { |
| 1902 | fprintf(stderr__stderrp, |
| 1903 | "%s: mount points must be created within the AFS file system\n", |
| 1904 | pn); |
| 1905 | return 1; |
| 1906 | } |
| 1907 | |
| 1908 | if (!cellName) { |
| 1909 | blob.in_size = 0; |
| 1910 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 1911 | blob.out = space; |
| 1912 | code = |
| 1913 | pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((30))))), |
| 1914 | &blob, 1); |
| 1915 | } |
| 1916 | |
| 1917 | code = GetCellName(cellName ? cellName : space, &info); |
| 1918 | if (code) { |
| 1919 | return 1; |
| 1920 | } |
| 1921 | if (!(as->parms[4].items)) { |
| 1922 | /* not fast, check which cell the mountpoint is being created in */ |
| 1923 | /* not fast, check name with VLDB */ |
| 1924 | code = VLDBInit(1, &info); |
| 1925 | if (code == 0) { |
| 1926 | /* make the check. Don't complain if there are problems with init */ |
| 1927 | code = |
| 1928 | ubik_VL_GetEntryByNameO(uclient, 0, volName, |
| 1929 | &vldbEntry); |
| 1930 | if (code == VL_NOENT(363524L)) { |
| 1931 | fprintf(stderr__stderrp, |
| 1932 | "%s: warning, volume %s does not exist in cell %s.\n", |
| 1933 | pn, volName, cellName ? cellName : space); |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | if (as->parms[3].items) /* if -rw specified */ |
| 1939 | strcpy(space, "%"); |
| 1940 | else |
| 1941 | strcpy(space, "#"); |
| 1942 | if (cellName) { |
| 1943 | /* cellular mount point, prepend cell prefix */ |
| 1944 | strcat(space, info.name); |
| 1945 | strcat(space, ":"); |
| 1946 | } |
| 1947 | strcat(space, volName); /* append volume name */ |
| 1948 | strcat(space, "."); /* stupid convention; these end with a period */ |
| 1949 | code = symlink(space, as->parms[0].items->data); |
| 1950 | if (code) { |
| 1951 | Die(errno(* __error()), as->parms[0].items->data); |
| 1952 | return 1; |
| 1953 | } |
| 1954 | return 0; |
| 1955 | } |
| 1956 | |
| 1957 | /* |
| 1958 | * Delete AFS mount points. Variables are used as follows: |
| 1959 | * tbuffer: Set to point to the null-terminated directory name of the mount point |
| 1960 | * (or ``.'' if none is provided) |
| 1961 | * tp: Set to point to the actual name of the mount point to nuke. |
| 1962 | */ |
| 1963 | static int |
| 1964 | RemoveMountCmd(struct cmd_syndesc *as, void *arock) |
| 1965 | { |
| 1966 | afs_int32 code = 0; |
| 1967 | struct ViceIoctl blob; |
| 1968 | struct cmd_item *ti; |
| 1969 | char tbuffer[1024]; |
| 1970 | char lsbuffer[1024]; |
| 1971 | char *tp; |
| 1972 | int error = 0; |
| 1973 | |
| 1974 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 1975 | /* once per file */ |
| 1976 | tp = (char *)strrchr(ti->data, '/'); |
| 1977 | if (tp) { |
| 1978 | strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */ |
| 1979 | tbuffer[code] = 0; |
| 1980 | tp++; /* skip the slash */ |
| 1981 | } else { |
| 1982 | strcpy(tbuffer, "."); |
| 1983 | tp = ti->data; |
| 1984 | } |
| 1985 | blob.in = tp; |
| 1986 | blob.in_size = strlen(tp) + 1; |
| 1987 | blob.out = lsbuffer; |
| 1988 | blob.out_size = sizeof(lsbuffer); |
| 1989 | code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((29))))), &blob, 1); |
| 1990 | if (code) { |
| 1991 | if (errno(* __error()) == EINVAL22) { |
| 1992 | fprintf(stderr__stderrp, "%s: '%s' is not a mount point.\n", pn, |
| 1993 | ti->data); |
| 1994 | } else { |
| 1995 | Die(errno(* __error()), ti->data); |
| 1996 | } |
| 1997 | error = 1; |
| 1998 | continue; /* don't bother trying */ |
| 1999 | } |
| 2000 | blob.out_size = 0; |
| 2001 | blob.in = tp; |
| 2002 | blob.in_size = strlen(tp) + 1; |
| 2003 | code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((28))))), &blob, 1); |
| 2004 | if (code) { |
| 2005 | Die(errno(* __error()), ti->data); |
| 2006 | error = 1; |
| 2007 | } |
| 2008 | } |
| 2009 | return error; |
| 2010 | } |
| 2011 | |
| 2012 | /* |
| 2013 | */ |
| 2014 | |
| 2015 | static int |
| 2016 | CheckServersCmd(struct cmd_syndesc *as, void *arock) |
| 2017 | { |
| 2018 | afs_int32 code; |
| 2019 | struct ViceIoctl blob; |
| 2020 | afs_int32 j; |
| 2021 | afs_int32 temp; |
| 2022 | char *tp; |
| 2023 | struct afsconf_cell info; |
| 2024 | struct chservinfo checkserv; |
| 2025 | |
| 2026 | memset(&checkserv, 0, sizeof(struct chservinfo)); |
| 2027 | blob.in_size = sizeof(struct chservinfo); |
| 2028 | blob.in = (caddr_t) & checkserv; |
| 2029 | |
| 2030 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2031 | blob.out = space; |
| 2032 | memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */ |
| 2033 | |
| 2034 | /* prepare flags for checkservers command */ |
| 2035 | temp = 2; /* default to checking local cell only */ |
| 2036 | if (as->parms[2].items) |
| 2037 | temp |= 1; /* set fast flag */ |
| 2038 | if (as->parms[1].items) |
| 2039 | temp &= ~2; /* turn off local cell check */ |
| 2040 | |
| 2041 | checkserv.magic = 0x12345678; /* XXX */ |
| 2042 | checkserv.tflags = temp; |
| 2043 | |
| 2044 | /* now copy in optional cell name, if specified */ |
| 2045 | if (as->parms[0].items) { |
| 2046 | code = GetCellName(as->parms[0].items->data, &info); |
| 2047 | if (code) { |
| 2048 | return 1; |
| 2049 | } |
| 2050 | strcpy(checkserv.tbuffer, info.name); |
| 2051 | checkserv.tsize = strlen(info.name) + 1; |
| 2052 | } else { |
| 2053 | strcpy(checkserv.tbuffer, "\0"); |
| 2054 | checkserv.tsize = 0; |
| 2055 | } |
| 2056 | |
| 2057 | if (as->parms[3].items) { |
| 2058 | checkserv.tinterval = atol(as->parms[3].items->data); |
| 2059 | |
| 2060 | /* sanity check */ |
| 2061 | if (checkserv.tinterval < 0) { |
| 2062 | printf |
| 2063 | ("Warning: The negative -interval is ignored; treated as an inquiry\n"); |
| 2064 | checkserv.tinterval = 0; |
| 2065 | } else if (checkserv.tinterval > 600) { |
| 2066 | printf |
| 2067 | ("Warning: The maximum -interval value is 10 mins (600 secs)\n"); |
| 2068 | checkserv.tinterval = 600; /* 10 min max interval */ |
| 2069 | } |
| 2070 | } else { |
| 2071 | checkserv.tinterval = -1; /* don't change current interval */ |
| 2072 | } |
| 2073 | |
| 2074 | code = pioctl(0, VIOCCKSERV((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((10))))), &blob, 1); |
| 2075 | if (code) { |
| 2076 | if ((errno(* __error()) == EACCES13) && (checkserv.tinterval > 0)) { |
| 2077 | printf("Must be root to change -interval\n"); |
| 2078 | return 1; |
| 2079 | } |
| 2080 | Die(errno(* __error()), 0); |
| 2081 | return 1; |
| 2082 | } |
| 2083 | memcpy(&temp, space, sizeof(afs_int32)); |
| 2084 | if (checkserv.tinterval >= 0) { |
| 2085 | if (checkserv.tinterval > 0) |
| 2086 | printf |
| 2087 | ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n", |
| 2088 | checkserv.tinterval, temp); |
| 2089 | else |
| 2090 | printf("The current down server probe interval is %d secs\n", |
| 2091 | temp); |
| 2092 | return 0; |
| 2093 | } |
| 2094 | if (temp == 0) { |
| 2095 | printf("All servers are running.\n"); |
| 2096 | } else { |
| 2097 | printf |
| 2098 | ("These servers unavailable due to network or server problems: "); |
| 2099 | for (j = 0;; j++) { |
| 2100 | memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32)); |
| 2101 | if (temp == 0) |
| 2102 | break; |
| 2103 | tp = hostutil_GetNameByINet(temp); |
| 2104 | printf(" %s", tp); |
| 2105 | } |
| 2106 | printf(".\n"); |
| 2107 | code = 1; /* XXX */ |
| 2108 | } |
| 2109 | return code; |
| 2110 | } |
| 2111 | |
| 2112 | static int |
| 2113 | MessagesCmd(struct cmd_syndesc *as, void *arock) |
| 2114 | { |
| 2115 | afs_int32 code = 0; |
| 2116 | struct ViceIoctl blob; |
| 2117 | struct gaginfo gagflags; |
| 2118 | struct cmd_item *show; |
| 2119 | |
| 2120 | memset(&gagflags, 0, sizeof(struct gaginfo)); |
| 2121 | blob.in_size = sizeof(struct gaginfo); |
| 2122 | blob.in = (caddr_t) & gagflags; |
| 2123 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2124 | blob.out = space; |
| 2125 | memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */ |
| 2126 | |
| 2127 | if ((show = as->parms[0].items)) { |
| 2128 | if (!strcasecmp(show->data, "user")) |
| 2129 | gagflags.showflags |= GAGUSER1; |
| 2130 | else if (!strcasecmp(show->data, "console")) |
| 2131 | gagflags.showflags |= GAGCONSOLE2; |
| 2132 | else if (!strcasecmp(show->data, "all")) |
| 2133 | gagflags.showflags |= GAGCONSOLE2 | GAGUSER1; |
| 2134 | else if (!strcasecmp(show->data, "none")) |
| 2135 | /* do nothing */ ; |
| 2136 | else { |
| 2137 | fprintf(stderr__stderrp, |
| 2138 | "unrecognized flag %s: must be in {user,console,all,none}\n", |
| 2139 | show->data); |
| 2140 | code = EINVAL22; |
| 2141 | } |
| 2142 | } |
| 2143 | |
| 2144 | if (code) |
| 2145 | return 1; |
| 2146 | |
| 2147 | code = pioctl(0, VIOC_GAG((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((44))))), &blob, 1); |
| 2148 | if (code) { |
| 2149 | Die(errno(* __error()), 0); |
| 2150 | return 1; |
| 2151 | } |
| 2152 | |
| 2153 | return 0; |
| 2154 | } |
| 2155 | |
| 2156 | static int |
| 2157 | CheckVolumesCmd(struct cmd_syndesc *as, void *arock) |
| 2158 | { |
| 2159 | afs_int32 code; |
| 2160 | struct ViceIoctl blob; |
| 2161 | |
| 2162 | blob.in_size = 0; |
| 2163 | blob.out_size = 0; |
| 2164 | code = pioctl(0, VIOCCKBACK((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((11))))), &blob, 1); |
| 2165 | if (code) { |
| 2166 | Die(errno(* __error()), 0); |
| 2167 | return 1; |
| 2168 | } |
| 2169 | |
| 2170 | printf("All volumeID/name mappings checked.\n"); |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
| 2174 | static int |
| 2175 | PreCacheCmd(struct cmd_syndesc *as, void *arock) |
| 2176 | { |
| 2177 | afs_int32 code; |
| 2178 | struct ViceIoctl blob; |
| 2179 | afs_int32 temp; |
| 2180 | |
| 2181 | if (!as->parms[0].items && !as->parms[1].items) { |
| 2182 | fprintf(stderr__stderrp, "%s: syntax error in precache cmd.\n", pn); |
| 2183 | return 1; |
| 2184 | } |
| 2185 | if (as->parms[0].items) { |
| 2186 | code = util_GetInt32(as->parms[0].items->data, &temp); |
| 2187 | if (code) { |
| 2188 | fprintf(stderr__stderrp, "%s: bad integer specified for precache size.\n", |
| 2189 | pn); |
| 2190 | return 1; |
| 2191 | } |
| 2192 | } else |
| 2193 | temp = 0; |
| 2194 | blob.in = (char *)&temp; |
| 2195 | blob.in_size = sizeof(afs_int32); |
| 2196 | blob.out_size = 0; |
| 2197 | code = pioctl(0, VIOCPRECACHE((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((12))))), &blob, 1); |
| 2198 | if (code) { |
| 2199 | Die(errno(* __error()), NULL((void *)0)); |
| 2200 | return 1; |
| 2201 | } |
| 2202 | |
| 2203 | printf("New precache size set.\n"); |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
| 2207 | static int |
| 2208 | SetCacheSizeCmd(struct cmd_syndesc *as, void *arock) |
| 2209 | { |
| 2210 | afs_int32 code; |
| 2211 | struct ViceIoctl blob; |
| 2212 | afs_int32 temp; |
| 2213 | |
| 2214 | if (!as->parms[0].items && !as->parms[1].items) { |
| 2215 | fprintf(stderr__stderrp, "%s: syntax error in setcachesize cmd.\n", pn); |
| 2216 | return 1; |
| 2217 | } |
| 2218 | if (as->parms[0].items) { |
| 2219 | code = util_GetHumanInt32(as->parms[0].items->data, &temp); |
| 2220 | if (code) { |
| 2221 | fprintf(stderr__stderrp, "%s: bad integer specified for cache size.\n", |
| 2222 | pn); |
| 2223 | return 1; |
| 2224 | } |
| 2225 | } else |
| 2226 | temp = 0; |
| 2227 | blob.in = (char *)&temp; |
| 2228 | blob.in_size = sizeof(afs_int32); |
| 2229 | blob.out_size = 0; |
| 2230 | code = pioctl(0, VIOCSETCACHESIZE((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((24))))), &blob, 1); |
| 2231 | if (code) { |
| 2232 | if (errno(* __error()) == EROFS30) { |
| 2233 | printf |
| 2234 | ("'fs setcache' not allowed on memory cache based cache managers.\n"); |
| 2235 | } else { |
| 2236 | Die(errno(* __error()), NULL((void *)0)); |
| 2237 | } |
| 2238 | return 1; |
| 2239 | } |
| 2240 | |
| 2241 | printf("New cache size set.\n"); |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
| 2245 | #define MAXGCSIZE16 16 |
| 2246 | static int |
| 2247 | GetCacheParmsCmd(struct cmd_syndesc *as, void *arock) |
| 2248 | { |
| 2249 | afs_int32 code, filesUsed; |
| 2250 | struct ViceIoctl blob; |
| 2251 | afs_int32 parms[MAXGCSIZE16]; |
| 2252 | double percentFiles, percentBlocks; |
| 2253 | afs_int32 flags = 0; |
| 2254 | |
| 2255 | if (as->parms[0].items){ /* -files */ |
| 2256 | flags = 1; |
| 2257 | } else if (as->parms[1].items){ /* -excessive */ |
| 2258 | flags = 2; |
| 2259 | } else { |
| 2260 | flags = 0; |
| 2261 | } |
| 2262 | |
| 2263 | memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */ |
| 2264 | if (flags){ |
| 2265 | blob.in = (char *)&flags; |
| 2266 | blob.in_size = sizeof(afs_int32); |
| 2267 | } else { /* be backward compatible */ |
| 2268 | blob.in = NULL((void *)0); |
| 2269 | blob.in_size = 0; |
| 2270 | } |
| 2271 | blob.out_size = sizeof(parms); |
| 2272 | blob.out = (char *)parms; |
| 2273 | code = pioctl(0, VIOCGETCACHEPARMS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((40))))), &blob, 1); |
| 2274 | if (code) { |
| 2275 | Die(errno(* __error()), NULL((void *)0)); |
| 2276 | return 1; |
| 2277 | } |
| 2278 | |
| 2279 | if (!flags){ |
| 2280 | printf("AFS using %d of the cache's available %d 1K byte blocks.\n", |
| 2281 | parms[1], parms[0]); |
| 2282 | if (parms[1] > parms[0]) |
| 2283 | printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n"); |
| 2284 | return 0; |
| 2285 | } |
| 2286 | |
| 2287 | percentBlocks = ((double)parms[1]/parms[0]) * 100; |
| 2288 | printf("AFS using %5.0f%% of cache blocks (%d of %d 1k blocks)\n", |
| 2289 | percentBlocks, parms[1], parms[0]); |
| 2290 | |
| 2291 | if (parms[2] == 0) |
| 2292 | return 0; |
| 2293 | |
| 2294 | filesUsed = parms[2] - parms[3]; |
| 2295 | percentFiles = ((double)filesUsed/parms[2]) * 100; |
| 2296 | printf(" %5.0f%% of the cache files (%d of %d files)\n", |
| 2297 | percentFiles, filesUsed, parms[2]); |
| 2298 | if (flags == 2){ |
| 2299 | printf(" afs_cacheFiles: %10d\n", parms[2]); |
| 2300 | printf(" IFFree: %10d\n", parms[3]); |
| 2301 | printf(" IFEverUsed: %10d\n", parms[4]); |
| 2302 | printf(" IFDataMod: %10d\n", parms[5]); |
| 2303 | printf(" IFDirtyPages: %10d\n", parms[6]); |
| 2304 | printf(" IFAnyPages: %10d\n", parms[7]); |
| 2305 | printf(" IFDiscarded: %10d\n", parms[8]); |
| 2306 | printf(" DCentries: %10d\n", parms[9]); |
| 2307 | printf(" 0k- 4K: %10d\n", parms[10]); |
| 2308 | printf(" 4k- 16k: %10d\n", parms[11]); |
| 2309 | printf(" 16k- 64k: %10d\n", parms[12]); |
| 2310 | printf(" 64k- 256k: %10d\n", parms[13]); |
| 2311 | printf(" 256k- 1M: %10d\n", parms[14]); |
| 2312 | printf(" >=1M: %10d\n", parms[15]); |
| 2313 | } |
| 2314 | |
| 2315 | if (percentBlocks > 90) |
| 2316 | printf("[cache size usage over 90%%, consider increasing cache size]\n"); |
| 2317 | if (percentFiles > 90) |
| 2318 | printf("[cache file usage over 90%%, consider increasing '-files' argument to afsd]\n"); |
| 2319 | |
| 2320 | return 0; |
| 2321 | } |
| 2322 | |
| 2323 | static int |
| 2324 | ListCellsCmd(struct cmd_syndesc *as, void *arock) |
| 2325 | { |
| 2326 | afs_int32 code; |
| 2327 | afs_int32 i, j; |
| 2328 | char *tp; |
| 2329 | struct ViceIoctl blob; |
| 2330 | int resolve; |
| 2331 | |
| 2332 | resolve = !(as->parms[0].items); /* -numeric */ |
| 2333 | |
| 2334 | for (i = 0;; i++) { |
| 2335 | tp = space; |
| 2336 | memcpy(tp, &i, sizeof(afs_int32)); |
| 2337 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2338 | blob.in_size = sizeof(afs_int32); |
| 2339 | blob.in = space; |
| 2340 | blob.out = space; |
| 2341 | code = pioctl(0, VIOCGETCELL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((27))))), &blob, 1); |
| 2342 | if (code < 0) { |
| 2343 | if (errno(* __error()) == EDOM33) |
| 2344 | break; /* done with the list */ |
| 2345 | Die(errno(* __error()), 0); |
| 2346 | return 1; |
| 2347 | } |
| 2348 | tp = space; |
| 2349 | printf("Cell %s on hosts", tp + AFS_MAXCELLHOSTS8 * sizeof(afs_int32)); |
| 2350 | for (j = 0; j < AFS_MAXCELLHOSTS8; j++) { |
| 2351 | afs_int32 addr; |
| 2352 | char *name, tbuffer[20]; |
| 2353 | |
| 2354 | memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32)); |
| 2355 | if (addr == 0) |
| 2356 | break; |
| 2357 | |
| 2358 | if (resolve) { |
| 2359 | name = hostutil_GetNameByINet(addr); |
| 2360 | } else { |
| 2361 | addr = ntohl(addr)(__builtin_constant_p(addr) ? ((((__uint32_t)(addr)) >> 24) | ((((__uint32_t)(addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(addr)) & (0xff << 8)) << 8) | (((__uint32_t)(addr)) << 24)) : __bswap32_var(addr )); |
| 2362 | sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, |
| 2363 | (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); |
| 2364 | name = tbuffer; |
| 2365 | } |
| 2366 | printf(" %s", name); |
| 2367 | } |
| 2368 | printf(".\n"); |
| 2369 | } |
| 2370 | return 0; |
| 2371 | } |
| 2372 | |
| 2373 | static int |
| 2374 | ListAliasesCmd(struct cmd_syndesc *as, void *arock) |
| 2375 | { |
| 2376 | afs_int32 code, i; |
| 2377 | char *tp, *aliasName, *realName; |
| 2378 | struct ViceIoctl blob; |
| 2379 | |
| 2380 | for (i = 0;; i++) { |
| 2381 | tp = space; |
| 2382 | memcpy(tp, &i, sizeof(afs_int32)); |
| 2383 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2384 | blob.in_size = sizeof(afs_int32); |
| 2385 | blob.in = space; |
| 2386 | blob.out = space; |
| 2387 | code = pioctl(0, VIOC_GETALIAS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((2))))), &blob, 1); |
| 2388 | if (code < 0) { |
| 2389 | if (errno(* __error()) == EDOM33) |
| 2390 | break; /* done with the list */ |
| 2391 | Die(errno(* __error()), 0); |
| 2392 | return 1; |
| 2393 | } |
| 2394 | tp = space; |
| 2395 | aliasName = tp; |
| 2396 | tp += strlen(aliasName) + 1; |
| 2397 | realName = tp; |
| 2398 | printf("Alias %s for cell %s\n", aliasName, realName); |
| 2399 | } |
| 2400 | return 0; |
| 2401 | } |
| 2402 | |
| 2403 | static int |
| 2404 | CallBackRxConnCmd(struct cmd_syndesc *as, void *arock) |
| 2405 | { |
| 2406 | afs_int32 code; |
| 2407 | struct ViceIoctl blob; |
| 2408 | struct cmd_item *ti; |
| 2409 | afs_int32 hostAddr; |
| 2410 | struct hostent *thp; |
| 2411 | |
| 2412 | ti = as->parms[0].items; |
| 2413 | if (ti) { |
| 2414 | thp = hostutil_GetHostByName(ti->data); |
| 2415 | if (!thp) { |
| 2416 | fprintf(stderr__stderrp, "host %s not found in host table.\n", ti->data); |
| 2417 | return 1; |
| 2418 | } |
| 2419 | else memcpy(&hostAddr, thp->h_addrh_addr_list[0], sizeof(afs_int32)); |
| 2420 | } else { |
| 2421 | hostAddr = 0; /* means don't set host */ |
| 2422 | } |
| 2423 | |
| 2424 | /* now do operation */ |
| 2425 | blob.in_size = sizeof(afs_int32); |
| 2426 | blob.out_size = sizeof(afs_int32); |
| 2427 | blob.in = (char *) &hostAddr; |
| 2428 | blob.out = (char *) &hostAddr; |
| 2429 | |
| 2430 | code = pioctl(0, VIOC_CBADDR((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((3))))), &blob, 1); |
| 2431 | if (code < 0) { |
| 2432 | Die(errno(* __error()), 0); |
| 2433 | return 1; |
| 2434 | } |
| 2435 | return 0; |
| 2436 | } |
| 2437 | |
| 2438 | static int |
| 2439 | NukeNFSCredsCmd(struct cmd_syndesc *as, void *arock) |
| 2440 | { |
| 2441 | afs_int32 code; |
| 2442 | struct ViceIoctl blob; |
| 2443 | struct cmd_item *ti; |
| 2444 | afs_int32 hostAddr; |
| 2445 | struct hostent *thp; |
| 2446 | |
| 2447 | ti = as->parms[0].items; |
| 2448 | thp = hostutil_GetHostByName(ti->data); |
| 2449 | if (!thp) { |
| 2450 | fprintf(stderr__stderrp, "host %s not found in host table.\n", ti->data); |
| 2451 | return 1; |
| 2452 | } |
| 2453 | else memcpy(&hostAddr, thp->h_addrh_addr_list[0], sizeof(afs_int32)); |
| 2454 | |
| 2455 | /* now do operation */ |
| 2456 | blob.in_size = sizeof(afs_int32); |
| 2457 | blob.out_size = sizeof(afs_int32); |
| 2458 | blob.in = (char *) &hostAddr; |
| 2459 | blob.out = (char *) &hostAddr; |
| 2460 | |
| 2461 | code = pioctl(0, VIOC_NFS_NUKE_CREDS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('O' )) << 8) | ((1))))), &blob, 1); |
| 2462 | if (code < 0) { |
| 2463 | Die(errno(* __error()), 0); |
| 2464 | return 1; |
| 2465 | } |
| 2466 | return 0; |
| 2467 | } |
| 2468 | |
| 2469 | static int |
| 2470 | NewCellCmd(struct cmd_syndesc *as, void *arock) |
| 2471 | { |
| 2472 | afs_int32 code, linkedstate = 0, size = 0, *lp; |
| 2473 | struct ViceIoctl blob; |
| 2474 | struct cmd_item *ti; |
| 2475 | char *tp, *cellname = 0; |
| 2476 | struct hostent *thp; |
| 2477 | afs_int32 fsport = 0, vlport = 0; |
| 2478 | afs_int32 scount; /* Number of servers to pass in pioctl call */ |
| 2479 | |
| 2480 | /* Yuck! |
| 2481 | * With the NEWCELL pioctl call, 3.4 clients take an array of |
| 2482 | * AFS_MAXHOSTS (13) servers while 3.5 clients take an array of |
| 2483 | * AFS_MAXCELLHOSTS (8) servers. To determine which we are talking to, |
| 2484 | * do a GETCELL pioctl and pass it a magic number. If an array of |
| 2485 | * 8 comes back, its a 3.5 client. If not, its a 3.4 client. |
| 2486 | * If we get back EDOM, there are no cells in the kernel yet, |
| 2487 | * and we'll assume a 3.5 client. |
| 2488 | */ |
| 2489 | tp = space; |
| 2490 | lp = (afs_int32 *) tp; |
| 2491 | *lp++ = 0; /* first cell entry */ |
| 2492 | *lp = 0x12345678; /* magic */ |
| 2493 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2494 | blob.in_size = sizeof(afs_int32) + sizeof(afs_int32); |
| 2495 | blob.in = space; |
| 2496 | blob.out = space; |
| 2497 | code = pioctl(0, VIOCGETCELL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((27))))), &blob, 1); |
| 2498 | if (code < 0 && errno(* __error()) != EDOM33) { |
| 2499 | Die(errno(* __error()), 0); |
| 2500 | return 1; |
| 2501 | } |
| 2502 | if (code < 1 && errno(* __error()) == EDOM33) { |
| 2503 | scount = AFS_MAXHOSTS13; |
| 2504 | } else { |
| 2505 | tp = space; |
| 2506 | cellname = tp + AFS_MAXCELLHOSTS8 * sizeof(afs_int32); |
| 2507 | scount = ((cellname[0] != '\0') ? AFS_MAXCELLHOSTS8 : AFS_MAXHOSTS13); |
| 2508 | } |
| 2509 | |
| 2510 | /* Now setup and do the NEWCELL pioctl call */ |
| 2511 | memset(space, 0, (scount + 1) * sizeof(afs_int32)); |
| 2512 | tp = space; |
| 2513 | lp = (afs_int32 *) tp; |
| 2514 | *lp++ = 0x12345678; |
| 2515 | tp += sizeof(afs_int32); |
| 2516 | for (ti = as->parms[1].items; ti; ti = ti->next) { |
| 2517 | thp = hostutil_GetHostByName(ti->data); |
| 2518 | if (!thp) { |
| 2519 | fprintf(stderr__stderrp, |
| 2520 | "%s: Host %s not found in host table, skipping it.\n", pn, |
| 2521 | ti->data); |
| 2522 | } else { |
| 2523 | memcpy(tp, thp->h_addrh_addr_list[0], sizeof(afs_int32)); |
| 2524 | tp += sizeof(afs_int32); |
| 2525 | } |
| 2526 | } |
| 2527 | if (as->parms[2].items) { |
| 2528 | /* |
| 2529 | * Link the cell, for the purposes of volume location, to the specified |
| 2530 | * cell. |
| 2531 | */ |
| 2532 | cellname = as->parms[2].items->data; |
| 2533 | linkedstate = 1; |
| 2534 | } |
| 2535 | #ifdef FS_ENABLE_SERVER_DEBUG_PORTS |
| 2536 | if (as->parms[3].items) { |
| 2537 | code = util_GetInt32(as->parms[3].items->data, &vlport); |
| 2538 | if (code) { |
| 2539 | fprintf(stderr__stderrp, |
| 2540 | "%s: bad integer specified for the fileserver port.\n", |
| 2541 | pn); |
| 2542 | return 1; |
| 2543 | } |
| 2544 | } |
| 2545 | if (as->parms[4].items) { |
| 2546 | code = util_GetInt32(as->parms[4].items->data, &fsport); |
| 2547 | if (code) { |
| 2548 | fprintf(stderr__stderrp, |
| 2549 | "%s: bad integer specified for the vldb server port.\n", |
| 2550 | pn); |
| 2551 | return 1; |
| 2552 | } |
| 2553 | } |
| 2554 | #endif |
| 2555 | tp = (char *)(space + (scount + 1) * sizeof(afs_int32)); |
| 2556 | lp = (afs_int32 *) tp; |
| 2557 | *lp++ = fsport; |
| 2558 | *lp++ = vlport; |
| 2559 | *lp = linkedstate; |
| 2560 | strcpy(space + ((scount + 4) * sizeof(afs_int32)), |
| 2561 | as->parms[0].items->data); |
| 2562 | size = ((scount + 4) * sizeof(afs_int32)) |
| 2563 | + strlen(as->parms[0].items->data) |
| 2564 | + 1 /* for null */ ; |
| 2565 | tp = (char *)(space + size); |
| 2566 | if (linkedstate) { |
| 2567 | strcpy(tp, cellname); |
| 2568 | size += strlen(cellname) + 1; |
| 2569 | } |
| 2570 | blob.in_size = size; |
| 2571 | blob.in = space; |
| 2572 | blob.out_size = 0; |
| 2573 | code = pioctl(0, VIOCNEWCELL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((26))))), &blob, 1); |
| 2574 | if (code < 0) { |
| 2575 | Die(errno(* __error()), 0); |
| 2576 | return 1; |
| 2577 | } |
| 2578 | return 0; |
| 2579 | } |
| 2580 | |
| 2581 | static int |
| 2582 | NewAliasCmd(struct cmd_syndesc *as, void *arock) |
| 2583 | { |
| 2584 | afs_int32 code; |
| 2585 | struct ViceIoctl blob; |
| 2586 | char *tp; |
| 2587 | char *aliasName, *realName; |
| 2588 | |
| 2589 | /* Now setup and do the NEWCELL pioctl call */ |
| 2590 | aliasName = as->parms[0].items->data; |
| 2591 | realName = as->parms[1].items->data; |
| 2592 | tp = space; |
| 2593 | strcpy(tp, aliasName); |
| 2594 | tp += strlen(aliasName) + 1; |
| 2595 | strcpy(tp, realName); |
| 2596 | tp += strlen(realName) + 1; |
| 2597 | |
| 2598 | blob.in_size = tp - space; |
| 2599 | blob.in = space; |
| 2600 | blob.out_size = 0; |
| 2601 | blob.out = space; |
| 2602 | code = pioctl(0, VIOC_NEWALIAS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((1))))), &blob, 1); |
| 2603 | if (code < 0) { |
| 2604 | if (errno(* __error()) == EEXIST17) { |
| 2605 | fprintf(stderr__stderrp, |
| 2606 | "%s: cell name `%s' in use by an existing cell.\n", pn, |
| 2607 | aliasName); |
| 2608 | } else { |
| 2609 | Die(errno(* __error()), 0); |
| 2610 | } |
| 2611 | return 1; |
| 2612 | } |
| 2613 | return 0; |
| 2614 | } |
| 2615 | |
| 2616 | static int |
| 2617 | WhichCellCmd(struct cmd_syndesc *as, void *arock) |
| 2618 | { |
| 2619 | afs_int32 code; |
| 2620 | struct cmd_item *ti; |
| 2621 | int error = 0; |
| 2622 | char cell[MAXCELLCHARS64]; |
| 2623 | |
| 2624 | SetDotDefault(&as->parms[0].items); |
| 2625 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 2626 | code = GetCell(ti->data, cell); |
| 2627 | if (code) { |
| 2628 | if (errno(* __error()) == ENOENT2) |
| 2629 | fprintf(stderr__stderrp, "%s: no such cell as '%s'\n", pn, ti->data); |
| 2630 | else |
| 2631 | Die(errno(* __error()), ti->data); |
| 2632 | error = 1; |
| 2633 | continue; |
| 2634 | } |
| 2635 | |
| 2636 | printf("File %s lives in cell '%s'\n", ti->data, cell); |
| 2637 | } |
| 2638 | return error; |
| 2639 | } |
| 2640 | |
| 2641 | static int |
| 2642 | WSCellCmd(struct cmd_syndesc *as, void *arock) |
| 2643 | { |
| 2644 | afs_int32 code; |
| 2645 | struct ViceIoctl blob; |
| 2646 | |
| 2647 | blob.in_size = 0; |
| 2648 | blob.in = NULL((void *)0); |
| 2649 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2650 | blob.out = space; |
| 2651 | |
| 2652 | code = pioctl(NULL((void *)0), VIOC_GET_WS_CELL((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((31))))), &blob, 1); |
| 2653 | if (code) { |
| 2654 | Die(errno(* __error()), NULL((void *)0)); |
| 2655 | return 1; |
| 2656 | } |
| 2657 | |
| 2658 | printf("This workstation belongs to cell '%s'\n", space); |
| 2659 | return 0; |
| 2660 | } |
| 2661 | |
| 2662 | /* |
| 2663 | static PrimaryCellCmd(as) |
| 2664 | struct cmd_syndesc *as; |
| 2665 | { |
| 2666 | fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n"); |
| 2667 | return 0; |
| 2668 | } |
| 2669 | */ |
| 2670 | |
| 2671 | static int |
| 2672 | MonitorCmd(struct cmd_syndesc *as, void *arock) |
| 2673 | { |
| 2674 | afs_int32 code; |
| 2675 | struct ViceIoctl blob; |
| 2676 | struct cmd_item *ti; |
| 2677 | afs_int32 hostAddr; |
| 2678 | struct hostent *thp; |
| 2679 | char *tp; |
| 2680 | int setp; |
| 2681 | |
| 2682 | ti = as->parms[0].items; |
| 2683 | setp = 1; |
| 2684 | if (ti) { |
| 2685 | /* set the host */ |
| 2686 | if (!strcmp(ti->data, "off")) |
| 2687 | hostAddr = 0xffffffff; |
| 2688 | else { |
| 2689 | thp = hostutil_GetHostByName(ti->data); |
| 2690 | if (!thp) { |
| 2691 | if (!strcmp(ti->data, "localhost")) { |
| 2692 | fprintf(stderr__stderrp, |
| 2693 | "localhost not in host table, assuming 127.0.0.1\n"); |
| 2694 | hostAddr = htonl(0x7f000001)(__builtin_constant_p(0x7f000001) ? ((((__uint32_t)(0x7f000001 )) >> 24) | ((((__uint32_t)(0x7f000001)) & (0xff << 16)) >> 8) | ((((__uint32_t)(0x7f000001)) & (0xff << 8)) << 8) | (((__uint32_t)(0x7f000001)) << 24)) : __bswap32_var(0x7f000001)); |
| 2695 | } else { |
| 2696 | fprintf(stderr__stderrp, "host %s not found in host table.\n", |
| 2697 | ti->data); |
| 2698 | return 1; |
| 2699 | } |
| 2700 | } else |
| 2701 | memcpy(&hostAddr, thp->h_addrh_addr_list[0], sizeof(afs_int32)); |
| 2702 | } |
| 2703 | } else { |
| 2704 | hostAddr = 0; /* means don't set host */ |
| 2705 | setp = 0; /* aren't setting host */ |
| 2706 | } |
| 2707 | |
| 2708 | /* now do operation */ |
| 2709 | blob.in_size = sizeof(afs_int32); |
| 2710 | blob.out_size = sizeof(afs_int32); |
| 2711 | blob.in = (char *)&hostAddr; |
| 2712 | blob.out = (char *)&hostAddr; |
| 2713 | code = pioctl(0, VIOC_AFS_MARINER_HOST((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((32))))), &blob, 1); |
| 2714 | if (code) { |
| 2715 | Die(errno(* __error()), 0); |
| 2716 | return 1; |
| 2717 | } |
| 2718 | if (setp) { |
| 2719 | printf("%s: new monitor host set.\n", pn); |
| 2720 | } else { |
| 2721 | /* now decode old address */ |
| 2722 | if (hostAddr == 0xffffffff) { |
| 2723 | printf("Cache monitoring is currently disabled.\n"); |
| 2724 | } else { |
| 2725 | tp = hostutil_GetNameByINet(hostAddr); |
| 2726 | printf("Using host %s for monitor services.\n", tp); |
| 2727 | } |
| 2728 | } |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
| 2732 | static int |
| 2733 | SysNameCmd(struct cmd_syndesc *as, void *arock) |
| 2734 | { |
| 2735 | afs_int32 code; |
| 2736 | struct ViceIoctl blob; |
| 2737 | struct cmd_item *ti; |
| 2738 | char *input = space; |
| 2739 | afs_int32 setp = 0; |
| 2740 | |
| 2741 | ti = as->parms[0].items; |
| 2742 | blob.in = space; |
| 2743 | blob.out = space; |
| 2744 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 2745 | blob.in_size = sizeof(afs_int32); |
| 2746 | input += sizeof(afs_int32); |
| 2747 | for (; ti; ti = ti->next) { |
| 2748 | setp++; |
| 2749 | blob.in_size += strlen(ti->data) + 1; |
| 2750 | if (blob.in_size > AFS_PIOCTL_MAXSIZE2048) { |
| 2751 | fprintf(stderr__stderrp, "%s: sysname%s too long.\n", pn, |
| 2752 | setp > 1 ? "s" : ""); |
| 2753 | return 1; |
| 2754 | } |
| 2755 | strcpy(input, ti->data); |
| 2756 | input += strlen(ti->data); |
| 2757 | *(input++) = '\0'; |
| 2758 | } |
| 2759 | memcpy(space, &setp, sizeof(afs_int32)); |
| 2760 | code = pioctl(0, VIOC_AFS_SYSNAME((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((38))))), &blob, 1); |
| 2761 | if (code) { |
| 2762 | Die(errno(* __error()), 0); |
| 2763 | return 1; |
| 2764 | } |
| 2765 | if (setp) { |
| 2766 | printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : ""); |
| 2767 | return 0; |
| 2768 | } |
| 2769 | input = space; |
| 2770 | memcpy(&setp, input, sizeof(afs_int32)); |
| 2771 | input += sizeof(afs_int32); |
| 2772 | if (!setp) { |
| 2773 | fprintf(stderr__stderrp, "No sysname name value was found\n"); |
| 2774 | return 1; |
| 2775 | } |
| 2776 | printf("Current sysname%s is", setp > 1 ? " list" : ""); |
| 2777 | for (; setp > 0; --setp) { |
| 2778 | printf(" \'%s\'", input); |
| 2779 | input += strlen(input) + 1; |
| 2780 | } |
| 2781 | printf("\n"); |
| 2782 | return 0; |
| 2783 | } |
| 2784 | |
| 2785 | static char *exported_types[] = { "null", "nfs", "" }; |
| 2786 | static int |
| 2787 | ExportAfsCmd(struct cmd_syndesc *as, void *arock) |
| 2788 | { |
| 2789 | afs_int32 code; |
| 2790 | struct ViceIoctl blob; |
| 2791 | struct cmd_item *ti; |
| 2792 | int export = 0, type = 0, mode = 0, exportcall, pwsync = |
| 2793 | 0, smounts = 0, clipags = 0, pagcb = 0; |
| 2794 | |
| 2795 | ti = as->parms[0].items; |
| 2796 | if (strcmp(ti->data, "nfs") == 0) |
| 2797 | type = 0x71; /* NFS */ |
| 2798 | else { |
| 2799 | fprintf(stderr__stderrp, |
| 2800 | "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", |
| 2801 | ti->data); |
| 2802 | return 1; |
| 2803 | } |
| 2804 | ti = as->parms[1].items; |
| 2805 | if (ti) { |
| 2806 | if (strcmp(ti->data, "on") == 0) |
| 2807 | export = 3; |
| 2808 | else if (strcmp(ti->data, "off") == 0) |
| 2809 | export = 2; |
| 2810 | else { |
| 2811 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2812 | return 1; |
| 2813 | } |
| 2814 | } |
| 2815 | if ((ti = as->parms[2].items)) { /* -noconvert */ |
| 2816 | if (strcmp(ti->data, "on") == 0) |
| 2817 | mode = 2; |
| 2818 | else if (strcmp(ti->data, "off") == 0) |
| 2819 | mode = 3; |
| 2820 | else { |
| 2821 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2822 | return 1; |
| 2823 | } |
| 2824 | } |
| 2825 | if ((ti = as->parms[3].items)) { /* -uidcheck */ |
| 2826 | if (strcmp(ti->data, "on") == 0) |
| 2827 | pwsync = 3; |
| 2828 | else if (strcmp(ti->data, "off") == 0) |
| 2829 | pwsync = 2; |
| 2830 | else { |
| 2831 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2832 | return 1; |
| 2833 | } |
| 2834 | } |
| 2835 | if ((ti = as->parms[4].items)) { /* -submounts */ |
| 2836 | if (strcmp(ti->data, "on") == 0) |
| 2837 | smounts = 3; |
| 2838 | else if (strcmp(ti->data, "off") == 0) |
| 2839 | smounts = 2; |
| 2840 | else { |
| 2841 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2842 | return 1; |
| 2843 | } |
| 2844 | } |
| 2845 | if ((ti = as->parms[5].items)) { /* -clipags */ |
| 2846 | if (strcmp(ti->data, "on") == 0) |
| 2847 | clipags = 3; |
| 2848 | else if (strcmp(ti->data, "off") == 0) |
| 2849 | clipags = 2; |
| 2850 | else { |
| 2851 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2852 | return 1; |
| 2853 | } |
| 2854 | } |
| 2855 | if ((ti = as->parms[6].items)) { /* -pagcb */ |
| 2856 | if (strcmp(ti->data, "on") == 0) |
| 2857 | pagcb = 3; |
| 2858 | else if (strcmp(ti->data, "off") == 0) |
| 2859 | pagcb = 2; |
| 2860 | else { |
| 2861 | fprintf(stderr__stderrp, "Illegal argument %s\n", ti->data); |
| 2862 | return 1; |
| 2863 | } |
| 2864 | } |
| 2865 | exportcall = |
| 2866 | (type << 24) | (pagcb << 10) | (clipags << 8) | |
| 2867 | (mode << 6) | (pwsync << 4) | (smounts << 2) | export; |
| 2868 | type &= ~0x70; |
| 2869 | /* make the call */ |
| 2870 | blob.in = (char *)&exportcall; |
| 2871 | blob.in_size = sizeof(afs_int32); |
| 2872 | blob.out = (char *)&exportcall; |
| 2873 | blob.out_size = sizeof(afs_int32); |
| 2874 | code = pioctl(0, VIOC_EXPORTAFS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((39))))), &blob, 1); |
| 2875 | if (code) { |
| 2876 | if (errno(* __error()) == ENODEV19) { |
| 2877 | fprintf(stderr__stderrp, |
| 2878 | "Sorry, the %s-exporter type is currently not supported on this AFS client\n", |
| 2879 | exported_types[type]); |
| 2880 | } else { |
| 2881 | Die(errno(* __error()), 0); |
| 2882 | } |
| 2883 | return 1; |
| 2884 | } |
| 2885 | |
| 2886 | if (exportcall & 1) { |
| 2887 | printf("'%s' translator is enabled with the following options:\n", |
| 2888 | exported_types[type]); |
| 2889 | printf("\tRunning in %s mode\n", |
| 2890 | (exportcall & 2 ? "strict unix" : |
| 2891 | "convert owner mode bits to world/other")); |
| 2892 | printf("\tRunning in %s mode\n", |
| 2893 | (exportcall & 4 ? "strict 'passwd sync'" : |
| 2894 | "no 'passwd sync'")); |
| 2895 | printf("\t%s\n", |
| 2896 | (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : |
| 2897 | "Only mounts to /afs allowed")); |
| 2898 | printf("\t%s\n", |
| 2899 | (exportcall & 16 ? "Client-assigned PAG's are used" : |
| 2900 | "Client-assigned PAG's are not used")); |
| 2901 | printf("\t%s\n", |
| 2902 | (exportcall & 32 ? |
| 2903 | "Callbacks are made to get creds from new clients" : |
| 2904 | "Callbacks are not made to get creds from new clients")); |
| 2905 | } else { |
| 2906 | printf("'%s' translator is disabled\n", exported_types[type]); |
| 2907 | } |
| 2908 | return 0; |
| 2909 | } |
| 2910 | |
| 2911 | |
| 2912 | static int |
| 2913 | GetCellCmd(struct cmd_syndesc *as, void *arock) |
| 2914 | { |
| 2915 | afs_int32 code; |
| 2916 | struct ViceIoctl blob; |
| 2917 | struct afsconf_cell info; |
| 2918 | struct cmd_item *ti; |
| 2919 | struct a { |
| 2920 | afs_int32 stat; |
| 2921 | afs_int32 junk; |
| 2922 | } args; |
| 2923 | int error = 0; |
| 2924 | |
| 2925 | memset(&args, '\0', sizeof args); /* avoid Purify UMR error */ |
| 2926 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 2927 | /* once per cell */ |
| 2928 | blob.out_size = sizeof(args); |
| 2929 | blob.out = (caddr_t) & args; |
| 2930 | code = GetCellName(ti->data, &info); |
| 2931 | if (code) { |
| 2932 | error = 1; |
| 2933 | continue; |
| 2934 | } |
| 2935 | blob.in_size = 1 + strlen(info.name); |
| 2936 | blob.in = info.name; |
| 2937 | code = pioctl(0, VIOC_GETCELLSTATUS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((35))))), &blob, 1); |
| 2938 | if (code) { |
| 2939 | if (errno(* __error()) == ENOENT2) |
| 2940 | fprintf(stderr__stderrp, "%s: the cell named '%s' does not exist\n", |
| 2941 | pn, info.name); |
| 2942 | else |
| 2943 | Die(errno(* __error()), info.name); |
| 2944 | error = 1; |
| 2945 | continue; |
| 2946 | } |
| 2947 | printf("Cell %s status: ", info.name); |
| 2948 | #ifdef notdef |
| 2949 | if (args.stat & 1) |
| 2950 | printf("primary "); |
| 2951 | #endif |
| 2952 | if (args.stat & 2) |
| 2953 | printf("no setuid allowed"); |
| 2954 | else |
| 2955 | printf("setuid allowed"); |
| 2956 | if (args.stat & 4) |
| 2957 | printf(", using old VLDB"); |
| 2958 | printf("\n"); |
| 2959 | } |
| 2960 | return error; |
| 2961 | } |
| 2962 | |
| 2963 | static int |
| 2964 | SetCellCmd(struct cmd_syndesc *as, void *arock) |
| 2965 | { |
| 2966 | afs_int32 code; |
| 2967 | struct ViceIoctl blob; |
| 2968 | struct afsconf_cell info; |
| 2969 | struct cmd_item *ti; |
| 2970 | struct a { |
| 2971 | afs_int32 stat; |
| 2972 | afs_int32 junk; |
| 2973 | char cname[64]; |
| 2974 | } args; |
| 2975 | int error = 0; |
| 2976 | |
| 2977 | /* Check arguments. */ |
| 2978 | if (as->parms[1].items && as->parms[2].items) { |
| 2979 | fprintf(stderr__stderrp, "Cannot specify both -suid and -nosuid.\n"); |
| 2980 | return 1; |
| 2981 | } |
| 2982 | |
| 2983 | /* figure stuff to set */ |
| 2984 | args.stat = 0; |
| 2985 | args.junk = 0; |
| 2986 | |
| 2987 | if (!as->parms[1].items) |
| 2988 | args.stat |= 2; /* default to -nosuid */ |
| 2989 | |
| 2990 | /* set stat for all listed cells */ |
| 2991 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 2992 | /* once per cell */ |
| 2993 | code = GetCellName(ti->data, &info); |
| 2994 | if (code) { |
| 2995 | error = 1; |
| 2996 | continue; |
| 2997 | } |
| 2998 | strcpy(args.cname, info.name); |
| 2999 | blob.in_size = sizeof(args); |
| 3000 | blob.in = (caddr_t) & args; |
| 3001 | blob.out_size = 0; |
| 3002 | blob.out = (caddr_t) 0; |
| 3003 | code = pioctl(0, VIOC_SETCELLSTATUS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((36))))), &blob, 1); |
| 3004 | if (code) { |
| 3005 | Die(errno(* __error()), info.name); /* XXX added cell name to Die() call */ |
| 3006 | error = 1; |
| 3007 | } |
| 3008 | } |
| 3009 | return error; |
| 3010 | } |
| 3011 | |
| 3012 | static int |
| 3013 | GetCellName(char *cellName, struct afsconf_cell *info) |
| 3014 | { |
| 3015 | struct afsconf_dir *tdir; |
| 3016 | int code; |
| 3017 | |
| 3018 | tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID)); |
| 3019 | if (!tdir) { |
| 3020 | fprintf(stderr__stderrp, |
| 3021 | "Could not process files in configuration directory (%s).\n", |
| 3022 | AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID)); |
| 3023 | return -1; |
| 3024 | } |
| 3025 | |
| 3026 | code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE"afsvldb", info); |
| 3027 | if (code) { |
| 3028 | fprintf(stderr__stderrp, "%s: cell %s not in %s\n", pn, cellName, |
| 3029 | AFSDIR_CLIENT_CELLSERVDB_FILEPATHgetDirPath(AFSDIR_CLIENT_CELLSERVDB_FILEPATH_ID)); |
| 3030 | return code; |
| 3031 | } |
| 3032 | |
| 3033 | return 0; |
| 3034 | } |
| 3035 | |
| 3036 | |
| 3037 | static int |
| 3038 | VLDBInit(int noAuthFlag, struct afsconf_cell *info) |
| 3039 | { |
| 3040 | afs_int32 code; |
| 3041 | |
| 3042 | code = ugen_ClientInit(noAuthFlag, (char *) AFSDIR_CLIENT_ETC_DIRPATHgetDirPath(AFSDIR_CLIENT_ETC_DIRPATH_ID), |
| 3043 | info->name, 0, &uclient, |
| 3044 | NULL((void *)0), pn, rxkad_clear0, |
| 3045 | VLDB_MAXSERVERS10, AFSCONF_VLDBSERVICE"afsvldb", 50, |
| 3046 | 0, 0, USER_SERVICE_ID52); |
| 3047 | rxInitDone = 1; |
| 3048 | return code; |
| 3049 | } |
| 3050 | |
| 3051 | static struct ViceIoctl gblob; |
| 3052 | static int debug = 0; |
| 3053 | /* |
| 3054 | * here follow some routines in suport of the setserverprefs and |
| 3055 | * getserverprefs commands. They are: |
| 3056 | * SetPrefCmd "top-level" routine |
| 3057 | * addServer adds a server to the list of servers to be poked into the |
| 3058 | * kernel. Will poke the list into the kernel if it threatens |
| 3059 | * to get too large. |
| 3060 | * pokeServers pokes the existing list of servers and ranks into the kernel |
| 3061 | * GetPrefCmd reads the Cache Manager's current list of server ranks |
| 3062 | */ |
| 3063 | |
| 3064 | /* |
| 3065 | * returns -1 if error message printed, |
| 3066 | * 0 on success, |
| 3067 | * errno value if error and no error message printed |
| 3068 | */ |
| 3069 | static int |
| 3070 | pokeServers(void) |
| 3071 | { |
| 3072 | int code; |
| 3073 | |
| 3074 | code = pioctl(0, VIOC_SETSPREFS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((46))))), &gblob, 1); |
| 3075 | if (code && (errno(* __error()) == EINVAL22)) { |
| 3076 | struct setspref *ssp; |
| 3077 | ssp = (struct setspref *)gblob.in; |
| 3078 | if (!(ssp->flags & DBservers1)) { |
| 3079 | gblob.in = (void *)&(ssp->servers[0]); |
| 3080 | gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp; |
| 3081 | code = pioctl(0, VIOC_SETSPREFS33((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((42))))), &gblob, 1); |
| 3082 | return code ? errno(* __error()) : 0; |
| 3083 | } |
| 3084 | fprintf(stderr__stderrp, |
| 3085 | "This cache manager does not support VL server preferences.\n"); |
| 3086 | return -1; |
| 3087 | } |
| 3088 | |
| 3089 | return code ? errno(* __error()) : 0; |
| 3090 | } |
| 3091 | |
| 3092 | /* |
| 3093 | * returns -1 if error message printed, |
| 3094 | * 0 on success, |
| 3095 | * errno value if error and no error message printed |
| 3096 | */ |
| 3097 | static int |
| 3098 | addServer(char *name, afs_int32 rank) |
| 3099 | { |
| 3100 | int t, code; |
| 3101 | struct setspref *ssp; |
| 3102 | struct spref *sp; |
| 3103 | struct hostent *thostent; |
| 3104 | int error = 0; |
| 3105 | |
| 3106 | #ifndef MAXUSHORT((unsigned short) ~0) |
| 3107 | #ifdef MAXSHORT |
| 3108 | #define MAXUSHORT((unsigned short) ~0) ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */ |
| 3109 | #else |
| 3110 | #define MAXUSHORT((unsigned short) ~0) ((unsigned short) ~0) |
| 3111 | #endif |
| 3112 | #endif |
| 3113 | |
| 3114 | thostent = hostutil_GetHostByName(name); |
| 3115 | if (!thostent) { |
| 3116 | fprintf(stderr__stderrp, "%s: couldn't resolve name.\n", name); |
| 3117 | return -1; |
| 3118 | } |
| 3119 | |
| 3120 | ssp = (struct setspref *)(gblob.in); |
| 3121 | |
| 3122 | for (t = 0; thostent->h_addr_list[t]; t++) { |
| 3123 | if (gblob.in_size > MAXINSIZE1300 - sizeof(struct spref)) { |
| 3124 | code = pokeServers(); |
| 3125 | if (code) |
| 3126 | error = code; |
| 3127 | ssp->num_servers = 0; |
| 3128 | } |
| 3129 | |
| 3130 | sp = (struct spref *)(gblob.in + gblob.in_size); |
| 3131 | memcpy(&(sp->server.s_addr), thostent->h_addr_list[t], |
| 3132 | sizeof(afs_uint32)); |
| 3133 | sp->rank = (rank > MAXUSHORT((unsigned short) ~0) ? MAXUSHORT((unsigned short) ~0) : rank); |
| 3134 | gblob.in_size += sizeof(struct spref); |
| 3135 | ssp->num_servers++; |
| 3136 | |
| 3137 | if (debug) |
| 3138 | fprintf(stderr__stderrp, "adding server %s, rank %d, ip addr 0x%lx\n", |
| 3139 | name, sp->rank, (long unsigned int) sp->server.s_addr); |
| 3140 | } |
| 3141 | |
| 3142 | return error; |
| 3143 | } |
| 3144 | |
| 3145 | |
| 3146 | static int |
| 3147 | SetPrefCmd(struct cmd_syndesc *as, void *arock) |
| 3148 | { |
| 3149 | FILE *infd; |
| 3150 | afs_int32 code; |
| 3151 | struct cmd_item *ti; |
| 3152 | char name[80]; |
| 3153 | afs_int32 rank; |
| 3154 | struct setspref *ssp; |
| 3155 | int error = 0; /* -1 means error message printed, |
| 3156 | * >0 means errno value for unprinted message */ |
| 3157 | |
| 3158 | ssp = (struct setspref *)space; |
| 3159 | ssp->flags = 0; |
| 3160 | ssp->num_servers = 0; |
| 3161 | gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; |
| 3162 | gblob.in = space; |
| 3163 | gblob.out = space; |
| 3164 | gblob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 3165 | |
| 3166 | |
| 3167 | if (geteuid()) { |
| 3168 | fprintf(stderr__stderrp, "Permission denied: requires root access.\n"); |
| 3169 | return 1; |
| 3170 | } |
| 3171 | |
| 3172 | ti = as->parms[2].items; /* -file */ |
| 3173 | if (ti) { |
| 3174 | if (debug) |
| 3175 | fprintf(stderr__stderrp, "opening file %s\n", ti->data); |
| 3176 | if (!(infd = fopen(ti->data, "r"))) { |
| 3177 | perror(ti->data); |
| 3178 | error = -1; |
| 3179 | } else { |
| 3180 | while (fscanf(infd, "%79s%ld", name, (long int *)&rank) != EOF(-1)) { |
| 3181 | code = addServer(name, (unsigned short)rank); |
| 3182 | if (code) |
| 3183 | error = code; |
| 3184 | } |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | ti = as->parms[3].items; /* -stdin */ |
| 3189 | if (ti) { |
| 3190 | while (scanf("%79s%ld", name, (long int *)&rank) != EOF(-1)) { |
| 3191 | code = addServer(name, (unsigned short)rank); |
| 3192 | if (code) |
| 3193 | error = code; |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */ |
| 3198 | if (ti) { |
| 3199 | if (!ti->next) { |
| 3200 | break; |
| 3201 | } |
| 3202 | code = addServer(ti->data, (unsigned short)atol(ti->next->data)); |
| 3203 | if (code) |
| 3204 | error = code; |
| 3205 | if (debug) |
| 3206 | printf("set fs prefs %s %s\n", ti->data, ti->next->data); |
| 3207 | ti = ti->next; |
| 3208 | } |
| 3209 | } |
| 3210 | code = pokeServers(); |
| 3211 | if (code) |
| 3212 | error = code; |
| 3213 | if (debug) |
| 3214 | printf("now working on vlservers, code=%d\n", code); |
| 3215 | |
| 3216 | ssp = (struct setspref *)space; |
| 3217 | ssp->flags = DBservers1; |
| 3218 | ssp->num_servers = 0; |
| 3219 | gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp; |
| 3220 | gblob.in = space; |
| 3221 | |
| 3222 | for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */ |
| 3223 | if (ti) { |
| 3224 | if (!ti->next) { |
| 3225 | break; |
| 3226 | } |
| 3227 | code = addServer(ti->data, (unsigned short)atol(ti->next->data)); |
| 3228 | if (code) |
| 3229 | error = code; |
| 3230 | if (debug) |
| 3231 | printf("set vl prefs %s %s\n", ti->data, ti->next->data); |
| 3232 | ti = ti->next; |
| 3233 | } |
| 3234 | } |
| 3235 | |
| 3236 | if (as->parms[1].items) { |
| 3237 | if (debug) |
| 3238 | printf("now poking vlservers\n"); |
| 3239 | code = pokeServers(); |
| 3240 | if (code) |
| 3241 | error = code; |
| 3242 | } |
| 3243 | |
| 3244 | if (error > 0) |
| 3245 | Die(error, 0); |
| 3246 | |
| 3247 | return error ? 1 : 0; |
| 3248 | } |
| 3249 | |
| 3250 | |
| 3251 | |
| 3252 | static int |
| 3253 | GetPrefCmd(struct cmd_syndesc *as, void *arock) |
| 3254 | { |
| 3255 | afs_int32 code; |
| 3256 | struct cmd_item *ti; |
| 3257 | char *name, tbuffer[20]; |
| 3258 | afs_int32 addr; |
| 3259 | FILE *outfd; |
| 3260 | int resolve; |
| 3261 | int vlservers = 0; |
| 3262 | struct ViceIoctl blob; |
| 3263 | struct sprefrequest *in; |
| 3264 | struct sprefinfo *out; |
| 3265 | int i; |
| 3266 | |
| 3267 | ti = as->parms[0].items; /* -file */ |
| 3268 | if (ti) { |
| 3269 | if (debug) |
| 3270 | fprintf(stderr__stderrp, "opening file %s\n", ti->data); |
| 3271 | if (!(outfd = freopen(ti->data, "w", stdout__stdoutp))) { |
| 3272 | perror(ti->data); |
| 3273 | return 1; |
| 3274 | } |
| 3275 | } |
| 3276 | |
| 3277 | ti = as->parms[1].items; /* -numeric */ |
| 3278 | resolve = !(ti); |
| 3279 | ti = as->parms[2].items; /* -vlservers */ |
| 3280 | vlservers |= (ti ? DBservers1 : 0); |
| 3281 | /* ti = as->parms[3].items; -cell */ |
| 3282 | |
| 3283 | in = (struct sprefrequest *)space; |
| 3284 | in->offset = 0; |
| 3285 | |
| 3286 | do { |
| 3287 | blob.in_size = sizeof(struct sprefrequest); |
| 3288 | blob.in = (char *)in; |
| 3289 | blob.out = space; |
| 3290 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 3291 | |
| 3292 | in->num_servers = |
| 3293 | (AFS_PIOCTL_MAXSIZE2048 - 2 * sizeof(short)) / sizeof(struct spref); |
| 3294 | in->flags = vlservers; |
| 3295 | |
| 3296 | do { |
| 3297 | code = pioctl(0, VIOC_GETSPREFS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((43))))), &blob, 1); |
| 3298 | if (code) { |
| 3299 | if ((errno(* __error()) != E2BIG7) || (2 * blob.out_size > 0x7FFF)) { |
| 3300 | perror("getserverprefs pioctl"); |
| 3301 | return 1; |
| 3302 | } |
| 3303 | blob.out_size *= 2; |
| 3304 | if (blob.out == space) |
| 3305 | blob.out = malloc(blob.out_size); |
| 3306 | else |
| 3307 | blob.out = realloc(blob.out, blob.out_size); |
| 3308 | } |
| 3309 | } while (code != 0); |
| 3310 | |
| 3311 | out = (struct sprefinfo *)blob.out; |
| 3312 | |
| 3313 | for (i = 0; i < out->num_servers; i++) { |
| 3314 | if (resolve) { |
| 3315 | name = hostutil_GetNameByINet(out->servers[i].server.s_addr); |
| 3316 | } else { |
| 3317 | addr = ntohl(out->servers[i].server.s_addr)(__builtin_constant_p(out->servers[i].server.s_addr) ? ((( (__uint32_t)(out->servers[i].server.s_addr)) >> 24) | ((((__uint32_t)(out->servers[i].server.s_addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(out->servers[ i].server.s_addr)) & (0xff << 8)) << 8) | ((( __uint32_t)(out->servers[i].server.s_addr)) << 24)) : __bswap32_var(out->servers[i].server.s_addr)); |
| 3318 | sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, |
| 3319 | (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); |
| 3320 | name = tbuffer; |
| 3321 | } |
| 3322 | printf("%-50s %5u\n", name, out->servers[i].rank); |
| 3323 | } |
| 3324 | |
| 3325 | in->offset = out->next_offset; |
| 3326 | } while (out->next_offset > 0); |
| 3327 | |
| 3328 | if (blob.out != space) |
| 3329 | free(blob.out); |
| 3330 | |
| 3331 | return 0; |
| 3332 | } |
| 3333 | |
| 3334 | static int |
| 3335 | StoreBehindCmd(struct cmd_syndesc *as, void *arock) |
| 3336 | { |
| 3337 | afs_int32 code = 0; |
| 3338 | struct ViceIoctl blob; |
| 3339 | struct cmd_item *ti; |
| 3340 | struct sbstruct tsb, tsb2; |
| 3341 | int verbose = 0; |
| 3342 | afs_int32 allfiles; |
| 3343 | char *t; |
| 3344 | int error = 0; |
| 3345 | |
| 3346 | tsb.sb_thisfile = -1; |
| 3347 | ti = as->parms[0].items; /* -kbytes */ |
| 3348 | if (ti) { |
| 3349 | if (!as->parms[1].items) { |
| 3350 | fprintf(stderr__stderrp, "%s: you must specify -files with -kbytes.\n", |
| 3351 | pn); |
| 3352 | return 1; |
| 3353 | } |
| 3354 | tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024; |
| 3355 | if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) { |
| 3356 | fprintf(stderr__stderrp, "%s: %s must be 0 or a positive number.\n", pn, |
| 3357 | ti->data); |
| 3358 | return 1; |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */ |
| 3363 | ti = as->parms[2].items; /* -allfiles */ |
| 3364 | if (ti) { |
| 3365 | allfiles = strtol(ti->data, &t, 10) * 1024; |
| 3366 | if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) { |
| 3367 | fprintf(stderr__stderrp, "%s: %s must be 0 or a positive number.\n", pn, |
| 3368 | ti->data); |
| 3369 | return 1; |
| 3370 | } |
| 3371 | } |
| 3372 | |
| 3373 | /* -verbose or -file only or no options */ |
| 3374 | if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items) |
| 3375 | || (!as->parms[0].items && !as->parms[1].items |
| 3376 | && !as->parms[2].items)) |
| 3377 | verbose = 1; |
| 3378 | |
| 3379 | blob.in = (char *)&tsb; |
| 3380 | blob.in_size = sizeof(struct sbstruct); |
| 3381 | |
| 3382 | /* once per -file */ |
| 3383 | for (ti = as->parms[1].items; ti; ti = ti->next) { |
| 3384 | /* Do this solely to see if the file is there */ |
| 3385 | |
| 3386 | blob.out = space; |
| 3387 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 3388 | code = pioctl(ti->data, VIOCWHEREIS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((14))))), &blob, 1); |
| 3389 | if (code) { |
| 3390 | Die(errno(* __error()), ti->data); |
| 3391 | error = 1; |
| 3392 | continue; |
| 3393 | } |
| 3394 | |
| 3395 | memset(&tsb2, 0, sizeof(tsb2)); |
| 3396 | blob.out = (char *)&tsb2; |
| 3397 | blob.out_size = sizeof(struct sbstruct); |
| 3398 | code = pioctl(ti->data, VIOC_STORBEHIND((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((47))))), &blob, 1); |
| 3399 | if (code) { |
| 3400 | Die(errno(* __error()), ti->data); |
| 3401 | error = 1; |
| 3402 | continue; |
| 3403 | } |
| 3404 | |
| 3405 | if (verbose && (blob.out_size == sizeof(tsb2))) { |
| 3406 | if (tsb2.sb_thisfile == -1) { |
| 3407 | fprintf(stdout__stdoutp, "Will store %s according to default.\n", |
| 3408 | ti->data); |
| 3409 | } else { |
| 3410 | fprintf(stdout__stdoutp, |
| 3411 | "Will store up to %d kbytes of %s asynchronously.\n", |
| 3412 | (tsb2.sb_thisfile / 1024), ti->data); |
| 3413 | } |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | /* If no files - make at least one pioctl call, or |
| 3418 | * set the allfiles default if we need to. |
| 3419 | */ |
| 3420 | if (!as->parms[1].items || (allfiles != -1)) { |
| 3421 | tsb.sb_default = allfiles; |
| 3422 | memset(&tsb2, 0, sizeof(tsb2)); |
| 3423 | blob.out = (char *)&tsb2; |
| 3424 | blob.out_size = sizeof(struct sbstruct); |
| 3425 | code = pioctl(0, VIOC_STORBEHIND((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((47))))), &blob, 1); |
| 3426 | if (code) { |
| 3427 | Die(errno(* __error()), ((allfiles == -1) ? 0 : "-allfiles")); |
| 3428 | error = 1; |
| 3429 | } |
| 3430 | } |
| 3431 | |
| 3432 | /* Having no arguments also reports the default store asynchrony */ |
| 3433 | if (!error && verbose && (blob.out_size == sizeof(tsb2))) { |
| 3434 | fprintf(stdout__stdoutp, "Default store asynchrony is %d kbytes.\n", |
| 3435 | (tsb2.sb_default / 1024)); |
| 3436 | } |
| 3437 | |
| 3438 | return error; |
| 3439 | } |
| 3440 | |
| 3441 | |
| 3442 | static int |
| 3443 | SetCryptCmd(struct cmd_syndesc *as, void *arock) |
| 3444 | { |
| 3445 | afs_int32 code = 0, flag; |
| 3446 | struct ViceIoctl blob; |
| 3447 | char *tp; |
| 3448 | |
| 3449 | tp = as->parms[0].items->data; |
| 3450 | if (strcmp(tp, "on") == 0) |
| 3451 | flag = 1; |
| 3452 | else if (strcmp(tp, "off") == 0) |
| 3453 | flag = 0; |
| 3454 | else { |
| 3455 | fprintf(stderr__stderrp, "%s: %s must be \"on\" or \"off\".\n", pn, tp); |
| 3456 | return EINVAL22; |
| 3457 | } |
| 3458 | |
| 3459 | blob.in = (char *)&flag; |
| 3460 | blob.in_size = sizeof(flag); |
| 3461 | blob.out_size = 0; |
| 3462 | code = pioctl(0, VIOC_SETRXKCRYPT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((56))))), &blob, 1); |
| 3463 | if (code) |
| 3464 | Die(errno(* __error()), NULL((void *)0)); |
| 3465 | return 0; |
| 3466 | } |
| 3467 | |
| 3468 | |
| 3469 | static int |
| 3470 | GetCryptCmd(struct cmd_syndesc *as, void *arock) |
| 3471 | { |
| 3472 | afs_int32 code = 0, flag; |
| 3473 | struct ViceIoctl blob; |
| 3474 | char *tp; |
| 3475 | |
| 3476 | blob.in = NULL((void *)0); |
| 3477 | blob.in_size = 0; |
| 3478 | blob.out_size = sizeof(flag); |
| 3479 | blob.out = space; |
| 3480 | |
| 3481 | code = pioctl(0, VIOC_GETRXKCRYPT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((55))))), &blob, 1); |
| 3482 | |
| 3483 | if (code) |
| 3484 | Die(errno(* __error()), NULL((void *)0)); |
| 3485 | else { |
| 3486 | tp = space; |
| 3487 | memcpy(&flag, tp, sizeof(afs_int32)); |
| 3488 | printf("Security level is currently "); |
| 3489 | if (flag == 1) |
| 3490 | printf("crypt (data security).\n"); |
| 3491 | else |
| 3492 | printf("clear.\n"); |
| 3493 | } |
| 3494 | return 0; |
| 3495 | } |
| 3496 | |
| 3497 | static char *modenames[] = { |
| 3498 | "offline", |
| 3499 | "online", |
| 3500 | "readonly", /* Not currently supported */ |
| 3501 | "fetchonly", /* Not currently supported */ |
| 3502 | "partial", /* Not currently supported */ |
| 3503 | NULL((void *)0) |
| 3504 | }; |
| 3505 | |
| 3506 | static char *policynames[] = { |
| 3507 | "client", |
| 3508 | "server", |
| 3509 | "closer", /* Not currently supported. */ |
| 3510 | "manual", /* Not currently supported. */ |
| 3511 | NULL((void *)0) |
| 3512 | }; |
| 3513 | |
| 3514 | static int |
| 3515 | DisconCmd(struct cmd_syndesc *as, void *arock) |
| 3516 | { |
| 3517 | struct cmd_item *ti; |
| 3518 | char *modename; |
| 3519 | char *policyname; |
| 3520 | int modelen, policylen; |
| 3521 | afs_int32 mode, policy, code, unixuid = 0; |
| 3522 | struct ViceIoctl blob; |
| 3523 | |
| 3524 | blob.in = NULL((void *)0); |
| 3525 | blob.in_size = 0; |
| 3526 | |
| 3527 | space[0] = space[1] = space[2] = space[3] = 0; |
| 3528 | |
| 3529 | ti = as->parms[0].items; |
| 3530 | if (ti) { |
| 3531 | modename = ti->data; |
| 3532 | modelen = strlen(modename); |
| 3533 | for (mode = 0; modenames[mode] != NULL((void *)0); mode++) |
| 3534 | if (!strncasecmp(modename, modenames[mode], modelen)) |
| 3535 | break; |
| 3536 | if (modenames[mode] == NULL((void *)0)) |
| 3537 | printf("Unknown discon mode \"%s\"\n", modename); |
| 3538 | else { |
| 3539 | space[0] = mode + 1; |
| 3540 | } |
| 3541 | } |
| 3542 | ti = as->parms[1].items; |
| 3543 | if (ti) { |
| 3544 | policyname = ti->data; |
| 3545 | policylen = strlen(policyname); |
| 3546 | for (policy = 0; policynames[policy] != NULL((void *)0); policy++) |
| 3547 | if (!strncasecmp(policyname, policynames[policy], policylen)) |
| 3548 | break; |
| 3549 | if (policynames[policy] == NULL((void *)0)) |
| 3550 | printf("Unknown discon mode \"%s\"\n", policyname); |
| 3551 | else { |
| 3552 | space[1] = policy + 1; |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | if (as->parms[2].items) { |
| 3557 | space[2] = 1; |
| 3558 | printf("force on\n"); |
| 3559 | } |
| 3560 | |
| 3561 | ti = as->parms[3].items; |
| 3562 | if (ti) { |
| 3563 | code = util_GetInt32(ti->data, &unixuid); |
| 3564 | if (code) { |
| 3565 | fprintf(stderr__stderrp, "%s: bad integer specified for uid.\n", pn); |
| 3566 | return 1; |
| 3567 | } |
| 3568 | space[3] = unixuid; |
| 3569 | } else |
| 3570 | space[3] = 0; |
| 3571 | |
| 3572 | blob.in = space; |
| 3573 | blob.in_size = 4 * sizeof(afs_int32); |
| 3574 | |
| 3575 | blob.out_size = sizeof(mode); |
| 3576 | blob.out = space; |
| 3577 | code = pioctl(0, VIOC_DISCON((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('C' )) << 8) | ((5))))), &blob, 1); |
| 3578 | if (code) |
| 3579 | Die(errno(* __error()), NULL((void *)0)); |
| 3580 | else { |
| 3581 | memcpy(&mode, space, sizeof mode); |
| 3582 | if (mode < sizeof modenames / sizeof (char *)) |
| 3583 | printf("Discon mode is now \"%s\"\n", modenames[mode]); |
| 3584 | else |
| 3585 | printf("Unknown discon mode %d\n", mode); |
| 3586 | } |
| 3587 | |
| 3588 | return 0; |
| 3589 | } |
| 3590 | |
| 3591 | #include "AFS_component_version_number.c" |
| 3592 | |
| 3593 | int |
| 3594 | main(int argc, char **argv) |
| 3595 | { |
| 3596 | afs_int32 code; |
| 3597 | struct cmd_syndesc *ts; |
| 3598 | |
| 3599 | #ifdef AFS_AIX32_ENV |
| 3600 | /* |
| 3601 | * The following signal action for AIX is necessary so that in case of a |
| 3602 | * crash (i.e. core is generated) we can include the user's data section |
| 3603 | * in the core dump. Unfortunately, by default, only a partial core is |
| 3604 | * generated which, in many cases, isn't too useful. |
| 3605 | */ |
| 3606 | struct sigaction nsa; |
| 3607 | |
| 3608 | sigemptyset(&nsa.sa_mask); |
| 3609 | nsa.sa_handler__sigaction_u.__sa_handler = SIG_DFL((__sighandler_t *)0); |
| 3610 | nsa.sa_flags = SA_FULLDUMP; |
| 3611 | sigaction(SIGSEGV11, &nsa, NULL((void *)0)); |
| 3612 | #endif |
| 3613 | |
| 3614 | /* try to find volume location information */ |
| 3615 | ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL((void *)0), |
| 3616 | "get client network interface addresses"); |
| 3617 | cmd_CreateAlias(ts, "gc"); |
| 3618 | |
| 3619 | ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL((void *)0), |
| 3620 | "set client network interface addresses"); |
| 3621 | cmd_AddParm(ts, "-address", CMD_LIST3, CMD_OPTIONAL1 | CMD_EXPANDS2, |
| 3622 | "client network interfaces"); |
| 3623 | cmd_CreateAlias(ts, "sc"); |
| 3624 | |
| 3625 | ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL((void *)0), |
| 3626 | "set server ranks"); |
| 3627 | cmd_AddParm(ts, "-servers", CMD_LIST3, CMD_OPTIONAL1 | CMD_EXPANDS2, |
| 3628 | "fileserver names and ranks"); |
| 3629 | cmd_AddParm(ts, "-vlservers", CMD_LIST3, CMD_OPTIONAL1 | CMD_EXPANDS2, |
| 3630 | "VL server names and ranks"); |
| 3631 | cmd_AddParm(ts, "-file", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3632 | "input from named file"); |
| 3633 | cmd_AddParm(ts, "-stdin", CMD_FLAG1, CMD_OPTIONAL1, "input from stdin"); |
| 3634 | cmd_CreateAlias(ts, "sp"); |
| 3635 | |
| 3636 | ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL((void *)0), |
| 3637 | "get server ranks"); |
| 3638 | cmd_AddParm(ts, "-file", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3639 | "output to named file"); |
| 3640 | cmd_AddParm(ts, "-numeric", CMD_FLAG1, CMD_OPTIONAL1, "addresses only"); |
| 3641 | cmd_AddParm(ts, "-vlservers", CMD_FLAG1, CMD_OPTIONAL1, "VL servers"); |
| 3642 | /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */ |
| 3643 | cmd_CreateAlias(ts, "gp"); |
| 3644 | |
| 3645 | ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL((void *)0), "set access control list"); |
| 3646 | cmd_AddParm(ts, "-dir", CMD_LIST3, 0, "directory"); |
| 3647 | cmd_AddParm(ts, "-acl", CMD_LIST3, 0, "access list entries"); |
| 3648 | cmd_AddParm(ts, "-clear", CMD_FLAG1, CMD_OPTIONAL1, "clear access list"); |
| 3649 | cmd_AddParm(ts, "-negative", CMD_FLAG1, CMD_OPTIONAL1, |
| 3650 | "apply to negative rights"); |
| 3651 | parm_setacl_id = ts->nParms; |
| 3652 | cmd_AddParm(ts, "-id", CMD_FLAG1, CMD_OPTIONAL1, |
| 3653 | "initial directory acl (DFS only)"); |
| 3654 | cmd_AddParm(ts, "-if", CMD_FLAG1, CMD_OPTIONAL1, |
| 3655 | "initial file acl (DFS only)"); |
| 3656 | cmd_CreateAlias(ts, "sa"); |
| 3657 | |
| 3658 | ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL((void *)0), |
| 3659 | "list access control list"); |
| 3660 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3661 | parm_listacl_id = ts->nParms; |
| 3662 | cmd_AddParm(ts, "-id", CMD_FLAG1, CMD_OPTIONAL1, "initial directory acl"); |
| 3663 | cmd_AddParm(ts, "-if", CMD_FLAG1, CMD_OPTIONAL1, "initial file acl"); |
| 3664 | cmd_AddParm(ts, "-cmd", CMD_FLAG1, CMD_OPTIONAL1, "output as 'fs setacl' command"); |
| 3665 | cmd_CreateAlias(ts, "la"); |
| 3666 | |
| 3667 | ts = cmd_CreateSyntax("getcalleraccess", GetCallerAccess, NULL((void *)0), |
| 3668 | "list callers access"); |
| 3669 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3670 | cmd_CreateAlias(ts, "gca"); |
| 3671 | |
| 3672 | ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL((void *)0), |
| 3673 | "clean up access control list"); |
| 3674 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3675 | |
| 3676 | ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL((void *)0), |
| 3677 | "copy access control list"); |
| 3678 | cmd_AddParm(ts, "-fromdir", CMD_SINGLE2, 0, |
| 3679 | "source directory (or DFS file)"); |
| 3680 | cmd_AddParm(ts, "-todir", CMD_LIST3, 0, |
| 3681 | "destination directory (or DFS file)"); |
| 3682 | cmd_AddParm(ts, "-clear", CMD_FLAG1, CMD_OPTIONAL1, |
| 3683 | "first clear dest access list"); |
| 3684 | parm_copyacl_id = ts->nParms; |
| 3685 | cmd_AddParm(ts, "-id", CMD_FLAG1, CMD_OPTIONAL1, "initial directory acl"); |
| 3686 | cmd_AddParm(ts, "-if", CMD_FLAG1, CMD_OPTIONAL1, "initial file acl"); |
| 3687 | |
| 3688 | cmd_CreateAlias(ts, "ca"); |
| 3689 | |
| 3690 | ts = cmd_CreateSyntax("flush", FlushCmd, NULL((void *)0), "flush file from cache"); |
| 3691 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3692 | ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL((void *)0), |
| 3693 | "flush mount symlink from cache"); |
| 3694 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3695 | |
| 3696 | ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL((void *)0), "set volume status"); |
| 3697 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3698 | cmd_AddParm(ts, "-max", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3699 | "disk space quota in 1K units"); |
| 3700 | #ifdef notdef |
| 3701 | cmd_AddParm(ts, "-min", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3702 | "disk space guaranteed"); |
| 3703 | cmd_AddParm(ts, "-motd", CMD_SINGLE2, CMD_OPTIONAL1, "message of the day"); |
| 3704 | #endif |
| 3705 | cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3706 | "offline message"); |
| 3707 | cmd_CreateAlias(ts, "sv"); |
| 3708 | |
| 3709 | ts = cmd_CreateSyntax("messages", MessagesCmd, NULL((void *)0), |
| 3710 | "control Cache Manager messages"); |
| 3711 | cmd_AddParm(ts, "-show", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3712 | "[user|console|all|none]"); |
| 3713 | |
| 3714 | ts = cmd_CreateSyntax("examine", ExamineCmd, NULL((void *)0), "display file/volume status"); |
| 3715 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3716 | cmd_CreateAlias(ts, "lv"); |
| 3717 | cmd_CreateAlias(ts, "listvol"); |
| 3718 | |
| 3719 | ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL((void *)0), "list volume quota"); |
| 3720 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3721 | cmd_AddParm(ts, "-human", CMD_FLAG1, CMD_OPTIONAL1, "human-readable listing"); |
| 3722 | cmd_CreateAlias(ts, "lq"); |
| 3723 | |
| 3724 | ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL((void *)0), |
| 3725 | "show server disk space usage"); |
| 3726 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3727 | cmd_AddParm(ts, "-human", CMD_FLAG1, CMD_OPTIONAL1, "human-readable listing"); |
| 3728 | cmd_CreateAlias(ts, "df"); |
| 3729 | |
| 3730 | ts = cmd_CreateSyntax("quota", QuotaCmd, NULL((void *)0), "show volume quota usage"); |
| 3731 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3732 | |
| 3733 | ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL((void *)0), "list mount point"); |
| 3734 | cmd_AddParm(ts, "-dir", CMD_LIST3, 0, "directory"); |
| 3735 | |
| 3736 | ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL((void *)0), "make mount point"); |
| 3737 | cmd_AddParm(ts, "-dir", CMD_SINGLE2, 0, "directory"); |
| 3738 | cmd_AddParm(ts, "-vol", CMD_SINGLE2, 0, "volume name"); |
| 3739 | cmd_AddParm(ts, "-cell", CMD_SINGLE2, CMD_OPTIONAL1, "cell name"); |
| 3740 | cmd_AddParm(ts, "-rw", CMD_FLAG1, CMD_OPTIONAL1, "force r/w volume"); |
| 3741 | cmd_AddParm(ts, "-fast", CMD_FLAG1, CMD_OPTIONAL1, |
| 3742 | "don't check name with VLDB"); |
| 3743 | |
| 3744 | #if defined(AFS_CACHE_BYPASS) |
| 3745 | ts = cmd_CreateSyntax("bypassthreshold", BypassThresholdCmd, 0, |
| 3746 | "get/set cache bypass file size threshold"); |
| 3747 | cmd_AddParm(ts, "-size", CMD_SINGLE2, CMD_OPTIONAL1, "file size"); |
| 3748 | #endif |
| 3749 | |
| 3750 | /* |
| 3751 | |
| 3752 | defect 3069 |
| 3753 | |
| 3754 | cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point"); |
| 3755 | */ |
| 3756 | |
| 3757 | |
| 3758 | ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL((void *)0), "remove mount point"); |
| 3759 | cmd_AddParm(ts, "-dir", CMD_LIST3, 0, "directory"); |
| 3760 | |
| 3761 | ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL((void *)0), |
| 3762 | "check local cell's servers"); |
| 3763 | cmd_AddParm(ts, "-cell", CMD_SINGLE2, CMD_OPTIONAL1, "cell to check"); |
| 3764 | cmd_AddParm(ts, "-all", CMD_FLAG1, CMD_OPTIONAL1, "check all cells"); |
| 3765 | cmd_AddParm(ts, "-fast", CMD_FLAG1, CMD_OPTIONAL1, |
| 3766 | "just list, don't check"); |
| 3767 | cmd_AddParm(ts, "-interval", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3768 | "seconds between probes"); |
| 3769 | |
| 3770 | ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL((void *)0), |
| 3771 | "check volumeID/name mappings"); |
| 3772 | cmd_CreateAlias(ts, "checkbackups"); |
| 3773 | |
| 3774 | |
| 3775 | ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL((void *)0), |
| 3776 | "set cache size"); |
| 3777 | cmd_AddParm(ts, "-blocks", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3778 | "size in 1K byte blocks (0 => reset)"); |
| 3779 | cmd_CreateAlias(ts, "cachesize"); |
| 3780 | |
| 3781 | cmd_AddParm(ts, "-reset", CMD_FLAG1, CMD_OPTIONAL1, |
| 3782 | "reset size back to boot value"); |
| 3783 | |
| 3784 | ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL((void *)0), |
| 3785 | "get cache usage info"); |
| 3786 | cmd_AddParm(ts, "-files", CMD_FLAG1, CMD_OPTIONAL1, "Show cach files used as well"); |
| 3787 | cmd_AddParm(ts, "-excessive", CMD_FLAG1, CMD_OPTIONAL1, "excessively verbose cache stats"); |
| 3788 | |
| 3789 | ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL((void *)0), |
| 3790 | "list configured cells"); |
| 3791 | cmd_AddParm(ts, "-numeric", CMD_FLAG1, CMD_OPTIONAL1, "addresses only"); |
| 3792 | |
| 3793 | ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, NULL((void *)0), |
| 3794 | "list configured cell aliases"); |
| 3795 | |
| 3796 | ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL((void *)0), "set volume quota"); |
| 3797 | cmd_AddParm(ts, "-path", CMD_SINGLE2, CMD_OPTIONAL1, "dir/file path"); |
| 3798 | cmd_AddParm(ts, "-max", CMD_SINGLE2, 0, "max quota in kbytes"); |
| 3799 | #ifdef notdef |
| 3800 | cmd_AddParm(ts, "-min", CMD_SINGLE2, CMD_OPTIONAL1, "min quota in kbytes"); |
| 3801 | #endif |
| 3802 | cmd_CreateAlias(ts, "sq"); |
| 3803 | |
| 3804 | ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL((void *)0), "configure new cell"); |
| 3805 | cmd_AddParm(ts, "-name", CMD_SINGLE2, 0, "cell name"); |
| 3806 | cmd_AddParm(ts, "-servers", CMD_LIST3, CMD_REQUIRED0, "primary servers"); |
| 3807 | cmd_AddParm(ts, "-linkedcell", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3808 | "linked cell name"); |
| 3809 | |
| 3810 | ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL((void *)0), |
| 3811 | "configure new cell alias"); |
| 3812 | cmd_AddParm(ts, "-alias", CMD_SINGLE2, 0, "alias name"); |
| 3813 | cmd_AddParm(ts, "-name", CMD_SINGLE2, 0, "real name of cell"); |
| 3814 | |
| 3815 | #ifdef FS_ENABLE_SERVER_DEBUG_PORTS |
| 3816 | /* |
| 3817 | * Turn this on only if you wish to be able to talk to a server which is listening |
| 3818 | * on alternative ports. This is not intended for general use and may not be |
| 3819 | * supported in the cache manager. It is not a way to run two servers at the |
| 3820 | * same host, since the cache manager cannot properly distinguish those two hosts. |
| 3821 | */ |
| 3822 | cmd_AddParm(ts, "-fsport", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3823 | "cell's fileserver port"); |
| 3824 | cmd_AddParm(ts, "-vlport", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3825 | "cell's vldb server port"); |
| 3826 | #endif |
| 3827 | |
| 3828 | ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL((void *)0), "list file's cell"); |
| 3829 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3830 | |
| 3831 | ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL((void *)0), "list file's location"); |
| 3832 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3833 | |
| 3834 | ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL((void *)0), "list workstation's cell"); |
Value stored to 'ts' is never read | |
| 3835 | |
| 3836 | /* |
| 3837 | ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, NULL, "obsolete (listed primary cell)"); |
| 3838 | */ |
| 3839 | |
| 3840 | /* set cache monitor host address */ |
| 3841 | ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL((void *)0), (char *)CMD_HIDDEN4); |
| 3842 | cmd_AddParm(ts, "-server", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3843 | "host name or 'off'"); |
| 3844 | cmd_CreateAlias(ts, "mariner"); |
| 3845 | |
| 3846 | ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL((void *)0), "get cell status"); |
| 3847 | cmd_AddParm(ts, "-cell", CMD_LIST3, 0, "cell name"); |
| 3848 | |
| 3849 | ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL((void *)0), "set cell status"); |
| 3850 | cmd_AddParm(ts, "-cell", CMD_LIST3, 0, "cell name"); |
| 3851 | cmd_AddParm(ts, "-suid", CMD_FLAG1, CMD_OPTIONAL1, "allow setuid programs"); |
| 3852 | cmd_AddParm(ts, "-nosuid", CMD_FLAG1, CMD_OPTIONAL1, |
| 3853 | "disallow setuid programs"); |
| 3854 | |
| 3855 | ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL((void *)0), |
| 3856 | "flush all data in volume"); |
| 3857 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3858 | |
| 3859 | ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL((void *)0), |
| 3860 | "get/set sysname (i.e. @sys) value"); |
| 3861 | cmd_AddParm(ts, "-newsys", CMD_LIST3, CMD_OPTIONAL1, "new sysname"); |
| 3862 | |
| 3863 | ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL((void *)0), |
| 3864 | "enable/disable translators to AFS"); |
| 3865 | cmd_AddParm(ts, "-type", CMD_SINGLE2, 0, "exporter name"); |
| 3866 | cmd_AddParm(ts, "-start", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3867 | "start/stop translator (on | off)"); |
| 3868 | cmd_AddParm(ts, "-convert", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3869 | "convert from afs to unix mode (on | off)"); |
| 3870 | cmd_AddParm(ts, "-uidcheck", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3871 | "run on strict 'uid check' mode (on | off)"); |
| 3872 | cmd_AddParm(ts, "-submounts", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3873 | "allow nfs mounts to subdirs of /afs/.. (on | off)"); |
| 3874 | cmd_AddParm(ts, "-clipags", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3875 | "enable use of client-assigned PAG's (on | off)"); |
| 3876 | cmd_AddParm(ts, "-pagcb", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3877 | "enable callbacks to get creds from new clients (on | off)"); |
| 3878 | |
| 3879 | |
| 3880 | ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL((void *)0), |
| 3881 | "store to server after file close"); |
| 3882 | cmd_AddParm(ts, "-kbytes", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3883 | "asynchrony for specified names"); |
| 3884 | cmd_AddParm(ts, "-files", CMD_LIST3, CMD_OPTIONAL1, "specific pathnames"); |
| 3885 | cmd_AddParm(ts, "-allfiles", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3886 | "new default (KB)"); |
| 3887 | cmd_AddParm(ts, "-verbose", CMD_FLAG1, CMD_OPTIONAL1, "show status"); |
| 3888 | cmd_CreateAlias(ts, "sb"); |
| 3889 | |
| 3890 | ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL((void *)0), |
| 3891 | "set cache manager encryption flag"); |
| 3892 | cmd_AddParm(ts, "-crypt", CMD_SINGLE2, 0, "on or off"); |
| 3893 | |
| 3894 | ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL((void *)0), |
| 3895 | "get cache manager encryption flag"); |
| 3896 | |
| 3897 | ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL((void *)0), |
| 3898 | "Manage per process RX statistics"); |
| 3899 | cmd_AddParm(ts, "-enable", CMD_FLAG1, CMD_OPTIONAL1, "Enable RX stats"); |
| 3900 | cmd_AddParm(ts, "-disable", CMD_FLAG1, CMD_OPTIONAL1, "Disable RX stats"); |
| 3901 | cmd_AddParm(ts, "-clear", CMD_FLAG1, CMD_OPTIONAL1, "Clear RX stats"); |
| 3902 | |
| 3903 | ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL((void *)0), |
| 3904 | "Manage per peer RX statistics"); |
| 3905 | cmd_AddParm(ts, "-enable", CMD_FLAG1, CMD_OPTIONAL1, "Enable RX stats"); |
| 3906 | cmd_AddParm(ts, "-disable", CMD_FLAG1, CMD_OPTIONAL1, "Disable RX stats"); |
| 3907 | cmd_AddParm(ts, "-clear", CMD_FLAG1, CMD_OPTIONAL1, "Clear RX stats"); |
| 3908 | |
| 3909 | ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL((void *)0), "configure callback connection address"); |
| 3910 | cmd_AddParm(ts, "-addr", CMD_SINGLE2, CMD_OPTIONAL1, "host name or address"); |
| 3911 | |
| 3912 | /* try to find volume location information */ |
| 3913 | ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL((void *)0), |
| 3914 | "get fid for file(s)"); |
| 3915 | cmd_AddParm(ts, "-path", CMD_LIST3, CMD_OPTIONAL1, "dir/file path"); |
| 3916 | |
| 3917 | ts = cmd_CreateSyntax("discon", DisconCmd, NULL((void *)0), |
| 3918 | "disconnection mode"); |
| 3919 | cmd_AddParm(ts, "-mode", CMD_SINGLE2, CMD_REQUIRED0, "offline | online"); |
| 3920 | cmd_AddParm(ts, "-policy", CMD_SINGLE2, CMD_OPTIONAL1, "client | server"); |
| 3921 | cmd_AddParm(ts, "-force", CMD_FLAG1, CMD_OPTIONAL1, "Force reconnection, despite any synchronization issues."); |
| 3922 | cmd_AddParm(ts, "-uid", CMD_SINGLE2, CMD_OPTIONAL1, "Numeric UID of user whose tokens to use at reconnect."); |
| 3923 | |
| 3924 | ts = cmd_CreateSyntax("nukenfscreds", NukeNFSCredsCmd, NULL((void *)0), "nuke credentials for NFS client"); |
| 3925 | cmd_AddParm(ts, "-addr", CMD_SINGLE2, 0, "host name or address"); |
| 3926 | |
| 3927 | ts = cmd_CreateSyntax("uuid", UuidCmd, NULL((void *)0), "manage the UUID for the cache manager"); |
| 3928 | cmd_AddParm(ts, "-generate", CMD_FLAG1, CMD_REQUIRED0, "generate a new UUID"); |
| 3929 | |
| 3930 | ts = cmd_CreateSyntax("precache", PreCacheCmd, 0, |
| 3931 | "set precache size"); |
| 3932 | cmd_AddParm(ts, "-blocks", CMD_SINGLE2, CMD_OPTIONAL1, |
| 3933 | "size in 1K byte blocks (0 => disable)"); |
| 3934 | |
| 3935 | code = cmd_Dispatch(argc, argv); |
| 3936 | if (rxInitDone) |
| 3937 | rx_Finalize(); |
| 3938 | |
| 3939 | return code; |
| 3940 | } |
| 3941 | |
| 3942 | static void |
| 3943 | Die(int errnum, char *filename) |
| 3944 | { |
| 3945 | switch (errnum) { |
| 3946 | case EINVAL22: |
| 3947 | if (filename) |
| 3948 | fprintf(stderr__stderrp, |
| 3949 | "%s: Invalid argument; it is possible that %s is not in AFS.\n", |
| 3950 | pn, filename); |
| 3951 | else |
| 3952 | fprintf(stderr__stderrp, "%s: Invalid argument.\n", pn); |
| 3953 | break; |
| 3954 | case ENOENT2: |
| 3955 | if (filename) |
| 3956 | fprintf(stderr__stderrp, "%s: File '%s' doesn't exist\n", pn, filename); |
| 3957 | else |
| 3958 | fprintf(stderr__stderrp, "%s: no such file returned\n", pn); |
| 3959 | break; |
| 3960 | case EROFS30: |
| 3961 | fprintf(stderr__stderrp, |
| 3962 | "%s: You can not change a backup or readonly volume\n", pn); |
| 3963 | break; |
| 3964 | case EACCES13: |
| 3965 | case EPERM1: |
| 3966 | if (filename) |
| 3967 | fprintf(stderr__stderrp, |
| 3968 | "%s: You don't have the required access rights on '%s'\n", |
| 3969 | pn, filename); |
| 3970 | else |
| 3971 | fprintf(stderr__stderrp, |
| 3972 | "%s: You do not have the required rights to do this operation\n", |
| 3973 | pn); |
| 3974 | break; |
| 3975 | default: |
| 3976 | if (filename) |
| 3977 | fprintf(stderr__stderrp, "%s:'%s'", pn, filename); |
| 3978 | else |
| 3979 | fprintf(stderr__stderrp, "%s", pn); |
| 3980 | fprintf(stderr__stderrp, ": %s\n", afs_error_message(errnum)); |
| 3981 | break; |
| 3982 | } |
| 3983 | } |
| 3984 | |
| 3985 | /* get clients interface addresses */ |
| 3986 | static int |
| 3987 | GetClientAddrsCmd(struct cmd_syndesc *as, void *arock) |
| 3988 | { |
| 3989 | afs_int32 code; |
| 3990 | struct ViceIoctl blob; |
| 3991 | struct sprefrequest *in; |
| 3992 | struct sprefinfo *out; |
| 3993 | |
| 3994 | in = (struct sprefrequest *)space; |
| 3995 | in->offset = 0; |
| 3996 | |
| 3997 | do { |
| 3998 | blob.in_size = sizeof(struct sprefrequest); |
| 3999 | blob.in = (char *)in; |
| 4000 | blob.out = space; |
| 4001 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 4002 | |
| 4003 | in->num_servers = |
| 4004 | (AFS_PIOCTL_MAXSIZE2048 - 2 * sizeof(short)) / sizeof(struct spref); |
| 4005 | /* returns addr in network byte order */ |
| 4006 | code = pioctl(0, VIOC_GETCPREFS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((50))))), &blob, 1); |
| 4007 | if (code) { |
| 4008 | perror("getClientInterfaceAddr pioctl"); |
| 4009 | return 1; |
| 4010 | } |
| 4011 | |
| 4012 | { |
| 4013 | int i; |
| 4014 | out = (struct sprefinfo *)blob.out; |
| 4015 | for (i = 0; i < out->num_servers; i++) { |
| 4016 | afs_int32 addr; |
| 4017 | char tbuffer[32]; |
| 4018 | addr = ntohl(out->servers[i].server.s_addr)(__builtin_constant_p(out->servers[i].server.s_addr) ? ((( (__uint32_t)(out->servers[i].server.s_addr)) >> 24) | ((((__uint32_t)(out->servers[i].server.s_addr)) & (0xff << 16)) >> 8) | ((((__uint32_t)(out->servers[ i].server.s_addr)) & (0xff << 8)) << 8) | ((( __uint32_t)(out->servers[i].server.s_addr)) << 24)) : __bswap32_var(out->servers[i].server.s_addr)); |
| 4019 | sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff, |
| 4020 | (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); |
| 4021 | printf("%-50s\n", tbuffer); |
| 4022 | } |
| 4023 | in->offset = out->next_offset; |
| 4024 | } |
| 4025 | } while (out->next_offset > 0); |
| 4026 | |
| 4027 | return 0; |
| 4028 | } |
| 4029 | |
| 4030 | static int |
| 4031 | SetClientAddrsCmd(struct cmd_syndesc *as, void *arock) |
| 4032 | { |
| 4033 | afs_int32 code, addr; |
| 4034 | struct cmd_item *ti; |
| 4035 | struct ViceIoctl blob; |
| 4036 | struct setspref *ssp; |
| 4037 | int sizeUsed = 0, i, flag; |
| 4038 | afs_uint32 existingAddr[1024]; /* existing addresses on this host */ |
| 4039 | int existNu; |
| 4040 | int error = 0; |
| 4041 | |
| 4042 | ssp = (struct setspref *)space; |
| 4043 | ssp->num_servers = 0; |
| 4044 | blob.in = space; |
| 4045 | blob.out = space; |
| 4046 | blob.out_size = AFS_PIOCTL_MAXSIZE2048; |
| 4047 | |
| 4048 | if (geteuid()) { |
| 4049 | fprintf(stderr__stderrp, "Permission denied: requires root access.\n"); |
| 4050 | return 1; |
| 4051 | } |
| 4052 | |
| 4053 | /* extract all existing interface addresses */ |
| 4054 | existNu = rx_getAllAddr(existingAddr, 1024); |
| 4055 | if (existNu < 0) |
| 4056 | return 1; |
| 4057 | |
| 4058 | sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */ |
| 4059 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 4060 | if (sizeUsed >= sizeof(space)) { |
| 4061 | fprintf(stderr__stderrp, "No more space\n"); |
| 4062 | return 1; |
| 4063 | } |
| 4064 | addr = extractAddr(ti->data, 20); /* network order */ |
| 4065 | if ((addr == AFS_IPINVALID0xffffffff) || (addr == AFS_IPINVALIDIGNORE0xfffffffe)) { |
| 4066 | fprintf(stderr__stderrp, "Error in specifying address: %s..ignoring\n", |
| 4067 | ti->data); |
| 4068 | error = 1; |
| 4069 | continue; |
| 4070 | } |
| 4071 | /* see if it is an address that really exists */ |
| 4072 | for (flag = 0, i = 0; i < existNu; i++) |
| 4073 | if (existingAddr[i] == addr) { |
| 4074 | flag = 1; |
| 4075 | break; |
| 4076 | } |
| 4077 | if (!flag) { /* this is an nonexistent address */ |
| 4078 | fprintf(stderr__stderrp, "Nonexistent address: 0x%08x..ignoring\n", addr); |
| 4079 | error = 1; |
| 4080 | continue; |
| 4081 | } |
| 4082 | /* copy all specified addr into ioctl buffer */ |
| 4083 | (ssp->servers[ssp->num_servers]).server.s_addr = addr; |
| 4084 | printf("Adding 0x%08x\n", addr); |
| 4085 | ssp->num_servers++; |
| 4086 | sizeUsed += sizeof(struct spref); |
| 4087 | } |
| 4088 | if (ssp->num_servers < 1) { |
| 4089 | fprintf(stderr__stderrp, "No addresses specified\n"); |
| 4090 | return 1; |
| 4091 | } |
| 4092 | blob.in_size = sizeUsed - sizeof(struct spref); |
| 4093 | |
| 4094 | code = pioctl(0, VIOC_SETCPREFS((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((51))))), &blob, 1); /* network order */ |
| 4095 | if (code) { |
| 4096 | Die(errno(* __error()), 0); |
| 4097 | error = 1; |
| 4098 | } |
| 4099 | |
| 4100 | return error; |
| 4101 | } |
| 4102 | |
| 4103 | static int |
| 4104 | FlushMountCmd(struct cmd_syndesc *as, void *arock) |
| 4105 | { |
| 4106 | afs_int32 code; |
| 4107 | struct ViceIoctl blob; |
| 4108 | struct cmd_item *ti; |
| 4109 | char *last_component; |
| 4110 | char *parent_dir; |
| 4111 | int error = 0; |
| 4112 | |
| 4113 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 4114 | if (GetLastComponent(ti->data, &parent_dir, |
| 4115 | &last_component, NULL((void *)0)) != 0) { |
| 4116 | error = 1; |
| 4117 | continue; |
| 4118 | } |
| 4119 | |
| 4120 | blob.in = last_component; |
| 4121 | blob.in_size = strlen(last_component) + 1; |
| 4122 | blob.out_size = 0; |
| 4123 | |
| 4124 | code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((52))))), &blob, 1); |
| 4125 | |
| 4126 | free(last_component); |
| 4127 | free(parent_dir); |
| 4128 | |
| 4129 | if (code != 0) { |
| 4130 | if (errno(* __error()) == EINVAL22) { |
| 4131 | fprintf(stderr__stderrp, "'%s' is not a mount point.\n", ti->data); |
| 4132 | } else { |
| 4133 | Die(errno(* __error()), (ti->data ? ti->data : parent_dir)); |
| 4134 | } |
| 4135 | error = 1; |
| 4136 | } |
| 4137 | } |
| 4138 | return error; |
| 4139 | } |
| 4140 | |
| 4141 | static int |
| 4142 | RxStatProcCmd(struct cmd_syndesc *as, void *arock) |
| 4143 | { |
| 4144 | afs_int32 code; |
| 4145 | afs_int32 flags = 0; |
| 4146 | struct ViceIoctl blob; |
| 4147 | |
| 4148 | if (as->parms[0].items) { /* -enable */ |
| 4149 | flags |= AFSCALL_RXSTATS_ENABLE0x1; |
| 4150 | } |
| 4151 | if (as->parms[1].items) { /* -disable */ |
| 4152 | flags |= AFSCALL_RXSTATS_DISABLE0x2; |
| 4153 | } |
| 4154 | if (as->parms[2].items) { /* -clear */ |
| 4155 | flags |= AFSCALL_RXSTATS_CLEAR0x4; |
| 4156 | } |
| 4157 | if (flags == 0) { |
| 4158 | fprintf(stderr__stderrp, "You must specify at least one argument\n"); |
| 4159 | return 1; |
| 4160 | } |
| 4161 | |
| 4162 | blob.in = (char *)&flags; |
| 4163 | blob.in_size = sizeof(afs_int32); |
| 4164 | blob.out_size = 0; |
| 4165 | |
| 4166 | code = pioctl(NULL((void *)0), VIOC_RXSTAT_PROC((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((53))))), &blob, 1); |
| 4167 | if (code != 0) { |
| 4168 | Die(errno(* __error()), NULL((void *)0)); |
| 4169 | return 1; |
| 4170 | } |
| 4171 | |
| 4172 | return 0; |
| 4173 | } |
| 4174 | |
| 4175 | static int |
| 4176 | RxStatPeerCmd(struct cmd_syndesc *as, void *arock) |
| 4177 | { |
| 4178 | afs_int32 code; |
| 4179 | afs_int32 flags = 0; |
| 4180 | struct ViceIoctl blob; |
| 4181 | |
| 4182 | if (as->parms[0].items) { /* -enable */ |
| 4183 | flags |= AFSCALL_RXSTATS_ENABLE0x1; |
| 4184 | } |
| 4185 | if (as->parms[1].items) { /* -disable */ |
| 4186 | flags |= AFSCALL_RXSTATS_DISABLE0x2; |
| 4187 | } |
| 4188 | if (as->parms[2].items) { /* -clear */ |
| 4189 | flags |= AFSCALL_RXSTATS_CLEAR0x4; |
| 4190 | } |
| 4191 | if (flags == 0) { |
| 4192 | fprintf(stderr__stderrp, "You must specify at least one argument\n"); |
| 4193 | return 1; |
| 4194 | } |
| 4195 | |
| 4196 | blob.in = (char *)&flags; |
| 4197 | blob.in_size = sizeof(afs_int32); |
| 4198 | blob.out_size = 0; |
| 4199 | |
| 4200 | code = pioctl(NULL((void *)0), VIOC_RXSTAT_PEER((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((54))))), &blob, 1); |
| 4201 | if (code != 0) { |
| 4202 | Die(errno(* __error()), NULL((void *)0)); |
| 4203 | return 1; |
| 4204 | } |
| 4205 | |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
| 4209 | static int |
| 4210 | GetFidCmd(struct cmd_syndesc *as, void *arock) |
| 4211 | { |
| 4212 | struct ViceIoctl blob; |
| 4213 | struct cmd_item *ti; |
| 4214 | |
| 4215 | afs_int32 code; |
| 4216 | int error = 0; |
| 4217 | char cell[MAXCELLCHARS64]; |
| 4218 | |
| 4219 | SetDotDefault(&as->parms[0].items); |
| 4220 | for (ti = as->parms[0].items; ti; ti = ti->next) { |
| 4221 | struct VenusFid vfid; |
| 4222 | |
| 4223 | blob.out_size = sizeof(struct VenusFid); |
| 4224 | blob.out = (char *) &vfid; |
| 4225 | blob.in_size = 0; |
| 4226 | |
| 4227 | code = pioctl(ti->data, VIOCGETFID((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((22))))), &blob, 1); |
| 4228 | if (code) { |
| 4229 | Die(errno(* __error()),ti->data); |
| 4230 | error = 1; |
| 4231 | continue; |
| 4232 | } |
| 4233 | |
| 4234 | code = GetCell(ti->data, cell); |
| 4235 | if (code) { |
| 4236 | if (errno(* __error()) == ENOENT2) |
| 4237 | fprintf(stderr__stderrp, "%s: no such cell as '%s'\n", pn, ti->data); |
| 4238 | else |
| 4239 | Die(errno(* __error()), ti->data); |
| 4240 | error = 1; |
| 4241 | continue; |
| 4242 | } |
| 4243 | |
| 4244 | printf("File %s (%u.%u.%u) located in cell %s\n", |
| 4245 | ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique, |
| 4246 | cell); |
| 4247 | |
| 4248 | } |
| 4249 | |
| 4250 | return error; |
| 4251 | } |
| 4252 |