ProxyAuth
Linux PAM to authenticate device via Bluetooth device
pam_bt_misc.c
Go to the documentation of this file.
1 #include "pam_bt_misc.h"
2 
3 const char *trusted_dir_path = "/etc/proxy_auth/";
4 
5 int verify_bt_addr(char *address, FILE *log_fp) {
6  char *curr = address;
7  int len = 0;
8 
9  int is_valid = 1;
10 
11  if (!address) {
12  return 0;
13  }
14 
15  if (strlen(address) <= BT_MAC_LEN) {
16  while (curr && len < strlen(address)) {
17  int is_div3 = (len + 1) % 3 == 0;
18 
19  if ( len > BT_MAC_LEN || //exceeds the BT String Len
20  (isxdigit(*curr) == 0 && !is_div3) || //not Alphanumeric when it should be
21  (isxdigit(*curr) == 0 && is_div3 && *curr != ':') //not a colon when it should be
22  ) {
23  is_valid = 0;
24  break;
25  }
26 
27  len++;
28  curr++;
29  }
30  }
31  else {
32  is_valid = 0;
33  }
34 
35  if (is_valid && len == BT_MAC_LEN) {
36  return 1;
37  }
38 
39  if (log_fp) {
40  fprintf(log_fp, "%s is an invalid Bluetooth Address\n", address);
41  }
42 
43  return 0;
44 }
45 
46 int is_dev_trusted(FILE *log_fp, char *dev, char **trusted_devices, int num_of_devices) {
47  for (int i = 0; i < num_of_devices; i++) {
48  if (strcmp(dev, trusted_devices[i]) == 0) {
49  return 1;
50  }
51  }
52  return 0;
53 }
54 
55 void free_device_list(char **device_list, int num_of_devices) {
56  if (device_list) {
57  for (int i = 0; i < num_of_devices; i++) {
58  free(device_list[i]);
59  device_list[i] = NULL;
60  }
61  free(device_list);
62  device_list = NULL;
63  }
64 }
int verify_bt_addr(char *address, FILE *log_fp)
Definition: pam_bt_misc.c:5
void free_device_list(char **device_list, int num_of_devices)
Definition: pam_bt_misc.c:55
const char * trusted_dir_path
Definition: pam_bt_misc.c:3
int is_dev_trusted(FILE *log_fp, char *dev, char **trusted_devices, int num_of_devices)
Definition: pam_bt_misc.c:46
#define BT_MAC_LEN
Definition: pam_bt_misc.h:9