comparison src/lib-master/master-login-auth.c @ 11086:260e190306b0 HEAD

Started using str_to_*() functions instead of libc's ones.
author Timo Sirainen <tss@iki.fi>
date Wed, 07 Apr 2010 01:49:00 +0300
parents 2e08ce368bc0
children 0979e9e1e124
comparison
equal deleted inserted replaced
11085:b262aad23e59 11086:260e190306b0
126 unsigned int id; 126 unsigned int id;
127 127
128 /* <id> <userid> [..] */ 128 /* <id> <userid> [..] */
129 129
130 list = t_strsplit(args, "\t"); 130 list = t_strsplit(args, "\t");
131 if (list[0] == NULL || list[1] == NULL) { 131 if (list[0] == NULL || list[1] == NULL ||
132 str_to_uint(list[0], &id) < 0) {
132 i_error("Auth server sent corrupted USER line"); 133 i_error("Auth server sent corrupted USER line");
133 return FALSE; 134 return FALSE;
134 } 135 }
135 id = (unsigned int)strtoul(list[0], NULL, 10);
136 136
137 request = master_login_auth_lookup_request(auth, id); 137 request = master_login_auth_lookup_request(auth, id);
138 if (request != NULL) { 138 if (request != NULL) {
139 request->callback(list + 1, NULL, request->context); 139 request->callback(list + 1, NULL, request->context);
140 i_free(request); 140 i_free(request);
147 const char *args) 147 const char *args)
148 { 148 {
149 struct master_login_auth_request *request; 149 struct master_login_auth_request *request;
150 unsigned int id; 150 unsigned int id;
151 151
152 id = (unsigned int)strtoul(args, NULL, 10); 152 if (str_to_uint(args, &id) < 0) {
153 i_error("Auth server sent corrupted NOTFOUND line");
154 return FALSE;
155 }
156
153 request = master_login_auth_lookup_request(auth, id); 157 request = master_login_auth_lookup_request(auth, id);
154 if (request != NULL) { 158 if (request != NULL) {
155 i_error("Authenticated user not found from userdb"); 159 i_error("Authenticated user not found from userdb");
156 request->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE, 160 request->callback(NULL, MASTER_AUTH_ERRMSG_INTERNAL_FAILURE,
157 request->context); 161 request->context);
167 struct master_login_auth_request *request; 171 struct master_login_auth_request *request;
168 const char *const *args, *error = NULL; 172 const char *const *args, *error = NULL;
169 unsigned int i, id; 173 unsigned int i, id;
170 174
171 args = t_strsplit(args_line, "\t"); 175 args = t_strsplit(args_line, "\t");
172 if (args[0] == NULL) { 176 if (args[0] == NULL || str_to_uint(args[0], &id) < 0) {
173 i_error("Auth server sent broken FAIL line"); 177 i_error("Auth server sent broken FAIL line");
174 return FALSE; 178 return FALSE;
175 } 179 }
176 for (i = 1; args[i] != NULL; i++) { 180 for (i = 1; args[i] != NULL; i++) {
177 if (strncmp(args[i], "reason=", 7) == 0) 181 if (strncmp(args[i], "reason=", 7) == 0)
178 error = args[i] + 7; 182 error = args[i] + 7;
179 } 183 }
180 184
181 id = (unsigned int)strtoul(args[0], NULL, 10);
182 request = master_login_auth_lookup_request(auth, id); 185 request = master_login_auth_lookup_request(auth, id);
183 if (request != NULL) { 186 if (request != NULL) {
184 if (error != NULL) 187 if (error != NULL)
185 i_error("Internal auth failure"); 188 i_error("Internal auth failure");
186 request->callback(NULL, error != NULL ? error : 189 request->callback(NULL, error != NULL ? error :
215 if (line == NULL) 218 if (line == NULL)
216 return; 219 return;
217 220
218 /* make sure the major version matches */ 221 /* make sure the major version matches */
219 if (strncmp(line, "VERSION\t", 8) != 0 || 222 if (strncmp(line, "VERSION\t", 8) != 0 ||
220 atoi(t_strcut(line + 8, '\t')) != 223 !str_uint_equals(t_strcut(line + 8, '\t'),
221 AUTH_MASTER_PROTOCOL_MAJOR_VERSION) { 224 AUTH_MASTER_PROTOCOL_MAJOR_VERSION)) {
222 i_error("Authentication server not compatible with " 225 i_error("Authentication server not compatible with "
223 "master process (mixed old and new binaries?)"); 226 "master process (mixed old and new binaries?)");
224 master_login_auth_disconnect(auth); 227 master_login_auth_disconnect(auth);
225 return; 228 return;
226 } 229 }