Port pamusb-agent and pamusb-conf to UDisks.
[pam_usb.git] / src / local.c
blob42bc2d1d10c9675051a330bcbeadbd6ea249a429
1 /*
2 * Copyright (c) 2003-2007 Andrea Luzzardi <scox@sig11.org>
4 * This file is part of the pam_usb project. pam_usb is free software;
5 * you can redistribute it and/or modify it under the terms of the GNU General
6 * Public License version 2, as published by the Free Software Foundation.
8 * pam_usb is distributed in the hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 * details.
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place, Suite 330, Boston, MA 02111-1307 USA
18 #include <stdio.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <utmp.h>
22 #include "log.h"
23 #include "conf.h"
25 int pusb_local_login(t_pusb_options *opts, const char *user)
27 struct utmp utsearch;
28 struct utmp *utent;
29 const char *from;
30 int i;
32 log_debug("Checking whether the caller is local or not...\n");
33 from = ttyname(STDIN_FILENO);
34 if (!from || !(*from))
36 log_debug("Couldn't retrieve the tty name, aborting.\n");
37 return (1);
39 if (!strncmp(from, "/dev/", strlen("/dev/")))
40 from += strlen("/dev/");
41 log_debug("Authentication request from tty %s\n", from);
42 strncpy(utsearch.ut_line, from, sizeof(utsearch.ut_line) - 1);
43 setutent();
44 utent = getutline(&utsearch);
45 endutent();
46 if (!utent)
48 log_debug("No utmp entry found for tty \"%s\"\n",
49 from);
50 return (1);
52 for (i = 0; i < 4; ++i)
54 if (utent->ut_addr_v6[i] != 0)
56 log_error("Remote authentication request: %s\n", utent->ut_host);
57 return (0);
60 log_debug("Caller is local (good)\n");
61 return (1);