Given an argument vector describing a user in the form: * * user ... ACL rules and flags ... * * this function validates, and if the syntax is valid, appends * the user definition to a list for later loading. * * The rules are tested for validity and if there obvious syntax errors * the function returns C_ERR and does nothing, otherwise C_OK is returned * and the user is a
| 1402 | * by reference (if not set to NULL) the argc_err argument with the index |
| 1403 | * of the argv vector that caused the error. */ |
| 1404 | int ACLAppendUserForLoading(sds *argv, int argc, int *argc_err) { |
| 1405 | if (argc < 2 || strcasecmp(argv[0],"user")) { |
| 1406 | if (argc_err) *argc_err = 0; |
| 1407 | return C_ERR; |
| 1408 | } |
| 1409 | |
| 1410 | /* Try to apply the user rules in a fake user to see if they |
| 1411 | * are actually valid. */ |
| 1412 | user *fakeuser = ACLCreateUnlinkedUser(); |
| 1413 | |
| 1414 | for (int j = 2; j < argc; j++) { |
| 1415 | if (ACLSetUser(fakeuser,argv[j],sdslen(argv[j])) == C_ERR) { |
| 1416 | if (errno != ENOENT) { |
| 1417 | ACLFreeUser(fakeuser); |
| 1418 | if (argc_err) *argc_err = j; |
| 1419 | return C_ERR; |
| 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /* Rules look valid, let's append the user to the list. */ |
| 1425 | sds *copy = zmalloc(sizeof(sds)*argc); |
| 1426 | for (int j = 1; j < argc; j++) copy[j-1] = sdsdup(argv[j]); |
| 1427 | copy[argc-1] = NULL; |
| 1428 | listAddNodeTail(UsersToLoad,copy); |
| 1429 | ACLFreeUser(fakeuser); |
| 1430 | return C_OK; |
| 1431 | } |
| 1432 | |
| 1433 | /* This function will load the configured users appended to the server |
| 1434 | * configuration via ACLAppendUserForLoading(). On loading errors it will |
no test coverage detected