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

Function gid_determine

exec/coroparse.c:194–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194static int gid_determine (const char *req_group)
195{
196 int corosync_gid = 0;
197 struct group group;
198 struct group * grpptr = &group;
199 struct group * temp_grp_pt;
200 char *grpbuffer;
201 int grplinelen, rc;
202 long int id;
203 char *ep;
204
205 id = strtol(req_group, &ep, 10);
206 if (*req_group != '\0' && *ep == '\0' && id >= 0 && id <= UINT_MAX) {
207 return (id);
208 }
209
210 grplinelen = sysconf (_SC_GETGR_R_SIZE_MAX);
211
212 if (grplinelen == -1) {
213 grplinelen = 256;
214 }
215
216 grpbuffer = malloc (grplinelen);
217
218 while ((rc = getgrnam_r (req_group, grpptr, grpbuffer, grplinelen, &temp_grp_pt)) == ERANGE) {
219 char *n;
220
221 grplinelen *= 2;
222 if (grplinelen <= 32678) {
223 n = realloc (grpbuffer, grplinelen);
224 if (n != NULL) {
225 grpbuffer = n;
226 continue;
227 }
228 }
229 }
230 if (rc != 0) {
231 free (grpbuffer);
232 sprintf (error_string_response, "getgrnam_r(): %s", strerror(rc));
233 return (-1);
234 }
235 if (temp_grp_pt == NULL) {
236 free (grpbuffer);
237 sprintf (error_string_response,
238 "The '%s' group is not found in /etc/group, please read the documentation.",
239 req_group);
240 return (-1);
241 }
242 corosync_gid = group.gr_gid;
243 free (grpbuffer);
244
245 return corosync_gid;
246}
247static char *strchr_rs (const char *haystack, int byte)
248{
249 const char *end_address = strchr (haystack, byte);

Callers 2

main_config_parser_cbFunction · 0.85
uidgid_config_parser_cbFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected