On Thursday 19 July 2007 15:49:44 Alexander Shishkin wrote:
> On 7/19/07, Tito <[EMAIL PROTECTED]> wrote:
> > Hi, would you mind to send the patch as attachment and
> > in diff -uN format.
> > I'm experiencing some difficulties to apply and test it.
> Oh, sorry about this. I always get a bit too carried away with git
> these days. :)
> Please find the patch attached.
>
> Regards,
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. ;-)
Ciao,
Tito
/* vi: set sw=4 ts=4: */
/*
* chpasswd.c
*
* Written for SLIND (from passwd.c) by Alexander Shishkin <[EMAIL PROTECTED]>
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#if ENABLE_GETOPT_LONG
#include <getopt.h> /* for struct option */
static const struct option chpasswd_opts[] = {
{ "encrypted", no_argument, NULL, 'e' },
{ "md5", no_argument, NULL, 'm' },
{ NULL, 0, NULL, 0 }
};
#endif
#define OPT_ENC 1
#define OPT_MD5 2
int chpasswd_main(int argc, char **argv);
int chpasswd_main(int argc, char **argv)
{
char *name, *cp, *myname, *ret;
char buf[80];
char salt[sizeof("$N$XXXXXXXX")];
int flag, amroot;
const struct passwd *pw;
struct rlimit rlimit_fsize;
const char *pwfile =
/* FIXME Busybox policy is try to use /etc/shadow
(if ENABLE_FEATURE_SHADOWPASSWDS is set)
and if not available use /etc/passwd instead .*/
#ifndef ENABLE_FEATURE_SHADOWPASSWDS
bb_path_passwd_file;
#else
bb_path_shadow_file;
#endif
opt_complementary = "m--e";
USE_GETOPT_LONG(applet_long_options = chpasswd_opts;)
amroot = (getuid() == 0);
myname = (char *) xstrdup(bb_getpwuid(NULL, getuid(), -1));
flag = getopt32(argc, argv, "me");
rlimit_fsize.rlim_cur = rlimit_fsize.rlim_max = 512L * 30000;
setrlimit(RLIMIT_FSIZE, &rlimit_fsize);
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
umask(077);
while (fgets(buf, sizeof buf, stdin) != NULL) {
cp = strchr(buf, '\n');
if (cp)
*cp = '\0';
else {
bb_error_msg("line too long.");
continue;
}
name = buf;
cp = strchr(name, ':');
if (cp)
*cp++ = '\0';
else {
bb_error_msg("missing new password.");
continue;
}
pw = getpwnam(name);
if (!pw)
bb_error_msg_and_die("unknown user %s", name);
logmode = LOGMODE_BOTH;
/* FIXME What are you checking here ? You provide ! from stdin ?
or you want to check pw->pw_passwd or spw->sp_pwdp for ! */
if (!amroot && cp[0] == '!') {
/* LOGMODE_BOTH */
bb_error_msg_and_die("The password for `%s' cannot be changed.", name);
}
if (!(flag & OPT_ENC)) {
crypt_make_salt(salt, 1);
if (flag & OPT_MD5) {
strcpy(salt, "$1$");
crypt_make_salt(salt + 3, 4);
}
ret = xstrdup(pw_encrypt(cp, salt));
} else
ret = xstrdup(cp);
if (!update_passwd(pwfile, pw->pw_name, ret)) {
/* LOGMODE_BOTH */
bb_info_msg("Password for `%s' changed by user `%s'", name, myname);
} else {
/* LOGMODE_BOTH */
bb_error_msg_and_die("An error occurred updating %s", pwfile);
}
free(ret);
}
if (ENABLE_FEATURE_CLEAN_UP) free(myname);
return 0;
}
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox