MCPcopy Create free account
hub / github.com/apache/httpd / set_group_privs

Function set_group_privs

modules/arch/unix/mod_unixd.c:90–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 */
89
90static int set_group_privs(void)
91{
92 if (!geteuid()) {
93 const char *name;
94
95 /* Get username if passed as a uid */
96
97 if (ap_unixd_config.user_name[0] == '#') {
98 struct passwd *ent;
99 uid_t uid = atol(&ap_unixd_config.user_name[1]);
100
101 if ((ent = getpwuid(uid)) == NULL) {
102 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL, APLOGNO(02155)
103 "getpwuid: couldn't determine user name from uid %ld, "
104 "you probably need to modify the User directive",
105 (long)uid);
106 return -1;
107 }
108
109 name = ent->pw_name;
110 }
111 else
112 name = ap_unixd_config.user_name;
113
114#if !defined(OS2)
115 /* OS/2 doesn't support groups. */
116 /*
117 * Set the GID before initgroups(), since on some platforms
118 * setgid() is known to zap the group list.
119 */
120 if (setgid(ap_unixd_config.group_id) == -1) {
121 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL, APLOGNO(02156)
122 "setgid: unable to set group id to Group %ld",
123 (long)ap_unixd_config.group_id);
124 return -1;
125 }
126
127 /* Reset `groups' attributes. */
128
129 if (initgroups(name, ap_unixd_config.group_id) == -1) {
130 ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL, APLOGNO(02157)
131 "initgroups: unable to set groups for User %s "
132 "and Group %ld", name, (long)ap_unixd_config.group_id);
133 return -1;
134 }
135#endif /* !defined(OS2) */
136 }
137 return 0;
138}
139
140static int
141unixd_drop_privileges(apr_pool_t *pool, server_rec *s)

Callers 1

mod_unixd.cFile · 0.85

Calls 2

initgroupsFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected