MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ACLAppendUserForLoading

Function ACLAppendUserForLoading

src/acl.cpp:1413–1440  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1411 * by reference (if not set to NULL) the argc_err argument with the index
1412 * of the argv vector that caused the error. */
1413int ACLAppendUserForLoading(sds *argv, int argc, int *argc_err) {
1414 if (argc < 2 || strcasecmp(argv[0],"user")) {
1415 if (argc_err) *argc_err = 0;
1416 return C_ERR;
1417 }
1418
1419 /* Try to apply the user rules in a fake user to see if they
1420 * are actually valid. */
1421 user *fakeuser = ACLCreateUnlinkedUser();
1422
1423 for (int j = 2; j < argc; j++) {
1424 if (ACLSetUser(fakeuser,argv[j],sdslen(argv[j])) == C_ERR) {
1425 if (errno != ENOENT) {
1426 ACLFreeUser(fakeuser);
1427 if (argc_err) *argc_err = j;
1428 return C_ERR;
1429 }
1430 }
1431 }
1432
1433 /* Rules look valid, let's append the user to the list. */
1434 sds *copy = (sds*)zmalloc(sizeof(sds)*argc, MALLOC_LOCAL);
1435 for (int j = 1; j < argc; j++) copy[j-1] = sdsdup(argv[j]);
1436 copy[argc-1] = NULL;
1437 listAddNodeTail(UsersToLoad,copy);
1438 ACLFreeUser(fakeuser);
1439 return C_OK;
1440}
1441
1442/* This function will load the configured users appended to the server
1443 * configuration via ACLAppendUserForLoading(). On loading errors it will

Callers 1

Calls 7

ACLCreateUnlinkedUserFunction · 0.85
ACLSetUserFunction · 0.85
sdslenFunction · 0.85
ACLFreeUserFunction · 0.85
zmallocFunction · 0.85
sdsdupFunction · 0.85
listAddNodeTailFunction · 0.85

Tested by

no test coverage detected