MCPcopy Create free account
hub / github.com/corosync/corosync / uid_determine

Function uid_determine

exec/coroparse.c:140–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138static char error_string_response[512];
139
140static int uid_determine (const char *req_user)
141{
142 int pw_uid = 0;
143 struct passwd passwd;
144 struct passwd* pwdptr = &passwd;
145 struct passwd* temp_pwd_pt;
146 char *pwdbuffer;
147 int pwdlinelen, rc;
148 long int id;
149 char *ep;
150
151 id = strtol(req_user, &ep, 10);
152 if (*req_user != '\0' && *ep == '\0' && id >= 0 && id <= UINT_MAX) {
153 return (id);
154 }
155
156 pwdlinelen = sysconf (_SC_GETPW_R_SIZE_MAX);
157
158 if (pwdlinelen == -1) {
159 pwdlinelen = 256;
160 }
161
162 pwdbuffer = malloc (pwdlinelen);
163
164 while ((rc = getpwnam_r (req_user, pwdptr, pwdbuffer, pwdlinelen, &temp_pwd_pt)) == ERANGE) {
165 char *n;
166
167 pwdlinelen *= 2;
168 if (pwdlinelen <= 32678) {
169 n = realloc (pwdbuffer, pwdlinelen);
170 if (n != NULL) {
171 pwdbuffer = n;
172 continue;
173 }
174 }
175 }
176 if (rc != 0) {
177 free (pwdbuffer);
178 sprintf (error_string_response, "getpwnam_r(): %s", strerror(rc));
179 return (-1);
180 }
181 if (temp_pwd_pt == NULL) {
182 free (pwdbuffer);
183 sprintf (error_string_response,
184 "The '%s' user is not found in /etc/passwd, please read the documentation.",
185 req_user);
186 return (-1);
187 }
188 pw_uid = passwd.pw_uid;
189 free (pwdbuffer);
190
191 return pw_uid;
192}
193
194static int gid_determine (const char *req_group)
195{

Callers 2

main_config_parser_cbFunction · 0.85
uidgid_config_parser_cbFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected