Ejemplo n.º 1
0
/**
 * Encrypt a password for storing in the MaxScale.cnf file
 *
 * @param argc	Argument count
 * @param argv	Argument vector
 */
int
main(int argc, char **argv)
{
	char	*enc, *pw;
	int	arg_count = 6;
	char	*home;
    char** arg_vector;
    int rval = 0;

	if (argc != 3)
	{
		fprintf(stderr, "Usage: %s <file> <password>\n", argv[0]);
		return 1;
	}

    arg_vector = malloc(sizeof(char*)*(arg_count + 1));

	if(arg_vector == NULL)
	{
	    fprintf(stderr,"Error: Memory allocation failed.\n");
	    return 1;
	}

	arg_vector[0] = strdup("logmanager");
	arg_vector[1] = strdup("-j");
	arg_vector[2] = strdup("/var/log/maxscale");

	arg_vector[3] = "-o";
	arg_vector[4] = "-l";
	arg_vector[5] = "LOGFILE_ERROR";
	arg_vector[6] = NULL;
	skygw_logmanager_init(arg_count,arg_vector);
	free(arg_vector[2]);
	free(arg_vector);
	
	pw = calloc(81,sizeof(char));

	if(pw == NULL){
		fprintf(stderr, "Error: cannot allocate enough memory.");
		return 1;
	}

	strncpy(pw,argv[2],80);

	if ((enc = encryptPassword(argv[1],pw)) != NULL){
		printf("%s\n", enc);
	}else{
		fprintf(stderr, "Failed to encode the password\n");
		rval = 1;
	}

	free(pw);
	skygw_log_sync_all();
	skygw_logmanager_done();
	return rval;
}
Ejemplo n.º 2
0
/**
 * test1	Allocate a server and do lots of other things
 *
  */
static int
test1()
{
SERVER   *server;
int     result;
char    *status;

        /* Server tests */
        ss_dfprintf(stderr,
                    "testserver : creating server called MyServer"); 
        server = server_alloc("MyServer", "HTTPD", 9876);
        skygw_log_sync_all();

        //ss_info_dassert(NULL != service, "New server with valid protocol and port must not be null");
        //ss_info_dassert(0 != service_isvalid(service), "Service must be valid after creation");

        ss_dfprintf(stderr, "\t..done\nTest Parameter for Server.");
        ss_info_dassert(NULL == serverGetParameter(server, "name"), "Parameter should be null when not set");
        serverAddParameter(server, "name", "value");
        skygw_log_sync_all();
        ss_info_dassert(0 == strcmp("value", serverGetParameter(server, "name")), "Parameter should be returned correctly");
        ss_dfprintf(stderr, "\t..done\nTesting Unique Name for Server.");
        ss_info_dassert(NULL == server_find_by_unique_name("uniquename"), "Should not find non-existent unique name.");
        server_set_unique_name(server, "uniquename");
        skygw_log_sync_all();
        ss_info_dassert(server == server_find_by_unique_name("uniquename"), "Should find by unique name.");
        ss_dfprintf(stderr, "\t..done\nTesting Status Setting for Server.");
        status = server_status(server);
        skygw_log_sync_all();
        ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running by default.");
        if (NULL != status) free(status);
        server_set_status(server, SERVER_MASTER);
        status = server_status(server);
        skygw_log_sync_all();
        ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status.");
        server_clear_status(server, SERVER_MASTER);		
		free(status);
        status = server_status(server);
        skygw_log_sync_all();
        ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared.");
        if (NULL != status) free(status);
        ss_dfprintf(stderr, "\t..done\nRun Prints for Server and all Servers.");
        printServer(server);
        printAllServers();
        skygw_log_sync_all();
        ss_dfprintf(stderr, "\t..done\nFreeing Server.");
        ss_info_dassert(0 != server_free(server), "Free should succeed");
        ss_dfprintf(stderr, "\t..done\n");
	return 0;
        
}