Re: [hackers] [ubase] Add nologin(8) || Mattias Andrée

2016-03-29 Thread Mattias Andrée
On Wed, 30 Mar 2016 07:09:44 +0200
k...@shike2.com wrote:

> > +.Os ubase  
> 
> Why it is in ubase? It is totally portable.
> 
> 

It probably belongs in sbase. Just let the
"/etc/nologin.txt" be compile-time configurable.


pgphEZBJbOUwV.pgp
Description: OpenPGP digital signature


Re: [hackers] [ubase] Add nologin(8) || Mattias Andrée

2016-03-29 Thread k0ga
> +.Os ubase

Why it is in ubase? It is totally portable.




[hackers] [ubase] Add nologin(8) || Mattias Andrée

2016-03-26 Thread git
commit 6e7386edb34f5acdd5dbbee68e85b16415a3b4aa
Author: Mattias Andrée 
AuthorDate: Sat Mar 26 11:30:56 2016 +0100
Commit: sin 
CommitDate: Sat Mar 26 19:08:10 2016 +

Add nologin(8)

Signed-off-by: Mattias Andrée 

diff --git a/Makefile b/Makefile
index 4ab1856..59616a4 100644
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,7 @@ BIN = \
mkswap\
mount \
mountpoint\
+   nologin   \
pagesize  \
passwd\
pidof \
@@ -129,6 +130,7 @@ MAN8 = \
lsusb.8 \
mkswap.8\
mount.8 \
+   nologin.8   \
pivot_root.8\
readahead.8 \
rmmod.8 \
diff --git a/nologin.8 b/nologin.8
new file mode 100644
index 000..9ea1328
--- /dev/null
+++ b/nologin.8
@@ -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 000..f06ec93
--- /dev/null
+++ b/nologin.c
@@ -0,0 +1,22 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+#include 
+#include 
+
+int
+main(void)
+{
+   int fd;
+   char buf[BUFSIZ];
+   ssize_t n;
+
+   fd = open("/etc/nologin.txt", O_RDONLY);
+   if (fd >= 0) {
+   while ((n = read(fd, buf, sizeof(buf))) > 0)
+   write(STDOUT_FILENO, buf, n);
+   close(fd);
+   } else {
+   printf("The account is currently unavailable.\n");
+   }
+   return 1;
+}