-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGROUPS.PAS
195 lines (184 loc) · 4.53 KB
/
GROUPS.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
{ @author: Sylvain Maltais ([email protected])
@created: 2024
@website(https://www.gladir.com/linux-0)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program GROUPS;
Uses DOS;
Var
I:Integer;
BaseDir,Entity:String;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Procedure TruncAfterSemicolon(Var S:String);
Var
I:Byte;
Begin
For I:=1to Length(S)do If S[I]=';'Then Begin
S[0]:=Chr(I-1);
Exit;
End;
End;
Function Path2Dir(Const Path:String):String;
Var
D:DirStr;
N:NameStr;
E:ExtStr;
Begin
Path2Dir:='';
If Path=''Then Exit;
FSplit(Path,D,N,E);
If E=''Then Begin
If D[Length(D)]<>'\'Then D:=D+'\';
D:=D+E;
End;
If D=''Then Path2Dir:='' Else
If D[Length(D)]<>'\'Then D:=D+'\';
Path2Dir:=D;
End;
Function IsWildCard(Const Path:String):Boolean;Begin
IsWildCard:=(Pos('*',Path)>0)or(Pos('?',Path)>0);
End;
Function DirExist(Dir:String):Boolean;
Var
Rec:SearchRec;
Begin
If Length(Dir)=0Then DirExist:=True
Else
Begin
TruncAfterSemicolon(Dir);
If Dir[Length(Dir)]='\'Then Dir:=Dir+'*.*' Else
If IsWildCard(Dir)Then Dir:=Path2Dir(Dir)+'*.*';
FindFirst(Dir,Directory,Rec);
DirExist:=DOSError=0;
End;
End;
Function GroupNameToGroupID(GroupName:String):String;
Var
FileGroup:Text;
I,CellPos:Integer;
CurrLine,CurrWord:String;
Cells:Array[0..6]of String;
Begin
GroupNameToGroupID:='';
{$I-}Assign(FileGroup,BaseDir+'/etc/group');
Reset(FileGroup);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de lire le fichier ',BaseDir,'/etc/group');
Halt(1);
End;
While Not EOF(FileGroup)do Begin
ReadLn(FileGroup,CurrLine);
FillChar(Cells,SizeOf(Cells),0);
CurrWord:='';
CellPos:=0;
For I:=1 to Length(CurrLine) do Begin
If CurrLine[I]=':'Then Begin
Cells[CellPos]:=CurrWord;
CurrWord:='';
Inc(CellPos);
If CellPos>5 Then Break;
End
Else
CurrWord:=CurrWord+CurrLine[I];
End;
If CurrWord<>''Then Begin
Cells[CellPos]:=CurrWord;
Inc(CellPos);
End;
If Cells[0]<>''Then Begin
If(Cells[0]=GroupName)Then Begin
Close(FileGroup);
GroupNameToGroupID:=Cells[2];
Exit;
End;
End;
End;
Close(FileGroup);
End;
Function GroupNameToGroupListName(GroupName:String):String;
Var
FileGroup:Text;
I,CellPos:Integer;
CurrLine,CurrWord,GroupList:String;
Cells:Array[0..6]of String;
Begin
GroupNameToGroupListName:='';
If GroupName=''Then Exit;
GroupList:=GroupName;
{$I-}Assign(FileGroup,BaseDir+'/etc/group');
Reset(FileGroup);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de lire le fichier ',BaseDir,'/etc/group');
Halt(1);
End;
While Not EOF(FileGroup)do Begin
ReadLn(FileGroup,CurrLine);
FillChar(Cells,SizeOf(Cells),0);
CurrWord:='';
CellPos:=0;
For I:=1 to Length(CurrLine) do Begin
If CurrLine[I]=':'Then Begin
Cells[CellPos]:=CurrWord;
CurrWord:='';
Inc(CellPos);
If CellPos>5 Then Break;
End
Else
CurrWord:=CurrWord+CurrLine[I];
End;
If CurrWord<>''Then Begin
Cells[CellPos]:=CurrWord;
Inc(CellPos);
End;
If Cells[0]<>''Then Begin
If(Cells[3]=GroupName)Then Begin
If GroupList<>''Then GroupList:=GroupList+' ';
GroupList:=GroupList+Cells[0];
End;
End;
End;
Close(FileGroup);
GroupNameToGroupListName:=GroupList;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('GROUPS : Cette commande permet d''afficher les groupes ',
'd''un utilisateur.');
WriteLn;
WriteLn('Syntaxe : GROUPS [options] [user]');
WriteLn;
WriteLn(' user Indique le nom de l''utilisateur');
WriteLn(' --cygwin Recherche dans les dossiers de Cygwin');
WriteLn(' --cygwin32 Recherche dans les dossiers de Cygwin en 32 bits');
WriteLn(' --cygwin64 Recherche dans les dossiers de Cygwin en 64 bits');
WriteLn(' --help Affiche l''aide de cette commande.');
End
Else
Begin
BaseDir:='';
Entity:=GetEnv('LOGNAME');
If Entity=''Then Entity:=GetEnv('USERNAME');
If Entity=''Then Entity:='root';
For I:=1 to ParamCount do Begin
If ParamStr(I)='--cygwin'Then Begin
If DirExist('/cygwin')Then BaseDir:='/cygwin' Else
If DirExist('/cygwin32')Then BaseDir:='/cygwin32' Else
If DirExist('/cygwin64')Then BaseDir:='/cygwin64';
End
Else
If ParamStr(I)='--cygwin64'Then BaseDir:='/cygwin64' Else
If ParamStr(I)='--cygwin32'Then BaseDir:='/cygwin32'
Else Entity:=ParamStr(I);
End;
WriteLn(GroupNameToGroupListName(Entity));
End;
END.