summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorLars Müller <lmuelle@samba.org>2006-02-16 16:22:44 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:10:10 -0500
commit394d1aeb8e2922a261efa78d65fc21defde63448 (patch)
tree4ae9cbaea3a9d8e5e9a9c7cb1a503f1577faf8b0 /source3
parentee078e61a6e4d0ae462ff480d89eb83298523ec3 (diff)
downloadsamba-394d1aeb8e2922a261efa78d65fc21defde63448.tar.gz
samba-394d1aeb8e2922a261efa78d65fc21defde63448.tar.bz2
samba-394d1aeb8e2922a261efa78d65fc21defde63448.zip
r13524: Add -t|--password-from-stdin option to pdbedit as we had with Samba 2.2.
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)
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in14
-rw-r--r--source3/utils/passwd_util.c65
-rw-r--r--source3/utils/pdbedit.c20
-rw-r--r--source3/utils/smbpasswd.c42
4 files changed, 85 insertions, 56 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 135c757fd8..5e903478ba 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -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
index 0000000000..efe00d5af2
--- /dev/null
+++ b/source3/utils/passwd_util.c
@@ -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);
+}
diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c
index f4d558f07d..1423d9486d 100644
--- a/source3/utils/pdbedit.c
+++ b/source3/utils/pdbedit.c
@@ -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);
}
}
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 4323ee29e0..9325c24881 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -197,48 +197,6 @@ static int process_options(int argc, char **argv, int 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.
*************************************************************/
static char *prompt_for_new_password(BOOL stdin_get)