RIP BOOL. Convert BOOL -> bool. I found a few interesting
[samba.git] / source3 / libsmb / passchange.c
index 0d3dcf4d75517ab4386ece05aa46a61c9f6bf4b6..83cfc3efbfb354bc8ad1990f570d76350fc71f3f 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,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"
@@ -34,12 +33,12 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
        struct in_addr ip;
 
        NTSTATUS result;
-       BOOL pass_must_change = False;
+       bool pass_must_change = False;
 
        *err_str = '\0';
 
        if(!resolve_name( remote_machine, &ip, 0x20)) {
-               slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
+               slprintf(err_str, err_str_len-1, "Unable to find an IP address for machine %s.\n",
                        remote_machine );
                return NT_STATUS_UNSUCCESSFUL;
        }
@@ -49,10 +48,10 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (!cli_connect(cli, remote_machine, &ip)) {
-               slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
-                       remote_machine, cli_errstr(cli) );
-               result = cli_nt_error(cli);
+       result = cli_connect(cli, remote_machine, &ip);
+       if (!NT_STATUS_IS_OK(result)) {
+               slprintf(err_str, err_str_len-1, "Unable to connect to SMB server on machine %s. Error was : %s.\n",
+                       remote_machine, nt_errstr(result) );
                cli_shutdown(cli);
                return result;
        }
@@ -80,39 +79,39 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
   
        /* Given things like SMB signing, restrict anonymous and the like, 
           try an authenticated connection first */
-       if (!cli_session_setup(cli, user_name, old_passwd, strlen(old_passwd)+1, old_passwd, strlen(old_passwd)+1, "")) {
-
-               result = cli_nt_error(cli);
-
-               if (!NT_STATUS_IS_OK(result)) {
-
-                       /* Password must change is the only valid error
-                        * condition here from where we can proceed, the rest
-                        * like account locked out or logon failure will lead
-                        * to errors later anyway */
-
-                       if (!NT_STATUS_EQUAL(result,
-                                            NT_STATUS_PASSWORD_MUST_CHANGE)) {
-                               slprintf(err_str, err_str_len-1, "Could not "
-                                        "connect to machine %s: %s\n",
-                                        remote_machine, cli_errstr(cli));
-                               cli_shutdown(cli);
-                               return result;
-                       }
-
-                       pass_must_change = True;
+       result = cli_session_setup(cli, user_name,
+                                  old_passwd, strlen(old_passwd)+1,
+                                  old_passwd, strlen(old_passwd)+1, "");
+
+       if (!NT_STATUS_IS_OK(result)) {
+
+               /* Password must change or Password expired are the only valid
+                * error conditions here from where we can proceed, the rest like
+                * account locked out or logon failure will lead to errors later
+                * anyway */
+
+               if (!NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) &&
+                   !NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED)) {
+                       slprintf(err_str, err_str_len-1, "Could not "
+                                "connect to machine %s: %s\n",
+                                remote_machine, cli_errstr(cli));
+                       cli_shutdown(cli);
+                       return result;
                }
 
+               pass_must_change = True;
+
                /*
                 * We should connect as the anonymous user here, in case
                 * the server has "must change password" checked...
                 * Thanks to <Nicholas.S.Jenkins@cdc.com> for this fix.
                 */
 
-               if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
+               result = cli_session_setup(cli, "", "", 0, "", 0, "");
+
+               if (!NT_STATUS_IS_OK(result)) {
                        slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",        
                                 remote_machine, cli_errstr(cli) );
-                       result = cli_nt_error(cli);
                        cli_shutdown(cli);
                        return result;
                }