nmblookup: Return if the lookup was successful or not.
[obnox/samba/samba-obnox.git] / source3 / passdb / machine_account_secrets.c
index 5758efe819c548e52ddc6d6d5817d905b8ce07d0..37ee9bcc4c4f6d6ad33ec3a66e50b8096f0bc4bb 100644 (file)
@@ -29,6 +29,7 @@
 #include "dbwrap/dbwrap.h"
 #include "../librpc/ndr/libndr.h"
 #include "util_tdb.h"
+#include "libcli/security/security.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_PASSDB
@@ -106,9 +107,12 @@ bool secrets_store_domain_sid(const char *domain, const struct dom_sid  *sid)
 
        ret = secrets_store(domain_sid_keystr(domain), sid, sizeof(struct dom_sid ));
 
-       /* Force a re-query, in case we modified our domain */
-       if (ret)
-               reset_global_sam_sid();
+       /* Force a re-query, in the case where we modified our domain */
+       if (ret) {
+               if (dom_sid_equal(get_global_sam_sid(), sid) == false) {
+                       reset_global_sam_sid();
+               }
+       }
        return ret;
 }
 
@@ -478,11 +482,13 @@ bool secrets_store_machine_pw_sync(const char *pass, const char *oldpass, const
                                   const char *realm,
                                   const char *salting_principal, uint32_t supported_enc_types,
                                   const struct dom_sid *domain_sid, uint32_t last_change_time,
+                                  uint32_t secure_channel_type,
                                   bool delete_join)
 {
        bool ret;
        uint8_t last_change_time_store[4];
        TALLOC_CTX *frame = talloc_stackframe();
+       uint8_t sec_channel_bytes[4];
        void *value;
 
        if (delete_join) {
@@ -512,13 +518,23 @@ bool secrets_store_machine_pw_sync(const char *pass, const char *oldpass, const
                return ret;
        }
 
-       /* We delete this and instead have the read code fall back to
-        * a default based on server role, as our caller can't specify
-        * this with any more certainty */
-       value = secrets_fetch(machine_sec_channel_type_keystr(domain), NULL);
-       if (value) {
-               SAFE_FREE(value);
-               ret = secrets_delete(machine_sec_channel_type_keystr(domain));
+       if (secure_channel_type == 0) {
+               /* We delete this and instead have the read code fall back to
+                * a default based on server role, as our caller can't specify
+                * this with any more certainty */
+               value = secrets_fetch(machine_sec_channel_type_keystr(domain), NULL);
+               if (value) {
+                       SAFE_FREE(value);
+                       ret = secrets_delete(machine_sec_channel_type_keystr(domain));
+                       if (!ret) {
+                               TALLOC_FREE(frame);
+                               return ret;
+                       }
+               }
+       } else {
+               SIVAL(&sec_channel_bytes, 0, secure_channel_type);
+               ret = secrets_store(machine_sec_channel_type_keystr(domain), 
+                                   &sec_channel_bytes, sizeof(sec_channel_bytes));
                if (!ret) {
                        TALLOC_FREE(frame);
                        return ret;