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

Function CreateNativeUser

pg_documentdb/src/commands/users.c:483–514  ·  view source on GitHub ↗

* CreateNativeUser creates a native PostgreSQL login role for the user */

Source from the content-addressed store, hash-verified

481 * CreateNativeUser creates a native PostgreSQL login role for the user
482 */
483static void
484CreateNativeUser(const CreateUserSpec *createUserSpec)
485{
486 /*Verify that native authentication is enabled*/
487 if (!IsNativeAuthEnabled)
488 {
489 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
490 errmsg(
491 "Native authentication is not enabled. Enable native authentication on this cluster to perform native user management operations.")));
492 }
493
494 ReportFeatureUsage(FEATURE_USER_CREATE);
495
496 /*Verify that the calling user is also native*/
497 if (IsCallingUserExternal())
498 {
499 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INSUFFICIENTPRIVILEGE),
500 errmsg(
501 "Only native users can create other native users. Authenticate as a built-in native administrative user to perform native user management operations.")));
502 }
503
504 StringInfo createUserInfo = makeStringInfo();
505 appendStringInfo(createUserInfo,
506 "CREATE ROLE %s WITH LOGIN PASSWORD %s;",
507 quote_identifier(createUserSpec->createUser),
508 quote_literal_cstr(PrehashPassword(createUserSpec->pwd)));
509
510 bool readOnly = false;
511 bool isNull = false;
512 ExtensionExecuteQueryViaSPI(createUserInfo->data, readOnly, SPI_OK_UTILITY,
513 &isNull);
514}
515
516
517/*

Callers 1

Calls 4

ReportFeatureUsageFunction · 0.85
IsCallingUserExternalFunction · 0.85
PrehashPasswordFunction · 0.85

Tested by

no test coverage detected