libnet: Use "all_zero" where appropriate
authorVolker Lendecke <vl@samba.org>
Sat, 31 Dec 2016 12:45:51 +0000 (12:45 +0000)
committerRalph Boehme <slow@samba.org>
Tue, 3 Jan 2017 15:04:28 +0000 (16:04 +0100)
... Saves a few bytes of footprint

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/libnet/libnet_dssync_passdb.c
source3/libnet/libnet_keytab.h
source3/libnet/libnet_samsync_display.c
source3/libnet/libnet_samsync_keytab.c
source3/libnet/libnet_samsync_ldif.c
source3/libnet/libnet_samsync_passdb.c

index 99e65c263adf6bc51a27a0719714c725faed9dc6..8e2a4593373c1dc8e6abfcb97bca3b16e3f68035 100644 (file)
@@ -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);
        }
 
index 43071ce3f876b45e7b3053eeeaa546b5c0c2de49..df6e957dfc4fbfb0ce5254c91dfb2fa789857712 100644 (file)
@@ -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;
index 034a23fe227e340e7cbb1eba998bc59ef65a899f..040742d72acc0db30bbd27207a0d975388b28a8e 100644 (file)
@@ -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);
index 3f7e895928fe34dd88df0860307146ba21d6ef21..5c072b921ad8027c3a1897d281bff7c04a3f8728 100644 (file)
@@ -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;
        }
 
index dafeadea3c7724d1aa399827b79889e69e98570a..170231636e0d0f9aeca0c96d12def14f75dab2a7 100644 (file)
@@ -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);
index 01373de08904302c2c80f01aacd096210a7075ba..9ba637e744cb7d5d1179fd3ef6a29a30661e2556 100644 (file)
@@ -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);
        }