Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6be6a18

Browse files
committed
Minor code cleanups, make in_group() check faster.
1 parentaceec9a commit6be6a18

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed

‎src/backend/catalog/aclchk.c

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.41 2000/10/02 04:49:28 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.42 2000/11/03 19:02:18 tgl Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -185,41 +185,40 @@ get_groname(AclId grosysid)
185185
staticbool
186186
in_group(AclIduid,AclIdgid)
187187
{
188-
Relationrelation;
189188
HeapTupletuple;
190-
Acl*tmp;
189+
Datumatt;
190+
boolisNull;
191+
IdList*tmp;
192+
AclId*aidp;
191193
inti,
192194
num;
193-
AclId*aidp;
194-
boolfound= false;
195195

196-
relation=heap_openr(GroupRelationName,RowExclusiveLock);
197196
tuple=SearchSysCacheTuple(GROSYSID,
198197
ObjectIdGetDatum(gid),
199198
0,0,0);
200-
if (HeapTupleIsValid(tuple)&&
201-
!heap_attisnull(tuple,Anum_pg_group_grolist))
199+
if (HeapTupleIsValid(tuple))
202200
{
203-
tmp= (IdList*)heap_getattr(tuple,
204-
Anum_pg_group_grolist,
205-
RelationGetDescr(relation),
206-
(bool*)NULL);
207-
/* be sure the IdList is not toasted */
208-
tmp=DatumGetIdListP(PointerGetDatum(tmp));
209-
/* XXX make me a function */
210-
num=IDLIST_NUM(tmp);
211-
aidp=IDLIST_DAT(tmp);
212-
for (i=0;i<num;++i)
213-
if (aidp[i]==uid)
201+
att=SysCacheGetAttr(GROSYSID,
202+
tuple,
203+
Anum_pg_group_grolist,
204+
&isNull);
205+
if (!isNull)
206+
{
207+
/* be sure the IdList is not toasted */
208+
tmp=DatumGetIdListP(att);
209+
/* scan it */
210+
num=IDLIST_NUM(tmp);
211+
aidp=IDLIST_DAT(tmp);
212+
for (i=0;i<num;++i)
214213
{
215-
found= true;
216-
break;
214+
if (aidp[i]==uid)
215+
return true;
217216
}
217+
}
218218
}
219219
else
220-
elog(NOTICE,"in_group: group %d not found",gid);
221-
heap_close(relation,RowExclusiveLock);
222-
returnfound;
220+
elog(NOTICE,"in_group: group %u not found",gid);
221+
return false;
223222
}
224223

225224
/*
@@ -230,11 +229,10 @@ in_group(AclId uid, AclId gid)
230229
staticint32
231230
aclcheck(char*relname,Acl*acl,AclIdid,AclIdTypeidtype,AclModemode)
232231
{
233-
unsignedi;
234232
AclItem*aip,
235233
*aidat;
236-
unsignednum,
237-
found_group;
234+
inti,
235+
num;
238236

239237
/*
240238
* If ACL is null, default to "OK" --- this should not happen,
@@ -252,52 +250,54 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
252250
/*
253251
* We'll treat the empty ACL like that, too, although this is more
254252
* like an error (i.e., you manually blew away your ACL array) -- the
255-
* system never creates an empty ACL.
253+
* system never creates an empty ACL, since there must always be
254+
* a "world" entry in the first slot.
256255
*/
257256
if (num<1)
258257
{
259258
elog(DEBUG,"aclcheck: zero-length ACL, returning 1");
260259
returnACLCHECK_OK;
261260
}
261+
Assert(aidat->ai_idtype==ACL_IDTYPE_WORLD);
262262

263263
switch (idtype)
264264
{
265265
caseACL_IDTYPE_UID:
266+
/* Look for exact match to user */
266267
for (i=1,aip=aidat+1;/* skip world entry */
267268
i<num&&aip->ai_idtype==ACL_IDTYPE_UID;
268269
++i,++aip)
269270
{
270271
if (aip->ai_id==id)
271272
{
272273
#ifdefACLDEBUG_TRACE
273-
elog(DEBUG,"aclcheck: found%d/%d",
274+
elog(DEBUG,"aclcheck: founduser %u/%d",
274275
aip->ai_id,aip->ai_mode);
275276
#endif
276277
return (aip->ai_mode&mode) ?ACLCHECK_OK :ACLCHECK_NO_PRIV;
277278
}
278279
}
279-
for (found_group=0;
280+
/* See if he has the permission via any group */
281+
for (;
280282
i<num&&aip->ai_idtype==ACL_IDTYPE_GID;
281283
++i,++aip)
282284
{
283-
if (in_group(id,aip->ai_id))
285+
if (aip->ai_mode&mode)
284286
{
285-
if (aip->ai_mode&mode)
287+
if (in_group(id,aip->ai_id))
286288
{
287-
found_group=1;
288-
break;
289-
}
290-
}
291-
}
292-
if (found_group)
293-
{
294289
#ifdefACLDEBUG_TRACE
295-
elog(DEBUG,"aclcheck: all groups ok");
290+
elog(DEBUG,"aclcheck: found group %u/%d",
291+
aip->ai_id,aip->ai_mode);
296292
#endif
297-
returnACLCHECK_OK;
293+
returnACLCHECK_OK;
294+
}
295+
}
298296
}
297+
/* Else, look to the world entry */
299298
break;
300299
caseACL_IDTYPE_GID:
300+
/* Look for this group ID */
301301
for (i=1,aip=aidat+1;/* skip world entry and
302302
* UIDs */
303303
i<num&&aip->ai_idtype==ACL_IDTYPE_UID;
@@ -310,14 +310,16 @@ aclcheck(char *relname, Acl *acl, AclId id, AclIdType idtype, AclMode mode)
310310
if (aip->ai_id==id)
311311
{
312312
#ifdefACLDEBUG_TRACE
313-
elog(DEBUG,"aclcheck: found%d/%d",
313+
elog(DEBUG,"aclcheck: foundgroup %u/%d",
314314
aip->ai_id,aip->ai_mode);
315315
#endif
316316
return (aip->ai_mode&mode) ?ACLCHECK_OK :ACLCHECK_NO_PRIV;
317317
}
318318
}
319+
/* Else, look to the world entry */
319320
break;
320321
caseACL_IDTYPE_WORLD:
322+
/* Only check the world entry */
321323
break;
322324
default:
323325
elog(ERROR,"aclcheck: bogus ACL id type: %d",idtype);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp