diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-01-08 02:39:47 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2000-01-08 02:39:47 +0000 |
commit | 196f6ac3d9ddf4915705f9a5b9187c7078285737 (patch) | |
tree | 66ccf80f2b4873788cf46da981d1a943f401ab03 | |
parent | a03625406292cf226978bdb1132f8e27013e8b81 (diff) | |
download | ATCD-196f6ac3d9ddf4915705f9a5b9187c7078285737.tar.gz |
ChangeLogTag:Fri Jan 7 20:01:48 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
-rw-r--r-- | ChangeLog | 43 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 43 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 43 | ||||
-rw-r--r-- | ace/OS.h | 2 | ||||
-rw-r--r-- | ace/OS.i | 49 | ||||
-rw-r--r-- | ace/Process.cpp | 52 | ||||
-rw-r--r-- | ace/Process.h | 21 | ||||
-rw-r--r-- | ace/Process.i | 65 | ||||
-rw-r--r-- | ace/config-chorus.h | 2 | ||||
-rw-r--r-- | ace/config-cray.h | 2 | ||||
-rw-r--r-- | ace/config-cygwin32-common.h | 2 | ||||
-rw-r--r-- | ace/config-freebsd-pthread.h | 2 | ||||
-rw-r--r-- | ace/config-freebsd.h | 2 | ||||
-rw-r--r-- | ace/config-hpux-9.x.h | 5 | ||||
-rw-r--r-- | ace/config-lynxos.h | 2 | ||||
-rw-r--r-- | ace/config-netbsd.h | 2 | ||||
-rw-r--r-- | ace/config-sunos4-g++.h | 2 | ||||
-rw-r--r-- | ace/config-sunos4-sun4.1.4.h | 2 | ||||
-rw-r--r-- | ace/config-sunos4-sun4.x.h | 2 | ||||
-rw-r--r-- | ace/config-sunos5.5.h | 2 | ||||
-rw-r--r-- | ace/config-win32-common.h | 2 |
21 files changed, 327 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog index 8bfb1a1b51b..1f8f429d940 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,46 @@ +Fri Jan 7 20:01:48 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/OS.i, + ace/config-sunos5.5.h: Some platforms seem to lack function + prototypes for setreuid() and setreguid(), even though they are + in the library. Therefore, I've added + + #define ACE_LACKS_SETREGID_PROTOTYPE + + and + + #define ACE_LACKS_SETREGID_PROTOTYPE + + macros to handle this case. + + * ace/Process: Added support to allow UNIX applications to + automagically set the real and effective user/group ids when + ACE_Process::spawn() is called. Thanks to Craig Perras + <cperras@watchguard.com> for contributing this. + + * ace: Updated the following files to include + + #define ACE_LACKS_SETREGID + #define ACE_LACKS_SETREUID + + config-chorus.h + config-cray.h:168 + config-cygwin32-common.h + config-freebsd-pthread.h + config-freebsd.h:33 + config-hpux-9.x.h + config-lynxos.h + config-netbsd.h + config-sunos4-g++.h + config-sunos4-sun4.1.4.h + config-win32-common.h + + Ideally, Ossama's autoconf stuff will auto-detect anything that + I'm missing. + + * ace/OS: Added wrapper facade methods for setregid() and + setregid(). + Fri Jan 7 16:05:32 2000 Ossama Othman <ossama@uci.edu> * configure.in: diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 8bfb1a1b51b..1f8f429d940 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,46 @@ +Fri Jan 7 20:01:48 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/OS.i, + ace/config-sunos5.5.h: Some platforms seem to lack function + prototypes for setreuid() and setreguid(), even though they are + in the library. Therefore, I've added + + #define ACE_LACKS_SETREGID_PROTOTYPE + + and + + #define ACE_LACKS_SETREGID_PROTOTYPE + + macros to handle this case. + + * ace/Process: Added support to allow UNIX applications to + automagically set the real and effective user/group ids when + ACE_Process::spawn() is called. Thanks to Craig Perras + <cperras@watchguard.com> for contributing this. + + * ace: Updated the following files to include + + #define ACE_LACKS_SETREGID + #define ACE_LACKS_SETREUID + + config-chorus.h + config-cray.h:168 + config-cygwin32-common.h + config-freebsd-pthread.h + config-freebsd.h:33 + config-hpux-9.x.h + config-lynxos.h + config-netbsd.h + config-sunos4-g++.h + config-sunos4-sun4.1.4.h + config-win32-common.h + + Ideally, Ossama's autoconf stuff will auto-detect anything that + I'm missing. + + * ace/OS: Added wrapper facade methods for setregid() and + setregid(). + Fri Jan 7 16:05:32 2000 Ossama Othman <ossama@uci.edu> * configure.in: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 8bfb1a1b51b..1f8f429d940 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,46 @@ +Fri Jan 7 20:01:48 2000 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/OS.i, + ace/config-sunos5.5.h: Some platforms seem to lack function + prototypes for setreuid() and setreguid(), even though they are + in the library. Therefore, I've added + + #define ACE_LACKS_SETREGID_PROTOTYPE + + and + + #define ACE_LACKS_SETREGID_PROTOTYPE + + macros to handle this case. + + * ace/Process: Added support to allow UNIX applications to + automagically set the real and effective user/group ids when + ACE_Process::spawn() is called. Thanks to Craig Perras + <cperras@watchguard.com> for contributing this. + + * ace: Updated the following files to include + + #define ACE_LACKS_SETREGID + #define ACE_LACKS_SETREUID + + config-chorus.h + config-cray.h:168 + config-cygwin32-common.h + config-freebsd-pthread.h + config-freebsd.h:33 + config-hpux-9.x.h + config-lynxos.h + config-netbsd.h + config-sunos4-g++.h + config-sunos4-sun4.1.4.h + config-win32-common.h + + Ideally, Ossama's autoconf stuff will auto-detect anything that + I'm missing. + + * ace/OS: Added wrapper facade methods for setregid() and + setregid(). + Fri Jan 7 16:05:32 2000 Ossama Othman <ossama@uci.edu> * configure.in: @@ -5794,6 +5794,8 @@ public: static int setuid (uid_t); static pid_t setsid (void); static int setpgid (pid_t pid, pid_t pgid); + static int setreuid (uid_t ruid, uid_t euid); + static int setregid (gid_t rgid, gid_t egid); static int system (const char *s); static pid_t waitpid (pid_t pid, ACE_exitcode *status = 0, @@ -1,7 +1,6 @@ // -*- C++ -*- // $Id$ - #if !defined (ACE_HAS_INLINED_OSCALLS) # undef ACE_INLINE # define ACE_INLINE @@ -50,6 +49,14 @@ typedef char *ACE_SOCKOPT_TYPE1; typedef const char *ACE_SOCKOPT_TYPE1; #endif /* ACE_HAS_VOIDPTR_SOCKOPT */ +#if defined (ACE_LACKS_SETREUID_PROTOTYPE) +extern int setreuid (uid_t ruid, uid_t euid); +#endif /* ACE_LACKS_SETREUID_PROTOTYPE */ + +#if defined (ACE_LACKS_SETREGID_PROTOTYPE) +extern int setregid (gid_t rgid, gid_t egid); +#endif /* ACE_LACKS_SETREGID_PROTOTYPE */ + #if defined (ACE_LACKS_WRITEV) extern "C" ACE_Export int writev (ACE_HANDLE handle, ACE_WRITEV_TYPE *iov, int iovcnt); #endif /* ACE_LACKS_WRITEV */ @@ -10471,12 +10478,48 @@ ACE_OS::setpgid (pid_t pid, pid_t pgid) ACE_UNUSED_ARG (pgid); ACE_NOTSUP_RETURN (-1); #elif defined (VXWORKS) || defined (ACE_PSOS) - // setpgid() is not supported, only one process anyway. + // <setpgid> is not supported, only one process anyway. ACE_UNUSED_ARG (pid); ACE_UNUSED_ARG (pgid); return 0; #else - ACE_OSCALL_RETURN (::setpgid (pid, pgid), pid_t, -1); + ACE_OSCALL_RETURN (::setpgid (pid, pgid), int, -1); +#endif /* ACE_WIN32 */ +} + +ACE_INLINE int +ACE_OS::setreuid (uid_t ruid, uid_t euid) +{ + ACE_TRACE ("ACE_OS::setreuid"); +#if defined (ACE_LACKS_SETREUID) + ACE_UNUSED_ARG (ruid); + ACE_UNUSED_ARG (euid); + ACE_NOTSUP_RETURN (-1); +#elif defined (VXWORKS) || defined (ACE_PSOS) + // <setpgid> is not supported, only one process anyway. + ACE_UNUSED_ARG (ruid); + ACE_UNUSED_ARG (euid); + return 0; +#else + ACE_OSCALL_RETURN (::setreuid (ruid, euid), int, -1); +#endif /* ACE_WIN32 */ +} + +ACE_INLINE int +ACE_OS::setregid (gid_t rgid, gid_t egid) +{ + ACE_TRACE ("ACE_OS::setregid"); +#if defined (ACE_LACKS_SETREGID) + ACE_UNUSED_ARG (rgid); + ACE_UNUSED_ARG (egid); + ACE_NOTSUP_RETURN (-1); +#elif defined (VXWORKS) || defined (ACE_PSOS) + // <setregid> is not supported, only one process anyway. + ACE_UNUSED_ARG (rgid); + ACE_UNUSED_ARG (egid); + return 0; +#else + ACE_OSCALL_RETURN (::setregid (rgid, egid), int, -1); #endif /* ACE_WIN32 */ } diff --git a/ace/Process.cpp b/ace/Process.cpp index c4a3a2249b8..53ed266db4c 100644 --- a/ace/Process.cpp +++ b/ace/Process.cpp @@ -112,20 +112,44 @@ ACE_Process::spawn (ACE_Process_Options &options) this->child_id_ = ACE::fork (options.command_line_argv ()[0], options.avoid_zombies ()); - // If we're the child and the options specified a non-default - // process group, try to set our pgid to it. (This will allow - // Process_Manager to wait for Processes by process-group.) - if (options.getgroup () != ACE_INVALID_PID - && this->child_id_ == 0 - && ACE_OS::setpgid (0, options.getgroup ()) < 0) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("%p.\n"), - ASYS_TEXT ("ACE_Process::spawn: setpgid failed."))); - if (this->child_id_ == 0) - child (ACE_OS::getppid ()); + { + // If we're the child and the options specified a non-default + // process group, try to set our pgid to it. This allows the + // <ACE_Process_Manager> to wait for processes by their + // process-group. + if (options.getgroup () != ACE_INVALID_PID + && ACE_OS::setpgid (0, + options.getgroup ()) < 0) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT ("%p.\n"), + ASYS_TEXT ("ACE_Process::spawn: setpgid failed."))); + +#if !defined (ACE_LACKS_SETREUID) + // Set user and group id's. + if (options.getruid () != (uid_t) -1 + || options.geteuid () != (uid_t) -1) + if (ACE_OS::setreuid (options.getruid (), + options.geteuid ()) == -1) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT ("%p.\n"), + ASYS_TEXT ("ACE_Process::spawn: setreuid failed."))); +#endif /* ACE_LACKS_SETREUID */ + +#if !defined (ACE_LACKS_SETREGID) + if (options.getrgid () != (uid_t) -1 + || options.getegid () != (uid_t) -1) + if (ACE_OS::setregid (options.getrgid (), + options.getegid ()) == -1) + ACE_ERROR ((LM_ERROR, + ASYS_TEXT ("%p.\n"), + ASYS_TEXT ("ACE_Process::spawn: setregid failed."))); +#endif /* ACE_LACKS_SETREGID */ + + this->child (ACE_OS::getppid ()); + } else if (this->child_id_ != -1) - parent (this->child_id_); + this->parent (this->child_id_); // If we're not supposed to exec, return the process id. if (ACE_BIT_ENABLED (options.creation_flags (), @@ -329,6 +353,10 @@ ACE_Process_Options::ACE_Process_Options (int ie, stdout_ (ACE_INVALID_HANDLE), stderr_ (ACE_INVALID_HANDLE), avoid_zombies_ (0), + ruid_ ((uid_t) -1), + euid_ ((uid_t) -1), + rgid_ ((uid_t) -1), + egid_ ((uid_t) -1), #endif /* ACE_WIN32 */ set_handles_called_ (0), environment_buf_index_ (0), diff --git a/ace/Process.h b/ace/Process.h index 8c36780f01e..b26e024fadd 100644 --- a/ace/Process.h +++ b/ace/Process.h @@ -195,8 +195,18 @@ public: // Set value for avoid_zombies. int avoid_zombies (void); // Get current value for avoid_zombies. -#endif /* ACE_WIN32 */ + // = Set/get real & effective user & group id associated with user. + int setreugid (const char* user); + void setruid (uid_t id); + void seteuid (uid_t id); + void setrgid (uid_t id); + void setegid (uid_t id); + uid_t getruid (void); + uid_t geteuid (void); + uid_t getrgid (void); + uid_t getegid (void); +#endif /* ACE_WIN32 */ protected: #if !defined (ACE_HAS_WINCE) @@ -241,8 +251,15 @@ protected: ACE_HANDLE stdin_; ACE_HANDLE stdout_; ACE_HANDLE stderr_; - // Avoid zombies for spawned processes. int avoid_zombies_; + // Avoid zombies for spawned processes. + + // = Real & effective user & group id's. + // These should be set to -1 to leave unchanged (default). + uid_t ruid_; + uid_t euid_; + uid_t rgid_; + uid_t egid_; #endif /* ACE_WIN32 */ #if !defined (ACE_HAS_WINCE) diff --git a/ace/Process.i b/ace/Process.i index 5a84fefb2ca..63c43e66684 100644 --- a/ace/Process.i +++ b/ace/Process.i @@ -204,6 +204,71 @@ ACE_Process_Options::avoid_zombies (int avoid_zombies) { avoid_zombies_ = avoid_zombies; } + +ACE_INLINE int +ACE_Process_Options::setreugid (const char* user) +{ + struct passwd *ent = ACE_OS::getpwnam (user); + + if (ent != 0) + { + this->euid_ = ent->pw_uid; + this->ruid_ = ent->pw_uid; + this->egid_ = ent->pw_gid; + this->rgid_ = ent->pw_gid; + return 0; + } + else + return -1; +} + +ACE_INLINE void +ACE_Process_Options::setruid (uid_t id) +{ + this->ruid_ = id; +} + +ACE_INLINE void +ACE_Process_Options::seteuid (uid_t id) +{ + this->euid_ = id; +} + +ACE_INLINE void +ACE_Process_Options::setrgid (uid_t id) +{ + this->rgid_ = id; +} + +ACE_INLINE void +ACE_Process_Options::setegid (uid_t id) +{ + this->egid_ = id; +} + +ACE_INLINE uid_t +ACE_Process_Options::getruid (void) +{ + return this->ruid_; +} + +ACE_INLINE uid_t +ACE_Process_Options::geteuid (void) +{ + return this->euid_; +} + +ACE_INLINE uid_t +ACE_Process_Options::getrgid (void) +{ + return this->rgid_; +} + +ACE_INLINE uid_t +ACE_Process_Options::getegid (void) +{ + return this->egid_; +} #endif /* ACE_WIN32 */ ACE_INLINE LPTSTR diff --git a/ace/config-chorus.h b/ace/config-chorus.h index 5e10f2811c4..c7fb293c8aa 100644 --- a/ace/config-chorus.h +++ b/ace/config-chorus.h @@ -67,6 +67,8 @@ #define ACE_LACKS_GETHOSTENT #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_GETSERVBYNAME #define ACE_LACKS_KEY_T #define ACE_LACKS_LONGLONG_T diff --git a/ace/config-cray.h b/ace/config-cray.h index 9bb277fc7a3..08287610452 100644 --- a/ace/config-cray.h +++ b/ace/config-cray.h @@ -166,6 +166,8 @@ #define ACE_LACKS_PRI_T #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_MPROTECT #define ACE_LACKS_MSYNC #define ACE_LACKS_READV diff --git a/ace/config-cygwin32-common.h b/ace/config-cygwin32-common.h index d609ea92f09..c3dea95a0d5 100644 --- a/ace/config-cygwin32-common.h +++ b/ace/config-cygwin32-common.h @@ -60,6 +60,8 @@ # define ACE_HAS_DLFCN_H_BROKEN_EXTERN_C # define ACE_HAS_VOIDPTR_SOCKOPT #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID # define ACE_LACKS_GETPGID // The strtok_r declaration is protected in string.h. extern "C" char *strtok_r __P ((char *__s, __const char *__delim, diff --git a/ace/config-freebsd-pthread.h b/ace/config-freebsd-pthread.h index 23ade0bae70..fab6307420a 100644 --- a/ace/config-freebsd-pthread.h +++ b/ace/config-freebsd-pthread.h @@ -41,6 +41,8 @@ #define ACE_HAS_RECURSIVE_THR_EXIT_SEMANTICS #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_RWLOCK_T #define ACE_LACKS_READDIR_R #define ACE_HAS_SIG_MACROS diff --git a/ace/config-freebsd.h b/ace/config-freebsd.h index 5ed3b1fe135..a948c2a3635 100644 --- a/ace/config-freebsd.h +++ b/ace/config-freebsd.h @@ -31,6 +31,8 @@ // Platform specific directives #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_RWLOCK_T #define ACE_LACKS_READDIR_R #define ACE_HAS_SIG_MACROS diff --git a/ace/config-hpux-9.x.h b/ace/config-hpux-9.x.h index c77788f0df7..be52880bc9d 100644 --- a/ace/config-hpux-9.x.h +++ b/ace/config-hpux-9.x.h @@ -19,6 +19,8 @@ #define ACE_HAS_IP_MULTICAST #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_HAS_BROKEN_CONVERSIONS // Optimize ACE_Handle_Set for select(). #define ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT @@ -26,9 +28,6 @@ // They forgot a const in the prototype of const_timewait... #define ACE_LACKS_CONST_TIMESPEC_PTR -#define ACE_LACKS_GETPGID -#define ACE_LACKS_SETPGID -#define ACE_HAS_IP_MULTICAST #define ACE_LACKS_SYSCALL #define ACE_LACKS_STRRECVFD diff --git a/ace/config-lynxos.h b/ace/config-lynxos.h index a91b7b79d29..09a58ad701d 100644 --- a/ace/config-lynxos.h +++ b/ace/config-lynxos.h @@ -91,6 +91,8 @@ #define ACE_LACKS_GETOPT_PROTO #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_MADVISE #define ACE_LACKS_MKTEMP #define ACE_LACKS_RWLOCK_T diff --git a/ace/config-netbsd.h b/ace/config-netbsd.h index 4862af16990..1b5dcc7d1ce 100644 --- a/ace/config-netbsd.h +++ b/ace/config-netbsd.h @@ -30,6 +30,8 @@ // Platform specific directives #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_LACKS_RWLOCK_T #define ACE_HAS_SIG_MACROS #define ACE_HAS_CHARPTR_DL diff --git a/ace/config-sunos4-g++.h b/ace/config-sunos4-g++.h index 40b37469fa3..09426046523 100644 --- a/ace/config-sunos4-g++.h +++ b/ace/config-sunos4-g++.h @@ -29,6 +29,8 @@ #define ACE_LACKS_SYSTIME_H #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_HAS_CHARPTR_SPRINTF #define ACE_HAS_UNION_WAIT diff --git a/ace/config-sunos4-sun4.1.4.h b/ace/config-sunos4-sun4.1.4.h index 7275e63d648..c75952384b4 100644 --- a/ace/config-sunos4-sun4.1.4.h +++ b/ace/config-sunos4-sun4.1.4.h @@ -9,6 +9,8 @@ #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID // Maximum compensation (10 ms) for early return from timed ::select (). #if !defined (ACE_TIMER_SKEW) diff --git a/ace/config-sunos4-sun4.x.h b/ace/config-sunos4-sun4.x.h index 9fcb4025ba7..07574ad4077 100644 --- a/ace/config-sunos4-sun4.x.h +++ b/ace/config-sunos4-sun4.x.h @@ -10,6 +10,8 @@ #define ACE_LACKS_SYSTIME_H #define ACE_LACKS_GETPGID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_HAS_CHARPTR_SPRINTF #define ACE_LACKS_POSIX_PROTOTYPES diff --git a/ace/config-sunos5.5.h b/ace/config-sunos5.5.h index a4727046b24..21a712cea4b 100644 --- a/ace/config-sunos5.5.h +++ b/ace/config-sunos5.5.h @@ -350,6 +350,8 @@ #endif /* i386 */ #define ACE_MALLOC_ALIGN 8 +#define ACE_LACKS_SETREUID_PROTOTYPE +#define ACE_LACKS_SETREGID_PROTOTYPE #if defined (_LARGEFILE_SOURCE) || (_FILE_OFFSET_BITS==64) #undef ACE_HAS_PROC_FS diff --git a/ace/config-win32-common.h b/ace/config-win32-common.h index 23cf05c1b6a..d7fbfdc40e6 100644 --- a/ace/config-win32-common.h +++ b/ace/config-win32-common.h @@ -48,6 +48,8 @@ #define ACE_LACKS_GETPGID #define ACE_LACKS_GETPPID #define ACE_LACKS_SETPGID +#define ACE_LACKS_SETREGID +#define ACE_LACKS_SETREUID #define ACE_HAS_THREAD_SAFE_ACCEPT #if !defined (ACE_HAS_WINCE) #define ACE_HAS_EXCEPTIONS |