- va_start(va, ctl);
- vsnprintf(buf, sizeof(buf), ctl, va);
- syslog(LOG_NOTICE, "%s",buf );
- va_end(va);
-}
-
-static int
-ChangeUser(const char *user, short dochdir)
-{
- struct passwd *pas;
-
- /*
- * Obtain password entry and change privilages
- */
-
- if ((pas = getpwnam(user)) == 0) {
- log("failed to get uid for %s", user);
- return(-1);
- }
- setenv("USER", pas->pw_name, 1);
- setenv("HOME", pas->pw_dir, 1);
- setenv("SHELL", "/bin/sh", 1);
-
- /*
- * Change running state to the user in question
- */
-
- if (initgroups(user, pas->pw_gid) < 0) {
- log("initgroups failed: %s %m", user);
- return(-1);
- }
- if (setregid(pas->pw_gid, pas->pw_gid) < 0) {
- log("setregid failed: %s %d", user, pas->pw_gid);
- return(-1);
- }
- if (setreuid(pas->pw_uid, pas->pw_uid) < 0) {
- log("setreuid failed: %s %d", user, pas->pw_uid);
- return(-1);
- }
- if (dochdir) {
- if (chdir(pas->pw_dir) < 0) {
- if (chdir(TMPDIR) < 0) {
- log("chdir failed: %s %s", user, pas->pw_dir);
- log("chdir failed: %s " TMPDIR, user);
- return(-1);
- }