0001-Bug-2503-Improve-setting-of-password-auth_driver.patch

patch - Jens Hoffmann, 12/11/2013 11:02 PM

Download (4.33 KB)

View differences:

include/User.h
21 21
#include "UserTemplate.h"
22 22
#include "Quotas.h"
23 23
#include "ObjectCollection.h"
24
#include "NebulaUtil.h"
24 25

  
25 26
using namespace std;
26 27

  
......
110 111
     *    @param error_str Returns the error reason, if any
111 112
     *    @returns -1 if the password is not valid
112 113
     */
113
    int set_password(const string& passwd, string& error_str)
114
    {
115
        int rc = 0;
116

  
117
        if (pass_is_valid(passwd, error_str))
118
        {
119
            password = passwd;
120
            invalidate_session();
121
        }
122
        else
123
        {
124
            rc = -1;
125
        }
126

  
127
        return rc;
128
    };
114
    int set_password(const string& passwd, string& error_str);
129 115

  
130 116
    /**
131 117
     *  Returns user password
src/rm/RequestManagerUser.cc
15 15
/* -------------------------------------------------------------------------- */
16 16

  
17 17
#include "RequestManagerUser.h"
18
#include "NebulaUtil.h"
19 18

  
20 19
using namespace std;
21 20

  
......
70 69
        return -1;
71 70
    }
72 71

  
73
    if (user->get_auth_driver() == UserPool::CORE_AUTH)
74
    {
75
        new_pass = one_util::sha1_digest(new_pass);
76
    }
77

  
78 72
    int rc = user->set_password(new_pass, error_str);
79 73

  
80 74
    if ( rc == 0 )
......
125 119
        return -1;
126 120
    }
127 121

  
128
    if ( !new_pass.empty() )
129
    {
130
        if ( new_auth == UserPool::CORE_AUTH)
131
        {
132
            new_pass = one_util::sha1_digest(new_pass);
133
        }
122
    rc = user->set_auth_driver(new_auth, error_str);
134 123

  
135
        // The password may be invalid, try to change it first
136
        rc = user->set_password(new_pass, error_str);
137
    }
138

  
139
    if ( rc == 0 )
124
    if ( rc == 0 && !new_pass.empty() )
140 125
    {
141
        rc = user->set_auth_driver(new_auth, error_str);
126
        rc = user->set_password(new_pass, error_str);
142 127
    }
143 128

  
144 129
    if ( rc == 0 )
src/um/User.cc
273 273
/* -------------------------------------------------------------------------- */
274 274
/* -------------------------------------------------------------------------- */
275 275

  
276
int User::set_password(const string& passwd, string& error_str)
277
{
278
    int rc = 0;
279

  
280
    if (pass_is_valid(passwd, error_str))
281
    {
282
        if (auth_driver == UserPool::CORE_AUTH)
283
        {
284
            password = one_util::sha1_digest(passwd);
285
        }
286
        else
287
        {
288
            password = passwd;
289
        }
290

  
291
        invalidate_session();
292
    }
293
    else
294
    {
295
        rc = -1;
296
    }
297

  
298
    return rc;
299
};
300

  
301

  
276 302
bool User::pass_is_valid(const string& pass, string& error_str)
277 303
{
278 304
    if ( pass.empty() )
279
-