cを使用して実行中の外部プロセスのuidとgidをプログラムで変更するにはどうすればよいですか?
質問する
672 次
1 に答える
3
A small example that includes the possibility to change uid et gid using existing user and group names:
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
// .. snip
// find user and group
struct passwd * pwd = getpwnam("new_user");
struct group * grp = getgrnam("new_group");
// not included : error checking
uid_t uid = pwd->pw_uid;
gid_t gid = grp->gr_gid;
setgid(gid);
setuid(uid);
edit: This only works for the current process
于 2012-04-05T10:35:30.100 に答える