aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/dmesg.c69
-rw-r--r--toys/lsb/hostname.c31
-rw-r--r--toys/lsb/killall.c79
-rw-r--r--toys/lsb/md5sum.c7
-rw-r--r--toys/lsb/mknod.c47
-rw-r--r--toys/lsb/mktemp.c54
-rw-r--r--toys/lsb/passwd.c389
-rw-r--r--toys/lsb/pidof.c27
-rw-r--r--toys/lsb/seq.c58
-rw-r--r--toys/lsb/sync.c16
10 files changed, 375 insertions, 402 deletions
diff --git a/toys/lsb/dmesg.c b/toys/lsb/dmesg.c
index 8d73513b..10032562 100644
--- a/toys/lsb/dmesg.c
+++ b/toys/lsb/dmesg.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * dmesg.c - display/control kernel ring buffer.
+/* dmesg.c - display/control kernel ring buffer.
*
* Copyright 2006, 2007 Rob Landley <rob@landley.net>
*
@@ -9,16 +7,16 @@
USE_DMESG(NEWTOY(dmesg, "s#n#c", TOYFLAG_BIN))
config DMESG
- bool "dmesg"
- default y
- help
- usage: dmesg [-n level] [-s bufsize] | -c
+ bool "dmesg"
+ default y
+ help
+ usage: dmesg [-n level] [-s bufsize] | -c
- Print or control the kernel ring buffer.
+ Print or control the kernel ring buffer.
- -n Set kernel logging level (1-9).
- -s Size of buffer to read (in bytes), default 16384.
- -c Clear the ring buffer after printing.
+ -n Set kernel logging level (1-9).
+ -s Size of buffer to read (in bytes), default 16384.
+ -c Clear the ring buffer after printing.
*/
#define FOR_dmesg
@@ -26,33 +24,32 @@ config DMESG
#include <sys/klog.h>
GLOBALS(
- long level;
- long size;
+ long level;
+ long size;
)
void dmesg_main(void)
{
- // For -n just tell kernel to which messages to keep.
- if (toys.optflags & 2) {
- if (klogctl(8, NULL, TT.level))
- error_exit("klogctl");
- } else {
- int size, i, last = '\n';
- char *data;
-
- // Figure out how much data we need, and fetch it.
- size = TT.size;
- if (size<2) size = 16384;
- data = xmalloc(size);
- size = klogctl(3 + (toys.optflags&1), data, size);
- if (size < 0) error_exit("klogctl");
-
- // Display data, filtering out level markers.
- for (i=0; i<size; ) {
- if (last=='\n' && data[i]=='<') i += 3;
- else xputc(last = data[i++]);
- }
- if (last!='\n') xputc('\n');
- if (CFG_TOYBOX_FREE) free(data);
- }
+ // For -n just tell kernel to which messages to keep.
+ if (toys.optflags & 2) {
+ if (klogctl(8, NULL, TT.level)) error_exit("klogctl");
+ } else {
+ int size, i, last = '\n';
+ char *data;
+
+ // Figure out how much data we need, and fetch it.
+ size = TT.size;
+ if (size<2) size = 16384;
+ data = xmalloc(size);
+ size = klogctl(3 + (toys.optflags&1), data, size);
+ if (size < 0) error_exit("klogctl");
+
+ // Display data, filtering out level markers.
+ for (i=0; i<size; ) {
+ if (last=='\n' && data[i]=='<') i += 3;
+ else xputc(last = data[i++]);
+ }
+ if (last!='\n') xputc('\n');
+ if (CFG_TOYBOX_FREE) free(data);
+ }
}
diff --git a/toys/lsb/hostname.c b/toys/lsb/hostname.c
index ca436833..23467fb3 100644
--- a/toys/lsb/hostname.c
+++ b/toys/lsb/hostname.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * hostname.c - Get/Set the hostname
+/* hostname.c - Get/Set the hostname
*
* Copyright 2012 Andre Renaud <andre@bluewatersys.com>
*
@@ -9,12 +7,12 @@
USE_HOSTNAME(NEWTOY(hostname, NULL, TOYFLAG_BIN))
config HOSTNAME
- bool "hostname"
- default y
- help
- usage: hostname [newname]
+ bool "hostname"
+ default y
+ help
+ usage: hostname [newname]
- Get/Set the current hostname
+ Get/Set the current hostname
*/
#define FOR_hostname
@@ -22,13 +20,12 @@ config HOSTNAME
void hostname_main(void)
{
- const char *hostname = toys.optargs[0];
- if (hostname) {
- if (sethostname(hostname, strlen(hostname)))
- perror_exit("set failed '%s'", hostname);
- } else {
- if (gethostname(toybuf, sizeof(toybuf)))
- perror_exit("get failed");
- xputs(toybuf);
- }
+ const char *hostname = toys.optargs[0];
+ if (hostname) {
+ if (sethostname(hostname, strlen(hostname)))
+ perror_exit("set failed '%s'", hostname);
+ } else {
+ if (gethostname(toybuf, sizeof(toybuf))) perror_exit("get failed");
+ xputs(toybuf);
+ }
}
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c
index ec9df62e..7883c53d 100644
--- a/toys/lsb/killall.c
+++ b/toys/lsb/killall.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * killall.c - Send signal (default: TERM) to all processes with given names.
+/* killall.c - Send signal (default: TERM) to all processes with given names.
*
* Copyright 2012 Andreas Heck <aheck@gmx.de>
*
@@ -9,68 +7,67 @@
USE_KILLALL(NEWTOY(killall, "<1?lq", TOYFLAG_USR|TOYFLAG_BIN))
config KILLALL
- bool "killall"
- default y
- help
- usage: killall [-l] [-q] [-SIG] PROCESS_NAME...
+ bool "killall"
+ default y
+ help
+ usage: killall [-l] [-q] [-SIG] PROCESS_NAME...
- Send a signal (default: TERM) to all processes with the given names.
+ Send a signal (default: TERM) to all processes with the given names.
- -l print list of all available signals
- -q don't print any warnings or error messages
+ -l print list of all available signals
+ -q don't print any warnings or error messages
*/
#define FOR_killall
#include "toys.h"
GLOBALS(
- int signum;
+ int signum;
)
static void kill_process(pid_t pid)
{
- int ret;
+ int ret;
- toys.exitval = 0;
- ret = kill(pid, TT.signum);
+ toys.exitval = 0;
+ ret = kill(pid, TT.signum);
- if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
+ if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
}
void killall_main(void)
{
- char **names;
+ char **names;
- if (toys.optflags & FLAG_l) {
- sig_to_num(NULL);
- return;
- }
+ if (toys.optflags & FLAG_l) {
+ sig_to_num(NULL);
+ return;
+ }
- TT.signum = SIGTERM;
- toys.exitval++;
+ TT.signum = SIGTERM;
+ toys.exitval++;
- if (!*toys.optargs) {
- toys.exithelp = 1;
- error_exit("Process name missing!");
- }
+ if (!*toys.optargs) {
+ toys.exithelp = 1;
+ error_exit("Process name missing!");
+ }
- names = toys.optargs;
+ names = toys.optargs;
- if (**names == '-') {
- if (0 > (TT.signum = sig_to_num((*names)+1))) {
- if (toys.optflags & FLAG_q) exit(1);
- error_exit("Invalid signal");
- }
- names++;
+ if (**names == '-') {
+ if (0 > (TT.signum = sig_to_num((*names)+1))) {
+ if (toys.optflags & FLAG_q) exit(1);
+ error_exit("Invalid signal");
+ }
+ names++;
- if (!*names) {
- toys.exithelp++;
- error_exit("Process name missing!");
- }
- }
+ if (!*names) {
+ toys.exithelp++;
+ error_exit("Process name missing!");
+ }
+ }
- for_each_pid_with_name_in(names, kill_process);
+ for_each_pid_with_name_in(names, kill_process);
- if (toys.exitval && !(toys.optflags & FLAG_q))
- error_exit("No such process");
+ if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process");
}
diff --git a/toys/lsb/md5sum.c b/toys/lsb/md5sum.c
index b0b35419..3b5571bb 100644
--- a/toys/lsb/md5sum.c
+++ b/toys/lsb/md5sum.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * md5sum.c - Calculate RFC 1321 md5 hash and sha1 hash.
+/* md5sum.c - Calculate RFC 1321 md5 hash and sha1 hash.
*
* Copyright 2012 Rob Landley <rob@landley.net>
*
@@ -219,8 +217,7 @@ static void do_hash(int fd, char *name)
buf = 0;
} while ((TT.count & 63) != 56);
if (sha1) count=bswap_64(count);
- for (i = 0; i < 8; i++)
- TT.buffer.c[56+i] = count >> (8*i);
+ for (i = 0; i < 8; i++) TT.buffer.c[56+i] = count >> (8*i);
transform();
if (sha1)
diff --git a/toys/lsb/mknod.c b/toys/lsb/mknod.c
index c1d78b10..bf9288ae 100644
--- a/toys/lsb/mknod.c
+++ b/toys/lsb/mknod.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * mknod.c - make block or character special file
+/* mknod.c - make block or character special file
*
* Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
*
@@ -9,15 +7,15 @@
USE_MKNOD(NEWTOY(mknod, "<2>4", TOYFLAG_BIN))
config MKNOD
- bool "mknod"
- default y
- help
- usage: mknod NAME TYPE [MAJOR MINOR]
-
- Create a special file NAME with a given type, possible types are
- b block device
- c or u character device
- p named pipe (ignores MAJOR/MINOR)
+ bool "mknod"
+ default y
+ help
+ usage: mknod NAME TYPE [MAJOR MINOR]
+
+ Create a special file NAME with a given type, possible types are
+ b block device
+ c or u character device
+ p named pipe (ignores MAJOR/MINOR)
*/
#define FOR_mknod
@@ -25,20 +23,19 @@ config MKNOD
void mknod_main(void)
{
- mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
- int major=0, minor=0, type;
- int mode = 0660;
-
- type = stridx("pcub", *toys.optargs[1]);
- if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);
- if (type) {
- if (toys.optc != 4) perror_exit("need major/minor");
+ mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
+ int major=0, minor=0, type;
+ int mode = 0660;
- major = atoi(toys.optargs[2]);
- minor = atoi(toys.optargs[3]);
- }
+ type = stridx("pcub", *toys.optargs[1]);
+ if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);
+ if (type) {
+ if (toys.optc != 4) perror_exit("need major/minor");
- if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor)))
- perror_exit("mknod %s failed", toys.optargs[0]);
+ major = atoi(toys.optargs[2]);
+ minor = atoi(toys.optargs[3]);
+ }
+ if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor)))
+ perror_exit("mknod %s failed", toys.optargs[0]);
}
diff --git a/toys/lsb/mktemp.c b/toys/lsb/mktemp.c
index 1b2222c0..86c2033e 100644
--- a/toys/lsb/mktemp.c
+++ b/toys/lsb/mktemp.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * mktemp.c - Create a temporary file or directory.
+/* mktemp.c - Create a temporary file or directory.
*
* Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
*
@@ -9,46 +7,46 @@
USE_MKTEMP(NEWTOY(mktemp, ">1q(directory)d(tmpdir)p:", TOYFLAG_BIN))
config MKTEMP
- bool "mktemp"
- default y
- help
- usage: mktemp [-dq] [-p DIR] [TEMPLATE]
+ bool "mktemp"
+ default y
+ help
+ usage: mktemp [-dq] [-p DIR] [TEMPLATE]
- Safely create new file and print its name. Default TEMPLATE is
- /tmp/tmp.XXXXXX and each trailing X is replaced with random char.
+ Safely create new file and print its name. Default TEMPLATE is
+ /tmp/tmp.XXXXXX and each trailing X is replaced with random char.
- -d, --directory Create directory instead of file
- -p DIR, --tmpdir=DIR Put new file in DIR
- -q Quiet
+ -d, --directory Create directory instead of file
+ -p DIR, --tmpdir=DIR Put new file in DIR
+ -q Quiet
*/
#define FOR_mktemp
#include "toys.h"
GLOBALS(
- char * tmpdir;
+ char * tmpdir;
)
void mktemp_main(void)
{
- int d_flag = toys.optflags & FLAG_d;
- char *tmp;
+ int d_flag = toys.optflags & FLAG_d;
+ char *tmp;
- tmp = *toys.optargs;
+ tmp = *toys.optargs;
- if (!tmp) {
- if (!TT.tmpdir) TT.tmpdir = "/tmp";
- tmp = "tmp.xxxxxx";
- }
- if (TT.tmpdir) tmp = xmsprintf("%s/%s", TT.tmpdir ? TT.tmpdir : "/tmp",
- *toys.optargs ? *toys.optargs : "tmp.XXXXXX");
+ if (!tmp) {
+ if (!TT.tmpdir) TT.tmpdir = "/tmp";
+ tmp = "tmp.xxxxxx";
+ }
+ if (TT.tmpdir) tmp = xmsprintf("%s/%s", TT.tmpdir ? TT.tmpdir : "/tmp",
+ *toys.optargs ? *toys.optargs : "tmp.XXXXXX");
- if (d_flag ? mkdtemp(tmp) == NULL : mkstemp(tmp) == -1)
- if (toys.optflags & FLAG_q)
- perror_exit("Failed to create temporary %s",
- d_flag ? "directory" : "file");
+ if (d_flag ? mkdtemp(tmp) == NULL : mkstemp(tmp) == -1)
+ if (toys.optflags & FLAG_q)
+ perror_exit("Failed to create temporary %s",
+ d_flag ? "directory" : "file");
- xputs(tmp);
+ xputs(tmp);
- if (CFG_TOYBOX_FREE && TT.tmpdir) free(tmp);
+ if (CFG_TOYBOX_FREE && TT.tmpdir) free(tmp);
}
diff --git a/toys/lsb/passwd.c b/toys/lsb/passwd.c
index ef119c5d..ff109f14 100644
--- a/toys/lsb/passwd.c
+++ b/toys/lsb/passwd.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * passwd.c - Program to upadte user password.
+/* passwd.c - Program to update user password.
*
* Copyright 2012 Ashwini Kumar <ak.ashwini@gmail.com>
* Modified 2012 Jason Kyungwan Han <asura321@gmail.com>
@@ -10,18 +8,17 @@
USE_PASSWD(NEWTOY(passwd, ">1a:dlu", TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
config PASSWD
- bool "passwd"
- default y
- help
- usage: passwd [-a ALGO] [-d] [-l] [-u] <account name>
-
- update user’s authentication tokens. Default : current user
+ bool "passwd"
+ default y
+ help
+ usage: passwd [-a ALGO] [-d] [-l] [-u] <account name>
- -a ALGO Encryption method (des, md5, sha256, sha512) default: des
- -d Set password to ''
- -l Lock (disable) account
- -u Unlock (enable) account
+ update user’s authentication tokens. Default : current user
+ -a ALGO Encryption method (des, md5, sha256, sha512) default: des
+ -d Set password to ''
+ -l Lock (disable) account
+ -u Unlock (enable) account
*/
#define FOR_passwd
@@ -29,7 +26,7 @@ config PASSWD
#include <time.h>
GLOBALS(
- char *algo;
+ char *algo;
)
#define MAX_SALT_LEN 20 //3 for id, 16 for key, 1 for '\0'
@@ -41,227 +38,225 @@ char *strcasestr(const char *haystack, const char *needle);
unsigned int random_number_generator(int fd)
{
- unsigned int randnum;
- xreadall(fd, &randnum, sizeof(randnum));
- return randnum;
+ unsigned int randnum;
+ xreadall(fd, &randnum, sizeof(randnum));
+ return randnum;
}
-
-
char inttoc(int i)
{
- // salt value uses 64 chracters in "./0-9a-zA-Z"
- const char character_set[]="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- i &= 0x3f; // masking for using 10 bits only
- return character_set[i];
+ // salt value uses 64 chracters in "./0-9a-zA-Z"
+ const char character_set[]="./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ i &= 0x3f; // masking for using 10 bits only
+ return character_set[i];
}
int get_salt(char *salt)
-{
- int i, salt_length = 0;
- int randfd;
- if(!strncmp(TT.algo,"des",3)){
- // 2 bytes salt value is used in des
- salt_length = 2;
- } else {
- *salt++ = '$';
- if(!strncmp(TT.algo,"md5",3)){
- *salt++ = '1';
- // 8 bytes salt value is used in md5
- salt_length = 8;
- } else if(!strncmp(TT.algo,"sha256",6)){
- *salt++ = '5';
- // 16 bytes salt value is used in sha256
- salt_length = 16;
- } else if(!strncmp(TT.algo,"sha512",6)){
- *salt++ = '6';
- // 16 bytes salt value is used in sha512
- salt_length = 16;
- } else return 1;
-
- *salt++ = '$';
- }
-
- randfd = xopen(URANDOM_PATH, O_RDONLY);
- for(i=0; i<salt_length; i++)
- salt[i] = inttoc(random_number_generator(randfd));
- salt[salt_length+1] = '\0';
- xclose(randfd);
-
- return 0;
+{
+ int i, salt_length = 0;
+ int randfd;
+ if(!strncmp(TT.algo,"des",3)){
+ // 2 bytes salt value is used in des
+ salt_length = 2;
+ } else {
+ *salt++ = '$';
+ if(!strncmp(TT.algo,"md5",3)){
+ *salt++ = '1';
+ // 8 bytes salt value is used in md5
+ salt_length = 8;
+ } else if(!strncmp(TT.algo,"sha256",6)){
+ *salt++ = '5';
+ // 16 bytes salt value is used in sha256
+ salt_length = 16;
+ } else if(!strncmp(TT.algo,"sha512",6)){
+ *salt++ = '6';
+ // 16 bytes salt value is used in sha512
+ salt_length = 16;
+ } else return 1;
+
+ *salt++ = '$';
+ }
+
+ randfd = xopen(URANDOM_PATH, O_RDONLY);
+ for(i=0; i<salt_length; i++)
+ salt[i] = inttoc(random_number_generator(randfd));
+ salt[salt_length+1] = '\0';
+ xclose(randfd);
+
+ return 0;
}
static int str_check(char *s, char *p)
{
- if((strcasestr(s, p) != NULL) || (strcasestr(p, s) != NULL))
- return 1;
- return 0;
+ if((strcasestr(s, p) != NULL) || (strcasestr(p, s) != NULL))
+ return 1;
+ return 0;
}
static void strength_check(char *newp, char *oldp, char *user)
{
- char *msg = NULL;
- if(strlen(newp) < 6) { //Min passwd len
- msg = "too short";
- xprintf("BAD PASSWORD: %s\n",msg);
- }
- if(!newp[0])
- return; //passwd is empty
-
- if(str_check(newp, user)) {
- msg = "user based password";
- xprintf("BAD PASSWORD: %s\n",msg);
- }
-
- if(oldp[0] && str_check(newp, oldp)) {
- msg = "based on old passwd";
- xprintf("BAD PASSWORD: %s\n",msg);
- }
+ char *msg = NULL;
+ if(strlen(newp) < 6) { //Min passwd len
+ msg = "too short";
+ xprintf("BAD PASSWORD: %s\n",msg);
+ }
+ if(!newp[0])
+ return; //passwd is empty
+
+ if(str_check(newp, user)) {
+ msg = "user based password";
+ xprintf("BAD PASSWORD: %s\n",msg);
+ }
+
+ if(oldp[0] && str_check(newp, oldp)) {
+ msg = "based on old passwd";
+ xprintf("BAD PASSWORD: %s\n",msg);
+ }
}
static int verify_passwd(char * pwd)
-{
- char * pass;
+{
+ char * pass;
- if (!pwd) return 1;
- if (pwd[0] == '!' || pwd[0] == '*') return 1;
+ if (!pwd) return 1;
+ if (pwd[0] == '!' || pwd[0] == '*') return 1;
- pass = crypt(toybuf, pwd);
- if (pass != NULL && strcmp(pass, pwd)==0)
- return 0;
+ pass = crypt(toybuf, pwd);
+ if (pass != NULL && strcmp(pass, pwd)==0)
+ return 0;
- return 1;
+ return 1;
}
static char *new_password(char *oldp, char *user)
{
- char *newp = NULL;
-
- if(read_password(toybuf, sizeof(toybuf), "New password:"))
- return NULL; //may be due to Ctrl-C
+ char *newp = NULL;
- newp = xstrdup(toybuf);
- strength_check(newp, oldp, user);
- if(read_password(toybuf, sizeof(toybuf), "Retype password:")) {
- free(newp);
- return NULL; //may be due to Ctrl-C
- }
+ if(read_password(toybuf, sizeof(toybuf), "New password:"))
+ return NULL; //may be due to Ctrl-C
- if(strcmp(newp, toybuf) == 0)
- return newp;
- else error_msg("Passwords do not match.\n");
- /*Failure Case */
+ newp = xstrdup(toybuf);
+ strength_check(newp, oldp, user);
+ if(read_password(toybuf, sizeof(toybuf), "Retype password:")) {
free(newp);
- return NULL;
+ return NULL; //may be due to Ctrl-C
+ }
+
+ if(strcmp(newp, toybuf) == 0)
+ return newp;
+ else error_msg("Passwords do not match.\n");
+ /*Failure Case */
+ free(newp);
+ return NULL;
}
void passwd_main(void)
{
- uid_t myuid;
- struct passwd *pw;
- struct spwd *sp;
- char *name = NULL;
- char *pass = NULL, *encrypted = NULL, *newp = NULL;
- char *orig = (char *)"";
- char salt[MAX_SALT_LEN];
- int ret = -1;
-
- myuid = getuid();
- if((myuid != 0) && (toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
- error_exit("You need to be root to do these actions\n");
-
- pw = getpwuid(myuid);
-
- if(!pw)
- error_exit("Unknown uid '%u'",myuid);
-
- if(toys.optargs[0])
- name = toys.optargs[0];
- else
- name = xstrdup(pw->pw_name);
-
- pw = getpwnam(name);
- if(!pw) error_exit("Unknown user '%s'",name);
-
- if(myuid != 0 && (myuid != pw->pw_uid))
- error_exit("You need to be root to change '%s' password\n", name);
-
- pass = pw->pw_passwd;
- if(pw->pw_passwd[0] == 'x') {
- /*get shadow passwd */
- sp = getspnam(name);
- if(sp)
- pass = sp->sp_pwdp;
+ uid_t myuid;
+ struct passwd *pw;
+ struct spwd *sp;
+ char *name = NULL;
+ char *pass = NULL, *encrypted = NULL, *newp = NULL;
+ char *orig = (char *)"";
+ char salt[MAX_SALT_LEN];
+ int ret = -1;
+
+ myuid = getuid();
+ if((myuid != 0) && (toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
+ error_exit("You need to be root to do these actions\n");
+
+ pw = getpwuid(myuid);
+
+ if(!pw)
+ error_exit("Unknown uid '%u'",myuid);
+
+ if(toys.optargs[0])
+ name = toys.optargs[0];
+ else
+ name = xstrdup(pw->pw_name);
+
+ pw = getpwnam(name);
+ if(!pw) error_exit("Unknown user '%s'",name);
+
+ if(myuid != 0 && (myuid != pw->pw_uid))
+ error_exit("You need to be root to change '%s' password\n", name);
+
+ pass = pw->pw_passwd;
+ if(pw->pw_passwd[0] == 'x') {
+ /*get shadow passwd */
+ sp = getspnam(name);
+ if(sp)
+ pass = sp->sp_pwdp;
+ }
+
+
+ if(!(toys.optflags & (FLAG_l | FLAG_u | FLAG_d))) {
+ printf("Changing password for %s\n",name);
+ if(pass[0] == '!')
+ error_exit("Can't change, password is locked for %s",name);
+ if(myuid != 0) {
+ /*Validate user */
+
+ if(read_password(toybuf, sizeof(toybuf), "Origial password:")) {
+ if(!toys.optargs[0]) free(name);
+ return;
+ }
+ orig = toybuf;
+ if(verify_passwd(pass))
+ error_exit("Authentication failed\n");
}
+ orig = xstrdup(orig);
- if(!(toys.optflags & (FLAG_l | FLAG_u | FLAG_d))) {
- printf("Changing password for %s\n",name);
- if(pass[0] == '!')
- error_exit("Can't change, password is locked for %s",name);
- if(myuid != 0) {
- /*Validate user */
-
- if(read_password(toybuf, sizeof(toybuf), "Origial password:")) {
- if(!toys.optargs[0]) free(name);
- return;
- }
- orig = toybuf;
- if(verify_passwd(pass))
- error_exit("Authentication failed\n");
- }
-
- orig = xstrdup(orig);
-
- /*Get new password */
- newp = new_password(orig, name);
- if(!newp) {
- free(orig);
- if(!toys.optargs[0]) free(name);
- return; //new password is not set well.
- }
-
- /*Encrypt the passwd */
- if(!(toys.optflags & FLAG_a)) TT.algo = "des";
-
- if(get_salt(salt))
- error_exit("Error: Unkown encryption algorithm\n");
-
- encrypted = crypt(newp, salt);
- free(newp);
- free(orig);
+ /*Get new password */
+ newp = new_password(orig, name);
+ if(!newp) {
+ free(orig);
+ if(!toys.optargs[0]) free(name);
+ return; //new password is not set well.
}
- else if(toys.optflags & FLAG_l) {
- if(pass[0] == '!')
- error_exit("password is already locked for %s",name);
- printf("Locking password for %s\n",name);
- encrypted = xmsprintf("!%s",pass);
- }
- else if(toys.optflags & FLAG_u) {
- if(pass[0] != '!')
- error_exit("password is already unlocked for %s",name);
- printf("Unlocking password for %s\n",name);
- encrypted = xstrdup(&pass[1]);
- }
- else if(toys.optflags & FLAG_d) {
- printf("Deleting password for %s\n",name);
- encrypted = (char*)xzalloc(sizeof(char)*2); //1 = "", 2 = '\0'
- }
+ /*Encrypt the passwd */
+ if(!(toys.optflags & FLAG_a)) TT.algo = "des";
- /*Update the passwd */
- if(pw->pw_passwd[0] == 'x')
- ret = update_password("/etc/shadow", name, encrypted);
- else
- ret = update_password("/etc/passwd", name, encrypted);
+ if(get_salt(salt))
+ error_exit("Error: Unkown encryption algorithm\n");
- if((toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
- free(encrypted);
-
- if(!toys.optargs[0]) free(name);
- if(!ret)
- error_msg("Success");
- else
- error_msg("Failure");
+ encrypted = crypt(newp, salt);
+ free(newp);
+ free(orig);
+ }
+ else if(toys.optflags & FLAG_l) {
+ if(pass[0] == '!')
+ error_exit("password is already locked for %s",name);
+ printf("Locking password for %s\n",name);
+ encrypted = xmsprintf("!%s",pass);
+ }
+ else if(toys.optflags & FLAG_u) {
+ if(pass[0] != '!')
+ error_exit("password is already unlocked for %s",name);
+
+ printf("Unlocking password for %s\n",name);
+ encrypted = xstrdup(&pass[1]);
+ }
+ else if(toys.optflags & FLAG_d) {
+ printf("Deleting password for %s\n",name);
+ encrypted = (char*)xzalloc(sizeof(char)*2); //1 = "", 2 = '\0'
+ }
+
+ /*Update the passwd */
+ if(pw->pw_passwd[0] == 'x')
+ ret = update_password("/etc/shadow", name, encrypted);
+ else
+ ret = update_password("/etc/passwd", name, encrypted);
+
+ if((toys.optflags & (FLAG_l | FLAG_u | FLAG_d)))
+ free(encrypted);
+
+ if(!toys.optargs[0]) free(name);
+ if(!ret)
+ error_msg("Success");
+ else
+ error_msg("Failure");
}
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index 45c398b4..03643015 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * pidof.c - Print the PIDs of all processes with the given names.
+/* pidof.c - Print the Process IDs of all processes with the given names.
*
* Copyright 2012 Andreas Heck <aheck@gmx.de>
*
@@ -9,24 +7,25 @@
USE_PIDOF(NEWTOY(pidof, "<1", TOYFLAG_USR|TOYFLAG_BIN))
config PIDOF
- bool "pidof"
- default y
- help
- usage: pidof [NAME]...
+ bool "pidof"
+ default y
+ help
+ usage: pidof [NAME]...
- Print the PIDs of all processes with the given names.
+ Print the PIDs of all processes with the given names.
*/
#include "toys.h"
-static void print_pid(pid_t pid) {
- xprintf("%s%ld", toys.exitval ? "" : " ", (long)pid);
- toys.exitval = 0;
+static void print_pid(pid_t pid)
+{
+ xprintf("%s%ld", toys.exitval ? "" : " ", (long)pid);
+ toys.exitval = 0;
}
void pidof_main(void)
{
- toys.exitval = 1;
- for_each_pid_with_name_in(toys.optargs, print_pid);
- if (!toys.exitval) xputc('\n');
+ toys.exitval = 1;
+ for_each_pid_with_name_in(toys.optargs, print_pid);
+ if (!toys.exitval) xputc('\n');
}
diff --git a/toys/lsb/seq.c b/toys/lsb/seq.c
index 2f8538cf..22e45dde 100644
--- a/toys/lsb/seq.c
+++ b/toys/lsb/seq.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * seq.c - Count from first to last, by increment.
+/* seq.c - Count from first to last, by increment.
*
* Copyright 2006 Rob Landley <rob@landley.net>
*
@@ -9,40 +7,40 @@
USE_SEQ(NEWTOY(seq, "<1>3?", TOYFLAG_USR|TOYFLAG_BIN))
config SEQ
- bool "seq"
- depends on TOYBOX_FLOAT
- default y
- help
- usage: seq [first] [increment] last
+ bool "seq"
+ depends on TOYBOX_FLOAT
+ default y
+ help
+ usage: seq [first] [increment] last
- Count from first to last, by increment. Omitted arguments default
- to 1. Two arguments are used as first and last. Arguments can be
- negative or floating point.
+ Count from first to last, by increment. Omitted arguments default
+ to 1. Two arguments are used as first and last. Arguments can be
+ negative or floating point.
*/
#include "toys.h"
void seq_main(void)
{
- double first, increment, last, dd;
+ double first, increment, last, dd;
- // Parse command line arguments, with appropriate defaults.
- // Note that any non-numeric arguments are treated as zero.
- first = increment = 1;
- switch (toys.optc) {
- case 3:
- increment = atof(toys.optargs[1]);
- case 2:
- first = atof(*toys.optargs);
- default:
- last = atof(toys.optargs[toys.optc-1]);
- }
+ // Parse command line arguments, with appropriate defaults.
+ // Note that any non-numeric arguments are treated as zero.
+ first = increment = 1;
+ switch (toys.optc) {
+ case 3:
+ increment = atof(toys.optargs[1]);
+ case 2:
+ first = atof(*toys.optargs);
+ default:
+ last = atof(toys.optargs[toys.optc-1]);
+ }
- // Yes, we're looping on a double. Yes rounding errors can accumulate if
- // you use a non-integer increment. Deal with it.
- for (dd=first; (increment>0 && dd<=last) || (increment <0 && dd>=last);
- dd+=increment)
- {
- printf("%g\n", dd);
- }
+ // Yes, we're looping on a double. Yes rounding errors can accumulate if
+ // you use a non-integer increment. Deal with it.
+ for (dd=first; (increment>0 && dd<=last) || (increment<0 && dd>=last);
+ dd+=increment)
+ {
+ printf("%g\n", dd);
+ }
}
diff --git a/toys/lsb/sync.c b/toys/lsb/sync.c
index 0d167147..b12a8cca 100644
--- a/toys/lsb/sync.c
+++ b/toys/lsb/sync.c
@@ -1,6 +1,4 @@
-/* vi: set sw=4 ts=4:
- *
- * sync.c - Write all pending data to disk.
+/* sync.c - Write all pending data to disk.
*
* Copyright 2007 Rob Landley <rob@landley.net>
*
@@ -9,17 +7,17 @@
USE_SYNC(NEWTOY(sync, NULL, TOYFLAG_BIN))
config SYNC
- bool "sync"
- default y
- help
- usage: sync
+ bool "sync"
+ default y
+ help
+ usage: sync
- Write pending cached data to disk (synchronize), blocking until done.
+ Write pending cached data to disk (synchronize), blocking until done.
*/
#include "toys.h"
void sync_main(void)
{
- sync();
+ sync();
}