Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header.
[samba.git] / source3 / rpc_client / cli_netlogon.c
index 18266739ac8e52f6f442a6fdbf95f393d56a25a8..f67a7175bf13e8dc701cb9f722c5130fca8181d7 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "includes.h"
 
-extern int DEBUGLEVEL;
 extern pstring global_myname;
 extern fstring global_myworkgroup;
 
@@ -57,7 +56,7 @@ static void gen_next_creds( struct cli_state *cli, DOM_CRED *new_clnt_cred)
 /****************************************************************************
 do a LSA Logon Control2
 ****************************************************************************/
-BOOL cli_net_logon_ctrl2(struct cli_state *cli, uint32 status_level)
+BOOL cli_net_logon_ctrl2(struct cli_state *cli, NTSTATUS status_level)
 {
   prs_struct rbuf;
   prs_struct buf; 
@@ -118,13 +117,14 @@ Ensure that the server credential returned matches the session key
 encrypt of the server challenge originally received. JRA.
 ****************************************************************************/
 
-BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan, 
-                   uint32 neg_flags, DOM_CHAL *srv_chal)
+NTSTATUS cli_net_auth2(struct cli_state *cli, uint16 sec_chan, 
+                       uint32 neg_flags, DOM_CHAL *srv_chal)
 {
   prs_struct rbuf;
   prs_struct buf; 
   NET_Q_AUTH_2 q_a;
   BOOL ok = False;
+  NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
   prs_init(&buf , 1024, cli->mem_ctx, MARSHALL);
   prs_init(&rbuf, 0,    cli->mem_ctx, UNMARSHALL);
@@ -144,7 +144,7 @@ BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan,
     DEBUG(0,("cli_net_auth2: Error : failed to marshall NET_Q_AUTH_2 struct.\n"));
     prs_mem_free(&buf);
     prs_mem_free(&rbuf);
-    return False;
+    return result;
   }
 
   /* send the data on \PIPE\ */
@@ -153,11 +153,12 @@ BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan,
     NET_R_AUTH_2 r_a;
 
     ok = net_io_r_auth_2("", &r_a, &rbuf, 0);
-               
-    if (ok && r_a.status != 0)
+    result = r_a.status;
+
+    if (ok && !NT_STATUS_IS_OK(result))
     {
       /* report error code */
-      DEBUG(0,("cli_net_auth2: Error %s\n", get_nt_error_msg(r_a.status)));
+      DEBUG(0,("cli_net_auth2: Error %s\n", get_nt_error_msg(result)));
       ok = False;
     }
 
@@ -200,7 +201,7 @@ password ?).\n", cli->desthost ));
   prs_mem_free(&buf);
   prs_mem_free(&rbuf);
 
-  return ok;
+  return result;
 }
 
 /****************************************************************************
@@ -243,7 +244,7 @@ BOOL cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal, DOM_CHAL *srv_
 
     ok = net_io_r_req_chal("", &r_c, &rbuf, 0);
                
-    if (ok && r_c.status != 0)
+    if (ok && !NT_STATUS_IS_OK(r_c.status))
     {
       /* report error code */
       DEBUG(0,("cli_net_req_chal: Error %s\n", get_nt_error_msg(r_c.status)));
@@ -308,7 +309,7 @@ BOOL cli_net_srv_pwset(struct cli_state *cli, uint8 hashed_mach_pwd[16])
 
     ok = net_io_r_srv_pwset("", &r_s, &rbuf, 0);
                
-    if (ok && r_s.status != 0)
+    if (ok && !NT_STATUS_IS_OK(r_s.status))
     {
       /* report error code */
       DEBUG(0,("cli_net_srv_pwset: %s\n", get_nt_error_msg(r_s.status)));
@@ -338,8 +339,9 @@ password ?).\n", cli->desthost ));
  returns level 3.
 ****************************************************************************/
 
