From 20c56e21ca4a5f2abcc618deb7d23e432721c88a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 31 Dec 2016 12:45:51 +0000 Subject: [PATCH] libnet: Use "all_zero" where appropriate ... Saves a few bytes of footprint Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/libnet/libnet_dssync_passdb.c | 7 ++----- source3/libnet/libnet_keytab.h | 1 - source3/libnet/libnet_samsync_display.c | 6 ++---- source3/libnet/libnet_samsync_keytab.c | 2 +- source3/libnet/libnet_samsync_ldif.c | 7 ++----- source3/libnet/libnet_samsync_passdb.c | 7 ++----- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/source3/libnet/libnet_dssync_passdb.c b/source3/libnet/libnet_dssync_passdb.c index 99e65c263ad..8e2a4593373 100644 --- a/source3/libnet/libnet_dssync_passdb.c +++ b/source3/libnet/libnet_dssync_passdb.c @@ -1105,7 +1105,6 @@ static NTSTATUS sam_account_from_object(struct samu *account, TALLOC_CTX *mem_ctx = account; const char *old_string, *new_string; time_t unix_time, stored_time; - uchar zero_buf[16]; NTSTATUS status; NTTIME lastLogon; @@ -1134,8 +1133,6 @@ static NTSTATUS sam_account_from_object(struct samu *account, uint32_t acct_flags; uint32_t units_per_week; - memset(zero_buf, '\0', sizeof(zero_buf)); - objectSid = cur->object.identifier->sid; GET_STRING_EX(sAMAccountName, true); DEBUG(0,("sam_account_from_object(%s, %s) start\n", @@ -1329,11 +1326,11 @@ static NTSTATUS sam_account_from_object(struct samu *account, think this channel is secure enough - don't set the passwords at all in that case */ - if (dBCSPwd.length == 16 && memcmp(dBCSPwd.data, zero_buf, 16) != 0) { + if (dBCSPwd.length == 16 && !all_zero(dBCSPwd.data, 16)) { pdb_set_lanman_passwd(account, dBCSPwd.data, PDB_CHANGED); } - if (unicodePwd.length == 16 && memcmp(unicodePwd.data, zero_buf, 16) != 0) { + if (unicodePwd.length == 16 && !all_zero(unicodePwd.data, 16)) { pdb_set_nt_passwd(account, unicodePwd.data, PDB_CHANGED); } diff --git a/source3/libnet/libnet_keytab.h b/source3/libnet/libnet_keytab.h index 43071ce3f87..df6e957dfc4 100644 --- a/source3/libnet/libnet_keytab.h +++ b/source3/libnet/libnet_keytab.h @@ -35,7 +35,6 @@ struct libnet_keytab_context { const char *keytab_name; struct ads_struct *ads; const char *dns_domain_name; - uint8_t zero_buf[16]; uint32_t count; struct libnet_keytab_entry *entries; bool clean_old_entries; diff --git a/source3/libnet/libnet_samsync_display.c b/source3/libnet/libnet_samsync_display.c index 034a23fe227..040742d72ac 100644 --- a/source3/libnet/libnet_samsync_display.c +++ b/source3/libnet/libnet_samsync_display.c @@ -60,19 +60,17 @@ static void display_account_info(uint32_t rid, struct netr_DELTA_USER *r) { fstring hex_nt_passwd, hex_lm_passwd; - uchar zero_buf[16]; - memset(zero_buf, '\0', sizeof(zero_buf)); /* Decode hashes from password hash (if they are not NULL) */ - if (memcmp(r->lmpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->lmpassword.hash, 16)) { pdb_sethexpwd(hex_lm_passwd, r->lmpassword.hash, r->acct_flags); } else { pdb_sethexpwd(hex_lm_passwd, NULL, 0); } - if (memcmp(r->ntpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->ntpassword.hash, 16)) { pdb_sethexpwd(hex_nt_passwd, r->ntpassword.hash, r->acct_flags); } else { pdb_sethexpwd(hex_nt_passwd, NULL, 0); diff --git a/source3/libnet/libnet_samsync_keytab.c b/source3/libnet/libnet_samsync_keytab.c index 3f7e895928f..5c072b921ad 100644 --- a/source3/libnet/libnet_samsync_keytab.c +++ b/source3/libnet/libnet_samsync_keytab.c @@ -76,7 +76,7 @@ static NTSTATUS fetch_sam_entry_keytab(TALLOC_CTX *mem_ctx, uint32_t kvno = 0; DATA_BLOB blob; - if (memcmp(r->ntpassword.hash, ctx->zero_buf, 16) == 0) { + if (all_zero(r->ntpassword.hash, 16)) { return NT_STATUS_OK; } diff --git a/source3/libnet/libnet_samsync_ldif.c b/source3/libnet/libnet_samsync_ldif.c index dafeadea3c7..170231636e0 100644 --- a/source3/libnet/libnet_samsync_ldif.c +++ b/source3/libnet/libnet_samsync_ldif.c @@ -652,13 +652,10 @@ static NTSTATUS fetch_account_info_to_ldif(TALLOC_CTX *mem_ctx, char *flags, *user_rdn; const char *ou; const char* nopasswd = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; - uchar zero_buf[16]; uint32_t rid = 0, group_rid = 0, gidNumber = 0; time_t unix_time; int i, ret; - memset(zero_buf, '\0', sizeof(zero_buf)); - /* Get the username */ fstrcpy(username, r->account_name.string); @@ -703,12 +700,12 @@ static NTSTATUS fetch_account_info_to_ldif(TALLOC_CTX *mem_ctx, fstrcpy(profilepath, r->profile_path.string); /* Get lm and nt password data */ - if (memcmp(r->lmpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->lmpassword.hash, 16)) { pdb_sethexpwd(hex_lm_passwd, r->lmpassword.hash, r->acct_flags); } else { pdb_sethexpwd(hex_lm_passwd, NULL, 0); } - if (memcmp(r->ntpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->ntpassword.hash, 16)) { pdb_sethexpwd(hex_nt_passwd, r->ntpassword.hash, r->acct_flags); } else { pdb_sethexpwd(hex_nt_passwd, NULL, 0); diff --git a/source3/libnet/libnet_samsync_passdb.c b/source3/libnet/libnet_samsync_passdb.c index 01373de0890..9ba637e744c 100644 --- a/source3/libnet/libnet_samsync_passdb.c +++ b/source3/libnet/libnet_samsync_passdb.c @@ -47,9 +47,6 @@ static NTSTATUS sam_account_from_delta(struct samu *account, { const char *old_string, *new_string; time_t unix_time, stored_time; - uchar zero_buf[16]; - - memset(zero_buf, '\0', sizeof(zero_buf)); /* Username, fullname, home dir, dir drive, logon script, acct desc, workstations, profile. */ @@ -217,11 +214,11 @@ static NTSTATUS sam_account_from_delta(struct samu *account, think this channel is secure enough - don't set the passwords at all in that case */ - if (memcmp(r->lmpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->lmpassword.hash, 16)) { pdb_set_lanman_passwd(account, r->lmpassword.hash, PDB_CHANGED); } - if (memcmp(r->ntpassword.hash, zero_buf, 16) != 0) { + if (!all_zero(r->ntpassword.hash, 16)) { pdb_set_nt_passwd(account, r->ntpassword.hash, PDB_CHANGED); }