r13524: Add -t|--password-from-stdin option to pdbedit as we had with Samba 2.2.
authorLars Müller <lmuelle@samba.org>
Thu, 16 Feb 2006 16:22:44 +0000 (16:22 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:10:10 +0000 (11:10 -0500)
This fixes bug #1386.

The initial changes had been made by Carsten Höger <choeger at
open-xhange dot com> for Samba 2.2 while being at SuSE. *sigh*

To not duplicate code from smbpasswd in pdbedit stdin_new_passwd() and
get_pass() are moved from smbpasswd to utils/passwd_util.c.
(This used to be commit dbdc5ba497c6010dbad47c9d77fc8bec5557a328)

source3/Makefile.in
source3/utils/passwd_util.c [new file with mode: 0644]
source3/utils/pdbedit.c
source3/utils/smbpasswd.c

index 135c757fd881eccfa6fc142636182259ff7d0d85..5e903478ba2636f9e28a3e7aad4314534a09d19d 100644 (file)
@@ -477,12 +477,12 @@ TESTPARM_OBJ = utils/testparm.o \
                $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(POPT_LIB_OBJ) \
               $(SECRETS_OBJ) $(LIBSAMBA_OBJ) $(RPC_PARSE_OBJ1) $(DOSERR_OBJ)
 
-SMBPASSWD_OBJ = utils/smbpasswd.o $(PASSCHANGE_OBJ) $(PARAM_OBJ) $(SECRETS_OBJ) \
+SMBPASSWD_OBJ = utils/smbpasswd.o utils/passwd_util.o $(PASSCHANGE_OBJ) $(PARAM_OBJ) $(SECRETS_OBJ) \
                $(LIBSMB_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ)\
                 $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) \
                $(SMBLDAP_OBJ) $(RPC_PARSE_OBJ) $(LIBMSRPC_OBJ)
 
-PDBEDIT_OBJ = utils/pdbedit.o $(PARAM_OBJ) $(PASSDB_OBJ) $(LIBSAMBA_OBJ) \
+PDBEDIT_OBJ = utils/pdbedit.o utils/passwd_util.o $(PARAM_OBJ) $(PASSDB_OBJ) $(LIBSAMBA_OBJ) \
                $(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) $(SECRETS_OBJ) \
                $(POPT_LIB_OBJ) $(SMBLDAP_OBJ) libsmb/asn1.o $(RPC_PARSE_OBJ1) $(DOSERR_OBJ)
 
@@ -666,7 +666,7 @@ PROTO_OBJ = $(SMBD_OBJ_MAIN) \
            $(RPC_SVC_OBJ) $(RPC_WKS_OBJ) $(RPC_DFS_OBJ) $(RPC_SPOOLSS_OBJ) \
            $(RPC_ECHO_OBJ) $(RPC_SVCCTL_OBJ) $(RPC_EVENTLOG_OBJ) $(SMBLDAP_OBJ) \
             $(IDMAP_OBJ) libsmb/spnego.o $(PASSCHANGE_OBJ) \
-            $(RPC_NTSVCS_OBJ)
+            $(RPC_NTSVCS_OBJ) utils/passwd_util.o
 
 WINBIND_WINS_NSS_OBJ = nsswitch/wins.o $(PARAM_OBJ) \
        $(LIBSMB_OBJ) $(LIB_NONSMBD_OBJ) $(NSSWINS_OBJ) $(KRBCLIENT_OBJ)
@@ -1583,6 +1583,11 @@ utils/net_proto.h:
          -h _NET_PROTO_H_ $(builddir)/utils/net_proto.h \
          $(NET_OBJ1)
 
+utils/passwd_proto.h:
+       @cd $(srcdir) && $(SHELL) $(MKPROTO_SH) $(AWK) \
+         -h _PASSWD_PROTO_H_ $(builddir)/utils/passwd_proto.h \
+         utils/passwd_util.o
+
 utils/ntlm_auth_proto.h: 
        @cd $(srcdir) && $(SHELL) $(MKPROTO_SH) $(AWK) \
          -h _NTLM_AUTH_PROTO_H_ $(builddir)/utils/ntlm_auth_proto.h \
@@ -1601,7 +1606,8 @@ headers:
        $(MAKE) web/swat_proto.h; \
        $(MAKE) client/client_proto.h; \
        $(MAKE) utils/ntlm_auth_proto.h; \
-       $(MAKE) utils/net_proto.h;
+       $(MAKE) utils/net_proto.h; \
+       $(MAKE) utils/passwd_proto.h;
 
 proto: headers 
 
