diff -Nur coreutils-5.97/lib/userspec.c coreutils-5.97-numeric/lib/userspec.c --- coreutils-5.97/lib/userspec.c 2005-09-22 02:05:39.000000000 -0400 +++ coreutils-5.97-numeric/lib/userspec.c 2006-08-08 11:22:34.000000000 -0400 @@ -105,7 +105,7 @@ static char const * parse_with_separator (char const *spec, char const *separator, uid_t *uid, gid_t *gid, - char **username, char **groupname) + char **username, char **groupname, bool numeric) { static const char *E_invalid_user = N_("invalid user"); static const char *E_invalid_group = N_("invalid group"); @@ -159,7 +159,11 @@ if (u != NULL) { - pwd = getpwnam (u); + if(numeric) + pwd = NULL; + else + pwd = getpwnam (u); + if (pwd == NULL) { bool use_login_group = (separator != NULL && g == NULL); @@ -195,7 +199,11 @@ if (g != NULL && error_msg == NULL) { /* Explicit group. */ - grp = getgrnam (g); + if(numeric) + grp = NULL; + else + grp = getgrnam (g); + if (grp == NULL) { unsigned long int tmp; @@ -243,11 +251,11 @@ char const * parse_user_spec (char const *spec, uid_t *uid, gid_t *gid, - char **username, char **groupname) + char **username, char **groupname, bool numeric) { char const *colon = strchr (spec, ':'); char const *error_msg = - parse_with_separator (spec, colon, uid, gid, username, groupname); + parse_with_separator (spec, colon, uid, gid, username, groupname, numeric); if (!colon && error_msg) { @@ -259,7 +267,7 @@ char const *dot = strchr (spec, '.'); if (dot - && ! parse_with_separator (spec, dot, uid, gid, username, groupname)) + && ! parse_with_separator (spec, dot, uid, gid, username, groupname, numeric)) error_msg = NULL; } @@ -284,7 +292,7 @@ char *tmp; tmp = strdup (argv[i]); - e = parse_user_spec (tmp, &uid, &gid, &username, &groupname); + e = parse_user_spec (tmp, &uid, &gid, &username, &groupname, false); free (tmp); printf ("%s: %lu %lu %s %s %s\n", argv[i], diff -Nur coreutils-5.97/lib/userspec.h coreutils-5.97-numeric/lib/userspec.h --- coreutils-5.97/lib/userspec.h 2004-04-04 01:51:11.000000000 -0500 +++ coreutils-5.97-numeric/lib/userspec.h 2006-08-08 11:43:41.000000000 -0400 @@ -2,9 +2,10 @@ # define USERSPEC_H 1 # include +#include const char * parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, - char **username_arg, char **groupname_arg); + char **username_arg, char **groupname_arg, bool numeric); #endif diff -Nur coreutils-5.97/src/chgrp.c coreutils-5.97-numeric/src/chgrp.c --- coreutils-5.97/src/chgrp.c 2006-05-27 10:59:09.000000000 -0400 +++ coreutils-5.97-numeric/src/chgrp.c 2006-08-08 11:57:44.000000000 -0400 @@ -71,6 +71,7 @@ {"silent", no_argument, NULL, 'f'}, {"reference", required_argument, NULL, REFERENCE_FILE_OPTION}, {"verbose", no_argument, NULL, 'v'}, + {"numeric", no_argument, NULL, 'n'}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -79,13 +80,15 @@ /* Return the group ID of NAME, or -1 if no name was specified. */ static gid_t -parse_group (const char *name) +parse_group (const char *name, bool numeric) { gid_t gid = -1; + struct group *grp = NULL; if (*name) { - struct group *grp = getgrnam (name); + if(!numeric) + grp = getgrnam (name); if (grp) gid = grp->gr_gid; else @@ -129,6 +132,10 @@ ownership of a symlink)\n\ "), stdout); fputs (_("\ + -n, --numeric treats OWNER and GROUP as numeric by default. User '0'\n\ + would be root rather then username '0'.\n\ +"), stdout); + fputs (_("\ --no-preserve-root do not treat `/' specially (the default)\n\ --preserve-root fail to operate recursively on `/'\n\ "), stdout); @@ -193,7 +200,7 @@ chopt_init (&chopt); - while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL)) + while ((optc = getopt_long (argc, argv, "HLPRcfhvn", long_options, NULL)) != -1) { switch (optc) @@ -246,6 +253,10 @@ case 'v': chopt.verbosity = V_high; break; + + case 'n': + chopt.numeric = true; + break; case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); @@ -299,7 +310,7 @@ { char *group_name = argv[optind++]; chopt.group_name = (*group_name ? group_name : NULL); - gid = parse_group (group_name); + gid = parse_group (group_name, chopt.numeric); } if (chopt.recurse & preserve_root) diff -Nur coreutils-5.97/src/chown-core.c coreutils-5.97-numeric/src/chown-core.c --- coreutils-5.97/src/chown-core.c 2005-05-30 03:31:51.000000000 -0400 +++ coreutils-5.97-numeric/src/chown-core.c 2006-08-08 11:07:50.000000000 -0400 @@ -57,6 +57,7 @@ chopt->force_silent = false; chopt->user_name = NULL; chopt->group_name = NULL; + chopt->numeric = false; } extern void diff -Nur coreutils-5.97/src/chown-core.h coreutils-5.97-numeric/src/chown-core.h --- coreutils-5.97/src/chown-core.h 2005-05-14 03:58:36.000000000 -0400 +++ coreutils-5.97-numeric/src/chown-core.h 2006-08-08 11:06:14.000000000 -0400 @@ -64,6 +64,10 @@ /* The name of the group to which ownership of the files is being given. */ char *group_name; + + /* Whether the supplied OWNER/GROUP combo should be treated as numeric or + defaultly as name then numeric. */ + bool numeric; }; void diff -Nur coreutils-5.97/src/chown.c coreutils-5.97-numeric/src/chown.c --- coreutils-5.97/src/chown.c 2005-05-14 03:58:36.000000000 -0400 +++ coreutils-5.97-numeric/src/chown.c 2006-08-08 11:57:33.000000000 -0400 @@ -78,6 +78,7 @@ {"silent", no_argument, NULL, 'f'}, {"reference", required_argument, NULL, REFERENCE_FILE_OPTION}, {"verbose", no_argument, NULL, 'v'}, + {"numeric", no_argument, NULL, 'n'}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -110,6 +111,10 @@ ownership of a symlink)\n\ "), stdout); fputs (_("\ + -n, --numeric treats OWNER and GROUP as numeric by default. User '0'\n\ + would be root rather then username '0'.\n\ +"), stdout); + fputs (_("\ --from=CURRENT_OWNER:CURRENT_GROUP\n\ change the owner and/or group of each file only if\n\ its current owner and/or group match those specified\n\ @@ -195,7 +200,7 @@ chopt_init (&chopt); - while ((optc = getopt_long (argc, argv, "HLPRcfhv", long_options, NULL)) + while ((optc = getopt_long (argc, argv, "HLPRcfhvn", long_options, NULL)) != -1) { switch (optc) @@ -238,7 +243,7 @@ char *u_dummy, *g_dummy; const char *e = parse_user_spec (optarg, &required_uid, &required_gid, - &u_dummy, &g_dummy); + &u_dummy, &g_dummy, chopt.numeric); if (e) error (EXIT_FAILURE, 0, "%s: %s", quote (optarg), e); break; @@ -260,6 +265,10 @@ chopt.verbosity = V_high; break; + case 'n': + chopt.numeric = true; + break; + case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: @@ -313,7 +322,7 @@ else { const char *e = parse_user_spec (argv[optind], &uid, &gid, - &chopt.user_name, &chopt.group_name); + &chopt.user_name, &chopt.group_name, chopt.numeric); if (e) error (EXIT_FAILURE, 0, "%s: %s", quote (argv[optind]), e);