From 656d5043b8a1a746cf7c949ee695db6c6251dfea Mon Sep 17 00:00:00 2001 From: Ashwini Sharma Date: Mon, 23 Dec 2013 07:23:28 -0600 Subject: Attached is an implementation for groupdel. This is aliased to delgroup, for a requirement at my end. Also lib/password.c is modified to along with. --- lib/password.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/password.c') diff --git a/lib/password.c b/lib/password.c index 34abf6e7..e184e0e0 100644 --- a/lib/password.c +++ b/lib/password.c @@ -118,6 +118,7 @@ static char *get_nextcolon(char *line, int cnt) * 2. complete entry for user details, when creating new user * 3. group members comma',' separated list, when adding user to group * 4. complete entry for group details, when creating new group + * 5. entry = NULL, delete the named entry user/group */ int update_password(char *filename, char* username, char* entry) { @@ -167,7 +168,7 @@ int update_password(char *filename, char* username, char* entry) { if (strncmp(line, namesfx, strlen(namesfx))) fprintf(newfp, "%s\n", line); - else { + else if (entry) { char *current_ptr = NULL; found = 1; @@ -180,7 +181,9 @@ int update_password(char *filename, char* username, char* entry) fprintf(newfp, "%s\n",current_ptr); } else fprintf(newfp, "%s\n",current_ptr); } else if (!strcmp(toys.which->name, "groupadd") || - !strcmp(toys.which->name, "addgroup")){ + !strcmp(toys.which->name, "addgroup") || + !strcmp(toys.which->name, "delgroup") || + !strcmp(toys.which->name, "groupdel")){ current_ptr = get_nextcolon(line, 3); //past gid/admin list *current_ptr = '\0'; fprintf(newfp, "%s", line); @@ -190,7 +193,7 @@ int update_password(char *filename, char* username, char* entry) free(line); } free(namesfx); - if (!found) fprintf(newfp, "%s\n", entry); + if (!found && entry) fprintf(newfp, "%s\n", entry); fcntl(fileno(exfp), F_SETLK, &lock); fclose(exfp); -- cgit v1.2.3