- exit(0);
-}
-
-static void EditFile(const char *user, const char *file)
-{
- int pid = fork();
-
- if (pid == 0) {
- /*
- * CHILD - change user and run editor
- */
- const char *ptr;
-
- if (ChangeUser(user, 1) < 0)
- exit(0);
- ptr = getenv("VISUAL");
- if (ptr == NULL || strlen(ptr) > 256)
- ptr = PATH_VI;
-
- ptr = xasprintf("%s %s", ptr, file);
- execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", ptr, NULL);
- bb_perror_msg_and_die("exec");
- }
- if (pid < 0) {
- /*
- * PARENT - failure
- */
- bb_perror_msg_and_die("fork");
- }
- wait4(pid, NULL, 0, NULL);
-}
-
-static int ChangeUser(const char *user, short dochdir)
-{
- struct passwd *pas;
-
- /*
- * Obtain password entry and change privileges
- */
-
- pas = getpwnam(user);
- if (pas == NULL) {
- bb_perror_msg_and_die("failed to get uid for %s", user);
- }
- setenv("USER", pas->pw_name, 1);
- setenv("HOME", pas->pw_dir, 1);
- setenv("SHELL", DEFAULT_SHELL, 1);
-
- /*
- * Change running state to the user in question
- */
- change_identity(pas);
-
- if (dochdir) {
- if (chdir(pas->pw_dir) < 0) {
- bb_perror_msg("chdir(%s) by %s failed", pas->pw_dir, user);
- xchdir(TMPDIR);
- }
- }
- return pas->pw_uid;