3 * $Id: banned.c,v 1.1 1999/04/20 00:19:04 mdw Exp $
5 * Ban a user from logging in
7 * (c) 1999 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of banned.
14 * banned is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * banned is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with banned; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1999/04/20 00:19:04 mdw
37 /*----- Header files ------------------------------------------------------*/
43 #include <sys/types.h>
49 /*----- Main code ---------------------------------------------------------*/
51 static const char *quis = "banned";
53 int main(int argc, char *argv[])
60 /* --- Resolve the program name --- */
65 for (q = argv[0]; *q; q++) {
72 /* --- Read the user's name --- */
74 pw = getpwuid(getuid());
76 fprintf(stderr, "%s: you don't exist. Go away.\n", quis);
80 /* --- Open the log file --- */
82 openlog(quis, 0, LOG_AUTH);
83 syslog(LOG_CRIT, "banned user `%s' attempted to log in", pw->pw_name);
85 /* --- Change directory to the user's home --- */
87 if (chdir(pw->pw_dir) < 0) {
88 fprintf(stderr, "%s: couldn't change directory: %s\n",
89 quis, strerror(errno));
93 /* --- Open the reason file --- */
95 if ((fd = open(".banned", O_RDONLY)) < 0) {
96 fprintf(stderr, "%s: couldn't open `.banned' file: %s\n",
97 quis, strerror(errno));
101 /* --- Dump the reason information out --- */
104 r = read(fd, buf, sizeof(buf));
108 fprintf(stderr, "%s: couldn't read: %s\n", quis, strerror(errno));
111 write(STDOUT_FILENO, buf, r);
117 return (EXIT_FAILURE);
120 /*----- That's all, folks -------------------------------------------------*/