| File: | venus/up.c |
| Location: | line 298, column 6 |
| Description: | Value stored to 'code' 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 | |
| 13 | #include <roken.h> |
| 14 | |
| 15 | #include <afs/afs_args.h> |
| 16 | #define VIRTUE |
| 17 | #define VICE |
| 18 | #include <afs/vice.h> |
| 19 | #undef VIRTUE |
| 20 | #undef VICE |
| 21 | #include <afs/venus.h> |
| 22 | #include <afs/sys_prototypes.h> |
| 23 | #include <afs/afsutil.h> |
| 24 | #include <afs/afs_consts.h> |
| 25 | |
| 26 | /* ************************************************************* */ |
| 27 | |
| 28 | #define MAXACL400 400 |
| 29 | |
| 30 | short verbose = 0; |
| 31 | short renameTargets = 0; |
| 32 | short oneLevel = 0; |
| 33 | short preserveDate = 1; |
| 34 | short preserveMountPoints = 0; |
| 35 | short forceOverwrite = 0; |
| 36 | |
| 37 | short setacl = 1; |
| 38 | short oldAcl = 0; |
| 39 | char file1[MAXPATHLEN1024], file2[MAXPATHLEN1024]; |
| 40 | |
| 41 | static char space[AFS_PIOCTL_MAXSIZE2048]; |
| 42 | |
| 43 | struct OldAcl { |
| 44 | int nplus; |
| 45 | int nminus; |
| 46 | int offset; |
| 47 | char data[1]; |
| 48 | }; |
| 49 | |
| 50 | static void ScanArgs(int argc, char *argv[]); |
| 51 | static short MakeParent(char *file, afs_int32 owner); |
| 52 | static int Copy(char *file1, char *file2, short recursive, int level); |
| 53 | static int isMountPoint(char *name, struct ViceIoctl *blob); |
| 54 | |
| 55 | |
| 56 | /* ************************************************************ */ |
| 57 | /* */ |
| 58 | /* main program */ |
| 59 | /* */ |
| 60 | /* ************************************************************ */ |
| 61 | |
| 62 | #include "AFS_component_version_number.c" |
| 63 | |
| 64 | int |
| 65 | main(int argc, char *argv[]) |
| 66 | { |
| 67 | #ifdef AFS_AIX32_ENV |
| 68 | /* |
| 69 | * The following signal action for AIX is necessary so that in case of a |
| 70 | * crash (i.e. core is generated) we can include the user's data section |
| 71 | * in the core dump. Unfortunately, by default, only a partial core is |
| 72 | * generated which, in many cases, isn't too useful. |
| 73 | */ |
| 74 | struct sigaction nsa; |
| 75 | |
| 76 | sigemptyset(&nsa.sa_mask); |
| 77 | nsa.sa_handler__sigaction_u.__sa_handler = SIG_DFL((__sighandler_t *)0); |
| 78 | nsa.sa_flags = SA_FULLDUMP; |
| 79 | sigaction(SIGSEGV11, &nsa, NULL((void *)0)); |
| 80 | #endif |
| 81 | ScanArgs(argc, argv); |
| 82 | |
| 83 | /* now read each line of the CopyList */ |
| 84 | if (Copy(file1, file2, !oneLevel, 0)) |
| 85 | return(1); /* some type of failure */ |
| 86 | |
| 87 | return(0); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | #define USAGE"usage: up [-v1frxm] from to\n" "usage: up [-v1frxm] from to\n" |
| 92 | static void |
| 93 | ScanArgs(int argc, char *argv[]) |
| 94 | { |
| 95 | /* skip program name */ |
| 96 | argc--, argv++; |
| 97 | |
| 98 | /* check for -flag options */ |
| 99 | while (argc > 0 && *argv[0] == '-') { |
| 100 | char *cp = *argv; |
| 101 | |
| 102 | if (strlen(cp) > 2) { |
| 103 | goto badoption; |
| 104 | } |
| 105 | |
| 106 | switch (*++cp) { |
| 107 | case 'v': |
| 108 | verbose = 1; |
| 109 | break; |
| 110 | |
| 111 | case '1': |
| 112 | oneLevel = 1; |
| 113 | break; |
| 114 | |
| 115 | case 'r': |
| 116 | renameTargets = 1; |
| 117 | break; |
| 118 | |
| 119 | case 'f': |
| 120 | forceOverwrite = 1; |
| 121 | break; |
| 122 | |
| 123 | case 'x': |
| 124 | preserveDate = 0; |
| 125 | break; |
| 126 | |
| 127 | case 'm': |
| 128 | preserveMountPoints = 1; |
| 129 | break; |
| 130 | |
| 131 | default: |
| 132 | cp--; |
| 133 | |
| 134 | badoption: |
| 135 | fprintf(stderr__stderrp, "Unknown option: '%s'\n", cp); |
| 136 | fprintf(stderr__stderrp, USAGE"usage: up [-v1frxm] from to\n"); |
| 137 | exit(1); |
| 138 | } |
| 139 | argc--, argv++; |
| 140 | } |
| 141 | |
| 142 | if (argc != 2) { |
| 143 | fprintf(stderr__stderrp, USAGE"usage: up [-v1frxm] from to\n"); |
| 144 | exit(1); |
| 145 | } |
| 146 | |
| 147 | strncpy(file1, argv[0], MAXPATHLEN1024); |
| 148 | strncpy(file2, argv[1], MAXPATHLEN1024); |
| 149 | |
| 150 | } /*ScanArgs */ |
| 151 | |
| 152 | |
| 153 | |
| 154 | /* |
| 155 | * MakeParent |
| 156 | * Make sure the parent directory of this file exists. Returns |
| 157 | * 1 if it exists, 0 otherwise. Note: the owner argument |
| 158 | * is a hack. All directories made will have this owner. |
| 159 | */ |
| 160 | static short |
| 161 | MakeParent(char *file, afs_int32 owner) |
| 162 | { |
| 163 | char parent[MAXPATHLEN1024]; |
| 164 | char *p; |
| 165 | struct stat s; |
| 166 | |
| 167 | strlcpy(parent, file, sizeof parent); |
| 168 | |
| 169 | p = strrchr(parent, '/'); |
| 170 | if (!p) { |
| 171 | strlcpy(parent, ".", sizeof parent); |
| 172 | } else if (p > parent) { |
| 173 | *p = '\0'; |
| 174 | } else { |
| 175 | p[1] = '\0'; |
| 176 | } |
| 177 | |
| 178 | if (stat(parent, &s) < 0) { |
| 179 | if (!MakeParent(parent, owner)) |
| 180 | return (0); |
| 181 | |
| 182 | if (verbose) { |
| 183 | printf("Creating directory %s\n", parent); |
| 184 | fflush(stdout__stdoutp); |
| 185 | } |
| 186 | |
| 187 | mkdir(parent, 0777); |
| 188 | chown(parent, owner, -1); |
| 189 | } |
| 190 | return (1); |
| 191 | } /*MakeParent */ |
| 192 | |
| 193 | |
| 194 | /* |
| 195 | * Copy |
| 196 | * This does the bulk of the work of the program. Handle one file, |
| 197 | * possibly copying subfiles if this is a directory |
| 198 | */ |
| 199 | static int |
| 200 | Copy(char *file1, char *file2, short recursive, int level) |
| 201 | { |
| 202 | struct stat s1, s2; /*Stat blocks */ |
| 203 | struct ViceIoctl blob; |
| 204 | char aclspace[MAXACL400]; |
| 205 | afs_int32 rcode = 0, code; |
| 206 | int goods2 = 1; |
| 207 | |
| 208 | code = lstat(file1, &s1); |
| 209 | if (code < 0) { |
| 210 | fprintf(stderr__stderrp, "Can't find %s\n", file1); |
| 211 | return 1; |
| 212 | } |
| 213 | |
| 214 | code = lstat(file2, &s2); |
| 215 | if (code < 0) { |
| 216 | if (!MakeParent(file2, s1.st_uid)) |
| 217 | return 0; |
| 218 | goods2 = 0; |
| 219 | } |
| 220 | |
| 221 | if ((s1.st_mode & S_IFMT0170000) == S_IFREG0100000) { |
| 222 | /* |
| 223 | * -------------------- Copy regular file -------------------- |
| 224 | */ |
| 225 | int f1, f2, n; |
| 226 | char buf[4096]; /* Must be bigger than sizeof (*head) */ |
| 227 | struct timeval tv[2]; |
| 228 | char tmpfile[MAXPATHLEN1024], newName[MAXPATHLEN1024]; |
| 229 | |
| 230 | if (verbose) { |
| 231 | printf("Level %d: File %s to %s\n", level, file1, file2); |
| 232 | fflush(stdout__stdoutp); |
| 233 | } |
| 234 | |
| 235 | /* Wonder if there is a security hole */ |
| 236 | if (((s1.st_mode & 04002) == 04002) || ((s1.st_mode & 04020) == 04020) |
| 237 | || ((s1.st_mode & 02002) == 02002)) { |
| 238 | fprintf(stderr__stderrp, |
| 239 | "WARNING: Mode-bits security hole in files %s and %s\n", |
| 240 | file1, file2); |
| 241 | } |
| 242 | |
| 243 | if (!goods2 || (s1.st_mtimest_mtim.tv_sec != s2.st_mtimest_mtim.tv_sec) || (s1.st_size != s2.st_size)) { /*c */ |
| 244 | /* Don't ovewrite a write protected file (unless force: -f) */ |
| 245 | if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { |
| 246 | fprintf(stderr__stderrp, |
| 247 | "File %s is write protected against its owner; not changed\n", |
| 248 | file2); |
| 249 | return 1; |
| 250 | } |
| 251 | |
| 252 | if (verbose) { |
| 253 | printf(" Copy file %s to %s (%u Bytes)\n", file1, file2, |
| 254 | (unsigned int) s1.st_size); |
| 255 | fflush(stdout__stdoutp); |
| 256 | } |
| 257 | |
| 258 | strlcpy(tmpfile, file2, sizeof tmpfile); /* Name of temporary file */ |
| 259 | strlcat(tmpfile, ".UPD", sizeof tmpfile); |
| 260 | |
| 261 | /* open file1 for input */ |
| 262 | f1 = open(file1, O_RDONLY0x0000); |
| 263 | if (f1 < 0) { |
| 264 | fprintf(stderr__stderrp, "Unable to open input file %s: %s\n", |
| 265 | file1, strerror(errno(* __error()))); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | /* open temporary output file */ |
| 270 | f2 = open(tmpfile, (O_WRONLY0x0001 | O_CREAT0x0200 | O_TRUNC0x0400), s1.st_mode); |
| 271 | if (f2 < 0) { |
| 272 | fprintf(stderr__stderrp, "Unable to open output file %s: %s\n", |
| 273 | tmpfile, strerror(errno(* __error()))); |
| 274 | fflush(stdout__stdoutp); |
| 275 | close(f1); |
| 276 | return 1; |
| 277 | } |
| 278 | |
| 279 | /* Copy file1 to temporary file */ |
| 280 | while ((n = read(f1, buf, sizeof(buf))) > 0) { |
| 281 | if (write(f2, buf, n) != n) { |
| 282 | fprintf(stderr__stderrp, |
| 283 | "Write failed, file %s must be copied again.\n", |
| 284 | file2); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* preserve access and modification times: ("-x" disables) */ |
| 289 | if (preserveDate) { |
| 290 | tv[0].tv_sec = s1.st_atimest_atim.tv_sec; |
| 291 | tv[0].tv_usec = 0; |
| 292 | tv[1].tv_sec = s1.st_mtimest_mtim.tv_sec; |
| 293 | tv[1].tv_usec = 0; |
| 294 | utimes(tmpfile, tv); |
| 295 | } |
| 296 | |
| 297 | /* Close the files */ |
| 298 | code = close(f1); |
Value stored to 'code' is never read | |
| 299 | code = close(f2); |
| 300 | if (code < 0) { |
| 301 | perror("close "); |
| 302 | rcode = 1; |
| 303 | } |
| 304 | |
| 305 | /* Rename file2 to file2.old. [-r] */ |
| 306 | if (renameTargets && goods2) { |
| 307 | strlcpy(newName, file2, sizeof newName); |
| 308 | strlcat(newName, ".old", sizeof newName); |
| 309 | if (verbose) { |
| 310 | printf(" Renaming %s to %s\n", file2, newName); |
| 311 | fflush(stdout__stdoutp); |
| 312 | } |
| 313 | if (rename(file2, newName) < 0) { |
| 314 | fprintf(stderr__stderrp, "Rename of %s to %s failed.\n", file2, |
| 315 | newName); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* Rename temporary file to file2 */ |
| 320 | code = rename(tmpfile, file2); |
| 321 | if (code < 0) { |
| 322 | fprintf(stderr__stderrp, "Rename of %s to %s failed.\n", tmpfile, |
| 323 | file2); |
| 324 | return 1; |
| 325 | } |
| 326 | |
| 327 | /* Re-stat file2 and compare file sizes */ |
| 328 | code = lstat(file2, &s2); |
| 329 | if (code < 0) { |
| 330 | fprintf(stderr__stderrp, "WARNING: Unable to stat new file %s\n", |
| 331 | file2); |
| 332 | return 1; |
| 333 | } |
| 334 | if (s1.st_size != s2.st_size) { |
| 335 | fprintf(stderr__stderrp, |
| 336 | "WARNING: New file %s is %u bytes long; should be %u\n", |
| 337 | file2, (unsigned int) s2.st_size, |
| 338 | (unsigned int) s1.st_size); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /*c */ |
| 343 | /* Set the user-id */ |
| 344 | if (s2.st_uid != s1.st_uid) { |
| 345 | if (verbose) { |
| 346 | printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); |
| 347 | fflush(stdout__stdoutp); |
| 348 | } |
| 349 | code = chown(file2, s1.st_uid, -1); |
| 350 | if (code) { |
| 351 | fprintf(stderr__stderrp, "Unable to set owner-id for %s to %d\n", |
| 352 | file2, s1.st_uid); |
| 353 | fflush(stdout__stdoutp); |
| 354 | rcode = 1; |
| 355 | s1.st_mode &= ~04000; /* Don't set suid bit */ |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /* Set the group-id */ |
| 360 | if (s2.st_gid != s1.st_gid) { |
| 361 | if (verbose) { |
| 362 | printf(" Set group-id for %s to %d\n", file2, s1.st_gid); |
| 363 | fflush(stdout__stdoutp); |
| 364 | } |
| 365 | code = chown(file2, -1, s1.st_gid); |
| 366 | if (code) { |
| 367 | fprintf(stderr__stderrp, "Unable to set group-id for %s to %d\n", |
| 368 | file2, s1.st_gid); |
| 369 | fflush(stdout__stdoutp); |
| 370 | rcode = 1; |
| 371 | s1.st_mode &= ~02000; /* Don't set sgid bit */ |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /* Set the mode bits */ |
| 376 | if (s1.st_mode != s2.st_mode) { |
| 377 | if (verbose) { |
| 378 | printf(" Set mode-bit for %s to %o\n", file2, |
| 379 | (s1.st_mode & 07777)); |
| 380 | fflush(stdout__stdoutp); |
| 381 | } |
| 382 | code = chmod(file2, s1.st_mode); |
| 383 | if (code) { |
| 384 | fprintf(stderr__stderrp, "Unable to set mode-bits for %s to %d\n", |
| 385 | file2, s1.st_mode); |
| 386 | rcode = 1; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | /* regular file */ |
| 391 | else if ((s1.st_mode & S_IFMT0170000) == S_IFLNK0120000) { |
| 392 | /* |
| 393 | * --------------------- Copy symlink -------------------- |
| 394 | */ |
| 395 | char linkvalue[MAXPATHLEN1024 + 1]; |
| 396 | int n; |
| 397 | |
| 398 | if (verbose) { |
| 399 | printf("Level %d: Symbolic link %s to %s\n", level, file1, file2); |
| 400 | fflush(stdout__stdoutp); |
| 401 | } |
| 402 | |
| 403 | /* Don't ovewrite a write protected directory (unless force: -f) */ |
| 404 | if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { |
| 405 | fprintf(stderr__stderrp, |
| 406 | "Link %s is write protected against its owner; not changed\n", |
| 407 | file2); |
| 408 | return 1; |
| 409 | } |
| 410 | |
| 411 | if (verbose) { |
| 412 | printf(" Copy symbolic link %s->%s to %s\n", file1, linkvalue, |
| 413 | file2); |
| 414 | fflush(stdout__stdoutp); |
| 415 | } |
| 416 | |
| 417 | n = readlink(file1, linkvalue, sizeof(linkvalue)); |
| 418 | if (n == -1) { |
| 419 | fprintf(stderr__stderrp, "Could not read symbolic link %s\n", file1); |
| 420 | perror("read link "); |
| 421 | return 1; |
| 422 | } |
| 423 | linkvalue[n] = 0; |
| 424 | |
| 425 | unlink(file2); /* Always make the new link (it was easier) */ |
| 426 | |
| 427 | code = symlink(linkvalue, file2); |
| 428 | if (code == -1) { |
| 429 | fprintf(stderr__stderrp, "Could not create symbolic link %s\n", file2); |
| 430 | perror("create link "); |
| 431 | return 1; |
| 432 | } |
| 433 | } |
| 434 | /*Dealing with symlink */ |
| 435 | else if (preserveMountPoints && (code = isMountPoint(file1, &blob))) { |
| 436 | /* |
| 437 | * --------------------- Copy mount point -------------------- |
| 438 | */ |
| 439 | |
| 440 | if (code > 1) { |
| 441 | perror("checking for mount point "); |
| 442 | return 1; |
| 443 | } |
| 444 | if (verbose) { |
| 445 | printf("Level %d: Mount point %s to %s\n", level, file1, file2); |
| 446 | fflush(stdout__stdoutp); |
| 447 | } |
| 448 | |
| 449 | /* Don't ovewrite a write protected directory (unless force: -f) */ |
| 450 | if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { |
| 451 | fprintf(stderr__stderrp, |
| 452 | "Target %s is write protected against its owner; not changed\n", |
| 453 | file2); |
| 454 | return 1; |
| 455 | } |
| 456 | |
| 457 | if (verbose) { |
| 458 | printf(" Copy mount point %s for vol %s to %s\n", file1, |
| 459 | blob.out, file2); |
| 460 | fflush(stdout__stdoutp); |
| 461 | } |
| 462 | |
| 463 | unlink(file2); /* Always make the new link (it was easier) */ |
| 464 | |
| 465 | strcat(blob.out, "."); /* stupid convention; these end with a period */ |
| 466 | code = symlink(blob.out, file2); |
| 467 | if (code == -1) { |
| 468 | fprintf(stderr__stderrp, "Could not create mount point %s for vol %s\n", |
| 469 | file2, blob.out); |
| 470 | perror("create mount point "); |
| 471 | return 1; |
| 472 | } |
| 473 | |
| 474 | } |
| 475 | /*Dealing with mount point */ |
| 476 | else if (((s1.st_mode & S_IFMT0170000) == S_IFDIR0040000) |
| 477 | && (recursive || (level == 0))) { |
| 478 | /* |
| 479 | * ----------------------- Copy directory ----------------------- |
| 480 | */ |
| 481 | DIR *dir; |
| 482 | int tfd, code, i; |
| 483 | struct OldAcl *oacl; |
| 484 | char tacl[MAXACL400]; |
| 485 | char f1[MAXPATHLEN1024], f2[MAXPATHLEN1024]; |
| 486 | char *p1, *p2; |
| 487 | struct dirent *d; |
| 488 | struct timeval tv[2]; |
| 489 | |
| 490 | if (verbose) { |
| 491 | printf("Level %d: Directory %s to %s\n", level, file1, file2); |
| 492 | fflush(stdout__stdoutp); |
| 493 | } |
| 494 | |
| 495 | /* Don't ovewrite a write protected directory (unless force: -f) */ |
| 496 | if (!forceOverwrite && goods2 && (s2.st_mode & 0200) == 0) { |
| 497 | fprintf(stderr__stderrp, |
| 498 | "Directory %s is write protected against its owner; not changed\n", |
| 499 | file2); |
| 500 | return 1; |
| 501 | } |
| 502 | |
| 503 | strlcpy(f1, file1, sizeof f1); |
| 504 | strlcpy(f2, file2, sizeof f2); |
| 505 | p1 = f1 + strlen(f1); |
| 506 | p2 = f2 + strlen(f2); |
| 507 | if (p1 == f1 || p1[-1] != '/') |
| 508 | *p1++ = '/'; |
| 509 | if (p2 == f2 || p2[-1] != '/') |
| 510 | *p2++ = '/'; |
| 511 | |
| 512 | dir = opendir(file1); |
| 513 | if (dir == NULL((void *)0)) { |
| 514 | fprintf(stderr__stderrp, "Couldn't open %s\n", file1); |
| 515 | return 1; |
| 516 | } |
| 517 | |
| 518 | while ((d = readdir(dir)) != NULL((void *)0)) { |
| 519 | if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) |
| 520 | continue; |
| 521 | strlcpy(p1, d->d_name, sizeof f1 - (p1 - f1)); |
| 522 | strlcpy(p2, d->d_name, sizeof f2 - (p2 - f2)); |
| 523 | code = Copy(f1, f2, recursive, level + 1); |
| 524 | if (code && !rcode) |
| 525 | rcode = 1; /* remember errors */ |
| 526 | } |
| 527 | |
| 528 | closedir(dir); |
| 529 | |
| 530 | if (verbose) { |
| 531 | printf("Level %d: Copied directory %s to %s\n", level, file1, |
| 532 | file2); |
| 533 | fflush(stdout__stdoutp); |
| 534 | } |
| 535 | |
| 536 | mkdir(file2, 0777); /* Handle case where MakeParent not invoked. */ |
| 537 | |
| 538 | if (verbose) { |
| 539 | printf(" Set owner-id for %s to %d\n", file2, s1.st_uid); |
| 540 | fflush(stdout__stdoutp); |
| 541 | } |
| 542 | code = chown(file2, s1.st_uid, -1); |
| 543 | if (code) { |
| 544 | fprintf(stderr__stderrp, "Unable to set owner-id for %s to %d\n", file2, |
| 545 | s1.st_uid); |
| 546 | fflush(stdout__stdoutp); |
| 547 | s1.st_mode &= ~04000; /* Don't set suid bit */ |
| 548 | } |
| 549 | |
| 550 | if (verbose) { |
| 551 | printf(" Set group-id for %s to %d\n", file2, s1.st_gid); |
| 552 | fflush(stdout__stdoutp); |
| 553 | } |
| 554 | code = chown(file2, -1, s1.st_gid); |
| 555 | if (code) { |
| 556 | fprintf(stderr__stderrp, "Unable to set group-id for %s to %d\n", file2, |
| 557 | s1.st_gid); |
| 558 | fflush(stdout__stdoutp); |
| 559 | s1.st_mode &= ~02000; /* Don't set sgid bit */ |
| 560 | } |
| 561 | |
| 562 | if (verbose) { |
| 563 | printf(" Set mode-bit for %s to %o\n", file2, |
| 564 | (s1.st_mode & 07777)); |
| 565 | fflush(stdout__stdoutp); |
| 566 | } |
| 567 | code = chmod(file2, s1.st_mode); |
| 568 | if (code) { |
| 569 | fprintf(stderr__stderrp, "Unable to set mode-bits for %s to %d\n", file2, |
| 570 | s1.st_mode); |
| 571 | fflush(stdout__stdoutp); |
| 572 | rcode = 1; |
| 573 | } |
| 574 | |
| 575 | if (setacl == 1) { |
| 576 | if (verbose) { |
| 577 | printf(" Set acls for %s\n", file2); |
| 578 | fflush(stdout__stdoutp); |
| 579 | } |
| 580 | |
| 581 | blob.in = aclspace; |
| 582 | blob.out = aclspace; |
| 583 | blob.in_size = 0; |
| 584 | blob.out_size = MAXACL400; |
| 585 | |
| 586 | if (oldAcl) { |
| 587 | /* Get an old-style ACL and convert it */ |
| 588 | if (verbose) { |
| 589 | printf(" Getting old style acl\n"); |
| 590 | fflush(stdout__stdoutp); |
| 591 | } |
| 592 | |
| 593 | for (i = 1; i < strlen(file1); i++) |
| 594 | if (file1[i] == '/') |
| 595 | break; |
| 596 | strlcpy(aclspace, &file1[i], sizeof aclspace); |
| 597 | |
| 598 | blob.in_size = 1 + strlen(aclspace); |
| 599 | tfd = open(file1, O_RDONLY0x0000, 0); |
| 600 | if (tfd < 0) { |
| 601 | perror("old-acl open "); |
| 602 | return 1; |
| 603 | } |
| 604 | code = ioctl(tfd, _VICEIOCTL(4)((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((4))))), &blob); |
| 605 | close(tfd); |
| 606 | if (code < 0) { |
| 607 | if (errno(* __error()) == EINVAL22) { |
| 608 | setacl = 0; |
| 609 | if (verbose) { |
| 610 | printf(" _VICEIOCTL(4) returns EINVAL\n"); |
| 611 | fflush(stdout__stdoutp); |
| 612 | } |
| 613 | } else { |
| 614 | return 1; |
| 615 | } |
| 616 | } |
| 617 | /* Now convert the thing. */ |
| 618 | oacl = (struct OldAcl *)(aclspace + 4); |
| 619 | sprintf(tacl, "%d\n%d\n", oacl->nplus, oacl->nminus); |
| 620 | strlcat(tacl, oacl->data, sizeof tacl); |
| 621 | strlcpy(aclspace, tacl, sizeof aclspace); |
| 622 | } /*Grab and convert old-style ACL */ |
| 623 | else { |
| 624 | /* Get a new-style ACL */ |
| 625 | if (verbose) { |
| 626 | printf(" Getting new style acl\n"); |
| 627 | fflush(stdout__stdoutp); |
| 628 | } |
| 629 | |
| 630 | code = pioctl(file1, _VICEIOCTL(2)((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((2))))), &blob, 1); |
| 631 | if (code < 0) { |
| 632 | if (errno(* __error()) == EINVAL22) { |
| 633 | setacl = 0; |
| 634 | if (verbose) { |
| 635 | printf(" _VICEIOCTL(2) returns EINVAL\n"); |
| 636 | fflush(stdout__stdoutp); |
| 637 | } |
| 638 | } else { |
| 639 | perror("getacl "); |
| 640 | return 1; |
| 641 | } |
| 642 | } |
| 643 | } /*Grab new-style ACL */ |
| 644 | |
| 645 | /* |
| 646 | * Now, set the new-style ACL. |
| 647 | */ |
| 648 | if (setacl == 1) { |
| 649 | if (verbose) { |
| 650 | printf(" Setting new style acl\n"); |
| 651 | fflush(stdout__stdoutp); |
| 652 | } |
| 653 | blob.out = aclspace; |
| 654 | blob.in = aclspace; |
| 655 | blob.out_size = 0; |
| 656 | blob.in_size = 1 + strlen(aclspace); |
| 657 | code = pioctl(file2, _VICEIOCTL(1)((unsigned int) ((unsigned long) ((0x80000000) | (((sizeof(struct ViceIoctl)) & ((1 << 13) - 1)) << 16) | ((('V' )) << 8) | ((1))))), &blob, 1); |
| 658 | if (code) { |
| 659 | if (errno(* __error()) == EINVAL22) { |
| 660 | setacl = 0; |
| 661 | if (verbose) { |
| 662 | printf(" _VICEIOCTL(1) returns EINVAL\n"); |
| 663 | fflush(stdout__stdoutp); |
| 664 | } |
| 665 | } else { |
| 666 | fprintf(stderr__stderrp, "Couldn't set acls for %s\n", file2); |
| 667 | return 1; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | if (setacl == 0) { |
| 673 | printf("Not setting acls\n"); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /* preserve access and modification times: ("-x" disables) */ |
| 678 | if (preserveDate) { |
| 679 | tv[0].tv_sec = s1.st_atimest_atim.tv_sec; |
| 680 | tv[0].tv_usec = 0; |
| 681 | tv[1].tv_sec = s1.st_mtimest_mtim.tv_sec; |
| 682 | tv[1].tv_usec = 0; |
| 683 | utimes(file2, tv); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | return rcode; |
| 688 | } /*Copy */ |
| 689 | |
| 690 | |
| 691 | static int |
| 692 | isMountPoint(char *name, struct ViceIoctl *blob) |
| 693 | { |
| 694 | afs_int32 code; |
| 695 | char true_name[1024]; /*dirname */ |
| 696 | char parent_dir[1024]; /*Parent directory of true name */ |
| 697 | char *last_component; /*Last component of true name */ |
| 698 | |
| 699 | sprintf(true_name, "%s%s", (name[0] == '/') ? "" : "./", name); |
| 700 | |
| 701 | /* |
| 702 | * Find rightmost slash, if any. |
| 703 | */ |
| 704 | last_component = (char *)strrchr(true_name, '/'); |
| 705 | if (last_component) { |
| 706 | /* |
| 707 | * Found it. Designate everything before it as the parent directory, |
| 708 | * everything after it as the final component. |
| 709 | */ |
| 710 | strncpy(parent_dir, true_name, last_component - true_name); |
| 711 | parent_dir[last_component - true_name] = 0; |
| 712 | last_component++; /*Skip the slash */ |
| 713 | } else { |
| 714 | /* |
| 715 | * No slash appears in the given file name. Set parent_dir to the current |
| 716 | * directory, and the last component as the given name. |
| 717 | */ |
| 718 | strlcpy(parent_dir, ".", sizeof parent_dir); |
| 719 | last_component = true_name; |
| 720 | } |
| 721 | |
| 722 | if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) { |
| 723 | fprintf(stderr__stderrp, |
| 724 | "up: you may not use '.' or '..' as the last component\n"); |
| 725 | fprintf(stderr__stderrp, "up: of a name in the 'up' command.\n"); |
| 726 | return 3; |
| 727 | } |
| 728 | |
| 729 | blob->in = last_component; |
| 730 | blob->in_size = strlen(last_component) + 1; |
| 731 | blob->out_size = AFS_PIOCTL_MAXSIZE2048; |
| 732 | blob->out = space; |
| 733 | memset(space, 0, AFS_PIOCTL_MAXSIZE2048); |
| 734 | |
| 735 | 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, 0); |
| 736 | |
| 737 | if (code == 0) { |
| 738 | printf("'%s' is a mount point for volume '%s'\n", name, space); |
| 739 | fflush(stdout__stdoutp); |
| 740 | return 1; |
| 741 | } else { |
| 742 | if (errno(* __error()) == EINVAL22) { |
| 743 | /* printf( "'%s' is not a mount point.\n", name); |
| 744 | * fflush(stdout); |
| 745 | */ |
| 746 | return 0; |
| 747 | } else { |
| 748 | fprintf(stderr__stderrp, "problem examining '%s' in '%s'.\n", |
| 749 | last_component, parent_dir); |
| 750 | return 2; |
| 751 | /* Die(errno, (ti->data ? ti->data : parent_dir)); |
| 752 | */ |
| 753 | } |
| 754 | } |
| 755 | } |