diff --git a/common/os_calls.c b/common/os_calls.c index f631b1d1..97100649 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -61,6 +61,9 @@ #include #include #endif +#ifdef HAVE_SETUSERCONTEXT +#include +#endif #include #include @@ -2878,6 +2881,31 @@ g_setlogin(const char *name) #endif } +/*****************************************************************************/ +#ifdef HAVE_SETUSERCONTEXT +int +g_set_allusercontext(int uid) +{ + int rv; + struct passwd *pwd = getpwuid(uid); + if (pwd == NULL) + { + LOG(LOG_LEVEL_ERROR, "No password entry for UID %d", uid); + rv = 1; + } + else + { + rv = setusercontext(NULL, pwd, uid, LOGIN_SETALL); + if (rv != 0) + { + LOG(LOG_LEVEL_ERROR, "setusercontext(%d) failed [%s]", + uid, g_get_strerror()); + } + } + + return (rv != 0); /* Return 0 or 1 */ +} +#endif /*****************************************************************************/ /* does not work in win32 returns pid of process that exits or zero if signal occurred */ diff --git a/common/os_calls.h b/common/os_calls.h index b1153571..c7dc1b67 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -93,6 +93,7 @@ int g_sck_socket_ok(int sck); int g_sck_can_send(int sck, int millis); int g_sck_can_recv(int sck, int millis); int g_sck_select(int sck1, int sck2); + /** * Gets the IP address of a connected peer, if it has one * @param sck File descriptor for peer @@ -183,6 +184,13 @@ int g_setuid(int pid); int g_setsid(void); int g_getlogin(char *name, unsigned int len); int g_setlogin(const char *name); +#ifdef HAVE_SETUSERCONTEXT +/** Sets the login user context (BSD systems only) + * @param uid UID of suer + * @return 0 for success + */ +int g_set_allusercontext(int uid); +#endif int g_waitchild(void); int g_waitpid(int pid); struct exit_status g_waitpid_status(int pid); diff --git a/configure.ac b/configure.ac index 94e809fc..de6d4b11 100644 --- a/configure.ac +++ b/configure.ac @@ -213,6 +213,12 @@ AM_COND_IF([DEVEL_DEBUG], [AX_APPEND_COMPILE_FLAGS([-g -O0])], [AX_APPEND_COMPILE_FLAGS([-O2])]) +# Function setusercontext() is in BSD -lutil but N/A on Solaris or GNU systems +AC_SEARCH_LIBS([setusercontext], [util]) + +# Define HAVE_XXXXX macros for some system functions +AC_CHECK_FUNCS([setusercontext]) + # Don't fail without working nasm if rfxcodec is not enabled if test "x$enable_rfxcodec" != xyes; then with_simd=no