On Saturday 21 July 2007 00:12:47 Tito wrote:
> On Friday 20 July 2007 23:22:56 Denis Vlasenko wrote:
> > On Thursday 19 July 2007 21:37, Alexander Shishkin wrote:
> > > On 7/19/07, Tito <[EMAIL PROTECTED]> wrote:
> > > > Hi,
> > > Hi,
> > >
> > > > attached you will find a drop in replacement
> > > > for chpasswd.c with some more busyboxification
> > > > (use of getopt32 and syslogging capabilities of
> > > > bb_*_msg_* functions) and some things it seems to me that
> > > > need to be fixed (this could be done to me being in hurry
> > > > and not understanding you code... in this case ignore it).
> > > > This code is only compile tested and needs more care and love. ;-)
> > > Thanks for pointing these things out! I've done some more tweaking on
> > > the applet. Attached please find an updated patch.
> >
> > Question: why malformed line without password results in warning,
> > but invalid username aborts?
> >
> > bb_error_msg("missing new password");
> > continue;
> > }
> > *pass++ = '\0';
> >
> > if (!getpwnam(name))
> > bb_error_msg_and_die("unknown user %s", name);
> >
> > Seems inconsistent to me.
> >
> > Btw, do we need to check that user exists? Without such check,
> > nonexistent users are just ignored and code is smaller.
> >
> > Testing it. Nice:
> >
> > echo -e "guest:qqqq\ntest:qqqq" | ./busybox chpasswd
> >
> > and crypt_make_salt() generates same salt for both! :))
> > Bunch of other bugs too: shadow passwords check is backwards,...
> >
> > Applied to svn. Enjoy/test.
> > --
> > vda
> >
>
> Hi,
> you were so fast this time, i was just reworking it....
> So here is a new version of chpasswd.c that saves some space.
> bloat-o-meter says:
>
> [EMAIL PROTECTED]:~/Desktop/busybox# scripts/bloat-o-meter busybox_old
> busybox_unstripped
> function old new delta
> .rodata 122925 122893 -32
> chpasswd_main 483 406 -77
> ------------------------------------------------------------------------------
> (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-109) Total: -109 bytes
>
> Little tested.
> Comments are welcome.
>
> Ciao,
> Tito
Hi,
here is a diff of my rework against svn, size reduction now is:
scripts/bloat-o-meter busybox_old busybox_unstripped
function old new delta
chpasswd_main 349 323 -26
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-26) Total: -26 bytes
it fixes also a bug in commandline parsing:
chpasswd must error out if -m and -e are set at the same time.
Little tested.
Ciao,
Tito
--- loginutils/chpasswd.c.orig 2007-07-21 00:28:43.000000000 +0200
+++ loginutils/chpasswd.c 2007-07-21 00:42:30.000000000 +0200
@@ -26,19 +26,13 @@
{
char *name, *pass;
char salt[sizeof("$N$XXXXXXXX")];
- int opt, rc;
+ int opt;
int rnd = rnd; /* we *want* it to be non-initialized! */
- const char *pwfile = bb_path_passwd_file;
- if (getuid() != 0)
+ if (getuid())
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
-#if ENABLE_FEATURE_SHADOWPASSWDS
- if (access(bb_path_shadow_file, F_OK) == 0)
- pwfile = bb_path_shadow_file;
-#endif
-
- opt_complementary = "m--e";
+ opt_complementary = "?m--e:e--m";
USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
opt = getopt32(argc, argv, "em");
@@ -48,8 +42,7 @@
bb_error_msg_and_die("missing new password");
*pass++ = '\0';
- //if (!getpwnam(name))
- // bb_error_msg_and_die("unknown user %s", name);
+ xuname2uid(name);
if (!(opt & OPT_ENC)) {
rnd = crypt_make_salt(salt, 1, rnd);
@@ -60,15 +53,17 @@
pass = pw_encrypt(pass, salt);
}
- rc = update_passwd(pwfile, name, pass);
/* LOGMODE_BOTH logs to syslog */
logmode = LOGMODE_BOTH;
- if (rc < 0)
- bb_error_msg_and_die("an error occurred updating %s", pwfile);
- if (rc > 0)
+
+ if ((ENABLE_FEATURE_SHADOWPASSWDS
+ && !update_passwd(bb_path_shadow_file, name, pass))
+ || !update_passwd(bb_path_passwd_file, name, pass)
+ ) {
+ bb_error_msg_and_die("an error occurred updating password for %s", name);
+ } else {
bb_info_msg("Password for '%s' changed", name);
- else
- bb_info_msg("User '%s' not found", name);
+ }
logmode = LOGMODE_STDIO;
free(name);
}
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox