status_t
LocalDebuggerInterface::_GetNextSystemWatchEvent(DebugEvent*& _event,
	KMessage& message)
{
	status_t error = B_OK;
	if (message.What() != B_SYSTEM_OBJECT_UPDATE)
		return B_BAD_DATA;

	int32 opcode = 0;
	if (message.FindInt32("opcode", &opcode) != B_OK)
		return B_BAD_DATA;

	DebugEvent* event = NULL;
	switch (opcode)
	{
		case B_THREAD_NAME_CHANGED:
		{
			int32 threadID = -1;
			if (message.FindInt32("thread", &threadID) != B_OK)
				break;

			thread_info info;
			error = get_thread_info(threadID, &info);
			if (error != B_OK)
				break;

			event = new(std::nothrow) ThreadRenamedEvent(fTeamID,
				threadID, threadID, info.name);
			break;
		}

		default:
		{
			error = B_BAD_DATA;
			break;
		}
	}

	if (event != NULL)
		_event = event;

	return error;
}
Esempio n. 2
0
File: grp.cpp Progetto: mariuz/haiku
static status_t
query_group_entry(const char* name, gid_t _gid, struct group *group,
	char *buffer, size_t bufferSize, struct group **_result)
{
	*_result = NULL;

	KMessage message(BPrivate::B_REG_GET_GROUP);
	if (name)
		message.AddString("name", name);
	else
		message.AddInt32("gid", _gid);

	KMessage reply;
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		reply);
	if (error != B_OK)
		return error;

	int32 gid;
	const char* password;

	if ((error = reply.FindInt32("gid", &gid)) != B_OK
		|| (error = reply.FindString("name", &name)) != B_OK
		|| (error = reply.FindString("password", &password)) != B_OK) {
		return error;
	}

	const char* members[MAX_GROUP_MEMBER_COUNT];
	int memberCount = 0;
	for (int memberCount = 0; memberCount < MAX_GROUP_MEMBER_COUNT;) {
		if (reply.FindString("members", members + memberCount) != B_OK)
			break;
		memberCount++;
	}

	error = BPrivate::copy_group_to_buffer(name, password, gid, members,
		memberCount, group, buffer, bufferSize);
	if (error == B_OK)
		*_result = group;

	return error;
}
Esempio n. 3
0
File: grp.cpp Progetto: mariuz/haiku
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;
}
Esempio n. 4
0
File: grp.cpp Progetto: mariuz/haiku
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;
}
Esempio n. 5
0
bool
Shell::GetActiveProcessInfo(ActiveProcessInfo& _info) const
{
	_info.Unset();

	// get the foreground process group
	pid_t process = tcgetpgrp(fFd);
	if (process < 0)
		return false;

	// get more info on the process group leader
	KMessage info;
	status_t error = get_extended_team_info(process, B_TEAM_INFO_BASIC, info);
	if (error != B_OK)
		return false;

	// fetch the name and the current directory from the info
	const char* name;
	int32 cwdDevice;
	int64 cwdDirectory;
	if (info.FindString("name", &name) != B_OK
		|| info.FindInt32("cwd device", &cwdDevice) != B_OK
		|| info.FindInt64("cwd directory", &cwdDirectory) != B_OK) {
		return false;
	}

	// convert the node ref into a path
	entry_ref cwdRef(cwdDevice, cwdDirectory, ".");
	BPath cwdPath;
	if (cwdPath.SetTo(&cwdRef) != B_OK)
		return false;

	// set the result
	_info.SetTo(process, name, cwdPath.Path());

	return true;
}
Esempio n. 6
0
int
getspnam_r(const char *name, struct spwd *spwd, char *buffer,
	size_t bufferSize, struct spwd **_result)
{
	*_result = NULL;

	KMessage message(BPrivate::B_REG_GET_USER);
	message.AddString("name", name);
	message.AddBool("shadow", true);

	KMessage reply;
	status_t error = BPrivate::send_authentication_request_to_registrar(message,
		reply);
	if (error != B_OK)
		return error;

	const char* password;
	int32 lastChanged;
	int32 min;
	int32 max;
	int32 warn;
	int32 inactive;
	int32 expiration;
	int32 flags;

	if ((error = reply.FindString("name", &name)) != B_OK
		|| (error = reply.FindString("shadow password", &password)) != B_OK
		|| (error = reply.FindInt32("last changed", &lastChanged)) != B_OK
		|| (error = reply.FindInt32("min", &min)) != B_OK
		|| (error = reply.FindInt32("max", &max)) != B_OK
		|| (error = reply.FindInt32("warn", &warn)) != B_OK
		|| (error = reply.FindInt32("inactive", &inactive)) != B_OK
		|| (error = reply.FindInt32("expiration", &expiration)) != B_OK
		|| (error = reply.FindInt32("flags", &flags)) != B_OK) {
		return error;
	}

	error = BPrivate::copy_shadow_pwd_to_buffer(name, password, lastChanged,
		min, max, warn, inactive, expiration, flags, spwd, buffer, bufferSize);
	if (error == B_OK)
		*_result = spwd;

	return error;
}
Esempio n. 7
0
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;
}
status_t
DefaultNotificationService::ToEventMask(const KMessage& eventSpecifier,
	uint32& eventMask)
{
	return eventSpecifier.FindInt32("event mask", (int32*)&eventMask);
}