diff --git a/source3/utils/passwd_util.c b/source3/utils/passwd_util.c
new file mode 100644 (file)
index 0000000..efe00d5
--- /dev/null
@@ -0,0 +1,65 @@
+/* 
+   Unix SMB/CIFS implementation.
+   passdb editing frontend
+   
+   Copyright (C) Simo Sorce      2000
+   Copyright (C) Andrew Bartlett 2001
+   Copyright (C) Jelmer Vernooij 2002
+
+   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; either version 2 of the License, or
+   (at your option) any later version.
+   
+   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., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+/*************************************************************
+ Utility function to prompt for passwords from stdin. Each
+ password entered must end with a newline.
+*************************************************************/
+char *stdin_new_passwd( void)
+{
+       static fstring new_pw;
+       size_t len;
+
+       ZERO_ARRAY(new_pw);
+
+       /*
+        * if no error is reported from fgets() and string at least contains
+        * the newline that ends the password, then replace the newline with
+        * a null terminator.
+        */
+       if ( fgets(new_pw, sizeof(new_pw), stdin) != NULL) {
+               if ((len = strlen(new_pw)) > 0) {
+                       if(new_pw[len-1] == '\n')
+                               new_pw[len - 1] = 0;
+               }
+       }
+       return(new_pw);
+}
+
+/*************************************************************
+ Utility function to get passwords via tty or stdin
+ Used if the '-t' option is set to silently get passwords
+ to enable scripting.
+*************************************************************/
+char *get_pass( char *prompt, BOOL stdin_get)
+{
+       char *p;
+       if (stdin_get) {
+               p = stdin_new_passwd();
+       } else {
+               p = getpass( prompt);
+       }
+       return smb_xstrdup( p);
+}
index f4d558f07dde0d03ccd46431c93bb6137b28da23..1423d9486d57b11306bcbd41f1f46d099ba37f25 100644 (file)
@@ -394,12 +394,13 @@ static int set_user_info (struct pdb_methods *in, const char *username,
 static int new_user (struct pdb_methods *in, const char *username,
                        const char *fullname, const char *homedir,
                        const char *drive, const char *script,
-                       const char *profile, char *user_sid, char *group_sid)
+                       const char *profile, char *user_sid, char *group_sid,
+                       BOOL stdin_get)
 {
        SAM_ACCOUNT *sam_pwent=NULL;
 
-       char *password1, *password2, *staticpass;
-       
+       char *password1, *password2;
+
        get_global_sam_sid();
 
        if (!NT_STATUS_IS_OK(pdb_init_sam_new(&sam_pwent, username))) {
@@ -407,12 +408,8 @@ static int new_user (struct pdb_methods *in, const char *username,
                return -1;
        }
 
-       staticpass = getpass("new password:");
-       password1 = SMB_STRDUP(staticpass);
-       memset(staticpass, 0, strlen(staticpass));
-       staticpass = getpass("retype new password:");
-       password2 = SMB_STRDUP(staticpass);
-       memset(staticpass, 0, strlen(staticpass));
+       password1 = get_pass( "new password:", stdin_get);
+       password2 = get_pass( "retype new password:", stdin_get);
        if (strcmp (password1, password2)) {
                fprintf (stderr, "Passwords does not match!\n");
                memset(password1, 0, strlen(password1));
@@ -636,6 +633,7 @@ int main (int argc, char **argv)
        static char *pwd_can_change_time = NULL;
        static char *pwd_must_change_time = NULL;
        static char *pwd_time_format = NULL;
+       BOOL pw_from_stdin = False;
 
        struct pdb_methods *bdef = NULL;
        poptContext pc;
@@ -673,6 +671,7 @@ int main (int argc, char **argv)
                {"pwd-can-change-time", 0, POPT_ARG_STRING, &pwd_can_change_time, 0, "Set password can change time (unix time in seconds since 1970 if time format not provided)", NULL },
                {"pwd-must-change-time", 0, POPT_ARG_STRING, &pwd_must_change_time, 0, "Set password must change time (unix time in seconds since 1970 if time format not provided)", NULL },
                {"time-format", 0, POPT_ARG_STRING, &pwd_time_format, 0, "The time format for time parameters", NULL },
+               {"password-from-stdin", 't', POPT_ARG_NONE, &pw_from_stdin, 0, "get password from standard in", NULL},
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
@@ -848,7 +847,8 @@ int main (int argc, char **argv)
                        } else {
                                return new_user (bdef, user_name, full_name, home_dir, 
                                                 home_drive, logon_script, 
-                                                profile_path, user_sid, group_sid);
+                                                profile_path, user_sid, group_sid,
+                                                pw_from_stdin);
                        }
                }
 
index 4323ee29e0ceed72821cf83f497a28af90c89335..9325c24881183e5216cfd251296f6101d4464092 100644 (file)
@@ -196,48 +196,6 @@ static int process_options(int argc, char **argv, int local_flags)
        return local_flags;
 }
 
-/*************************************************************
- Utility function to prompt for passwords from stdin. Each
- password entered must end with a newline.
-*************************************************************/
-static char *stdin_new_passwd(void)
-{
-       static fstring new_pw;
-       size_t len;
-
-       ZERO_ARRAY(new_pw);
-
-       /*
-        * if no error is reported from fgets() and string at least contains
-        * the newline that ends the password, then replace the newline with
-        * a null terminator.
-        */
-       if ( fgets(new_pw, sizeof(new_pw), stdin) != NULL) {
-               if ((len = strlen(new_pw)) > 0) {
-                       if(new_pw[len-1] == '\n')
-                               new_pw[len - 1] = 0; 
-               }
-       }
-       return(new_pw);
-}
-
-
-/*************************************************************
- Utility function to get passwords via tty or stdin
- Used if the '-s' option is set to silently get passwords
- to enable scripting.
-*************************************************************/
-static char *get_pass( const char *prompt, BOOL stdin_get)
-{
-       char *p;
-       if (stdin_get) {
-               p = stdin_new_passwd();
-       } else {
-               p = getpass(prompt);
-       }
-       return smb_xstrdup(p);
-}
-
 /*************************************************************
  Utility function to prompt for new password.
 *************************************************************/