static JBoolean jGetUserInfo ( const uid_t uid, jUIDInfo* info ) { if (theUserInfoMap.IsEmpty()) { theUserInfoMap.SetCompareFunction(jCompareUIDs); theUserInfoMap.SetSortOrder(JOrderedSetT::kSortAscending); atexit(jCleanUserInfoMap); } const jUIDInfo target = { uid, NULL, NULL }; JIndex i; if (theUserInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i)) { *info = theUserInfoMap.GetElement(i); } else { passwd* pwbuf = getpwuid(uid); if (pwbuf != NULL) { info->userName = new JString(pwbuf->pw_name); assert( info->userName != NULL ); info->realName = new JString(pwbuf->pw_gecos); assert( info->realName != NULL ); info->homeDirectory = new JString(pwbuf->pw_dir); assert( info->homeDirectory != NULL ); info->shell = new JString(pwbuf->pw_shell); assert( info->shell != NULL ); info->id = uid; const JBoolean inserted = theUserInfoMap.InsertSorted(*info, kJFalse); assert( inserted ); } else { info->userName = info->realName = info->homeDirectory = info->shell = NULL; } } return JI2B( info->userName != NULL ); }
static JBoolean jGetGroupInfo ( const gid_t gid, jGIDInfo* info ) { if (groupInfoMap.IsEmpty()) { groupInfoMap.SetCompareFunction(jCompareGIDs); groupInfoMap.SetSortOrder(JOrderedSetT::kSortAscending); } const jGIDInfo target = { gid, NULL }; JIndex i; if (groupInfoMap.SearchSorted(target, JOrderedSetT::kAnyMatch, &i)) { *info = groupInfoMap.GetElement(i); } else { group* grpbuf = getgrgid(gid); if (grpbuf != NULL) { info->groupName = new JString(grpbuf->gr_name); assert( info->groupName != NULL ); info->id = gid; const JBoolean inserted = groupInfoMap.InsertSorted(*info, kJFalse); assert( inserted ); } else { info->groupName = NULL; } } return JI2B( info->groupName != NULL ); }