[hackers] [ubase] Add initial su(1) || sin
commit ff2e11638f03fb259b0d698996e998bd7a431974
Author: sin <sin_AT_2f30.org>
Date: Thu Oct 17 23:02:55 2013 +0100
Add initial su(1)
diff --git a/Makefile b/Makefile
index 7dd2704..d9ff21e 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -36,6 +36,7 @@ SRC = \
pivot_root.c \
ps.c \
rmmod.c \
+ su.c \
swapoff.c \
swapon.c \
truncate.c \
diff --git a/config.mk b/config.mk
index 5c62469..34d1efe 100644
--- a/config.mk
+++ b/config.mk
_AT_@ -10,10 +10,10 @@ MANPREFIX = $(PREFIX)/share/man
LD = $(CC)
CPPFLAGS = -D_BSD_SOURCE -D_GNU_SOURCE
CFLAGS = -g -ansi -Wall -Wno-long-long $(CPPFLAGS)
-LDFLAGS = -g
+LDFLAGS = -g -lcrypt
#CC = tcc
#LD = $(CC)
#CPPFLAGS = -D_BSD_SOURCE -D_GNU_SOURCE
#CFLAGS = -Os -Wall $(CPPFLAGS)
-#LDFLAGS =
+#LDFLAGS = -lcrypt
diff --git a/su.c b/su.c
new file mode 100644
index 0000000..d2e28e8
--- /dev/null
+++ b/su.c
_AT_@ -0,0 +1,94 @@
+/* See LICENSE file for copyright and license details. */
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+#include <shadow.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [username]
", argv0);
+}
+
+int
+main(int argc, char **argv)
+{
+ char *usr, *pass, *cryptpass;
+ char **newargv;
+ struct spwd *spw;
+ struct passwd *pw;
+ uid_t uid;
+ int i;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc < 1)
+ usr = "root";
+ else if (argc == 1)
+ usr = argv[0];
+ else
+ usage();
+
+ uid = getuid();
+
+ spw = getspnam(usr);
+ if (!spw)
+ eprintf("getspnam: %s:", usr);
+
+ switch (spw->sp_pwdp[0]) {
+ case '!':
+ case '*':
+ enprintf(EXIT_FAILURE, "Denied
");
+ case '$':
+ break;
+ default:
+ enprintf(EXIT_FAILURE, "Invalid shadow record
");
+ }
+
+ if (uid) {
+ pass = getpass("Password: ");
+ if (!pass)
+ eprintf("getpass:");
+ }
+
+ cryptpass = crypt(pass, spw->sp_pwdp);
+ for (i = 0; pass[i]; i++)
+ pass[i] = '
Received on Fri Oct 18 2013 - 00:05:23 CEST
This archive was generated by hypermail 2.3.0
: Fri Oct 18 2013 - 00:13:13 CEST