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

Function ACLLoadConfiguredUsers

src/acl.cpp:1445–1486  ·  view source on GitHub ↗

This function will load the configured users appended to the server * configuration via ACLAppendUserForLoading(). On loading errors it will * log an error and return C_ERR, otherwise C_OK will be returned. */

Source from the content-addressed store, hash-verified

1443 * configuration via ACLAppendUserForLoading(). On loading errors it will
1444 * log an error and return C_ERR, otherwise C_OK will be returned. */
1445int ACLLoadConfiguredUsers(void) {
1446 listIter li;
1447 listNode *ln;
1448 listRewind(UsersToLoad,&li);
1449 while ((ln = listNext(&li)) != NULL) {
1450 sds *aclrules = (sds*)listNodeValue(ln);
1451 sds username = aclrules[0];
1452
1453 if (ACLStringHasSpaces(aclrules[0],sdslen(aclrules[0]))) {
1454 serverLog(LL_WARNING,"Spaces not allowed in ACL usernames");
1455 return C_ERR;
1456 }
1457
1458 user *u = ACLCreateUser(username,sdslen(username));
1459 if (!u) {
1460 u = ACLGetUserByName(username,sdslen(username));
1461 serverAssert(u != NULL);
1462 ACLSetUser(u,"reset",-1);
1463 }
1464
1465 /* Load every rule defined for this user. */
1466 for (int j = 1; aclrules[j]; j++) {
1467 if (ACLSetUser(u,aclrules[j],sdslen(aclrules[j])) != C_OK) {
1468 const char *errmsg = ACLSetUserStringError();
1469 serverLog(LL_WARNING,"Error loading ACL rule '%s' for "
1470 "the user named '%s': %s",
1471 aclrules[j],aclrules[0],errmsg);
1472 return C_ERR;
1473 }
1474 }
1475
1476 /* Having a disabled user in the configuration may be an error,
1477 * warn about it without returning any error to the caller. */
1478 if (u->flags & USER_FLAG_DISABLED) {
1479 serverLog(LL_NOTICE, "The user '%s' is disabled (there is no "
1480 "'on' modifier in the user description). Make "
1481 "sure this is not a configuration error.",
1482 aclrules[0]);
1483 }
1484 }
1485 return C_OK;
1486}
1487
1488/* This function loads the ACL from the specified filename: every line
1489 * is validated and should be either empty or in the format used to specify

Callers 1

ACLLoadUsersAtStartupFunction · 0.85

Calls 9

listRewindFunction · 0.85
listNextFunction · 0.85
ACLStringHasSpacesFunction · 0.85
sdslenFunction · 0.85
serverLogFunction · 0.85
ACLCreateUserFunction · 0.85
ACLGetUserByNameFunction · 0.85
ACLSetUserFunction · 0.85
ACLSetUserStringErrorFunction · 0.85

Tested by

no test coverage detected