diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2000-04-20 02:33:20 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2000-04-20 02:33:20 +0400 |
commit | f06a3648d543c404968edde157414ce3ee6a8770 (patch) | |
tree | 227a075c943efc3feef281b03a631b9a241da1e5 /winsup/cygwin/syscalls.cc | |
parent | ceba50edbea883972b93f95c1f0e6afda5702b1b (diff) |
* syscalls.cc (setuid): Allow switching user context after
successful call to ImpersonateLogedOnUser (NT only).
(setgid): Ditto.
(seteuid): Call setuid.
(setegid): Call setgid.
Diffstat (limited to 'winsup/cygwin/syscalls.cc')
-rw-r--r-- | winsup/cygwin/syscalls.cc | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index ca9777f79..23faca911 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -1689,41 +1689,79 @@ mknod () } /* setgid: POSIX 4.2.2.1 */ -/* FIXME: unimplemented! */ extern "C" int -setgid (gid_t) +setgid (gid_t gid) { - set_errno (ENOSYS); + if (os_being_run == winNT) + { + if (gid != (gid_t) -1) + { + if (!getgrgid (gid)) + { + set_errno (EINVAL); + return -1; + } + myself->gid = gid; + } + } + else + set_errno (ENOSYS); return 0; } +extern char *internal_getlogin (struct pinfo *pi); + /* setuid: POSIX 4.2.2.1 */ -/* FIXME: unimplemented! */ extern "C" int -setuid (uid_t) +setuid (uid_t uid) { - set_errno (ENOSYS); + if (os_being_run == winNT) + { + if (uid != (uid_t) -1) + { + struct passwd *pw_new = getpwuid (uid); + if (!pw_new) + { + set_errno (EINVAL); + return -1; + } + + struct pinfo pi; + pi.psid = (PSID) pi.sidbuf; + struct passwd *pw_cur = getpwnam (internal_getlogin (&pi)); + if (pw_cur != pw_new) + { + set_errno (EPERM); + return -1; + } + myself->uid = uid; + strcpy (myself->username, pi.username); + CopySid (40, myself->psid, pi.psid); + strcpy (myself->logsrv, pi.logsrv); + strcpy (myself->domain, pi.domain); + } + } + else + set_errno (ENOSYS); return 0; } /* seteuid: standards? */ extern "C" int -seteuid (uid_t) +seteuid (uid_t uid) { - set_errno (ENOSYS); - return 0; + return setuid (uid); } /* setegid: from System V. */ extern "C" int -setegid (gid_t) +setegid (gid_t gid) { - set_errno (ENOSYS); - return 0; + return setgid (gid); } /* chroot: privileged Unix system call. */ |