home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!ucbvax!bloom-beacon!bloom-picayune.mit.edu!news.mit.edu!probe
- From: probe@mit.edu (Richard Basch)
- Newsgroups: comp.unix.aix
- Subject: libs.a: group caching
- Message-ID: <PROBE.92Aug15233023@tardis.mit.edu>
- Date: 16 Aug 92 03:30:33 GMT
- Sender: news@athena.mit.edu (News system)
- Distribution: comp.unix.aix
- Organization: Massachusetts Institute of Technology
- Lines: 79
- Nntp-Posting-Host: tardis.mit.edu
-
-
- At MIT/Athena, we have a variant of the standard login program... it
- looks up the users from a central database and adds the user temporarily
- to the workstation's /etc/passwd file (and all the other files
- associated with the RISC/6000). It also looks up the user's groups and
- adds those, also (primarily for the benefit of NFS).
-
- What I have discovered is that adding a user using the calls:
-
- setuserdb(S_WRITE|S_READ);
- setpwdb(S_WRITE|S_READ);
- ...
- putuserattr(...);
- ...
- putgroupattr(...);
- ...
- endpwdb();
- enduserdb();
- ...
- setpcred(user,0);
- setpenv(...);
-
- does not properly initialize the user's grouplist... The user's
- grouplist will be a RANDOM subset of what is in /etc/group, even though
- the user appears to be in all of the groups according to /etc/group and
- the groups seem to be correctly listed in /etc/security/*.
-
- I am assuming the internals of setpcred() are something like the
- following... I used something like the following in my own testing and
- found that the grouptoID() calls were failing even though all the
- various entries appeared to be in the files... (Actually, my testing
- included some extra features such as eliminating duplicate gids, but
- I am not sure if the AIX internal routines do that, though it would be
- easy enough to test).
-
- char *group;
- gid_t gid, gids[NGROUPS];
- int groups=0, i;
-
- if (getuserattr(user, S_GROUPS, (void *)&group, SEC_LIST)==0) {
- while (*group && groups<NGROUPS) {
- if (grouptoID(group, &gid))
- gids[groups++] = gid;
- while (*group++) ;
- }
- setgroups(groups,gids);
- }
-
- Anyway, after nm'ing the library and doing some more testing, I was
- guessing that various old data may have been cached by the library
- routines and not updated properly with putgroupattr() calls.
-
- The only solution to the problem that I found was to use the following
- code prior to calling setpcred():
-
- /* Make sure there are no dangling references to userdb/pwdb */
- i = chksessions();
- while (i--) enduserdb();
- i = chkpsessions();
- while (i--) endpwdb();
-
- /* Clear cache of group entries */
- endgroups();
-
- Does anyone know what is going on, and if this is truly a bug... it
- appears to be a bug in 3.1.6 and 3.1.8. I have not yet tested 3.2.
-
- The only reason I do the multiple enduserdb()/endpwdb() is to ensure
- everything is properly flushed before doing endgroups(). The structure
- of our login program was such that the reference count on the
- userdb/pwdb was already 0, but I tend to have a paranoid programming
- style...
-
- Also, am I using these routines correctly? Obviously, I could refer to
- source code, but it seems like such a waste to taint myself if I can
- find out the information with "nm" and black-box testing. I wouldn't
- need to use these routines if libs.a caching worked properly...
-
- -Richard
-