ProxyAuth
Linux PAM to authenticate device via Bluetooth device
src
pam_post_auth.c
Go to the documentation of this file.
1
#include "
pam_post_auth.h
"
2
3
int
exec_deauth
(
char
*bt_addr,
const
char
*username, FILE *log_fp,
const
char
*
trusted_dir_path
) {
4
int
pid = fork();
5
6
if
(pid == 0) {
//child process
7
char
*path = NULL;
8
9
char
curr_time[50];
10
11
if
(log_fp) {
12
get_login_time
(curr_time);
13
}
14
15
int
len = strlen(
trusted_dir_path
) + strlen(
DEAUTH
);
16
17
if
(!(path = malloc(
sizeof
(
char
) + len + 1))) {
18
perror(
"malloc"
);
19
fprintf(log_fp,
"%s: (exec_deauth) malloc Error\n"
, curr_time);
20
return
PAM_BUF_ERR;
21
}
22
23
if
(!(strncpy(path,
trusted_dir_path
, strlen(
trusted_dir_path
)))) {
24
perror(
"strncpy"
);
25
fprintf(log_fp,
"%s: (exec_deauth) strncpy Error\n"
, curr_time);
26
return
PAM_BUF_ERR;
27
}
28
29
path[strlen(
trusted_dir_path
)] =
'\0'
;
30
31
if
(!(strncat(path,
DEAUTH
, strlen(
DEAUTH
) + 1))) {
32
perror(
"strncat"
);
33
fprintf(log_fp,
"%s: (exec_deauth) strncat Error\n"
, curr_time);
34
return
PAM_BUF_ERR;
35
}
36
path[len] =
'\0'
;
37
38
struct
passwd *pass = NULL;
39
if
(!(pass = getpwnam(username))) {
40
fprintf(log_fp,
"%s: (exec_deauth) getpwnam Error. Trued to get uid of user %s\n"
, curr_time, username);
41
perror(
"getpwnam"
);
42
return
PAM_SYSTEM_ERR;
43
}
44
45
setuid(pass->pw_uid);
46
47
if
((execl(path, path, bt_addr, NULL)) == -1) {
48
perror(
"exec"
);
49
fprintf(log_fp,
"%s: (exec_deauth) execl Error\n"
, curr_time);
50
return
PAM_SYSTEM_ERR;
51
}
52
}
53
return
PAM_SUCCESS;
54
}
trusted_dir_path
const char * trusted_dir_path
Definition:
pam_bt_misc.c:3
get_login_time
void get_login_time(char *curr_time)
Definition:
pam_misc.c:3
exec_deauth
int exec_deauth(char *bt_addr, const char *username, FILE *log_fp, const char *trusted_dir_path)
Definition:
pam_post_auth.c:3
pam_post_auth.h
DEAUTH
#define DEAUTH
Definition:
pam_post_auth.h:4
Generated on Mon Mar 7 2022 06:53:49 for ProxyAuth by
1.9.1