* CreateNativeUser creates a native PostgreSQL login role for the user */
| 481 | * CreateNativeUser creates a native PostgreSQL login role for the user |
| 482 | */ |
| 483 | static void |
| 484 | CreateNativeUser(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 | /* |
no test coverage detected