* Scan a line and place it into a group structure. */
| 597 | * Scan a line and place it into a group structure. |
| 598 | */ |
| 599 | static bool |
| 600 | __gr_scan(char *line, struct group *gr) |
| 601 | { |
| 602 | char *loc; |
| 603 | int ndx; |
| 604 | |
| 605 | /* Assign non-member information to structure. */ |
| 606 | gr->gr_name = line; |
| 607 | if ((loc = strchr(line, ':')) == NULL) |
| 608 | return (false); |
| 609 | *loc = '\0'; |
| 610 | gr->gr_passwd = loc + 1; |
| 611 | if (*gr->gr_passwd == ':') |
| 612 | *gr->gr_passwd = '\0'; |
| 613 | else { |
| 614 | if ((loc = strchr(loc + 1, ':')) == NULL) |
| 615 | return (false); |
| 616 | *loc = '\0'; |
| 617 | } |
| 618 | if (sscanf(loc + 1, "%u", &gr->gr_gid) != 1) |
| 619 | return (false); |
| 620 | |
| 621 | /* Assign member information to structure. */ |
| 622 | if ((loc = strchr(loc + 1, ':')) == NULL) |
| 623 | return (false); |
| 624 | line = loc + 1; |
| 625 | gr->gr_mem = NULL; |
| 626 | ndx = 0; |
| 627 | do { |
| 628 | gr->gr_mem = reallocf(gr->gr_mem, sizeof(*gr->gr_mem) * |
| 629 | (ndx + 1)); |
| 630 | if (gr->gr_mem == NULL) |
| 631 | return (false); |
| 632 | |
| 633 | /* Skip locations without members (i.e., empty string). */ |
| 634 | do { |
| 635 | gr->gr_mem[ndx] = strsep(&line, ","); |
| 636 | } while (gr->gr_mem[ndx] != NULL && *gr->gr_mem[ndx] == '\0'); |
| 637 | } while (gr->gr_mem[ndx++] != NULL); |
| 638 | |
| 639 | return (true); |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * Create a struct group from a line. |