Example #1
0
static void
uboxRemUser(Ubox* box, User *u)
{
	User **h, *up;

	h = &box->ihash[userHash(u->uid)];
	for(up = *h; up != nil && up != u; up = up->ihash)
		h = &up->ihash;
	assert(up == u);
	*h = up->ihash;
	box->len -= strlen(u->uid);

	h = &box->nhash[userHash(u->uname)];
	for(up = *h; up != nil && up != u; up = up->nhash)
		h = &up->nhash;
	assert(up == u);
	*h = up->nhash;
	box->len -= strlen(u->uname);

	h = &box->head;
	for(up = *h; up != nil && strcmp(up->uid, u->uid) != 0; up = up->next)
		h = &up->next;
	assert(up == u);
	*h = u->next;
	u->next = nil;

	box->len -= 4;
	box->nuser--;
}
Example #2
0
bool PasswordFile::getHMACuser( const std::string& hash, const std::string& key,
				PwdFileUser& user ) const
{
	FILE*		file;
	char		line[ PWD_FILE_LINE_SIZE ];
	unsigned char	binKey[ MAX_HMAC_KEY_SIZE ];
	int		keySize;

	crypto::HMAC_SHA256 userHash( hash );
	if (( keySize = base64_decode( key.data(), key.size(),
				       binKey, MAX_HMAC_KEY_SIZE )) < 0 )	{
		std::string msg = "Cannot convert '" + key + "' to a HMAC binary key";
		throw std::runtime_error( msg );
	}

	if ( !boost::filesystem::exists( m_filename ) && !m_create )	{
		std::string msg = "password file '";
		msg += m_filename + "' does not exist";
		throw std::runtime_error( msg );
	}

	if (( file = fopen( m_filename.c_str(), "r" )) == NULL )	{
		int err = errno;
		std::string msg = "password file '";
		msg += m_filename + "' could not be opened: " + strerror( err );
		throw std::runtime_error( msg );
	}

	while ( !feof( file ) )	{
		char* ret = fgets( line, PWD_FILE_LINE_SIZE, file );
		if ( ret == NULL )	{
			if ( feof( file ))	{
				fclose( file );
				return false;
			}
			else	{
				int err = errno;
				fclose( file );
				std::string msg = "error reading from password file '";
				msg += m_filename + "': " + strerror( err );
				throw std::runtime_error( msg );
			}
		}
		std::string uname = pwdLineUser( line );
		if ( uname.empty())
			continue;
		if ( !m_caseSensitive )
			boost::algorithm::to_lower( uname );
		crypto::HMAC_SHA256 hsh( binKey, keySize, uname );
		if ( hsh == userHash )	{
			fclose( file );
			bool found = parsePwdLine( line, user );
			assert( found == true );
			return true;
		}
	}
	return false;
}
Example #3
0
static User*
_userByUid(Ubox* box, char* uid)
{
	User *u;

	if(box != nil){
		for(u = box->ihash[userHash(uid)]; u != nil; u = u->ihash){
			if(strcmp(u->uid, uid) == 0)
				return u;
		}
	}
	vtSetError("uname: uid '%s' not found", uid);
	return nil;
}
Example #4
0
static User*
_userByUname(Ubox* box, char* uname)
{
	User *u;

	if(box != nil){
		for(u = box->nhash[userHash(uname)]; u != nil; u = u->nhash){
			if(strcmp(u->uname, uname) == 0)
				return u;
		}
	}
	vtSetError("uname: uname '%s' not found", uname);
	return nil;
}
Example #5
0
static void
uboxAddUser(Ubox* box, User* u)
{
	User **h, *up;

	h = &box->ihash[userHash(u->uid)];
	u->ihash = *h;
	*h = u;
	box->len += strlen(u->uid);

	h = &box->nhash[userHash(u->uname)];
	u->nhash = *h;
	*h = u;
	box->len += strlen(u->uname);

	h = &box->head;
	for(up = *h; up != nil && strcmp(up->uid, u->uid) < 0; up = up->next)
		h = &up->next;
	u->next = *h;
	*h = u;

	box->len += 4;
	box->nuser++;
}