Restore 3.0 behaviour with empty /etc/hosts
[gd/samba/.git] / source3 / libsmb / ntlmssp.c
index 73680709859caddf58c1f5d3b0de285f0ac966de..7082ea7e4e782d392748e350ee31141cf247f706 100644 (file)
@@ -9,7 +9,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -122,7 +121,7 @@ static const uint8 *get_challenge(const struct ntlmssp_state *ntlmssp_state)
  *
  */
    
-static BOOL may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
+static bool may_set_challenge(const struct ntlmssp_state *ntlmssp_state)
 {
        return True;
 }
@@ -401,7 +400,7 @@ static const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
 }
 
 static void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
-                                     uint32 neg_flags, BOOL allow_lm) {
+                                     uint32 neg_flags, bool allow_lm) {
        if (neg_flags & NTLMSSP_NEGOTIATE_UNICODE) {
                ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_UNICODE;
                ntlmssp_state->neg_flags &= ~NTLMSSP_NEGOTIATE_OEM;
@@ -502,18 +501,19 @@ DATA_BLOB ntlmssp_weaken_keys(NTLMSSP_STATE *ntlmssp_state, TALLOC_CTX *mem_ctx)
 
 /**
  * Next state function for the Negotiate packet
- * 
+ *
  * @param ntlmssp_state NTLMSSP State
  * @param request The request, as a DATA_BLOB
  * @param request The reply, as an allocated DATA_BLOB, caller to free.
- * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent. 
+ * @return Errors or MORE_PROCESSING_REQUIRED if a reply is sent.
  */
 
 static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
                                         const DATA_BLOB request, DATA_BLOB *reply) 
 {
        DATA_BLOB struct_blob;
-       fstring dnsname, dnsdomname;
+       const char *dnsname;
+       char *dnsdomname = NULL;
        uint32 neg_flags = 0;
        uint32 ntlmssp_command, chal_flags;
        const uint8 *cryptkey;
@@ -536,7 +536,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
                }
                debug_ntlmssp_flags(neg_flags);
        }
-       
+
        ntlmssp_handle_neg_flags(ntlmssp_state, neg_flags, lp_lanman_auth());
 
        /* Ask our caller what challenge they would like in the packet */
@@ -549,31 +549,37 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
 
        /* The flags we send back are not just the negotiated flags,
         * they are also 'what is in this packet'.  Therfore, we
-        * operate on 'chal_flags' from here on 
+        * operate on 'chal_flags' from here on
         */
 
        chal_flags = ntlmssp_state->neg_flags;
 
        /* get the right name to fill in as 'target' */
-       target_name = ntlmssp_target_name(ntlmssp_state, 
-                                         neg_flags, &chal_flags); 
-       if (target_name == NULL) 
+       target_name = ntlmssp_target_name(ntlmssp_state,
+                                         neg_flags, &chal_flags);
+       if (target_name == NULL)
                return NT_STATUS_INVALID_PARAMETER;
 
        ntlmssp_state->chal = data_blob_talloc(ntlmssp_state->mem_ctx, cryptkey, 8);
        ntlmssp_state->internal_chal = data_blob_talloc(ntlmssp_state->mem_ctx, cryptkey, 8);
-       
 
        /* This should be a 'netbios domain -> DNS domain' mapping */
-       dnsdomname[0] = '\0';
-       get_mydnsdomname(dnsdomname);
+       dnsdomname = get_mydnsdomname(ntlmssp_state->mem_ctx);
+       if (!dnsdomname) {
+               dnsdomname = talloc_strdup(ntlmssp_state->mem_ctx, "");
+       }
+       if (!dnsdomname) {
+               return NT_STATUS_NO_MEMORY;
+       }
        strlower_m(dnsdomname);
-       
-       dnsname[0] = '\0';
-       get_mydnsfullname(dnsname);
-       
+
+       dnsname = get_mydnsfullname();
+       if (!dnsname) {
+               dnsname = "";
+       }
+
        /* This creates the 'blob' of names that appears at the end of the packet */
-       if (chal_flags & NTLMSSP_CHAL_TARGET_INFO) 
+       if (chal_flags & NTLMSSP_CHAL_TARGET_INFO)
        {
                msrpc_gen(&struct_blob, "aaaaa",
                          NTLMSSP_NAME_TYPE_DOMAIN, target_name,
@@ -593,9 +599,9 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
                } else {
                        gen_string = "CdAdbddB";
                }
-               
+
                msrpc_gen(reply, gen_string,
-                         "NTLMSSP", 
+                         "NTLMSSP",
                          NTLMSSP_CHALLENGE,
                          target_name,
                          chal_flags,
@@ -603,7 +609,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
                          0, 0,
                          struct_blob.data, struct_blob.length);
        }
-               
+
        data_blob_free(&struct_blob);
 
        ntlmssp_state->expected_state = NTLMSSP_AUTH;
@@ -613,7 +619,7 @@ static NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
 
 /**
  * Next state function for the Authenticate packet
- * 
+ *
  * @param ntlmssp_state NTLMSSP State
  * @param request The request, as a DATA_BLOB
  * @param request The reply, as an allocated DATA_BLOB, caller to free.
@@ -631,7 +637,7 @@ static NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
        NTSTATUS nt_status = NT_STATUS_OK;
 
        /* used by NTLM2 */
-       BOOL doing_ntlm2 = False;
+       bool doing_ntlm2 = False;
 
        uchar session_nonce[16];
        uchar session_nonce_hash[16];
@@ -820,7 +826,8 @@ static NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
                                                          session_key.data);
                                DEBUG(10,("ntlmssp_server_auth: Created NTLM session key.\n"));
                        } else {
-                               static const uint8 zeros[24] = { 0, };
+                               uint8 zeros[24];
+                               ZERO_STRUCT(zeros);
                                session_key = data_blob_talloc(
                                        ntlmssp_state->mem_ctx, NULL, 16);
                                if (session_key.data == NULL) {
@@ -1063,9 +1070,11 @@ static NTSTATUS ntlmssp_client_challenge(struct ntlmssp_state *ntlmssp_state,
        }
 
        if (!ntlmssp_state->nt_hash || !ntlmssp_state->lm_hash) {
-               static const uchar zeros[16] = { 0, };
+               uchar zeros[16];
                /* do nothing - blobs are zero length */
 
+               ZERO_STRUCT(zeros);
+
                /* session key is all zeros */
                session_key = data_blob_talloc(ntlmssp_state->mem_ctx, zeros, 16);