View | Details | Raw Unified | Return to bug 194723 | Differences between
and this patch

Collapse All | Expand All

(-)./files/patch-pam_google_authenticator.c (+76 lines)
Added Link Here
1
*** pam_google_authenticator.c.orig	Thu Jan 30 15:17:38 2014
2
--- pam_google_authenticator.c	Fri Oct 31 19:42:43 2014
3
***************
4
*** 503,512 ****
5
  }
6
  #endif
7
  
8
- static int get_timestamp(void) {
9
-   return get_time()/30;
10
- }
11
- 
12
  static int comparator(const void *a, const void *b) {
13
    return *(unsigned int *)a - *(unsigned int *)b;
14
  }
15
--- 503,508 ----
16
***************
17
*** 538,543 ****
18
--- 534,574 ----
19
    return NULL;
20
  }
21
  
22
+ #if !defined(STEPSIZE)
23
+ static int get_timestamp(void) {
24
+   return get_time()/30;
25
+ }
26
+ #else
27
+ static int get_timestamp(pam_handle_t *pamh, const char *secret_filename,
28
+                        const char *buf) {
29
+   const char *value = get_cfg_value(pamh, "STEP_SIZE", buf);
30
+   if (!value) {
31
+     // Default step size is 30.
32
+     free((void *)value);
33
+     return 30;
34
+   } else if (value == &oom) {
35
+     // Out of memory. This is a fatal error.
36
+     return 0;
37
+   }
38
+ 
39
+   char *endptr;
40
+   errno = 0;
41
+   int step = (int)strtoul(value, &endptr, 10);
42
+   if (errno || !*value || value == endptr ||
43
+       (*endptr && *endptr != ' ' && *endptr != '\t' &&
44
+        *endptr != '\n' && *endptr != '\r') ||
45
+       step < 1 || step > 60) {
46
+     free((void *)value);
47
+     log_message(LOG_ERR, pamh, "Invalid STEP_SIZE option in \"%s\"",
48
+                 secret_filename);
49
+     return 0;
50
+   }
51
+   free((void *)value);
52
+ 
53
+   return get_time()/step;
54
+ }
55
+ #endif
56
+ 
57
  static int set_cfg_value(pam_handle_t *pamh, const char *key, const char *val,
58
                           char **buf) {
59
    size_t key_len = strlen(key);
60
***************
61
*** 1162,1168 ****
62
    }
63
  
64
    // Compute verification codes and compare them with user input
65
!   const int tm = get_timestamp();
66
    const char *skew_str = get_cfg_value(pamh, "TIME_SKEW", *buf);
67
    if (skew_str == &oom) {
68
      // Out of memory. This is a fatal error
69
--- 1193,1199 ----
70
    }
71
  
72
    // Compute verification codes and compare them with user input
73
!   const int tm = get_timestamp(pamh, secret_filename, *buf);
74
    const char *skew_str = get_cfg_value(pamh, "TIME_SKEW", *buf);
75
    if (skew_str == &oom) {
76
      // Out of memory. This is a fatal error

Return to bug 194723