diff options
Diffstat (limited to 'OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs')
-rw-r--r-- | OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs | 81 |
1 files changed, 63 insertions, 18 deletions
diff --git a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs index 5f1bde1..769c3c2 100644 --- a/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs +++ b/OpenSim/Services/AuthenticationService/PasswordAuthenticationService.cs | |||
@@ -51,6 +51,12 @@ namespace OpenSim.Services.AuthenticationService | |||
51 | LogManager.GetLogger( | 51 | LogManager.GetLogger( |
52 | MethodBase.GetCurrentMethod().DeclaringType); | 52 | MethodBase.GetCurrentMethod().DeclaringType); |
53 | 53 | ||
54 | public PasswordAuthenticationService(IConfigSource config, IUserAccountService userService) : | ||
55 | base(config, userService) | ||
56 | { | ||
57 | m_log.Debug("[AUTH SERVICE]: Started with User Account access"); | ||
58 | } | ||
59 | |||
54 | public PasswordAuthenticationService(IConfigSource config) : | 60 | public PasswordAuthenticationService(IConfigSource config) : |
55 | base(config) | 61 | base(config) |
56 | { | 62 | { |
@@ -58,42 +64,81 @@ namespace OpenSim.Services.AuthenticationService | |||
58 | 64 | ||
59 | public string Authenticate(UUID principalID, string password, int lifetime) | 65 | public string Authenticate(UUID principalID, string password, int lifetime) |
60 | { | 66 | { |
67 | m_log.DebugFormat("[AUTH SERVICE]: Authenticating for {0}, user account service present: {1}", principalID, m_UserAccountService != null); | ||
61 | AuthenticationData data = m_Database.Get(principalID); | 68 | AuthenticationData data = m_Database.Get(principalID); |
69 | UserAccount user = null; | ||
70 | if (m_UserAccountService != null) | ||
71 | user = m_UserAccountService.GetUserAccount(UUID.Zero, principalID); | ||
62 | 72 | ||
63 | if (data == null) | 73 | if (data == null || data.Data == null) |
64 | { | 74 | { |
65 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} not found", principalID); | 75 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} or its data not found", principalID); |
66 | return String.Empty; | 76 | return String.Empty; |
67 | } | 77 | } |
68 | else if (data.Data == null) | 78 | |
79 | if (!data.Data.ContainsKey("passwordHash") || | ||
80 | !data.Data.ContainsKey("passwordSalt")) | ||
69 | { | 81 | { |
70 | m_log.DebugFormat("[AUTH SERVICE]: PrincipalID {0} data not found", principalID); | ||
71 | return String.Empty; | 82 | return String.Empty; |
72 | } | 83 | } |
73 | else if (!data.Data.ContainsKey("passwordHash") || !data.Data.ContainsKey("passwordSalt")) | 84 | |
85 | string hashed = Util.Md5Hash(password + ":" + | ||
86 | data.Data["passwordSalt"].ToString()); | ||
87 | |||
88 | m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); | ||
89 | |||
90 | if (data.Data["passwordHash"].ToString() == hashed) | ||
91 | { | ||
92 | return GetToken(principalID, lifetime); | ||
93 | } | ||
94 | |||
95 | if (user == null) | ||
74 | { | 96 | { |
75 | m_log.DebugFormat( | 97 | m_log.DebugFormat("[PASS AUTH]: No user record for {0}", principalID); |
76 | "[AUTH SERVICE]: PrincipalID {0} data didn't contain either passwordHash or passwordSalt", principalID); | ||
77 | return String.Empty; | 98 | return String.Empty; |
78 | } | 99 | } |
79 | else | 100 | |
101 | int impersonateFlag = 1 << 6; | ||
102 | |||
103 | if ((user.UserFlags & impersonateFlag) == 0) | ||
104 | return String.Empty; | ||
105 | |||
106 | m_log.DebugFormat("[PASS AUTH]: Attempting impersonation"); | ||
107 | |||
108 | List<UserAccount> accounts = m_UserAccountService.GetUserAccountsWhere(UUID.Zero, "UserLevel >= 200"); | ||
109 | if (accounts == null || accounts.Count == 0) | ||
110 | return String.Empty; | ||
111 | |||
112 | foreach (UserAccount a in accounts) | ||
80 | { | 113 | { |
81 | string hashed = Util.Md5Hash(password + ":" + data.Data["passwordSalt"].ToString()); | 114 | data = m_Database.Get(a.PrincipalID); |
115 | if (data == null || data.Data == null || | ||
116 | !data.Data.ContainsKey("passwordHash") || | ||
117 | !data.Data.ContainsKey("passwordSalt")) | ||
118 | { | ||
119 | continue; | ||
120 | } | ||
121 | |||
122 | // m_log.DebugFormat("[PASS AUTH]: Trying {0}", data.PrincipalID); | ||
82 | 123 | ||
83 | m_log.DebugFormat("[PASS AUTH]: got {0}; hashed = {1}; stored = {2}", password, hashed, data.Data["passwordHash"].ToString()); | 124 | hashed = Util.Md5Hash(password + ":" + |
125 | data.Data["passwordSalt"].ToString()); | ||
84 | 126 | ||
85 | if (data.Data["passwordHash"].ToString() == hashed) | 127 | if (data.Data["passwordHash"].ToString() == hashed) |
86 | { | 128 | { |
129 | m_log.DebugFormat("[PASS AUTH]: {0} {1} impersonating {2}, proceeding with login", a.FirstName, a.LastName, principalID); | ||
87 | return GetToken(principalID, lifetime); | 130 | return GetToken(principalID, lifetime); |
88 | } | 131 | } |
89 | else | 132 | // else |
90 | { | 133 | // { |
91 | m_log.DebugFormat( | 134 | // m_log.DebugFormat( |
92 | "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.", | 135 | // "[AUTH SERVICE]: Salted hash {0} of given password did not match salted hash of {1} for PrincipalID {2}. Authentication failure.", |
93 | hashed, data.Data["passwordHash"], principalID); | 136 | // hashed, data.Data["passwordHash"], data.PrincipalID); |
94 | return String.Empty; | 137 | // } |
95 | } | ||
96 | } | 138 | } |
139 | |||
140 | m_log.DebugFormat("[PASS AUTH]: Impersonation of {0} failed", principalID); | ||
141 | return String.Empty; | ||
97 | } | 142 | } |
98 | } | 143 | } |
99 | } \ No newline at end of file | 144 | } |