* Helper function to parse a role document from an array element or single document */
| 1021 | * Helper function to parse a role document from an array element or single document |
| 1022 | */ |
| 1023 | static void |
| 1024 | ParseRoleDocument(bson_iter_t *rolesArrayIter, RolesInfoSpec *rolesInfoSpec) |
| 1025 | { |
| 1026 | bson_iter_t roleDocIter; |
| 1027 | bson_iter_recurse(rolesArrayIter, &roleDocIter); |
| 1028 | |
| 1029 | const char *roleName = NULL; |
| 1030 | uint32_t roleNameLength = 0; |
| 1031 | const char *dbName = NULL; |
| 1032 | uint32_t dbNameLength = 0; |
| 1033 | |
| 1034 | while (bson_iter_next(&roleDocIter)) |
| 1035 | { |
| 1036 | const char *roleKey = bson_iter_key(&roleDocIter); |
| 1037 | |
| 1038 | if (strcmp(roleKey, "role") == 0) |
| 1039 | { |
| 1040 | if (bson_iter_type(&roleDocIter) != BSON_TYPE_UTF8) |
| 1041 | { |
| 1042 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1043 | errmsg("'role' field must be a string."))); |
| 1044 | } |
| 1045 | |
| 1046 | roleName = bson_iter_utf8(&roleDocIter, &roleNameLength); |
| 1047 | } |
| 1048 | |
| 1049 | /* db is required as part of every role document. */ |
| 1050 | else if (strcmp(roleKey, "db") == 0) |
| 1051 | { |
| 1052 | if (bson_iter_type(&roleDocIter) != BSON_TYPE_UTF8) |
| 1053 | { |
| 1054 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1055 | errmsg("'db' field must be a string."))); |
| 1056 | } |
| 1057 | |
| 1058 | dbName = bson_iter_utf8(&roleDocIter, &dbNameLength); |
| 1059 | |
| 1060 | if (strcmp(dbName, "admin") != 0) |
| 1061 | { |
| 1062 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1063 | errmsg( |
| 1064 | "Unsupported value specified for db. Only 'admin' is allowed."))); |
| 1065 | } |
| 1066 | } |
| 1067 | else |
| 1068 | { |
| 1069 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1070 | errmsg("Unknown property '%s' in role document.", roleKey))); |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | if (roleName == NULL || dbName == NULL) |
| 1075 | { |
| 1076 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 1077 | errmsg("'role' and 'db' are required fields."))); |
| 1078 | } |
| 1079 | |
| 1080 | /* Only add role to the list if both role name and db name have valid lengths */ |
no outgoing calls
no test coverage detected