-static uint32 cli_net_sam_logon_internal(struct cli_state *cli, NET_ID_INFO_CTR *ctr, 
-                       NET_USER_INFO_3 *user_info3, uint16 validation_level)
+static NTSTATUS cli_net_sam_logon_internal(struct cli_state *cli, NET_ID_INFO_CTR *ctr, 
+                                          NET_USER_INFO_3 *user_info3, 
+                                          uint16 validation_level)
 {
        DOM_CRED new_clnt_cred;
        DOM_CRED dummy_rtn_creds;
@@ -347,7 +349,7 @@ static uint32 cli_net_sam_logon_internal(struct cli_state *cli, NET_ID_INFO_CTR
        prs_struct buf; 
        NET_Q_SAM_LOGON q_s;
        NET_R_SAM_LOGON r_s;
-       uint32 retval = 0;
+       NTSTATUS retval = NT_STATUS_OK;
 
        gen_next_creds( cli, &new_clnt_cred);
 
@@ -398,38 +400,38 @@ static uint32 cli_net_sam_logon_internal(struct cli_state *cli, NET_ID_INFO_CTR
         * the call.
         */
        
-       if (retval == NT_STATUS_INVALID_INFO_CLASS) {
+       if (NT_STATUS_V(retval) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) {
                goto out;
        }
 
-       if (retval != 0) {
+       if (!NT_STATUS_IS_OK(retval)) {
                /* report error code */
                DEBUG(0,("cli_net_sam_logon_internal: %s\n", get_nt_error_msg(r_s.status)));
                goto out;
-    }
+       }
 
-    /* Update the credentials. */
-    if (!clnt_deal_with_creds(cli->sess_key, &cli->clnt_cred, &r_s.srv_creds)) {
+       /* Update the credentials. */
+       if (!clnt_deal_with_creds(cli->sess_key, &cli->clnt_cred, &r_s.srv_creds)) {
                /*
                 * Server replied with bad credential. Fail.
                 */
                DEBUG(0,("cli_net_sam_logon_internal: server %s replied with bad credential (bad machine \
 password ?).\n", cli->desthost ));
                retval = NT_STATUS_WRONG_PASSWORD;
-    }
-
-    if (r_s.switch_value != validation_level) {
+       }
+       
+       if (r_s.switch_value != validation_level) {
                /* report different switch_value */
                DEBUG(0,("cli_net_sam_logon: switch_value of %x expected %x\n", (unsigned int)validation_level,
-                                       (unsigned int)r_s.switch_value));
+                        (unsigned int)r_s.switch_value));
                retval = NT_STATUS_INVALID_PARAMETER;
-    }
+       }
 
-  out:
+out:
 
        prs_mem_free(&buf);
        prs_mem_free(&rbuf);
-
+       
        return retval;
 }
 
@@ -437,18 +439,18 @@ password ?).\n", cli->desthost ));
 LSA SAM Logon - interactive or network.
 ****************************************************************************/
 
-BOOL cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3)
+NTSTATUS cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, 
+                         NET_USER_INFO_3 *user_info3)
 {
-       BOOL ok = True;
        uint16 validation_level=3;
-       uint32 ret_err_code;
+       NTSTATUS result;
 
-       ret_err_code = cli_net_sam_logon_internal(cli, ctr, user_info3, validation_level);
+       result = cli_net_sam_logon_internal(cli, ctr, user_info3, 
+                                            validation_level);
 
-       if(ret_err_code == NT_STATUS_NOPROBLEMO) {
+       if (NT_STATUS_IS_OK(result)) {
                DEBUG(10,("cli_net_sam_logon: Success \n"));
-               ok = True;
-       } else if (ret_err_code == NT_STATUS_INVALID_INFO_CLASS) {
+       } else if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_INVALID_INFO_CLASS)) {
                DEBUG(10,("cli_net_sam_logon: STATUS INVALID INFO CLASS \n"));
 
                validation_level=2;
@@ -458,15 +460,13 @@ BOOL cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, NET_USER_INF
                 * for the error. If its error, return False. 
                 */
 
-               if(cli_net_sam_logon_internal(cli, ctr, user_info3, validation_level) != 0)
-                       ok = False;
-
+               result = cli_net_sam_logon_internal(cli, ctr, user_info3,
+                                                    validation_level);
        } else {
                DEBUG(10,("cli_net_sam_logon: Error\n"));
-               ok = False;
        }
 
-       return ok;
+       return result;
 }
 
 /***************************************************************************
@@ -520,7 +520,7 @@ BOOL cli_net_sam_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr)
 
     ok = net_io_r_sam_logoff("", &r_s, &rbuf, 0);
                
-    if (ok && r_s.status != 0)
+    if (ok && !NT_STATUS_IS_OK(r_s.status))
     {
       /* report error code */
       DEBUG(0,("cli_net_sam_logoff: %s\n", get_nt_error_msg(r_s.status)));