(void) umask((mode_t)UMASK);
#endif /* UMASK */
- /*
- * so we know where we are... (do as user)
- */
- if (!getwd(cwd)) {
- (void) fprintf(stderr, "%s: Can't get working directory!\n", Argv[0]);
- exit(1);
- }
-
#ifdef NO_ROOT_SUDO
if (uid == 0) {
- (void) fprintf(stderr, "You are already root, you don't need to use sudo.\n");
+ (void) fprintf(stderr,
+ "You are already root, you don't need to use sudo.\n");
exit(1);
}
#endif
+ /*
+ * so we know where we are... (do as user)
+ */
+ if (!getwd(cwd)) {
+ /* try as root... */
+ set_perms(PERM_ROOT);
+ if (!getwd(cwd)) {
+ (void) fprintf(stderr, "%s: Can't get working directory!\n",
+ Argv[0]);
+ (void) strcpy(cwd, "unknown");
+ }
+ set_perms(PERM_USER);
+ }
+
/*
* load the host global variable from gethostname()
* and use gethostbyname() if we want it to be fully qualified.