aboutsummaryrefslogtreecommitdiff
path: root/package/libpam-tacplus/0004-fix-build-failure-when-time_t-is-64-bits.patch
blob: c349674d1638a7beafa4b9696cc473af7db59434 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
From 74a6cc484a83270273b373da17c05c1e394d3dd9 Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Date: Sun, 17 May 2020 21:55:11 +0200
Subject: [PATCH] fix build failure when time_t is 64 bits

Build can fail if time_t is 64 bits and not 32 bits because of the
following warning (which results in a build failure due to -Werror):

tacc.c: In function 'main':
tacc.c:346:25: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'time_t' {aka 'long long int'} [-Werror=format=]
         sprintf(buf, "%lu", time(0));
                       ~~^   ~~~~~~~
                       %llu

Instead of casting time_t to unsigned long as already done in
pam_tacplus.c, use strftime which seems the right approach to
convert time_t into a string. While at it, also update pam_tacplus.c.

Fixes:
 - http://autobuild.buildroot.org/results/874433d8cb30d21332f23024081a8b6d7b3254ae

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
[Retrieved from:
https://github.com/kravietz/pam_tacplus/commit/74a6cc484a83270273b373da17c05c1e394d3dd9]
---
 pam_tacplus.c |  6 +++++-
 tacc.c        | 12 ++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/pam_tacplus.c b/pam_tacplus.c
index 7d8bb5f..a0cb83d 100644
--- a/pam_tacplus.c
+++ b/pam_tacplus.c
@@ -86,10 +86,14 @@ int _pam_send_account(int tac_fd, int type, const char *user, char *tty,
 	char buf[64];
 	struct tac_attrib *attr;
 	int retval;
+	time_t t;
+	struct tm tm;
 
 	attr = (struct tac_attrib *) xcalloc(1, sizeof(struct tac_attrib));
 
-	sprintf(buf, "%lu", (unsigned long) time(NULL));
+	t = time(NULL);
+	gmtime_r(&t, &tm);
+	strftime(buf, sizeof(buf), "%s", &tm);
 
 	if (type == TAC_PLUS_ACCT_FLAG_START) {
 		tac_add_attrib(&attr, "start_time", buf);
diff --git a/tacc.c b/tacc.c
index ef9d081..affc649 100644
--- a/tacc.c
+++ b/tacc.c
@@ -342,8 +342,12 @@ int main(int argc, char **argv) {
     if (do_account) {
         /* start accounting */
         struct tac_attrib *attr = NULL;
+        time_t t;
+        struct tm tm;
 
-        sprintf(buf, "%lu", time(0));
+        t = time(0);
+        gmtime_r(&t, &tm);
+        strftime(buf, sizeof(buf), "%s", &tm);
         tac_add_attrib(&attr, "start_time", buf);
 
         // this is not crypto but merely an identifier
@@ -452,7 +456,11 @@ int main(int argc, char **argv) {
     if (do_account) {
         /* stop accounting */
         struct tac_attrib *attr = NULL;
-        sprintf(buf, "%lu", time(0));
+        time_t t;
+        struct tm tm;
+        t = time(0);
+        gmtime_r(&t, &tm);
+        strftime(buf, sizeof(buf), "%s", &tm);
         tac_add_attrib(&attr, "stop_time", buf);
         sprintf(buf, "%hu", task_id);
         tac_add_attrib(&attr, "task_id", buf);