Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 149628 Details for
Bug 231525
RFE: add '--hint' option
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
adds '--hint' option to useradd
shadow-4.0.18.1-hint.patch (text/plain), 11.08 KB, created by
Enrico Scholz
on 2007-03-08 20:43:40 UTC
(
hide
)
Description:
adds '--hint' option to useradd
Filename:
MIME Type:
Creator:
Enrico Scholz
Created:
2007-03-08 20:43:40 UTC
Size:
11.08 KB
patch
obsolete
>--- /dev/null 2007-03-03 00:05:55.498089215 +0100 >+++ shadow-4.0.18.1/libmisc/follow-hint.c 2007-03-08 21:38:20.000000000 +0100 >@@ -0,0 +1,147 @@ >+/* Copyright (C) 2007 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * 3. Neither the name of Julianne F. Haugh nor the names of its contributors >+ * may be used to endorse or promote products derived from this software >+ * without specific prior written permission. >+ * >+ * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND >+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE >+ * ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE >+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL >+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS >+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) >+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT >+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY >+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ */ >+ >+#ifdef HAVE_CONFIG_H >+# include <config.h> >+#endif >+ >+#include "follow-hint.h" >+ >+#include <unistd.h> >+#include <stdlib.h> >+#include <stdio.h> >+#include <errno.h> >+#include <sys/wait.h> >+ >+#include "getdef.h" >+#include "defines.h" >+ >+#ifndef TRANSLATE_ID_DEFAULT_PROG >+#define TRANSLATE_ID_DEFAULT_PROG "/usr/libexec/shadow-translate-id" >+#endif >+ >+char const * hint_get_translate_prog() >+{ >+ char const *res = getdef_str("TRANSLATE_ID_PROG"); >+ if (res==0) >+ res = TRANSLATE_ID_DEFAULT_PROG; >+ >+ return res; >+} >+ >+int hint_follow (char const *args[], >+ uid_t (*fn)(char const *), >+ uid_t *res) >+{ >+ pid_t pid; >+ int p[2]; >+ >+ if (pipe(p)<0) { >+ perror("pipe()"); >+ return ERR_HINT_GENERAL; >+ } >+ >+ pid = fork(); >+ if (pid==-1) { >+ perror("fork()"); >+ close(p[0]); >+ close(p[1]); >+ >+ return ERR_HINT_GENERAL; >+ } >+ else if (pid==0) { >+ if (p[1]!=1 && dup2(p[1], 1)<0) { >+ perror("dup2()"); >+ _exit (1); >+ } >+ close(p[0]); >+ >+ execv(args[0], args); >+ >+ if (errno==ENOENT) >+ _exit (0); // no translator -> no hint >+ else >+ _exit (1); >+ } >+ else { >+ char tmp[32 + sizeof(uid_t)*3]; // we expect a numeric string so this is enough >+ char *ptr = tmp; >+ size_t cnt = sizeof(tmp)-1; >+ int status; >+ int rc; >+ close(p[1]); >+ >+ if (TEMP_FAILURE_RETRY(waitpid(pid, &status, 0))<0) { >+ perror("waitpid()"); >+ >+ rc = ERR_HINT_GENERAL; >+ goto err; >+ } >+ >+ if (status!=0) { >+ fprintf(stderr, _("translate-id script failed with %d\n"), status); >+ >+ rc = ERR_HINT_BAD_ARG; >+ goto err; >+ } >+ >+ for (;;) { >+ ssize_t l = TEMP_FAILURE_RETRY(read(p[0], ptr, cnt)); >+ if (l<0) { >+ perror("read()"); >+ rc = ERR_HINT_GENERAL; >+ goto err; >+ } >+ else if (l>=cnt) { // we do not expect so much data >+ fprintf(stderr, _("translate-id provides too much data\n")); >+ >+ rc = ERR_HINT_BAD_ARG; >+ goto err; >+ } >+ else if (l==0) >+ break; >+ else { >+ ptr += l; >+ cnt -= l; >+ } >+ } >+ >+ close(p[0]); >+ while (ptr>tmp && ptr[-1]=='\n') --ptr; // strip trailing <CR> >+ *ptr = '\0'; >+ >+ if (ptr==tmp) >+ return ERR_HINT_IGNORE; >+ else { >+ *res = fn(tmp); >+ return ERR_HINT_OK; >+ } >+ >+ err: >+ close(p[0]); >+ return rc; >+ } >+} >--- /dev/null 2007-03-03 00:05:55.498089215 +0100 >+++ shadow-4.0.18.1/libmisc/follow-hint.h 2007-03-08 21:21:06.000000000 +0100 >@@ -0,0 +1,34 @@ >+// $Id: init.el,v 1.1 2007/03/07 10:33:29 ensc Exp ensc $ --*- c -*-- >+ >+// Copyright (C) 2007 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> >+// >+// This program is free software; you can redistribute it and/or modify >+// it under the terms of the GNU General Public License as published by >+// the Free Software Foundation; version 2 of the License. >+// >+// This program is distributed in the hope that it will be useful, >+// but WITHOUT ANY WARRANTY; without even the implied warranty of >+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+// GNU General Public License for more details. >+// >+// You should have received a copy of the GNU General Public License >+// along with this program; if not, write to the Free Software >+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. >+ >+ >+#ifndef H_SHADOW_UTILS_LIBMISC_FOLLOW_HINT_H >+#define H_SHADOW_UTILS_LIBMISC_FOLLOW_HINT_H >+ >+#include <sys/types.h> >+ >+#define ERR_HINT_OK 0 >+#define ERR_HINT_IGNORE 1 >+#define ERR_HINT_GENERAL 2 >+#define ERR_HINT_BAD_ARG 3 >+ >+extern char const * hint_get_translate_prog(); >+extern int hint_follow (char const *args[], >+ uid_t (*fn)(char const *), >+ uid_t *res); >+ >+#endif // H_SHADOW_UTILS_LIBMISC_FOLLOW_HINT_H >--- shadow-4.0.18.1/libmisc/Makefile.am.hint 2007-03-08 20:59:45.000000000 +0100 >+++ shadow-4.0.18.1/libmisc/Makefile.am 2007-03-08 20:59:45.000000000 +0100 >@@ -21,6 +21,7 @@ > failure.c \ > failure.h \ > fields.c \ >+ follow-hint.c \ > getdate.h \ > getdate.y \ > hushed.c \ >--- shadow-4.0.18.1/lib/getdef.c.hint 2006-06-24 15:17:18.000000000 +0200 >+++ shadow-4.0.18.1/lib/getdef.c 2007-03-08 21:22:23.000000000 +0100 >@@ -80,6 +80,7 @@ > {"UMASK", NULL}, > {"USERDEL_CMD", NULL}, > {"USERGROUPS_ENAB", NULL}, >+ {"TRANSLATE_ID_PROG", NULL}, > #ifndef USE_PAM > {"CHFN_AUTH", NULL}, > {"CHSH_AUTH", NULL}, >--- shadow-4.0.18.1/src/useradd.c.hint 2007-03-08 20:59:45.000000000 +0100 >+++ shadow-4.0.18.1/src/useradd.c 2007-03-08 21:23:11.000000000 +0100 >@@ -59,6 +59,8 @@ > #endif > #include "shadowio.h" > >+#include <follow-hint.h> >+ > #ifndef SKEL_DIR > #define SKEL_DIR "/etc/skel" > #endif >@@ -72,6 +74,9 @@ > #ifndef LASTLOG_FILE > #define LASTLOG_FILE "/var/log/lastlog" > #endif >+ >+#define OPT_HINT 1000 >+ > /* > * Global variables > */ >@@ -92,6 +97,7 @@ > > #define VALID(s) (strcspn (s, ":\n") == strlen (s)) > >+static char const *hint_str = 0; > static const char *user_name = ""; > static const char *user_pass = "!!"; > static uid_t user_id; >@@ -125,7 +131,7 @@ > Gflg = 0, /* secondary group set for new account */ > kflg = 0, /* specify a directory to fill new user directory */ > mflg = 0, /* create user's home directory if it doesn't exist */ >- lflg = 0; /* do not add user to lastlog database file */ >+ lflg = 0, /* do not add user to lastlog database file */ > Mflg = 0, /* do NOT create user's home directory no matter what */ > nflg = 0, /* do NOT create a group having the same name as the user */ > oflg = 0, /* permit non-unique user ID to be specified with -u */ >@@ -151,6 +157,7 @@ > #define E_GRP_UPDATE 10 /* can't update group file */ > #define E_HOMEDIR 12 /* can't create home directory */ > #define E_MAIL_SPOOL 13 /* can't create mail spool */ >+#define E_GENERAL 14 /* some unspecific, general error */ > > #define DGROUP "GROUP=" > #define HOME "HOME=" >@@ -645,6 +652,8 @@ > " account\n" > " -s, --shell SHELL the login shell for the new user account\n" > " -u, --uid UID force use the UID for the new user account\n" >+ " --hint STR pass STR to the 'translate-id' script; stdout output\n" >+ " of this script will act like '-u <output>'\n" > #ifdef WITH_SELINUX > " -Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping\n" > #endif >@@ -1047,6 +1056,7 @@ > {"non-unique", no_argument, NULL, 'o'}, > {"password", required_argument, NULL, 'p'}, > {"shell", required_argument, NULL, 's'}, >+ {"hint", required_argument, NULL, OPT_HINT}, > #ifdef WITH_SELINUX > {"selinux-user", required_argument, NULL, 'Z'}, > #endif >@@ -1252,6 +1262,10 @@ > exit (E_BAD_ARG); > } > break; >+ case OPT_HINT: >+ hint_str = optarg; >+ break; >+ > #endif > default: > usage (); >@@ -1260,6 +1274,32 @@ > } > } > >+ if (!uflg && hint_str) { >+ char const * args[] = { >+ hint_get_translate_prog(), >+ "USER", >+ hint_str, >+ optind == argc-1 ? argv[optind] : 0, >+ 0 >+ }; >+ >+ switch (hint_follow(args, get_uid, &user_id)) { >+ case ERR_HINT_OK: >+ ++uflg; >+ break; >+ >+ case ERR_HINT_IGNORE: >+ break; >+ >+ case ERR_HINT_BAD_ARG: >+ exit (E_BAD_ARG); >+ >+ case ERR_HINT_GENERAL: >+ default: >+ exit (E_GENERAL); >+ } >+ } >+ > if (mflg && Mflg) /* the admin is not decided .. create or not ? */ > usage(); > >--- shadow-4.0.18.1/src/groupadd.c.hint 2007-03-08 20:59:45.000000000 +0100 >+++ shadow-4.0.18.1/src/groupadd.c 2007-03-08 21:22:52.000000000 +0100 >@@ -47,6 +47,7 @@ > #include "groupio.h" > #include "nscd.h" > #include "prototypes.h" >+#include "follow-hint.h" > #ifdef SHADOWGRP > #include "sgroupio.h" > static int is_shadow_grp; >@@ -61,6 +62,9 @@ > #define E_GID_IN_USE 4 /* gid not unique (when -o not used) */ > #define E_NAME_IN_USE 9 /* group name not unique */ > #define E_GRP_UPDATE 10 /* can't update group file */ >+#define E_GENERAL 11 /* general error */ >+ >+#define OPT_HINT 1000 > > /* > * Global variables >@@ -107,6 +111,8 @@ > " -K, --key KEY=VALUE overrides /etc/login.defs defaults\n" > " -o, --non-unique allow create group with duplicate\n" > " (non-unique) GID\n" >+ " --hint STR pass STR to the 'translate-id' script; stdout output\n" >+ " of this script will act like '-g <output>'\n" > "\n")); > exit (E_USAGE); > } >@@ -401,6 +407,7 @@ > int main (int argc, char **argv) > { > struct stat s; >+ char const *hint_str = 0; > #ifdef USE_PAM > pam_handle_t *pamh = NULL; > struct passwd *pampw; >@@ -434,6 +441,7 @@ > {"help", no_argument, NULL, 'h'}, > {"key", required_argument, NULL, 'K'}, > {"non-unique", required_argument, NULL, 'o'}, >+ {"hint", required_argument, NULL, OPT_HINT}, > {NULL, 0, NULL, '\0'} > }; > >@@ -486,12 +494,42 @@ > case 'o': > oflg++; > break; >+ case OPT_HINT: >+ hint_str = optarg; >+ break; > default: > usage (); > } > } > } > >+ if (!gflg && hint_str) { >+ char const * args[] = { >+ hint_get_translate_prog(), >+ "GROUP", >+ hint_str, >+ optind == argc-1 ? argv[optind] : 0, >+ 0 >+ }; >+ >+ switch (hint_follow(args, get_gid, &group_id)) { >+ case ERR_HINT_OK: >+ ++gflg; >+ break; >+ >+ case ERR_HINT_IGNORE: >+ break; >+ >+ case ERR_HINT_BAD_ARG: >+ exit (E_BAD_ARG); >+ >+ case ERR_HINT_GENERAL: >+ default: >+ exit (E_GENERAL); >+ } >+ } >+ >+ > if (oflg && !gflg) > usage (); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 231525
: 149628