groupdel(8) will complain (and delete) lines which do not have exactly
three colon characters in them. This is annoying in yp environments
where the last line of /etc/group is usually a single `+' character,
which is equivalent to `+:*::'

Invoking groupdel when /etc/group contains a final `+' line yields:

  # groupdel foo
  userdel: Malformed entry `+'. Skipping

and the `+' line disappears.

The following diff attempts to recognize and preserve such a line.


Index: user.c
===================================================================
RCS file: /cvs/src/usr.sbin/user/user.c,v
retrieving revision 1.100
diff -u -p -r1.100 user.c
--- user.c      27 Aug 2014 06:51:35 -0000      1.100
+++ user.c      4 Oct 2014 12:01:57 -0000
@@ -1281,6 +1281,13 @@ rm_user_from_groups(char *login_name)
                }
                if (cc != 3) {
                        buf[strcspn(buf, "\n")] = '\0';
+
+                       /* Preserve a malformed but historical `+' line */
+                       if (strcmp(buf, "+") == 0) {
+                               strlcat(buf, "\n", sizeof buf);
+                               goto do_write;
+                       }
+
                        warnx("Malformed entry `%s'. Skipping", buf);
                        continue;
                }
@@ -1299,6 +1306,7 @@ rm_user_from_groups(char *login_name)
                                cp++;
                        }
                }
+do_write:
                if (fwrite(buf, strlen(buf), 1, to) != 1) {
                        warn("can't remove gid for `%s': short write to `%s'",
                            login_name, f);

Reply via email to