int getgrouplist(const char* user, gid_t baseGroup, gid_t* groupList, int* groupCount) { int maxGroupCount = *groupCount; *groupCount = 0; status_t error = B_OK; // prepare request KMessage message(BPrivate::B_REG_GET_USER_GROUPS); if (message.AddString("name", user) != B_OK || message.AddInt32("max count", maxGroupCount) != B_OK) { return -1; } // send request KMessage reply; error = BPrivate::send_authentication_request_to_registrar(message, reply); if (error != B_OK) return -1; // unpack reply int32 count; const int32* groups; int32 groupsSize; if (reply.FindInt32("count", &count) != B_OK || reply.FindData("groups", B_INT32_TYPE, (const void**)&groups, &groupsSize) != B_OK) { return -1; } memcpy(groupList, groups, groupsSize); *groupCount = count; // add the base group if (*groupCount < maxGroupCount) groupList[*groupCount] = baseGroup; ++*groupCount; return *groupCount <= maxGroupCount ? *groupCount : -1; }
static status_t init_group_db() { if (sGroupEntries != NULL) return B_OK; // ask the registrar KMessage message(BPrivate::B_REG_GET_GROUP_DB); status_t error = BPrivate::send_authentication_request_to_registrar(message, sGroupDBReply); if (error != B_OK) return error; // unpack the reply int32 count; group** entries; int32 numBytes; if ((error = sGroupDBReply.FindInt32("count", &count)) != B_OK || (error = sGroupDBReply.FindData("entries", B_RAW_TYPE, (const void**)&entries, &numBytes)) != B_OK) { return error; } // relocate the entries addr_t baseAddress = (addr_t)entries; for (int32 i = 0; i < count; i++) { group* entry = relocate_pointer(baseAddress, entries[i]); relocate_pointer(baseAddress, entry->gr_name); relocate_pointer(baseAddress, entry->gr_passwd); relocate_pointer(baseAddress, entry->gr_mem); int32 k = 0; for (; entry->gr_mem[k] != (void*)-1; k++) relocate_pointer(baseAddress, entry->gr_mem[k]); entry->gr_mem[k] = NULL; } sGroupEntries = entries; sGroupEntryCount = count; return B_OK; }
static status_t init_shadow_pwd_db() { if (sShadowPwdEntries != NULL) return B_OK; // ask the registrar KMessage message(BPrivate::B_REG_GET_SHADOW_PASSWD_DB); status_t error = BPrivate::send_authentication_request_to_registrar(message, sShadowPwdDBReply); if (error != B_OK) return error; // unpack the reply int32 count; spwd** entries; int32 numBytes; if ((error = sShadowPwdDBReply.FindInt32("count", &count)) != B_OK || (error = sShadowPwdDBReply.FindData("entries", B_RAW_TYPE, (const void**)&entries, &numBytes)) != B_OK) { return error; } // relocate the entries addr_t baseAddress = (addr_t)entries; for (int32 i = 0; i < count; i++) { spwd* entry = relocate_pointer(baseAddress, entries[i]); relocate_pointer(baseAddress, entry->sp_namp); relocate_pointer(baseAddress, entry->sp_pwdp); } sShadowPwdEntries = entries; sShadowPwdEntryCount = count; return B_OK; }