1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-18 06:04:06 +03:00

util: add a crypt strerror helper

This will be used by Python also.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15756

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Douglas Bagnall 2024-12-11 14:30:04 +13:00 committed by Andreas Schneider
parent c7597380b4
commit 5f365e71c1
3 changed files with 27 additions and 15 deletions

View File

@ -88,3 +88,27 @@ int talloc_crypt_blob(TALLOC_CTX *mem_ctx,
} }
return 0; return 0;
} }
char *talloc_crypt_errstring(TALLOC_CTX *mem_ctx, int error)
{
char buf[1024];
int err;
if (error == ERANGE) {
return talloc_strdup(
mem_ctx,
"Password exceeds maximum length allowed for crypt() hashing");
}
if (error == ENOTRECOVERABLE) {
/* probably weird RHEL7 crypt, see crypt_as_best_we_can() */
goto unknown;
}
err = strerror_r(error, buf, sizeof(buf));
if (err != 0) {
goto unknown;
}
return talloc_strndup(mem_ctx, buf, sizeof(buf));
unknown:
return talloc_strdup(mem_ctx, "Unknown error");
}

View File

@ -3,3 +3,5 @@ int talloc_crypt_blob(TALLOC_CTX *mem_ctx,
const char *phrase, const char *phrase,
const char *cmd, const char *cmd,
DATA_BLOB *blob); DATA_BLOB *blob);
char *talloc_crypt_errstring(TALLOC_CTX *mem_ctx, int error);

View File

@ -1661,21 +1661,7 @@ static int setup_primary_userPassword_hash(
cmd, cmd,
hash_blob); hash_blob);
if (ret != 0) { if (ret != 0) {
char buf[1024]; const char *reason = talloc_crypt_errstring(frame, ret);
const char *reason = NULL;
if (ret == ERANGE) {
reason = "Password exceeds maximum length allowed for crypt() hashing";
} else if (ret == ENOTRECOVERABLE) {
/* probably weird RHEL7 crypt, see talloc_crypt_blob() */
reason = "Unknown error";
} else {
int err = strerror_r(ret, buf, sizeof(buf));
if (err == 0) {
reason = buf;
} else {
reason = "Unknown error";
}
}
ldb_asprintf_errstring( ldb_asprintf_errstring(
ldb, ldb,
"setup_primary_userPassword: generation of a %s " "setup_primary_userPassword: generation of a %s "