~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/libsmb/passchange.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 Change a password on a remote machine using IPC calls.
25
25
*************************************************************/
26
26
 
27
 
BOOL remote_password_change(const char *remote_machine, const char *user_name, 
 
27
NTSTATUS remote_password_change(const char *remote_machine, const char *user_name, 
28
28
                            const char *old_passwd, const char *new_passwd,
29
29
                            char *err_str, size_t err_str_len)
30
30
{
41
41
        if(!resolve_name( remote_machine, &ip, 0x20)) {
42
42
                slprintf(err_str, err_str_len-1, "unable to find an IP address for machine %s.\n",
43
43
                        remote_machine );
44
 
                return False;
 
44
                return NT_STATUS_UNSUCCESSFUL;
45
45
        }
46
46
 
47
47
        ZERO_STRUCT(cli);
49
49
        if (!cli_initialise(&cli) || !cli_connect(&cli, remote_machine, &ip)) {
50
50
                slprintf(err_str, err_str_len-1, "unable to connect to SMB server on machine %s. Error was : %s.\n",
51
51
                        remote_machine, cli_errstr(&cli) );
52
 
                return False;
 
52
                return NT_STATUS_UNSUCCESSFUL;
53
53
        }
54
54
  
55
55
        make_nmb_name(&calling, global_myname() , 0x0);
59
59
                slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",
60
60
                        remote_machine, cli_errstr(&cli) );
61
61
                cli_shutdown(&cli);
62
 
                return False;
 
62
                return NT_STATUS_UNSUCCESSFUL;
63
63
        }
64
64
  
65
65
        cli.protocol = PROTOCOL_NT1;
67
67
        if (!cli_negprot(&cli)) {
68
68
                slprintf(err_str, err_str_len-1, "machine %s rejected the negotiate protocol. Error was : %s.\n",        
69
69
                        remote_machine, cli_errstr(&cli) );
 
70
                result = cli_nt_error(&cli);
70
71
                cli_shutdown(&cli);
71
 
                return False;
 
72
                return result;
72
73
        }
73
74
  
74
75
        /* Given things like SMB signing, restrict anonymous and the like, 
79
80
 
80
81
                if (!NT_STATUS_IS_OK(result)) {
81
82
 
82
 
                        /* Password must change is the only valid error
83
 
                         * condition here from where we can proceed, the rest
84
 
                         * like account locked out or logon failure will lead
85
 
                         * to errors later anyway */
86
 
 
87
 
                        if (!NT_STATUS_EQUAL(result,
88
 
                                             NT_STATUS_PASSWORD_MUST_CHANGE)) {
 
83
                        /* Password must change or Password expired are the only valid
 
84
                         * error conditions here from where we can proceed, the rest like
 
85
                         * account locked out or logon failure will lead to errors later
 
86
                         * anyway */
 
87
 
 
88
                        if (!NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) &&
 
89
                            !NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED)) {
 
90
 
89
91
                                slprintf(err_str, err_str_len-1, "Could not "
90
92
                                         "connect to machine %s: %s\n",
91
93
                                         remote_machine, cli_errstr(&cli));
92
94
                                cli_shutdown(&cli);
93
 
                                return False;
 
95
                                return result;
94
96
                        }
95
97
 
96
98
                        pass_must_change = True;
105
107
                if (!cli_session_setup(&cli, "", "", 0, "", 0, "")) {
106
108
                        slprintf(err_str, err_str_len-1, "machine %s rejected the session setup. Error was : %s.\n",        
107
109
                                 remote_machine, cli_errstr(&cli) );
 
110
                        result = cli_nt_error(&cli);
108
111
                        cli_shutdown(&cli);
109
 
                        return False;
 
112
                        return result;
110
113
                }
111
114
 
112
115
                cli_init_creds(&cli, "", "", NULL);
117
120
        if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) {
118
121
                slprintf(err_str, err_str_len-1, "machine %s rejected the tconX on the IPC$ share. Error was : %s.\n",
119
122
                        remote_machine, cli_errstr(&cli) );
 
123
                result = cli_nt_error(&cli);
120
124
                cli_shutdown(&cli);
121
 
                return False;
 
125
                return result;
122
126
        }
123
127
 
124
128
        /* Try not to give the password away too easily */
149
153
                        if (!cli_oem_change_password(&cli, user_name, new_passwd, old_passwd)) {
150
154
                                slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
151
155
                                         remote_machine, cli_errstr(&cli) );
 
156
                                result = cli_nt_error(&cli);
152
157
                                cli_shutdown(&cli);
153
 
                                return False;
 
158
                                return result;
154
159
                        }
155
160
                } else {
156
161
                        slprintf(err_str, err_str_len-1,
157
162
                                "SAMR connection to machine %s failed. Error was %s, "
158
163
                                "but LANMAN password changed are disabled\n",
159
164
                                nt_errstr(result), remote_machine);
 
165
                        result = cli_nt_error(&cli);
160
166
                        cli_shutdown(&cli);
161
 
                        return False;
 
167
                        return result;
162
168
                }
163
169
        }
164
170
 
166
172
                                                             new_passwd, old_passwd))) {
167
173
                /* Great - it all worked! */
168
174
                cli_shutdown(&cli);
169
 
                return True;
 
175
                return NT_STATUS_OK;
170
176
 
171
177
        } else if (!(NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) 
172
178
                     || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) {
175
181
                slprintf(err_str, err_str_len-1, "machine %s rejected the password change: Error was : %s.\n",
176
182
                         remote_machine, get_friendly_nt_error_msg(result));
177
183
                cli_shutdown(&cli);
178
 
                return False;
 
184
                return result;
179
185
        }
180
186
 
181
187
        /* OK, that failed, so try again... */
197
203
                                                old_passwd)))) {
198
204
                /* Great - it all worked! */
199
205
                cli_shutdown(&cli);
200
 
                return True;
 
206
                return NT_STATUS_OK;
201
207
        } else {
202
208
                if (!(NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) 
203
209
                      || NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) {
207
213
                                 "machine %s rejected the (anonymous) password change: Error was : %s.\n",
208
214
                                 remote_machine, get_friendly_nt_error_msg(result));
209
215
                        cli_shutdown(&cli);
210
 
                        return False;
 
216
                        return result;
211
217
                }
212
218
                
213
219
                /* We have failed to change the user's password, and we think the server
219
225
                                /* SAMR failed, but the old LanMan protocol worked! */
220
226
 
221
227
                                cli_shutdown(&cli);
222
 
                                return True;
 
228
                                return NT_STATUS_OK;
223
229
                        }
224
230
                        slprintf(err_str, err_str_len-1, 
225
231
                                 "machine %s rejected the password change: Error was : %s.\n",
226
232
                                 remote_machine, cli_errstr(&cli) );
 
233
                        result = cli_nt_error(&cli);
227
234
                        cli_shutdown(&cli);
228
 
                        return False;
 
235
                        return result;
229
236
                } else {
230
237
                        slprintf(err_str, err_str_len-1,
231
238
                                "SAMR connection to machine %s failed. Error was %s, "
232
239
                                "but LANMAN password changed are disabled\n",
233
240
                                nt_errstr(result), remote_machine);
234
241
                        cli_shutdown(&cli);
235
 
                        return False;
 
242
                        return NT_STATUS_UNSUCCESSFUL;
236
243
                }
237
244
        }
238
245
}