* Update native user */
| 860 | * Update native user |
| 861 | */ |
| 862 | static Datum |
| 863 | UpdateNativeUser(UpdateUserSpec *spec) |
| 864 | { |
| 865 | /*Verify that native authentication is enabled*/ |
| 866 | if (!IsNativeAuthEnabled) |
| 867 | { |
| 868 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED), |
| 869 | errmsg( |
| 870 | "Native authentication is not enabled. Enable native authentication on this cluster to perform native user management operations."))); |
| 871 | } |
| 872 | |
| 873 | ReportFeatureUsage(FEATURE_USER_UPDATE); |
| 874 | |
| 875 | /*Verify that the calling user is also native*/ |
| 876 | if (IsCallingUserExternal()) |
| 877 | { |
| 878 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INSUFFICIENTPRIVILEGE), |
| 879 | errmsg( |
| 880 | "Only native users can create other native users. Authenticate as a built-in native administrative user to perform native user management operations."))); |
| 881 | } |
| 882 | |
| 883 | if (spec->pwd == NULL || spec->pwd[0] == '\0') |
| 884 | { |
| 885 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 886 | errmsg("The password field must not be left empty."))); |
| 887 | } |
| 888 | |
| 889 | /* Verify password meets complexity requirements */ |
| 890 | if (EnableUsernamePasswordConstraints && !IsPasswordValid(spec->updateUser, |
| 891 | spec->pwd)) |
| 892 | { |
| 893 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 894 | errmsg("Invalid password, use a different password."))); |
| 895 | } |
| 896 | |
| 897 | StringInfo updateUserInfo = makeStringInfo(); |
| 898 | appendStringInfo(updateUserInfo, "ALTER USER %s WITH PASSWORD %s;", quote_identifier( |
| 899 | spec->updateUser), quote_literal_cstr(PrehashPassword( |
| 900 | spec->pwd))); |
| 901 | |
| 902 | bool readOnly = false; |
| 903 | bool isNull = false; |
| 904 | ExtensionExecuteQueryViaSPI(updateUserInfo->data, readOnly, SPI_OK_UTILITY, |
| 905 | &isNull); |
| 906 | |
| 907 | pgbson_writer finalWriter; |
| 908 | PgbsonWriterInit(&finalWriter); |
| 909 | PgbsonWriterAppendInt32(&finalWriter, "ok", 2, 1); |
| 910 | PG_RETURN_POINTER(PgbsonWriterGetPgbson(&finalWriter)); |
| 911 | } |
| 912 | |
| 913 | |
| 914 | /* |
no test coverage detected