-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpamcheck.c
69 lines (60 loc) · 1.89 KB
/
pamcheck.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2016 Olli-Pekka Wallin <[email protected]>
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>
#include <utmp.h>
#include <err.h>
#include <security/pam_appl.h>
#include <security/pam_misc.h>
#include <stdio.h>
#include "pamcheck.h"
#define NAME_WIDTH 8
int getLoggedusers (FILE *lfp)
{
FILE *ufp;
int numberOfUsers = 0;
struct utmp usr;
ufp = utmpFile(_PATH_UTMP);
// fprintf(lfp, " utmp ... %s\n", _PATH_UTMP);
while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) {
if (*usr.ut_name && *usr.ut_line && *usr.ut_line != '~') {
if (usr.ut_type == USER_PROCESS) {
if (!found_user_in_list(usr.ut_user)) {
fprintf(lfp, " utmp, added user %s\n", usr.ut_user );
add_to_list (usr.ut_user);
}
numberOfUsers++;
}
}
}
return numberOfUsers;
}
FILE *utmpFile(char *name)
{
FILE *ufp;
if (!(ufp = fopen(name, "r"))) {
err(1, "%s", name);
}
return(ufp);
}
static struct pam_conv conv = {
misc_conv,
NULL
};
int checkPamUser (const char *username)
{
pam_handle_t *pamh=NULL;
int retval;
retval = pam_start("check_user", username, &conv, &pamh);
if (retval != PAM_SUCCESS) {
return -1;
}
return retval;
}