| 1306 | } |
| 1307 | |
| 1308 | void read_args(int f_in, char *mod_name, char *buf, size_t bufsiz, int rl_nulls, |
| 1309 | int unescape, char ***argv_p, int *argc_p, char **request_p) |
| 1310 | { |
| 1311 | int maxargs = MAX_ARGS; |
| 1312 | int dot_pos = 0, argc = 0, request_len = 0; |
| 1313 | char **argv, *p; |
| 1314 | int rl_flags = (rl_nulls ? RL_EOL_NULLS : 0); |
| 1315 | |
| 1316 | #ifdef ICONV_OPTION |
| 1317 | rl_flags |= (protect_args && ic_recv != (iconv_t)-1 ? RL_CONVERT : 0); |
| 1318 | #endif |
| 1319 | |
| 1320 | argv = new_array(char *, maxargs); |
| 1321 | if (mod_name && !protect_args) |
| 1322 | argv[argc++] = "rsyncd"; |
| 1323 | |
| 1324 | if (request_p) |
| 1325 | *request_p = NULL; |
| 1326 | |
| 1327 | while (1) { |
| 1328 | if (read_line(f_in, buf, bufsiz, rl_flags) == 0) |
| 1329 | break; |
| 1330 | |
| 1331 | if (argc == maxargs-1) { |
| 1332 | maxargs += MAX_ARGS; |
| 1333 | argv = realloc_array(argv, char *, maxargs); |
| 1334 | } |
| 1335 | |
| 1336 | if (dot_pos) { |
| 1337 | if (request_p && request_len < 1024) { |
| 1338 | int len = strlen(buf); |
| 1339 | if (request_len) |
| 1340 | request_p[0][request_len++] = ' '; |
| 1341 | *request_p = realloc_array(*request_p, char, request_len + len + 1); |
| 1342 | memcpy(*request_p + request_len, buf, len + 1); |
| 1343 | request_len += len; |
| 1344 | } |
| 1345 | if (mod_name) |
| 1346 | glob_expand_module(mod_name, buf, &argv, &argc, &maxargs); |
| 1347 | else |
| 1348 | glob_expand(buf, &argv, &argc, &maxargs); |
| 1349 | } else { |
| 1350 | p = strdup(buf); |
| 1351 | /* An option arg the client escaped with safe_arg() (no |
| 1352 | * remote shell un-escapes it for a daemon). File args |
| 1353 | * after the dot are handled by glob_expand() below. */ |
| 1354 | if (unescape) |
| 1355 | unbackslash_arg(p); |
| 1356 | argv[argc++] = p; |
| 1357 | if (*p == '.' && p[1] == '\0') |
| 1358 | dot_pos = argc; |
| 1359 | } |
| 1360 | } |
| 1361 | argv[argc] = NULL; |
| 1362 | |
| 1363 | glob_expand(NULL, NULL, NULL, NULL); |
| 1364 | |
| 1365 | *argc_p = argc; |
no test coverage detected