" -g|--group <groupname> } add this to\n"
" -G|--gid <gid> } the group list\n"
"other really-options:\n"
- " -h|--help display this message"
- " -R|--chroot <dir> chroot (but *not* chdir)",
+ " -h|--help display this message\n"
+ " -R|--chroot <dir> chroot (but *not* chdir)\n",
stderr) == EOF) { perror("write usage"); exit(-1); }
}
};
#ifdef REALLY_CHECK_FILE
-static void checkroot(void) {
+static int checkroot(void) {
int r;
r= access(REALLY_CHECK_FILE,W_OK);
- if (r) { perror("sorry"); exit(-1); }
+ if (r) return -1;
+ return 0;
}
#endif
#ifdef REALLY_CHECK_GID
-static void checkroot(void) {
+static int checkroot(void) {
gid_t groups[512];
int r, i;
- r= getgid(); if (r==REALLY_CHECK_GID) return;
+ r= getgid(); if (r==REALLY_CHECK_GID) return 0;
if (r<0) { perror("getgid check"); exit(-1); }
r= getgroups(sizeof(groups)/sizeof(groups[0]),groups);
if (r<0) { perror("getgroups check"); exit(-1); }
for (i=0; i<r; i++)
- if (groups[i] == REALLY_CHECK_GID) return;
- fputs("sorry\n",stderr); exit(-1);
+ if (groups[i] == REALLY_CHECK_GID) return 0;
+ return -1;
}
#endif
#ifdef REALLY_CHECK_NONE
-static void checkroot(void) {
+static int checkroot(void) {
+ return 0;
}
#endif
int i, j, ngroups, ngroups_in, maingid, orgmaingid, mainuid, orgmainuid, r;
const char *cp;
- checkroot();
+ orgmainuid= getuid();
+ if (orgmainuid && checkroot()) { perror("sorry"); exit(-1); }
myopt(&argv,cmdinfos);
if (opt_groupsclear && !opt_ngids)
if (chroot(opt_chroot)) { perror("chroot failed"); exit(-1); }
}
orgmaingid= getgid();
- orgmainuid= getuid();
if (orgmaingid<0) { perror("getgid failed"); exit(-1); }
if (opt_user) {
r= initgroups(opt_user,pw->pw_gid);