From 5afbecdc2ecff643002d3c94ffcc9c4212cf6c0d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 May 2004 12:05:54 +0000 Subject: r625: - handle passwords longer than length 14 (thanks to abartlet for pointing out the bug) - delete unicodePwd if not storing a plaintext password (This used to be commit 6c3f22a685c55f183f4e0e4303e3d9990f4b39b5) --- source4/rpc_server/samr/dcesrv_samr.c | 9 ++- source4/rpc_server/samr/samdb.c | 117 ++++++++++++++++++++++------------ 2 files changed, 82 insertions(+), 44 deletions(-) diff --git a/source4/rpc_server/samr/dcesrv_samr.c b/source4/rpc_server/samr/dcesrv_samr.c index 1d64fad5ba..44bf55b013 100644 --- a/source4/rpc_server/samr/dcesrv_samr.c +++ b/source4/rpc_server/samr/dcesrv_samr.c @@ -488,7 +488,7 @@ static NTSTATUS samr_CreateDomainGroup(struct dcesrv_call_state *dce_call, TALLO ret = samdb_copy_template(d_state->sam_ctx, mem_ctx, &msg, "(&(name=TemplateGroup)(objectclass=groupTemplate))"); if (ret != 0) { - DEBUG(1,("Failed to load TemplateUser from samdb\n")); + DEBUG(1,("Failed to load TemplateGroup from samdb\n")); return NT_STATUS_INTERNAL_DB_CORRUPTION; } @@ -1771,9 +1771,12 @@ static NTSTATUS samr_SetUserInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX return status; } - /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ + /* mark all the message elements as LDB_FLAG_MOD_REPLACE, + unless they are already marked with some other flag */ for (i=0;inum_values;j++) { if (strcasecmp(el->name, "objectClass") == 0 && - (strcasecmp((char *)el->values[j].data, "userTemplate") == 0 || + (strcasecmp((char *)el->values[j].data, "Template") == 0 || + strcasecmp((char *)el->values[j].data, "userTemplate") == 0 || strcasecmp((char *)el->values[j].data, "groupTemplate") == 0)) { continue; } @@ -626,6 +627,21 @@ int samdb_msg_add_string(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg return ldb_msg_add_string(sam_ctx->ldb, msg, a, s); } +/* + add a delete element operation to a message +*/ +int samdb_msg_add_delete(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg, + const char *attr_name) +{ + struct samdb_context *sam_ctx = ctx; + char *a = talloc_strdup(mem_ctx, attr_name); + if (a == NULL) { + return -1; + } + ldb_set_alloc(sam_ctx->ldb, samdb_alloc, mem_ctx); + return ldb_msg_add_empty(sam_ctx->ldb, msg, a, LDB_FLAG_MOD_DELETE); +} + /* add a uint_t element to a message */ @@ -815,6 +831,7 @@ NTSTATUS samdb_set_password(void *ctx, TALLOC_CTX *mem_ctx, NTTIME now_nt; double now_double; int i; + BOOL lm_hash_ok; /* we need to know the time to compute password age */ unix_to_nt_time(&now_nt, now); @@ -873,14 +890,17 @@ NTSTATUS samdb_set_password(void *ctx, TALLOC_CTX *mem_ctx, } /* compute the new nt and lm hashes */ - E_deshash(new_pass, lmNewHash.hash); + lm_hash_ok = E_deshash(new_pass, lmNewHash.hash); E_md4hash(new_pass, ntNewHash.hash); /* check the immediately past password */ - if (pwdHistoryLength > 0 && - (memcmp(lmNewHash.hash, lmPwdHash.hash, 16) == 0 || - memcmp(ntNewHash.hash, ntPwdHash.hash, 16) == 0)) { - return NT_STATUS_PASSWORD_RESTRICTION; + if (pwdHistoryLength > 0) { + if (lm_hash_ok && memcmp(lmNewHash.hash, lmPwdHash.hash, 16) == 0) { + return NT_STATUS_PASSWORD_RESTRICTION; + } + if (memcmp(ntNewHash.hash, ntPwdHash.hash, 16) == 0) { + return NT_STATUS_PASSWORD_RESTRICTION; + } } /* check the password history */ @@ -888,14 +908,18 @@ NTSTATUS samdb_set_password(void *ctx, TALLOC_CTX *mem_ctx, ntPwdHistory_len = MIN(ntPwdHistory_len, pwdHistoryLength); if (pwdHistoryLength > 0) { - if (strcmp(unicodePwd, new_pass) == 0 || - memcmp(lmNewHash.hash, lmPwdHash.hash, 16) == 0 || - memcmp(ntNewHash.hash, ntPwdHash.hash, 16) == 0) { + if (unicodePwd && strcmp(unicodePwd, new_pass) == 0) { + return NT_STATUS_PASSWORD_RESTRICTION; + } + if (lm_hash_ok && memcmp(lmNewHash.hash, lmPwdHash.hash, 16) == 0) { + return NT_STATUS_PASSWORD_RESTRICTION; + } + if (memcmp(ntNewHash.hash, ntPwdHash.hash, 16) == 0) { return NT_STATUS_PASSWORD_RESTRICTION; } } - for (i=0;i 0) { - new_lmPwdHistory = talloc_array_p(mem_ctx, struct samr_Hash, - pwdHistoryLength); - if (!new_lmPwdHistory) { - return NT_STATUS_NO_MEMORY; - } - new_ntPwdHistory = talloc_array_p(mem_ctx, struct samr_Hash, - pwdHistoryLength); - if (!new_ntPwdHistory) { - return NT_STATUS_NO_MEMORY; - } - for (i=0;i