~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to packages/extra/users/users.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2005-05-30 11:59:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050530115910-x5pbzm4qqta4i94h
Tags: 2.0.0-2
debian/fp-compiler.postinst.in: forgot to reapply the patch that
correctly creates the slave link to pc(1).  (Closes: #310907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
  EUserLookupError = Class(Exception);
9
9
  EGroupLookupError = Class(Exception);
10
10
  EShadowLookupError = Class(Exception);
11
 
  
12
 
{ User functions }  
13
 
  
 
11
 
 
12
{ User functions }
 
13
 
14
14
Function  getpwnam(Const UserName: String) : PPasswordRecord;
15
15
Procedure GetUserData(Const UserName : String; Var Data : TPasswordRecord); overload;
16
16
Procedure GetUserData(Uid : Integer; Var Data : TPasswordRecord); overload;
22
22
Procedure GetUserList(List : Tstrings);overload;
23
23
Procedure GetUserList(List : TStrings; WithIDs : Boolean);overload;
24
24
 
25
 
{ Group functions }  
 
25
{ Group functions }
26
26
 
27
27
Function  getgrnam(Const GroupName: String) : PGroup;
28
28
Procedure GetGroupData(Const GroupName : String; Var Data : TGroup); overload;
41
41
Procedure GetUserShadowData(Const UserName : String; Var Data : TPasswordFileEntry);overload;
42
42
Procedure GetUserShadowData(UID : Integer; Var Data : TPasswordFileEntry);overload;
43
43
 
44
 
{ Extra functions }  
 
44
{ Extra functions }
45
45
 
46
46
Function GetUserGroup(Const UserName : String) : String;
47
47
 
67
67
Var P : PPasswordRecord;
68
68
 
69
69
begin
70
 
  P:=Getpwnam(UserName); 
 
70
  P:=Getpwnam(UserName);
71
71
  If P<>Nil then
72
72
    Data:=P^
73
73
  else
79
79
Var P : PPasswordRecord;
80
80
 
81
81
begin
82
 
  P:=Getpwuid(Uid); 
 
82
  P:=Getpwuid(Uid);
83
83
  If P<>Nil then
84
84
    Data:=P^
85
85
  else
92
92
  UserData : TPasswordRecord;
93
93
 
94
94
begin
95
 
  GetuserData(UID,UserData);   
 
95
  GetuserData(UID,UserData);
96
96
  Result:=strpas(UserData.pw_Name);
97
97
end;
98
98
 
99
99
function  GetUserId(Const UserName : String) : Integer;
100
100
 
101
 
Var 
 
101
Var
102
102
  UserData : TPasswordRecord;
103
103
 
104
104
begin
108
108
 
109
109
function  GetUserGId(Const UserName : String) : Integer;
110
110
 
111
 
Var 
 
111
Var
112
112
  UserData : TPasswordRecord;
113
113
 
114
114
begin
118
118
 
119
119
function GetUserDir(Const UserName : String): String;
120
120
 
121
 
Var 
 
121
Var
122
122
  UserData : TPasswordRecord;
123
123
 
124
124
begin
128
128
 
129
129
function  GetUserDescription(Const UserName : String): String;
130
130
 
131
 
Var 
 
131
Var
132
132
  UserData : TPasswordRecord;
133
133
 
134
134
begin
158
158
        If WithIDs then
159
159
          List.Add(Format('%d=%s',[P^.pw_uid,strpas(p^.pw_name)]))
160
160
        else
161
 
          List.Add(strpas(p^.pw_name));  
 
161
          List.Add(strpas(p^.pw_name));
162
162
        end;
163
 
    until (P=Nil); 
 
163
    until (P=Nil);
164
164
  finally
165
165
    endpwent;
166
 
  end;   
167
 
end;  
 
166
  end;
 
167
end;
168
168
 
169
169
{ ---------------------------------------------------------------------
170
170
    Group Functions
171
171
  ---------------------------------------------------------------------}
172
 
  
 
172
 
173
173
 
174
174
Function  getgrnam(Const GroupName: String) : PGroup;
175
175
 
182
182
Var P : PGroup;
183
183
 
184
184
begin
185
 
  P:=Getgrnam(GroupName); 
 
185
  P:=Getgrnam(GroupName);
186
186
  If P<>Nil then
187
187
    Data:=P^
188
188
  else
194
194
Var P : PGroup;
195
195
 
196
196
begin
197
 
  P:=Getgrgid(gid); 
 
197
  P:=Getgrgid(gid);
198
198
  If P<>Nil then
199
199
    Data:=P^
200
200
  else
243
243
        If WithIDs then
244
244
          List.Add(Format('%d=%s',[G^.gr_gid,strpas(G^.gr_name)]))
245
245
        else
246
 
          List.Add(strpas(G^.gr_name));  
 
246
          List.Add(strpas(G^.gr_name));
247
247
        end;
248
 
    until (G=Nil); 
 
248
    until (G=Nil);
249
249
  finally
250
250
    endgrent;
251
 
  end;   
 
251
  end;
252
252
end;
253
253
 
254
254
Function PCharListToStrings(P : PPChar; List : TStrings) : Integer;
260
260
    List.Add(StrPas(P^));
261
261
    P:=PPChar(PChar(P)+SizeOf(PChar));
262
262
    end;
263
 
  Result:=List.Count;  
 
263
  Result:=List.Count;
264
264
end;
265
265
 
266
266
 
267
267
Procedure GetGroupMembers(GID : Integer;List : TStrings);
268
268
 
269
 
Var 
 
269
Var
270
270
  G : TGroup;
271
271
 
272
272
begin
276
276
 
277
277
Procedure GetGroupMembers(Const GroupName : String;List : TStrings);
278
278
 
279
 
Var 
 
279
Var
280
280
  G : TGroup;
281
281
 
282
282
begin
286
286
 
287
287
{ Shadow password functions }
288
288
 
289
 
function getspnam(UserName : String): PPasswordFileEntry; 
 
289
function getspnam(UserName : String): PPasswordFileEntry;
290
290
 
291
291
begin
292
292
  result:=shadow.getspnam(Pchar(UserName));
300
300
 
301
301
Procedure GetUserShadowData(Const UserName : String; Var Data : TPasswordFileEntry);
302
302
 
303
 
Var 
 
303
Var
304
304
  P : PPasswordFileEntry;
305
305
 
306
306
begin
308
308
  If P=Nil then
309
309
    If (GetUID<>0) and (GetEUID<>0) then
310
310
      Raise EShadowLookupError.Create(EShadowNotPermitted)
311
 
    else  
 
311
    else
312
312
      Raise EShadowLookupError.CreateFmt(ENoShadowEntry,[UserName])
313
313
  else
314
314
    Data:=P^;
320
320
  GetUserShadowData(GetUserName(UID),Data);
321
321
end;
322
322
 
323
 
{ Extra functions }  
 
323
{ Extra functions }
324
324
 
325
325
Function GetUserGroup(Const UserName : String) : String;
326
326
 
328
328
  GetGroupName(GetUserGid(UserName));
329
329
end;
330
330
 
331
 
end.
 
 
b'\\ No newline at end of file'
 
331
end.