Mercurial > hg > toybox
annotate toys/lsb/passwd.c @ 1140:ef0bf6560071 draft
Forgot to set new pending entry to default n.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 08 Dec 2013 13:21:14 -0600 |
parents | 6df194c6de88 |
children | 0752b2d58909 |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
1 /* passwd.c - Program to update user password. |
626 | 2 * |
3 * Copyright 2012 Ashwini Kumar <ak.ashwini@gmail.com> | |
4 * Modified 2012 Jason Kyungwan Han <asura321@gmail.com> | |
5 * | |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
6 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/passwd.html |
626 | 7 |
8 USE_PASSWD(NEWTOY(passwd, ">1a:dlu", TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN)) | |
9 | |
10 config PASSWD | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
11 bool "passwd" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
12 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
13 help |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
14 usage: passwd [-a ALGO] [-dlu] <account name> |
626 | 15 |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
16 update user's authentication tokens. Default : current user |
626 | 17 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
18 -a ALGO Encryption method (des, md5, sha256, sha512) default: des |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
19 -d Set password to '' |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
20 -l Lock (disable) account |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
21 -u Unlock (enable) account |
626 | 22 */ |
23 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
24 #define FOR_passwd |
626 | 25 #include "toys.h" |
26 | |
674
7e846e281e38
New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
27 GLOBALS( |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
28 char *algo; |
626 | 29 ) |
30 | |
31 #ifndef _GNU_SOURCE | |
32 char *strcasestr(const char *haystack, const char *needle); | |
33 #endif | |
34 | |
35 static int str_check(char *s, char *p) | |
36 { | |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
37 if (strcasestr(s, p) || strcasestr(p, s)) return 1; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
38 return 0; |
626 | 39 } |
40 | |
41 static void strength_check(char *newp, char *oldp, char *user) | |
42 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
43 char *msg = NULL; |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
44 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
45 if (strlen(newp) < 6) { //Min passwd len |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
46 msg = "too short"; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
47 xprintf("BAD PASSWORD: %s\n",msg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
48 } |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
49 if (!newp[0]) return; //passwd is empty |
626 | 50 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
51 if (str_check(newp, user)) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
52 msg = "user based password"; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
53 xprintf("BAD PASSWORD: %s\n",msg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
54 } |
626 | 55 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
56 if (oldp[0] && str_check(newp, oldp)) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
57 msg = "based on old passwd"; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
58 xprintf("BAD PASSWORD: %s\n",msg); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
59 } |
626 | 60 } |
61 | |
62 static int verify_passwd(char * pwd) | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
63 { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
64 char * pass; |
626 | 65 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
66 if (!pwd) return 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
67 if (pwd[0] == '!' || pwd[0] == '*') return 1; |
626 | 68 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
69 pass = crypt(toybuf, pwd); |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
70 if (pass && !strcmp(pass, pwd)) return 0; |
626 | 71 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
72 return 1; |
626 | 73 } |
74 | |
75 static char *new_password(char *oldp, char *user) | |
76 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
77 char *newp = NULL; |
626 | 78 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
79 if (read_password(toybuf, sizeof(toybuf), "New password:")) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
80 return NULL; //may be due to Ctrl-C |
626 | 81 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
82 newp = xstrdup(toybuf); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
83 strength_check(newp, oldp, user); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
84 if (read_password(toybuf, sizeof(toybuf), "Retype password:")) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
85 free(newp); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
86 return NULL; //may be due to Ctrl-C |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
87 } |
626 | 88 |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
89 if (!strcmp(newp, toybuf)) return newp; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
90 else error_msg("Passwords do not match.\n"); |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
91 // Failure Case |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
92 free(newp); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
93 return NULL; |
626 | 94 } |
95 | |
96 void passwd_main(void) | |
97 { | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
98 uid_t myuid; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
99 struct passwd *pw; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
100 struct spwd *sp; |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
101 char *name = NULL, *pass = NULL, *encrypted = NULL, *newp = NULL, |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
102 *orig = (char *)"", salt[MAX_SALT_LEN]; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
103 int ret = -1; |
626 | 104 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
105 myuid = getuid(); |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
106 if (myuid && (toys.optflags & (FLAG_l | FLAG_u | FLAG_d))) |
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
107 error_exit("Not root"); |
626 | 108 |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
109 pw = xgetpwuid(myuid); |
626 | 110 |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
111 if (*toys.optargs) name = toys.optargs[0]; |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
112 else name = xstrdup(pw->pw_name); |
626 | 113 |
1130
6df194c6de88
Add xgetpwnam() to lib/xwrap.c.
Rob Landley <rob@landley.net>
parents:
1089
diff
changeset
|
114 pw = xgetpwnam(name); |
626 | 115 |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
116 if (myuid && (myuid != pw->pw_uid)) |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
117 error_exit("You need to be root to change '%s' password\n", name); |
626 | 118 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
119 pass = pw->pw_passwd; |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
120 if (pw->pw_passwd[0] == 'x') { |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
121 //get shadow passwd |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
122 sp = getspnam(name); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
123 if (sp) pass = sp->sp_pwdp; |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
124 } |
626 | 125 |
126 | |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
127 if (!(toys.optflags & (FLAG_l | FLAG_u | FLAG_d))) { |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
128 |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
129 if (!(toys.optflags & FLAG_a)) TT.algo = "des"; |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
130 if (get_salt(salt, TT.algo) == -1) |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
131 error_exit("Error: Unkown encryption algorithm\n"); |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
132 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
133 printf("Changing password for %s\n",name); |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
134 if (myuid && pass[0] == '!') |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
135 error_exit("Can't change, password is locked for %s",name); |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
136 if (myuid) { |
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
137 //Validate user |
626 | 138 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
139 if (read_password(toybuf, sizeof(toybuf), "Origial password:")) { |
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
140 if (!toys.optargs[0]) free(name); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
141 return; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
142 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
143 orig = toybuf; |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
144 if (verify_passwd(pass)) error_exit("Authentication failed\n"); |
626 | 145 } |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
146 |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
147 orig = xstrdup(orig); |
626 | 148 |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
149 // Get new password |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
150 newp = new_password(orig, name); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
151 if (!newp) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
152 free(orig); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
153 if (!toys.optargs[0]) free(name); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
154 return; //new password is not set well. |
626 | 155 } |
156 | |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
157 encrypted = crypt(newp, salt); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
158 free(newp); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
159 free(orig); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
160 } else if (toys.optflags & FLAG_l) { |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
161 if (pass[0] == '!') error_exit("password is already locked for %s",name); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
162 printf("Locking password for %s\n",name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
163 encrypted = xmsprintf("!%s",pass); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
164 } else if (toys.optflags & FLAG_u) { |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
165 if (pass[0] != '!') error_exit("password is already unlocked for %s",name); |
626 | 166 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
167 printf("Unlocking password for %s\n",name); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
168 encrypted = xstrdup(&pass[1]); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
169 } else if (toys.optflags & FLAG_d) { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
170 printf("Deleting password for %s\n",name); |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
171 encrypted = xstrdup(""); //1 = "", 2 = '\0' |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
172 } |
626 | 173 |
1089
77235d224b1d
Prep work for useradd by Ashwini Sharma.
Rob Landley <rob@landley.net>
parents:
1013
diff
changeset
|
174 // Update the passwd |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
175 if (pw->pw_passwd[0] == 'x') |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
176 ret = update_password("/etc/shadow", name, encrypted); |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
177 else ret = update_password("/etc/passwd", name, encrypted); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
178 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
179 if ((toys.optflags & (FLAG_l | FLAG_u | FLAG_d))) free(encrypted); |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
674
diff
changeset
|
180 |
1013
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
181 if (!toys.optargs[0]) free(name); |
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
182 if (!ret) error_msg("Success"); |
c1a115650476
Whitespace changes to passwd.
Rob Landley <rob@landley.net>
parents:
694
diff
changeset
|
183 else error_msg("Failure"); |
626 | 184 } |