[BusyBox] [PATCH] (tinylogin 1.02) set passwords from script
Torrey Hoffman
thoffman at arnor.net
Thu Jul 25 15:50:06 UTC 2002
I find it useful to be able to change passwords from a script. Here is
a patch to the passwd applet of tinylogin 1.02 which adds a "-p" option
that allows you to do that.
If there is some other way to achieve this, I'd like to know about it.
Torrey Hoffman
thoffman at arnor.net
torrey.hoffman at myrio.com
diff -urN -X dontdiff tinylogin-1.02-vanilla/passwd.c tinylogin-1.02/passwd.c
--- tinylogin-1.02-vanilla/passwd.c Thu Jan 3 02:39:44 2002
+++ tinylogin-1.02/passwd.c Thu Jul 25 14:22:36 2002
@@ -19,6 +19,7 @@
static int create_backup(const char *backup, FILE * fp);
static int new_password(const struct passwd *pw, int amroot, int algo);
+static int encrypt_password(char *pass, int algo);
static void set_filesize_limit();
@@ -48,6 +49,8 @@
int lflg = 0; /* -l - lock account */
int uflg = 0; /* -u - unlock account */
int dflg = 0; /* -d - delete password */
+ int pflg = 0; /* -p - set password from argument */
+ char pass[9];
const struct passwd *pw;
unsigned short ruid;
@@ -56,11 +59,16 @@
#endif /* TLG_FEATURE_SHADOWPASSWDS */
amroot = (getuid() == 0);
openlog("passwd", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH);
- while ((flag = getopt(argc, argv, "a:dlu")) != EOF) {
+ while ((flag = getopt(argc, argv, "a:p:dlu")) != EOF) {
switch (flag) {
case 'a':
algo = get_algo(optarg);
break;
+ case 'p':
+ pflg++;
+ // copy at most 8 chars from option, forces null termination.
+ STRFCPY(pass, optarg);
+ break;
case 'd':
dflg++;
break;
@@ -109,7 +117,7 @@
#endif /* TLG_FEATURE_SHADOWPASSWDS */
STRFCPY(crypt_passwd, cp);
- if (!(dflg || lflg || uflg)) {
+ if (!(dflg || lflg || uflg || pflg)) {
if (!amroot) {
if (cp[0] == '!') {
syslog(LOG_WARNING, "password locked for `%s'", np);
@@ -120,6 +128,13 @@
if (new_password(pw, amroot, algo)) {
error_msg_and_die( "The password for %s is unchanged.\n", name);
}
+ } else if (pflg) {
+ if (!amroot)
+ error_msg_and_die("Only root can set passwords via command line.\n");
+ if (strlen(pass) < 6)
+ error_msg_and_die("Sorry, minimum password length is 5.\n");
+ printf("Changing password for %s\n",name);
+ encrypt_password(pass,algo);
} else if (lflg) {
if (crypt_passwd[0] != '!') {
memmove(&crypt_passwd[1], crypt_passwd,
@@ -394,6 +409,13 @@
}
bzero(cp, strlen(cp));
bzero(orig, sizeof(orig));
+
+ return encrypt_password(pass, algo);
+}
+
+static int encrypt_password(char *pass, int algo)
+{
+ char *cp;
#ifdef TLG_FEATURE_SHA1_PASSWORDS
if (algo == 2) {
More information about the busybox
mailing list