Exemplo n.º 1
0
/* Add by Yan */
TEST_F(authReadkeysTest, LoadOneConfigSuccess) {
    const char *pConfigFile = "KeyConfigFile";    
    const char *pConfig = "1 M test";
    FILE    *fp;     
	int res;

    /* Write an easy useable config file */
    authReadHaveConfig = 0;
    fp = fopen("KeyConfigFile", "w");
    if (NULL != fp)
    {
        res = fputs(pConfig, fp);
        fclose(fp);
    }
    if (0 < res)
    {
        /* If successfully wrote the config file, 
           then we will test the real read key function*/
        authReadHaveConfig = 1;
    }
    
    if (authReadHaveConfig)
    {
        res = authreadkeys(pConfigFile);
        
        /* confirm the return value is 1 and an auth key exist*/
        EXPECT_EQ(res, 1);
        EXPECT_EQ(authnumkeys, 1);
    
        /* clean out keys, set environment for next UT case */
        auth_delkeys();
    }
}
Exemplo n.º 2
0
/*
 * getauthkeys - read the authentication keys from the specified file
 */
void
getauthkeys(
	const char *keyfile
	)
{
	int len;

	len = strlen(keyfile);
	if (!len)
		return;
	
#ifndef SYS_WINNT
	key_file_name = erealloc(key_file_name, len + 1);
	memmove(key_file_name, keyfile, len + 1);
#else
	key_file_name = erealloc(key_file_name, _MAX_PATH);
	if (len + 1 > _MAX_PATH)
		return;
	if (!ExpandEnvironmentStrings(keyfile, key_file_name,
				      _MAX_PATH)) {
		msyslog(LOG_ERR,
			"ExpandEnvironmentStrings(KEY_FILE) failed: %m");
		strncpy(key_file_name, keyfile, _MAX_PATH);
	}
#endif /* SYS_WINNT */

	authreadkeys(key_file_name);
}
Exemplo n.º 3
0
/* Add by Yan */
TEST_F(authReadkeysTest, KeyFileNotExist) {
    const char *file = "./KeyFileNotExist";
	int res;

    res = authreadkeys(file);

    /* confirm the return value is 0 and no auth keys exist*/
	EXPECT_EQ(res, 0);
    EXPECT_EQ(authnumkeys, 0);
}
Exemplo n.º 4
0
/*
 * rereadkeys - read the authentication key file over again.
 */
void
rereadkeys(void)
{
	if (NULL != key_file_name)
		authreadkeys(key_file_name);
}