[PATCH] add-shell, remove-shell: new applets

Denys Vlasenko vda.linux at googlemail.com
Wed Nov 3 01:48:57 UTC 2010


On Wednesday 20 October 2010 17:30, Tito wrote:
> Hi,
> was not sure if it could be removed and was to lazy to test.
> Fixed.
> Thanks for your hint.
> Attached v2 of thr patch.
> Ciao,
> Tito

Tito, you are turning update_passwd() into a Franken-function.

It sings. It dances. It has so many uses it's hard to understand
both the meaning of its parameters in all its many (nine!) 
possible ways to be called, and more importantly,
it's hard to understand its source. Or rather, now it's even
hardER to understand its source.

Yes, this way add-shell and remove shell is smaller.
Is it worth the reduced simplicity?


+
+#define REMOVE_SHELL (ENABLE_REMOVE_SHELL && (!ENABLE_ADD_SHELL || applet_name[6] == '-'))
+#define ADD_SHELL    (ENABLE_ADD_SHELL && (!ENABLE_REMOVE_SHELL || applet_name[3] == '-'))
+
 int FAST_FUNC update_passwd(const char *filename,
                const char *name,
                const char *new_passwd,
@@ -167,7 +177,16 @@
                line = xmalloc_fgetline(old_fp);
                if (!line) /* EOF/error */
                        break;
-               if (strncmp(name_colon, line, user_len) != 0) {
+               if (ADD_SHELL || REMOVE_SHELL) {
+                       /* remove colon */      
+                       name_colon[user_len - 1] = '\0';
+                       if (strcmp(name_colon, line) != 0) {
+                               fprintf(new_fp, "%s\n", line);
+                               goto next;
+                       } else if (REMOVE_SHELL) {
+                               changed_lines++;
+                       }
+               } else if (strncmp(name_colon, line, user_len) != 0) {
                        fprintf(new_fp, "%s\n", line);
                        goto next;
                }
@@ -247,7 +266,7 @@
                                bb_error_msg("can't find %s in %s", member, filename);
                }
 #endif
-               if ((ENABLE_ADDUSER || ENABLE_ADDGROUP)
+               if ((ENABLE_ADDUSER || ENABLE_ADDGROUP || ENABLE_ADD_SHELL)
                 && applet_name[0] == 'a' && !member
                ) {
                        /* add user or group */


-- 
vda


More information about the busybox mailing list