Add g_setallusercontext() for *BSD systems

This commit is contained in:
matt335672
2022-12-15 15:06:55 +00:00
parent cd58d14cef
commit 48e46d183a
3 changed files with 42 additions and 0 deletions
+28
View File
@@ -61,6 +61,9 @@
#include <time.h>
#include <grp.h>
#endif
#ifdef HAVE_SETUSERCONTEXT
#include <login_cap.h>
#endif
#include <stdlib.h>
#include <string.h>
@@ -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 */
+8
View File
@@ -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);