tar: cry murder and bail out if file shrinks under us while we tar it up
[oweals/busybox.git] / loginutils / addgroup.c
index f4962ffb97e33a5e8df404f498d4a5d555c1b822..0172e6041dde858aeb3ee980434785b79ae473ee 100644 (file)
@@ -9,11 +9,6 @@
  *
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
 #include "busybox.h"
 
 /* make sure gr_name isn't taken, make sure gid is kosher
@@ -26,7 +21,7 @@ static int group_study(struct group *g)
        struct group *grp;
        const int max = 65000;
 
-       etc_group = bb_xfopen(bb_path_group_file, "r");
+       etc_group = xfopen(bb_path_group_file, "r");
 
        /* make sure gr_name isn't taken, make sure gid is kosher */
        desired = g->gr_gid;
@@ -67,13 +62,13 @@ static int addgroup(char *group, gid_t gid, const char *user)
                return 1;
 
        /* add entry to group */
-       file = bb_xfopen(bb_path_group_file, "a");
+       file = xfopen(bb_path_group_file, "a");
        /* group:passwd:gid:userlist */
        fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
        fclose(file);
 
 #if ENABLE_FEATURE_SHADOWPASSWDS
-       file = bb_xfopen(bb_path_gshadow_file, "a");
+       file = xfopen(bb_path_gshadow_file, "a");
        fprintf(file, "%s:!::\n", group);
        fclose(file);
 #endif
@@ -93,18 +88,17 @@ int addgroup_main(int argc, char **argv)
 {
        char *group;
        gid_t gid = 0;
-       
-       /* check for min, max and missing args and exit on error */
-       bb_opt_complementally = "-1:?2:?";
 
-       if (bb_getopt_ulflags(argc, argv, "g:", &group)) {
-               gid = bb_xgetlarg(group, 10, 0, LONG_MAX);
+       /* check for min, max and missing args and exit on error */
+       opt_complementary = "-1:?2:?";
+       if (getopt32(argc, argv, "g:", &group)) {
+               gid = xatoul_range(group, 0, (gid_t)ULONG_MAX);
        }
        /* move past the commandline options */
        argv += optind;
 
        /* need to be root */
-       if(geteuid()) {
+       if (geteuid()) {
                bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
        }