Re: [hackers] [sbase][PATCH] Add nologin(8) (from ubase) and simplify it

From: Lucas Gabriel Vuotto <l.vuotto92_AT_gmail.com>
Date: Mon, 4 Apr 2016 09:24:52 -0300

On 04/04/16 08:22, Mattias Andrée wrote:
> Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
> ---
> Makefile | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> config.def.h | 1 +
> nologin.8 | 21 ++++++++++
> nologin.c | 19 +++++++++
> 4 files changed, 158 insertions(+), 7 deletions(-)
> create mode 100644 config.def.h
> create mode 100644 nologin.8
> create mode 100644 nologin.c
>
> diff --git a/Makefile b/Makefile
> index 6b2bfdf..5e611ee 100644
> --- a/Makefile
> +++ b/Makefile
> _AT_@ -6,6 +6,7 @@ include config.mk
> HDR =\
> arg.h\
> compat.h\
> + config.h\
> crypt.h\
> fs.h\
> md5.h\
> _AT_@ -129,6 +130,7 @@ BIN =\
> nice\
> nl\
> nohup\
> + nologin\
> od\
> pathchk\
> paste\
> _AT_@ -179,11 +181,109 @@ BIN =\
> xinstall\
> yes
>
> +MAN1 =\
> + basename.1\
> + cal.1\
> + cat.1\
> + chgrp.1\
> + chmod.1\
> + chown.1\
> + chroot.1\
> + cksum.1\
> + cmp.1\
> + cols.1\
> + comm.1\
> + cp.1\
> + cron.1\
> + cut.1\
> + date.1\
> + dirname.1\
> + du.1\
> + echo.1\
> + ed.1\
> + env.1\
> + expand.1\
> + expr.1\
> + false.1\
> + find.1\
> + flock.1\
> + fold.1\
> + getconf.1\
> + grep.1\
> + head.1\
> + join.1\
> + hostname.1\
> + kill.1\
> + link.1\
> + ln.1\
> + logger.1\
> + logname.1\
> + ls.1\
> + md5sum.1\
> + mkdir.1\
> + mkfifo.1\
> + mktemp.1\
> + mv.1\
> + nice.1\
> + nl.1\
> + nohup.1\
> + od.1\
> + pathchk.1\
> + paste.1\
> + printenv.1\
> + printf.1\
> + pwd.1\
> + readlink.1\
> + renice.1\
> + rm.1\
> + rmdir.1\
> + sed.1\
> + seq.1\
> + setsid.1\
> + sha1sum.1\
> + sha224sum.1\
> + sha256sum.1\
> + sha384sum.1\
> + sha512sum.1\
> + sha512-224sum.1\
> + sha512-256sum.1\
> + sleep.1\
> + sort.1\
> + split.1\
> + sponge.1\
> + strings.1\
> + sync.1\
> + tail.1\
> + tar.1\
> + tee.1\
> + test.1\
> + tftp.1\
> + time.1\
> + touch.1\
> + tr.1\
> + true.1\
> + tsort.1\
> + tty.1\
> + uname.1\
> + unexpand.1\
> + uniq.1\
> + unlink.1\
> + uudecode.1\
> + uuencode.1\
> + wc.1\
> + which.1\
> + whoami.1\
> + xargs.1\
> + xinstall.1\
> + yes.1
> +
> +MAN8 =\
> + nologin.8
> +
> LIBUTFOBJ = $(LIBUTFSRC:.c=.o)
> LIBUTILOBJ = $(LIBUTILSRC:.c=.o)
> OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ)
> SRC = $(BIN:=.c)
> -MAN = $(BIN:=.1)
>
> all: $(BIN)
>
> _AT_@ -191,6 +291,9 @@ $(BIN): $(LIB) $(@:=.o)
>
> $(OBJ): $(HDR) config.mk
>
> +config.h:
> + cp config.def.h $_AT_
> +
> .o:
> $(CC) $(LDFLAGS) -o $_AT_ $< $(LIB)
>
> _AT_@ -216,17 +319,21 @@ install: all
> cd $(DESTDIR)$(PREFIX)/bin && ln -f test [ && chmod 755 $(BIN)
> mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
> mkdir -p $(DESTDIR)$(MANPREFIX)/man1
> - for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
> - cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
> + mkdir -p $(DESTDIR)$(MANPREFIX)/man8
> + for m in $(MAN1); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
> + for m in $(MAN8); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man8/"$$m"; done
> + cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN1)
> + cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8)
> mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
>
> uninstall:
> cd $(DESTDIR)$(PREFIX)/bin && rm -f $(BIN) [ install
> - cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN)
> + cd $(DESTDIR)$(MANPREFIX)/man1 && rm -f $(MAN1)
> + cd $(DESTDIR)$(MANPREFIX)/man8 && rm -f $(MAN8)
>
> dist: clean
> mkdir -p sbase-$(VERSION)
> - cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN) libutf libutil $(HDR) sbase-$(VERSION)
> + cp -r LICENSE Makefile README TODO config.mk $(SRC) $(MAN1) $(MAN8) libutf libutil $(HDR) config.def.h sbase-$(VERSION)
> tar -cf sbase-$(VERSION).tar sbase-$(VERSION)
> gzip sbase-$(VERSION).tar
> rm -rf sbase-$(VERSION)
> _AT_@ -261,8 +368,11 @@ sbase-box-install: sbase-box
> ln -sf sbase-box $(DESTDIR)$(PREFIX)/bin/[
> mv -f $(DESTDIR)$(PREFIX)/bin/xinstall $(DESTDIR)$(PREFIX)/bin/install
> mkdir -p $(DESTDIR)$(MANPREFIX)/man1
> - for m in $(MAN); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
> - cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN)
> + mkdir -p $(DESTDIR)$(MANPREFIX)/man8
> + for m in $(MAN1); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man1/"$$m"; done
> + for m in $(MAN8); do sed "s/^\.Os sbase/.Os sbase $(VERSION)/g" < "$$m" > $(DESTDIR)$(MANPREFIX)/man8/"$$m"; done
> + cd $(DESTDIR)$(MANPREFIX)/man1 && chmod 644 $(MAN1)
> + cd $(DESTDIR)$(MANPREFIX)/man8 && chmod 644 $(MAN8)
> mv -f $(DESTDIR)$(MANPREFIX)/man1/xinstall.1 $(DESTDIR)$(MANPREFIX)/man1/install.1
>
> sbase-box-uninstall: uninstall
> diff --git a/config.def.h b/config.def.h
> new file mode 100644
> index 0000000..6ed6d69
> --- /dev/null
> +++ b/config.def.h
> _AT_@ -0,0 +1 @@
> +#define NOLOGIN_PATH "/etc/nologin.txt"
> diff --git a/nologin.8 b/nologin.8
> new file mode 100644
> index 0000000..9ea1328
> --- /dev/null
> +++ b/nologin.8
> _AT_@ -0,0 +1,21 @@
> +.Dd March 26, 2016
> +.Dt NOLOGIN 8
> +.Os ubase
> +.Sh NAME
> +.Nm nologin
> +.Nd refuse login
> +.Sh SYNOPSIS
> +.Nm
> +.Sh DESCRIPTION
> +.Nm
> +prints a message informing the user that she
> +is not allowed to log in. If /etc/nologin.txt
> +exists, its content is printed instead of
> +the default message.
> +.Pp
> +.Nm
> +is intended to be specified as the user's
> +default shell.
> +.Sh EXIT STATUS
> +.Nm
> +returns a status code indicating failure.
> diff --git a/nologin.c b/nologin.c
> new file mode 100644
> index 0000000..17ea156
> --- /dev/null
> +++ b/nologin.c
> _AT_@ -0,0 +1,19 @@
> +/* See LICENSE file for copyright and license details. */
> +#include <stdio.h>
> +
> +#include "config.h"
> +#include "text.h"
> +#include "util.h"
> +
> +int
> +main(void)
> +{
> + FILE *fp;
> + if ((fp = fopen(NOLOGIN_PATH, "r"))) {
> + concat(fp, NOLOGIN_PATH, stdout, "<stdout>");
> + fshut(fp, NOLOGIN_PATH), fshut(stdout, "<stdout>");

Shouldn't this be

+ fshut(fp, NOLOGIN_PATH);
+ fshut(fp, stdout, "<stdout>");

?

Note the ',' at the end of the first fshut.

> + } else {
> + printf("The account is currently unavailable.\n");
> + }
> + return 1;
> +}
>



-- lv.
Received on Mon Apr 04 2016 - 14:24:52 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 04 2016 - 14:36:16 CEST