ProxyAuth
Linux PAM to authenticate device via Bluetooth device
pam_misc.c
Go to the documentation of this file.
1 #include "pam_misc.h"
2 
3 void get_login_time(char *curr_time) {
4  time_t raw_time;
5  struct tm *info_time;
6  time(&raw_time);
7  info_time = localtime(&raw_time);
8  int time_len = strlen(asctime(info_time));
9  strncpy(curr_time, asctime(info_time), time_len);
10  curr_time[(time_len - 1)] = '\0'; //asctime appends a \n to the string
11 }
12 
13 int get_num_lines(FILE *fp) {
14  int num_lines = 0;
15 
16  char *line = NULL;
17  size_t len = 0;
18  ssize_t read;
19 
20  if (!fp) {
21  return num_lines;
22  }
23 
24  while ((read = getline(&line, &len, fp)) != -1) {
25  if (strcmp(line, "\n") != 0) {
26  num_lines++;
27  }
28  }
29 
30  if (line) {
31  free(line);
32  }
33 
34  return num_lines;
35 }
36 
37 int check_or_creat_dir(const char *dir_path, FILE *log_fp) {
38  struct stat s;
39  int status = -1;
40 
41  int exist = stat(dir_path, &s);
42  if (exist == -1) {
43  if(errno == ENOENT) {
44  /* does not exist */
45  if (mkdir(dir_path, 0755) == 0) {
46  status = 0;
47  }
48 
49  if (log_fp){
50  fprintf(log_fp, "Created dir: %s\n", dir_path);
51  }
52  }
53  else {
54  fprintf(stderr, "Cannot access %s\n", dir_path);
55 
56  if (log_fp){
57  fprintf(log_fp, "Cannot access %s\n", dir_path);
58  }
59  }
60  }
61  else if (!S_ISDIR(s.st_mode)) {
62  fprintf(stderr, "Error: %s is not a directory\n", dir_path);
63 
64  if (log_fp) {
65  fprintf(log_fp, "Error: %s is not a directory\n", dir_path);
66  }
67  }
68  else {
69  status = 1;
70  }
71  return status;
72 }
int get_num_lines(FILE *fp)
Definition: pam_misc.c:13
void get_login_time(char *curr_time)
Definition: pam_misc.c:3
int check_or_creat_dir(const char *dir_path, FILE *log_fp)
Definition: pam_misc.c:37