MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ACLAppendUserForLoading

Function ACLAppendUserForLoading

app/redis-6.2.6/src/acl.c:1404–1431  ·  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

1402 * by reference (if not set to NULL) the argc_err argument with the index
1403 * of the argv vector that caused the error. */
1404int 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

Callers 1

Calls 8

strcasecmpFunction · 0.85
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