- return filedes[0];
- }
-
- /*
- * CHILD
- */
-
- close(filedes[0]);
-
- if (ChangeUser(user, 0) < 0)
- exit(0);
-
- xfunc_error_retval = 0;
- fd = xopen(file, O_RDONLY);
- buf[0] = 0;
- write(filedes[1], buf, 1);
- while ((n = read(fd, buf, sizeof(buf))) > 0) {
- write(filedes[1], buf, n);
- }
- 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);