[hackers] [ubase] passwd: improvements || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Thu, 10 Jul 2014 23:04:11 +0200

commit f48d545c77c013aa6da92b011a053699cb45622c
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu Jul 10 17:51:51 2014 +0000

    passwd: improvements
    
    - add shadow support.
    - allow passwd without argument, prompt which user password is changed.

diff --git a/Makefile b/Makefile
index 0348f48..37d4ec3 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -18,6 +18,7 @@ LIB = \
         util/agetcwd.o \
         util/agetline.o \
         util/apathmax.o \
+ util/concat.o \
         util/ealloc.o \
         util/eprintf.o \
         util/estrtol.o \
diff --git a/TODO b/TODO
index acf49ef..23cc945 100644
--- a/TODO
+++ b/TODO
_AT_@ -31,4 +31,4 @@ Misc
 ====
 
  * Decide what to do with 'bool vs int' debate.
- * Beautify passwd(1) + shadow support.
+ * Beautify passwd(1).
diff --git a/passwd.1 b/passwd.1
index bf860cb..893a53d 100644
--- a/passwd.1
+++ b/passwd.1
_AT_@ -2,12 +2,10 @@
 .SH NAME
  Bpasswd R - Change a user's password
 .SH SYNOPSIS
- Bpasswd R Iusername R
+ Bpasswd R [ Iusername R]
 .SH DESCRIPTION
  Bpasswd R changes the user's password. The user is prompted
 for their current password. If the current password is correctly typed,
 a new password is requested. The new password must be entered twice to
 avoid typing errors. The superuser is not required to provide a user's
 current password.
-.SH BUGS
-Currently there's no shadow support.
diff --git a/passwd.c b/passwd.c
index c647c9a..359de4d 100644
--- a/passwd.c
+++ b/passwd.c
_AT_@ -11,51 +11,82 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <limits.h>
+#include <shadow.h>
+
 #include "config.h"
 #include "passwd.h"
 #include "util.h"
+#include "text.h"
 
 static void
 usage(void)
 {
- eprintf("usage: %s username
", argv0);
+ eprintf("usage: %s [username]
", argv0);
+}
+
+static int
+gettempfile(char *template)
+{
+ int fd;
+
+ umask(077);
+ fd = mkostemp(template, O_RDWR);
+ if (fd < 0)
+ weprintf("mkstemp:");
+ return fd;
 }
 
 int
 main(int argc, char *argv[])
 {
- char *pass;
         char *cryptpass1 = NULL, *cryptpass2 = NULL, *cryptpass3 = NULL;
- char *p;
+ char shadowfile[PATH_MAX], *inpass, *p, *pwd = NULL;
         char template[] = "/tmp/pw.XXXXXX";
- uid_t uid;
         struct passwd *pw;
- int ffd, tfd;
- int r;
+ struct spwd *spw = NULL, *spwent;
+ uid_t uid;
+ FILE *fp = NULL, *tfp = NULL;
+ int ffd = -1, tfd = -1, r, status = EXIT_FAILURE;
 
         ARGBEGIN {
         default:
                 usage();
         } ARGEND;
 
- if (argc != 1)
- usage();
-
         pw_init();
 
         errno = 0;
- pw = getpwnam(argv[0]);
- if (errno)
- eprintf("getpwnam: %s:", argv[0]);
- else if (!pw)
- eprintf("who are you?
");
+ if (argc == 0)
+ pw = getpwuid(getuid());
+ else
+ pw = getpwnam(argv[0]);
+ if (!pw) {
+ if (errno)
+ eprintf("getpwnam: %s:", argv[0]);
+ else
+ eprintf("who are you?
");
+ }
 
- if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '
Received on Thu Jul 10 2014 - 23:04:11 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 10 2014 - 23:12:08 CEST