Hi Henrique

Thank you for your detailled bug description.

On Fri, Feb 10, 2006 at 12:54:04PM -0200, Henrique de Moraes Holschuh wrote:
> 
> The bug is in routine existing_user_ok.  It must not return 2 if $new_uid is
> undefined.  In that case, only 0 and 1 are valid results.

Can you try the attached patch for adduser 3.82. Adduser returns now
correctly "0" if you try to add the same user again and again.


> I miss a third return value, "3" for users which exist but are not in the
> system range (which is a valid result independent of $new_uid being defined
> or not).  It is useful to generate a printf (gtx("The user `%s' already
> exists as a non-system user. Aborting\n"), $new_name) error message.

I consider this for some of the next releases.

Jörg

-- 
Was denen einen ihr Watergate, ist den anderen ihr Firstgate.
- Thomas Bliessner, <[EMAIL PROTECTED]>
Index: adduser
===================================================================
--- adduser     (Revision 475)
+++ adduser     (Arbeitskopie)
@@ -223,10 +223,15 @@
 #################
 if ($action eq "addsysgroup") {
     # Check if requested group already exists and we can exit safely
-    if (existing_group_ok($new_name, $new_gid)) {
+    if (existing_group_ok($new_name, $new_gid) == 1) {
        printf (gtx("The group `%s' already exists as a system group. 
Exiting...\n"), $new_name) if $verbose;
        exit 0;
     }
+    if (existing_group_ok($new_name, $new_gid) == 2) {
+       printf (gtx("The group `%s' already exists, but has a different gid, 
aborting...\n"), $new_name) if $verbose;
+       exit 1;
+    }
+
     dief (gtx("The group `%s' already exists and is not a system 
group.\n"),$new_name)
        if (defined getgrnam($new_name));
     dief (gtx("The GID `%s' is already in use.\n"),$new_gid)
@@ -600,8 +605,8 @@
 }
 
 # returns 0 if the the user doesn't exist or
-# returns 1 if the user already exists with the specified uid
-# returns 2 if the user already exists with a different uid
+# returns 1 if the user already exists with the specified uid (or $new_uid 
wasn't specified)
+# returns 2 if the user already exists, but $new_uid doesn't matches its uid
 sub existing_user_ok {
     my($new_name,$new_uid) = @_;
     my ($dummy1,$dummy2,$uid);
@@ -609,6 +614,9 @@
        if( defined($new_uid) && $uid == $new_uid ) {
            return 1;
        }
+       if (! defined($new_uid)) { 
+               return 1;
+       }
        if( $uid >= $config{"first_system_uid"} &&
            $uid <= $config{"last_system_uid" } ) {
                return 2;
@@ -619,9 +627,8 @@
 }
 
 # returns 0 if the group doesn't exist or
-# returns 1 if 
-#     - the group already exists as a system group or
-#     - if an explicit GID is given, that GID matches the existing group.
+# returns 1 if the group already exists with the specified gid (or $new_gid 
wasn't specified)
+# returns 2 if the group already exists, but $new_gid doesn't match its gid 
 sub existing_group_ok {
     my($new_name,$new_gid) = @_;
     my ($dummy1,$dummy2,$gid);
@@ -629,9 +636,12 @@
        if( defined($new_gid) && $gid == $new_gid ) {
            return 1;
        }
+       if (! defined($new_gid)) {
+               return 1;
+       }
        if( $gid >= $config{"first_system_gid"} &&
            $gid <= $config{"last_system_gid" } ) {
-               return 1;
+               return 2;
        }
     } else {
        return 0;

Attachment: signature.asc
Description: Digital signature

Reply via email to