MCPcopy Create free account
hub / github.com/documentdb/documentdb / ParseCreateRoleSpec

Function ParseCreateRoleSpec

pg_documentdb/src/commands/roles.c:282–382  ·  view source on GitHub ↗

* ParseCreateRoleSpec parses the createRole command parameters */

Source from the content-addressed store, hash-verified

280 * ParseCreateRoleSpec parses the createRole command parameters
281 */
282static void
283ParseCreateRoleSpec(pgbson *createRoleBson, CreateRoleSpec *createRoleSpec)
284{
285 bson_iter_t createRoleIter;
286 PgbsonInitIterator(createRoleBson, &createRoleIter);
287 bool dbFound = false;
288 bool rolesFound = false;
289 bool privilegesFound = false;
290 while (bson_iter_next(&createRoleIter))
291 {
292 const char *key = bson_iter_key(&createRoleIter);
293
294 if (strcmp(key, "createRole") == 0)
295 {
296 EnsureTopLevelFieldType(key, &createRoleIter, BSON_TYPE_UTF8);
297 uint32_t strLength = 0;
298 createRoleSpec->roleName = bson_iter_utf8(&createRoleIter, &strLength);
299
300 if (strLength == 0)
301 {
302 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
303 errmsg(
304 "The 'createRole' field must not be left empty.")));
305 }
306
307 if (ContainsReservedPgRoleNamePrefix(createRoleSpec->roleName) ||
308 IsReservedInternalRoleName(createRoleSpec->roleName))
309 {
310 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
311 errmsg(
312 "Role name '%s' is reserved and can't be used as a custom role name.",
313 createRoleSpec->roleName)));
314 }
315
316 if (IS_NATIVE_BUILTIN_ROLE(createRoleSpec->roleName))
317 {
318 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
319 errmsg(
320 "Role name '%s' is a built-in role and can't be used as a custom role name.",
321 createRoleSpec->roleName)));
322 }
323 }
324 else if (strcmp(key, "roles") == 0)
325 {
326 rolesFound = true;
327 ParseRolesArray(&createRoleIter, createRoleSpec);
328 }
329 else if (strcmp(key, "privileges") == 0)
330 {
331 privilegesFound = true;
332 ParsePrivilegesArray(&createRoleIter, createRoleSpec);
333 }
334 else if (strcmp(key, "$db") == 0 && EnableRolesAdminDBCheck)
335 {
336 EnsureTopLevelFieldType(key, &createRoleIter, BSON_TYPE_UTF8);
337 uint32_t strLength = 0;
338 const char *dbName = bson_iter_utf8(&createRoleIter, &strLength);
339

Callers 1

create_roleFunction · 0.85

Calls 7

PgbsonInitIteratorFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
ParseRolesArrayFunction · 0.85
ParsePrivilegesArrayFunction · 0.85
IsCommonSpecIgnoredFieldFunction · 0.85

Tested by

no test coverage detected