[hackers] [ubase] Add initial implementation of passwd(1) || sin

From: <git_AT_suckless.org>
Date: Thu, 05 Jun 2014 17:57:37 +0200

commit 1ec996439ab06930041afb534a230cd8dd3d95ee
Author: sin <sin_AT_2f30.org>
Date: Thu Jun 5 12:48:45 2014 +0100

    Add initial implementation of passwd(1)
    
    No shadow support yet.

diff --git a/Makefile b/Makefile
index a68d3ce..c8ba952 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -3,15 +3,17 @@ include config.mk
 .POSIX:
 .SUFFIXES: .c .o
 
-HDR = arg.h config.def.h proc.h reboot.h rtc.h util.h
+HDR = arg.h config.def.h passwd.h proc.h reboot.h rtc.h text.h util.h
 LIB = \
         util/agetcwd.o \
+ util/agetline.o \
         util/apathmax.o \
         util/ealloc.o \
         util/eprintf.o \
         util/estrtol.o \
         util/estrtoul.o \
         util/explicit_bzero.o \
+ util/passwd.o \
         util/proc.o \
         util/putword.o \
         util/recurse.o \
_AT_@ -43,6 +45,7 @@ SRC = \
         mount.c \
         mountpoint.c \
         pagesize.c \
+ passwd.c \
         pidof.c \
         pivot_root.c \
         ps.c \
diff --git a/README b/README
index fae6dce..8dbd1a7 100644
--- a/README
+++ b/README
_AT_@ -8,9 +8,9 @@ The following programs are currently implemented:
 
     chvt clear ctrlaltdel dd df dmesg eject fallocate free getty halt
     hwclock id insmod killall5 login lsmod lsusb mknod mkswap mount
- mountpoint pagesize pidof pivot_root ps respawn rmmod stat su
- swapoff swapon switch_root sysctl truncate umount unshare uptime
- watch who
+ mountpoint pagesize passwd pidof pivot_root ps respawn rmmod stat
+ su swapoff swapon switch_root sysctl truncate umount unshare
+ uptime watch who
 
 The complement of ubase is sbase[1] which mostly follows POSIX and
 provides all the portable tools. Together they are intended to form a
diff --git a/TODO b/TODO
index 1b47500..da61687 100644
--- a/TODO
+++ b/TODO
_AT_@ -9,7 +9,6 @@ Tools to be implemented
  * losetup(8)
  * lspci
  * mkswap [-L]
- * passwd
  * adduser
  * addgroup
  * rmuser
diff --git a/passwd.c b/passwd.c
new file mode 100644
index 0000000..52e583b
--- /dev/null
+++ b/passwd.c
_AT_@ -0,0 +1,142 @@
+/* See LICENSE file for copyright and license details. */
+#include <errno.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "passwd.h"
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s login
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *pass, *cryptpass1, *cryptpass2, *cryptpass3;
+ char *p;
+ char template[] = "/tmp/pw.XXXXXX";
+ struct passwd *pw;
+ int ffd, tfd;
+ int r;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc != 1)
+ usage();
+
+ errno = 0;
+ pw = getpwnam(argv[0]);
+ if (errno)
+ eprintf("getpwnam: %s:", argv[0]);
+ else if (!pw)
+ eprintf("who are you?
");
+
+ switch (pw->pw_passwd[0]) {
+ case '!':
+ case '*':
+ eprintf("denied
");
+ }
+
+ if (pw->pw_passwd[0] == '
Received on Thu Jun 05 2014 - 17:57:37 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 05 2014 - 18:00:09 CEST