summaryrefslogtreecommitdiffstats
path: root/src/nologin.c
blob: a74428186a70a362a914717b212a0e583834a0c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * SPDX-FileCopyrightText: 2004 The FreeBSD Project.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */


#ident "$Id$"

#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>

int main (void)
{
	const char *user, *tty;
	uid_t uid;

	tty = ttyname (0);
	if (NULL == tty) {
		tty = "UNKNOWN";
	}
	user = getlogin ();
	if (NULL == user) {
		user = "UNKNOWN";
	}

	char *ssh_origcmd = getenv("SSH_ORIGINAL_COMMAND");
	uid = getuid (); /* getuid() is always successful */
	openlog ("nologin", LOG_CONS, LOG_AUTH);
	syslog (LOG_CRIT, "Attempted login by %s (UID: %d) on %s%s%s",
	        user, uid, tty,
		(ssh_origcmd ? " SSH_ORIGINAL_COMMAND=" : ""),
		(ssh_origcmd ? ssh_origcmd : ""));
	closelog ();

	printf ("%s", "This account is currently not available.\n");

	return EXIT_FAILURE;
}