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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
--- a/libtac/include/libtac.h
+++ b/libtac/include/libtac.h
@@ -131,6 +131,7 @@
extern int tac_timeout;
void tac_set_dscp(uint8_t val);
+void tac_enable_readtimeout(int enable);
int tac_connect(struct addrinfo **, char **, int);
int tac_connect_single(struct addrinfo *, const char *, struct addrinfo *, int);
char *tac_ntop(const struct sockaddr *);
@@ -138,6 +139,7 @@
int tac_authen_send(int, const char *, char *, char *,
char *);
int tac_authen_read(int);
+int tac_authen_read_timeout(int, int);
int tac_cont_send(int, char *);
HDR *_tac_req_header(u_char, int);
void _tac_crypt(u_char *, HDR *, int);
@@ -148,6 +150,7 @@
int tac_acct_send(int, int, const char *, char *, char *,
struct tac_attrib *);
int tac_acct_read(int, struct areply *);
+int tac_acct_read_timeout(int, struct areply *, int);
void *xcalloc(size_t, size_t);
void *xrealloc(void *, size_t);
char *xstrcpy(char *, const char *, size_t);
@@ -155,6 +158,7 @@
int tac_author_send(int, const char *, char *, char *,
struct tac_attrib *);
int tac_author_read(int, struct areply *);
+int tac_author_read_timeout(int, struct areply *, int);
int tac_add_attrib_pair(struct tac_attrib **, char *, char,
char *);
int tac_add_attrib_truncate(struct tac_attrib **attr, char *name, char *value);
--- a/libtac/lib/acct_r.c
+++ b/libtac/lib/acct_r.c
@@ -32,7 +32,7 @@
* LIBTAC_STATUS_PROTOCOL_ERR
* >= 0 : server response, see TAC_PLUS_AUTHEN_STATUS_...
*/
-int tac_acct_read(int fd, struct areply *re) {
+int tac_acct_read_timeout(int fd, struct areply *re, int timeout) {
HDR th;
struct acct_reply *tb = NULL;
int len_from_header, r, len_from_body;
@@ -42,9 +42,9 @@
re->msg = NULL;
if (tac_readtimeout_enable &&
- tac_read_wait(fd,tac_timeout*1000, TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
+ tac_read_wait(fd,timeout*1000, TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
re->msg = xstrdup(acct_syserr_msg);
re->status = LIBTAC_STATUS_READ_TIMEOUT;
free(tb);
@@ -80,7 +80,7 @@
if (tac_readtimeout_enable &&
tac_read_wait(fd,timeleft,len_from_header,NULL) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
re->msg = xstrdup(acct_syserr_msg);
re->status = LIBTAC_STATUS_READ_TIMEOUT;
free(tb);
@@ -156,3 +156,7 @@
free(tb);
return re->status;
}
+
+int tac_acct_read(int fd, struct areply *re) {
+ return tac_acct_read_timeout(fd, re, tac_timeout);
+}
--- a/libtac/lib/authen_r.c
+++ b/libtac/lib/authen_r.c
@@ -34,7 +34,7 @@
* LIBTAC_STATUS_PROTOCOL_ERR
* >= 0 : server response, see TAC_PLUS_AUTHEN_STATUS_...
*/
-int tac_authen_read(int fd) {
+int tac_authen_read_timeout(int fd, int timeout) {
HDR th;
struct authen_reply *tb = NULL;
int len_from_header, r, len_from_body;
@@ -44,9 +44,9 @@
/* read the reply header */
if (tac_readtimeout_enable &&
- tac_read_wait(fd,tac_timeout*1000,TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
+ tac_read_wait(fd,timeout*1000,TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
status=LIBTAC_STATUS_READ_TIMEOUT;
free(tb);
return status;
@@ -77,7 +77,7 @@
if (tac_readtimeout_enable &&
tac_read_wait(fd,timeleft,len_from_header,NULL) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
status=LIBTAC_STATUS_READ_TIMEOUT;
}
r = read(fd, tb, len_from_header);
@@ -136,3 +136,7 @@
free(tb);
return status;
} /* tac_authen_read */
+
+int tac_authen_read(int fd) {
+ return tac_authen_read_timeout(fd, tac_timeout);
+}
--- a/libtac/lib/author_r.c
+++ b/libtac/lib/author_r.c
@@ -38,7 +38,8 @@
* LIBTAC_STATUS_PROTOCOL_ERR
* >= 0 : server response, see TAC_PLUS_AUTHOR_STATUS_...
*/
-int tac_author_read(int fd, struct areply *re) {
+
+int tac_author_read_timeout(int fd, struct areply *re, int timeout) {
HDR th;
struct author_reply *tb = NULL;
int len_from_header, r, len_from_body;
@@ -49,10 +50,10 @@
bzero(re, sizeof(struct areply));
if (tac_readtimeout_enable &&
- tac_read_wait(fd,tac_timeout*1000,TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
+ tac_read_wait(fd,timeout*1000,TAC_PLUS_HDR_SIZE,&timeleft) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
re->msg = xstrdup(author_syserr_msg);
re->status = LIBTAC_STATUS_READ_TIMEOUT;
free(tb);
@@ -88,7 +89,7 @@
tac_read_wait(fd,timeleft,len_from_header,NULL) < 0 ) {
TACSYSLOG((LOG_ERR,\
- "%s: reply timeout after %d secs", __FUNCTION__, tac_timeout))
+ "%s: reply timeout after %d secs", __FUNCTION__, timeout))
re->msg = xstrdup(author_syserr_msg);
re->status = LIBTAC_STATUS_READ_TIMEOUT;
free(tb);
@@ -240,3 +241,7 @@
free(tb);
return re->status;
}
+
+int tac_author_read(int fd, struct areply *re) {
+ return tac_author_read_timeout(fd, re, tac_timeout);
+}
--- a/libtac/lib/connect.c
+++ b/libtac/lib/connect.c
@@ -41,6 +41,11 @@
tac_dscp = val;
}
+
+void tac_enable_readtimeout(int enable) {
+ tac_readtimeout_enable = !!enable;
+}
+
/* Returns file descriptor of open connection
to the first available server from list passed
in server table.
|