-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlibnss_log_credentials.c
65 lines (57 loc) · 1.95 KB
/
libnss_log_credentials.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
/*
* Written by José Miguel Silva Caldeira <[email protected]> 2017/05/22
*
* 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 2 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 - see the file LICENSE.
*
* As figuras imaginárias têm mais relevo e verdade que as reais.
* "Fernando Pessoa"
*/
#include <nss.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h> /* strcmp,strncpy,... */
#include <log_credentials_common.h>
int verify_if_need_run(char *service) {
char filename[500];
sprintf(filename, "/etc/pam.d/%s", service);
int is_only_for_true_users = 0;
char buffer[1024];
FILE *fp = fopen(filename, "r");
if (fp) {
while (fgets(buffer, sizeof(buffer), fp)) {
if (strstr(buffer, " log_credentials.so ") != NULL &&
strstr(buffer, " onlytrueusers") != NULL) {
is_only_for_true_users = 1;
break;
}
}
fclose(fp);
}
return is_only_for_true_users;
}
enum nss_status _nss_log_credentials_getpwnam_r(char *name,
struct passwd *result,
char *buffer, size_t buflen,
int *errnop) {
if (name == NULL || verify_if_need_run(__progname)) {
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
result->pw_name = name;
result->pw_uid = 60000;
result->pw_gid = 60000;
result->pw_dir = "/";
result->pw_shell = "/sbin/nologin";
return NSS_STATUS_SUCCESS;
}