summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 135c757fd88..5e903478ba2 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 00000000000..efe00d5af28
--- /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 f4d558f07dd..1423d9486d5 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 4323ee29e0c..9325c248811 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)