// _AddAuthentication
status_t
AuthenticationServer::_AddAuthentication(const char* context,
	const char* server, const char* share, const char* user,
	const char* password, bool makeDefault)
{
	AutoLocker<Locker> _(fLock);
	ServerKey key(context, server);
	// get the server entry
	ServerEntry* serverEntry = fServerEntries->Get(key);
	if (!serverEntry) {
		// server entry does not exist yet: create a new one
		serverEntry = new(nothrow) ServerEntry;
		if (!serverEntry)
			return B_NO_MEMORY;
		status_t error = fServerEntries->Put(key, serverEntry);
		if (error != B_OK) {
			delete serverEntry;
			return error;
		}
	}
	// put the authentication
	status_t error = serverEntry->SetAuthentication(share, user, password);
	if (error == B_OK) {
		if (makeDefault || !serverEntry->UseDefaultAuthentication())
			serverEntry->SetDefaultAuthentication(user, password);
		if (makeDefault)
			serverEntry->SetUseDefaultAuthentication(true);
	}
	return error;
}
/*!
	If share is NULL, the default authentication for the server is returned.
*/
bool
AuthenticationServer::_GetAuthentication(const char* context,
	const char* server, const char* share, String* user, String* password)
{
	if (!context || !server || !user || !password)
		return B_BAD_VALUE;
	// get the server entry
	AutoLocker<Locker> _(fLock);
	ServerKey key(context, server);
	ServerEntry* serverEntry = fServerEntries->Get(key);
	if (!serverEntry)
		return false;
	// get the authentication
	const Authentication* authentication = NULL;
	if (share) {
		serverEntry->GetAuthentication(share);
		if (!authentication && serverEntry->UseDefaultAuthentication())
			authentication = &serverEntry->GetDefaultAuthentication();
	} else
		authentication = &serverEntry->GetDefaultAuthentication();
	if (!authentication || !authentication->IsValid())
		return false;
	return (user->SetTo(authentication->GetUser())
		&& password->SetTo(authentication->GetPassword()));
}