/*FUNCTION*/ int hook_getowner(pExecuteObject pEo, char *pszFileName, char *pszOwnerBuffer, long cbOwnerBuffer ){ /*noverbatim CUT*/ return file_getowner(pszFileName,pszOwnerBuffer,cbOwnerBuffer); }
int main(int argc, char *argv[]) { struct stat from_sb, to_sb; mode_t *set; u_long fset; u_long fclr; int ch, no_target; int trysys; u_int iflags; const char *group, *owner, *to_name; const char *etcdir; fclr = 0; fset = 0; iflags = 0; trysys = 0; group = NULL; owner = NULL; etcdir = NULL; while ((ch = getopt(argc, argv, "L:B:bCcD:df:g:lMm:o:pSsUv")) != -1) switch((char)ch) { case 'B': suffix = optarg; /* FALLTHROUGH */ case 'b': dobackup = 1; break; case 'C': docompare = 1; break; case 'c': /* For backwards compatibility. */ break; case 'D': destdir = optarg; break; case 'd': dodir = 1; break; case 'f': fflags = optarg; break; case 'g': group = optarg; break; case 'L': etcdir = optarg; break; case 'l': trysys = 1; break; case 'M': nommap = 1; break; case 'm': if (!(set = setmode(optarg))) errx(EX_USAGE, "invalid file mode: %s", optarg); mode = getmode(set, 0); free(set); break; case 'o': owner = optarg; break; case 'p': docompare = dopreserve = 1; break; case 'S': safecopy = 1; break; case 's': dostrip = 1; break; case 'U': dounpriv = 1; break; case 'v': verbose = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; /* some options make no sense when creating directories */ if (dostrip && dodir) { warnx("-d and -s may not be specified together"); usage(); } if (getenv("DONTSTRIP") != NULL) { warnx("DONTSTRIP set - will not strip installed binaries"); dostrip = 0; } /* must have at least two arguments, except when creating directories */ if (argc < 2 && !dodir) usage(); /* need to make a temp copy so we can compare stripped version */ if (docompare && dostrip) safecopy = 1; /* no etcdir specified, always try the system */ if (etcdir == NULL) trysys = 1; uid = (uid_t)-1; gid = (gid_t)-1; /* get group and owner id's */ if (group != NULL && !dounpriv) { if (etcdir && file_getgroup(etcdir, group, &gid)) { ; } else if (trysys && (gp = getgrnam(group)) != NULL) { gid = gp->gr_gid; } else { gid = (gid_t)numeric_id(group, "group"); } } if (owner != NULL && !dounpriv) { if (etcdir && file_getowner(etcdir, owner, &uid)) { ; } else if (trysys && (pp = getpwnam(owner)) != NULL) { uid = pp->pw_uid; } else { uid = (uid_t)numeric_id(owner, "user"); } } if (fflags != NULL && !dounpriv) { if (strtofflags(&fflags, &fset, &fclr)) errx(EX_USAGE, "%s: invalid flag", fflags); iflags |= SETFLAGS; } if (dodir) { for (; *argv != NULL; ++argv) install_dir(*argv); exit(EX_OK); /* NOTREACHED */ } to_name = argv[argc - 1]; no_target = stat(to_name, &to_sb); if (!no_target && S_ISDIR(to_sb.st_mode)) { for (; *argv != to_name; ++argv) install(*argv, to_name, fset, fclr, iflags | DIRECTORY); exit(EX_OK); /* NOTREACHED */ } /* can't do file1 file2 directory/file */ if (argc != 2) { if (no_target) warnx("target directory `%s' does not exist", argv[argc - 1]); else warnx("target `%s' is not a directory", argv[argc - 1]); usage(); } if (!no_target) { if (stat(*argv, &from_sb)) err(EX_OSERR, "%s", *argv); if (!S_ISREG(to_sb.st_mode)) { errno = EFTYPE; err(EX_OSERR, "%s", to_name); } if (to_sb.st_dev == from_sb.st_dev && to_sb.st_ino == from_sb.st_ino) errx(EX_USAGE, "%s and %s are the same file", *argv, to_name); } install(*argv, to_name, fset, fclr, iflags); exit(EX_OK); /* NOTREACHED */ }