forked from ibv/LDAP-Admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassDlg.pas
125 lines (110 loc) · 3.74 KB
/
PassDlg.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{ LDAPAdmin - Passdlg.pas
* Copyright (C) 2003-2013 Tihomir Karlovic
*
* Author: Tihomir Karlovic
*
*
* This file 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
* (at your option) any later version.
*
* This file is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
}
unit PassDlg;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType,
{$ENDIF}
SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, Buttons,
LDAPClasses, Password, Samba, ExtCtrls;
const
sUserPassword = 'userPassword';
type
TPasswordDlg = class(TForm)
Label1: TLabel;
Password: TEdit;
OKBtn: TButton;
CancelBtn: TButton;
Password2: TEdit;
Label2: TLabel;
cbMethod: TComboBox;
lbMethod: TLabel;
cbSambaPassword: TCheckBox;
cbPosixPassword: TCheckBox;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure cbPosixPasswordClick(Sender: TObject);
private
fEntry: TLdapEntry;
fSamba: TSamba3Account;
fPasswordAttribute: string;
fDefaultHashType: Integer;
public
constructor Create(AOwner: TComponent; Entry: TLdapEntry; const AttributeName: string = sUserPassword); reintroduce;
end;
var
PasswordDlg: TPasswordDlg;
implementation
{$R *.dfm}
uses Config, Constant, Connection;
constructor TPasswordDlg.Create(AOwner: TComponent; Entry: TLdapEntry; const AttributeName: string = sUserPassword);
begin
inherited Create(AOwner);
if Entry.Attributes.Count <= 1 then
Entry.Read;
fPasswordAttribute := AttributeName;
fDefaultHashType := (Entry.Session as TConnection).Account.ReadInteger(rPosixPwdHashType, Integer(chSha1));
if (fDefaultHashType < 0) or (fDefaultHashType >= cbMethod.Items.Count) then
fDefaultHashType := Integer(chSha1);
cbMethod.ItemIndex := fDefaultHashType;
fEntry := Entry;
if (AnsiCompareText(AttributeName, sUserPassword) = 0) and
(Entry.AttributesByName['objectclass'].IndexOf('sambasamaccount') <> -1) then
begin
cbPosixPassword.Visible := true;
cbSambaPassword.Visible := true;
end
else
cbSambaPassword.Checked := false;
end;
procedure TPasswordDlg.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if (ModalResult = mrOk) then
begin
if Password.Text <> Password2.Text then
raise Exception.Create(stPassDiff);
if cbSambaPassword.Checked then
begin
fSamba := TSamba3Account.Create(fEntry);
try
if (fEntry.Session as TConnection).Account.ReadBool(rSambaLMPasswords) then
fSamba.LMPasswords := true;
fSamba.SetUserPassword(Password.Text);
finally
fSamba.Free;
end;
end;
if cbPosixPassword.Checked then
fEntry.AttributesByName[fPasswordAttribute].AsString := GetPasswordString(THashType(cbMethod.ItemIndex), Password.Text);
if fDefaultHashType <> cbMethod.ItemIndex then
(fEntry.Session as TConnection).Account.WriteInteger(rPosixPwdHashType, cbMethod.ItemIndex);
end;
end;
procedure TPasswordDlg.cbPosixPasswordClick(Sender: TObject);
begin
cbMethod.Enabled := cbPosixPassword.Checked;
end;
end.