コード例 #1
0
void
delete_bootstrap_services(bootstrap_info_t *bootstrap)
{
	server_t  *serverp;
	service_t *servicep;
	service_t *next;
	
	for (  servicep = FIRST(services)
	     ; !IS_END(servicep, services)
	     ; servicep = next)
	{
		next = NEXT(servicep);
	  	if (bootstrap != servicep->bootstrap)
			continue;

		if (!servicep->isActive || !servicep->server) {
			delete_service(servicep);
			continue;
		}

		serverp = servicep->server;
		delete_service(servicep);
		serverp->active_services--;
		if (!active_server(serverp))
			delete_server(serverp);
	}
}
コード例 #2
0
int WINAPI manage_npf_driver(LPCTSTR LogFileName, char operation)
{
	FILE *log;
	DWORD ReturnValue = NO_ERROR;

	if (LogFileName != NULL)
		log = fopen(LogFileName, "a");
	else
		log = NULL;

	switch(operation)
	{
	case 's':
		ReturnValue = start_service(log,"NPF");
		break;

	case 'x':
		ReturnValue = stop_service(log,"NPF");
		break;

	case 'u':
		ReturnValue = delete_service(log,"NPF");
		break;

	case 'i':
		ReturnValue = create_driver_service(log,"NPF","NetGroup Packet Filter Driver","system32\\drivers\\npf.sys");
		break;

	case 'r':
		(void)delete_service(log,"NPF");
		Sleep(100);
		ReturnValue = create_driver_service(log,"NPF","NetGroup Packet Filter Driver","system32\\drivers\\npf.sys");
		break;

	case 'a':
		ReturnValue = change_start_type_service(log,"NPF", SERVICE_AUTO_START);
		break;

	case 'd':
		ReturnValue = change_start_type_service(log,"NPF", SERVICE_DEMAND_START);
		break;

	default:
		ReturnValue = ERROR_INVALID_PARAMETER;
		break;
	}

	if (log != NULL)
		fclose(log);

	return (int)ReturnValue;

}
コード例 #3
0
void
delete_server(server_t *serverp)
{
	service_t *servicep;
	service_t *next;

	info("Deleting server %s", serverp->cmd);
	ASSERT(serverp->prev->next == serverp);
	ASSERT(serverp->next->prev == serverp);
	serverp->prev->next = serverp->next;
	serverp->next->prev = serverp->prev;

	for (  servicep = FIRST(services)
	     ; !IS_END(servicep, services)
	     ; servicep = next)
	{
		next = NEXT(servicep);
	  	if (serverp == servicep->server)
			delete_service(servicep);
	}

	deallocate_bootstrap(serverp->bootstrap);

	if (serverp->port)
		mach_port_mod_refs(mach_task_self(), serverp->port,
				   MACH_PORT_RIGHT_RECEIVE, -1);

	free(serverp);
}	
コード例 #4
0
ファイル: viriatum.c プロジェクト: hivesolutions/viriatum
ERROR_CODE destroy_service() {
    /* prints a debug message about the initial stage
    of the service structures destruction */
    V_DEBUG("Destroying the service structures\n");

    /* deletes the service, disallowing any further
    access to the service instance, and then sets its
    reference back to the original (unset sate) */
    delete_service(service);
    service = NULL;

    /* prints a debug message about the final stage
    of the service structures destruction */
    V_DEBUG("Finished destroying the service structures\n");

    /* raises no error to the caller method, normal
    exit operation (should provide no problem) */
    RAISE_NO_ERROR;
}
コード例 #5
0
long test3(const char* timeLog_filepath, int num_of_clients, int ksm )
{
    char shell_command[BUFSIZ];
    char cache_filepath[1024];
    char client_name[1024];
    char group_name[1024];
    int i,j,k;
    long total_time = 0.0L;
    FILE* timeLog_file = NULL;
    char* base_client_name = 
              (ksm==2)? KSM2_BASE_CLIENT_NAME:KSM1_BASE_CLIENT_NAME;

    // Create client principals and its cache for each client
    for( i = 0; i < num_of_clients; i++ ) {
        //printf("\rCreating client principal and ticket cache %d of %d",
        //     i+1, num_of_clients);
        snprintf(client_name, 1024, "%s%d", base_client_name, i);
        create_client_princ( client_name );
        create_client_cache( client_name );
    }
    //printf("\n");

    // Execute all client request sequentially
    for( i = 1; i <= group_count; i++ ) {        
        memset(group_name, 0, 1024);
        snprintf(group_name, 1024, "group%d", i);

        int a[num_of_clients], nvalues = num_of_clients;
        
        for( k = 0; k < nvalues; k++ ) a[k] = k; 
        for( k = 0; k < nvalues -1; k++) {
            int c = rand() / (RAND_MAX/(nvalues-k) + 1 );
            int t = a[k]; a[k] = a[k+c]; a[k+c] = t;
        }

        for( j = 0; j < group_size; j++ ) {
            int cid = a[j];  // client id
            snprintf(client_name, 1024, "%s%d", base_client_name, cid);
            snprintf(cache_filepath, 1024, "%s/%s%d.cache", 
                        RUNTIME_DIR, base_client_name, cid);
        
             
             if( client_exec( group_name, cache_filepath,
                         timeLog_filepath, ksm) < 0 )
             { 
                 for( k = 0; k < num_of_clients; k++ ) {
                     snprintf(client_name, 1024, "%s%d", 
                                        base_client_name, k);
                     delete_client_cache( client_name );
                     delete_client_princ( client_name );
                 }
                 delete_service("group",group_count); 
                 printf("Client failed\n");
                 exit(1);
             }
    
             long last_val = get_last_value( timeLog_filepath );
    
             if( last_val > 100 || last_val < 0) {
                 snprintf(shell_command, BUFSIZ,"%s %s",
                             DEL_LAST_LINE, 
                             timeLog_filepath,
                             NULL);
                 // Reject data that's out of range
                 system(shell_command);
                 if (ksm == 2) {
                     delete_client_cache( client_name );
                     create_client_cache( client_name );                    
                 }
    //               printf("last_val too high, reject%ld\n", last_val);
                 j--;
             }   
        }
    }
   
    timeLog_file = fopen(timeLog_filepath, "r");
    
    if( timeLog_file != NULL ) {
        char line[128];
        for(i = 0; i < group_size*group_count; i++ ) {

            if( fgets(line, sizeof(line), 
                   timeLog_file) != NULL ) 
            {
                total_time += atol( line );
            }
        }
        fclose(timeLog_file);
    }
    else {
        perror( timeLog_filepath );
    }

    for( i = 0; i < num_of_clients; i++ ) {
        snprintf(client_name, 1024, "%s%d", base_client_name, i);
        delete_client_cache( client_name );
        delete_client_princ( client_name );
    }
    //printf("\n"); 
    return total_time;
}
コード例 #6
0
int main(int argc, char* argv[]) 
{
    // Simulation configuration
    int num_of_clients = 50;
    
    // Indexing
    int i,j,n,l;

    // Temporary Logging
    generalLog_filepath = TEST3_GENERAL_LOG;

    starting_k = 5;
    max_k = 20;
    ignore_count = 3;
    
    if( getenv("SUDO_UID") ) {
        user_uid = atoi(getenv("SUDO_UID"));
    }
    else {
        printf("You need sudo to run the test\n");
        exit(0);
    }
#ifdef HARD_UPPER_LIMIT
    if( argc > 1 ) {
        upper_limit = atoi(argv[1]);
    }
#endif

    if( argc > 2 ) {
        num_of_clients = atoi(argv[2]);
    }

    seteuid(user_uid);  setfsuid(user_uid);

    setup_logs();
    // Statistical variables
    running_stats_t rs;
    //set_default_running_stats( &rs );

    create_service("group",group_count);


    for( l=1; l <= sizeof(group_size_array)/sizeof(int); l++) {
        group_size = group_size_array[l-1];
        num_of_clients = group_size;
        set_default_running_stats( &rs );
             
        printf("===================Pre-test Runs=====================\n");
        for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations
            timeLog_file = fopen( timeLog_filepath, "w" );
            fclose(timeLog_file);
            test3( timeLog_filepath, num_of_clients, 1);
        }
        
        printf("===================Starting KSM1=====================\n");
        resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" );
        fprintf(resultsLogRAW_file,
              "===================Starting KSM1=====================\n");
        if(resultsLogRAW_file) fclose(resultsLogRAW_file);
        run_test3(&rs, num_of_clients, 1);
        log_data( test3_dat_ksm1_filepath, group_size, &rs );


        set_default_running_stats( &rs );
        printf("===================Pre-test Runs=====================\n");
        for( j = 0; j < ignore_count; j++ ) { // ignore first few iterations
            timeLog_file = fopen( timeLog_filepath, "w" );
            fclose(timeLog_file);
            test3( timeLog_filepath, num_of_clients, 2);
        }
        
        printf("===================Starting KSM2=====================\n");
        resultsLogRAW_file = fopen( resultsLogRAW_filepath, "a" );
        fprintf(resultsLogRAW_file,
                "===================Starting KSM2=====================\n");
        if(resultsLogRAW_file) fclose(resultsLogRAW_file);
    
        run_test3(&rs, num_of_clients, 2);
        log_data( test3_dat_ksm2_filepath, group_size, &rs );

    }

    
    delete_service("group",group_count);

    merge_data(test3_dat_filepath, test3_dat_ksm1_filepath,
                                   test3_dat_ksm2_filepath);
    remove(test3_dat_ksm1_filepath);
    remove(test3_dat_ksm2_filepath);
    remove(timeLog_filepath);

    return 0;
}
コード例 #7
0
ファイル: mrbig.c プロジェクト: qbranch-code/Qbranch.MrBig
int main(int argc, char **argv)
{
	int i;
	char *p;

	startup_log("main()");
	dirsep = '\\';
	GetModuleFileName(NULL, cfgdir, sizeof cfgdir);
	startup_log("cfgdir = '%s'", cfgdir);
	p = strrchr(cfgdir, dirsep);
	if (p) *p = '\0';
	cfgfile[0] = '\0';
	snprcat(cfgfile, sizeof cfgfile,
		"%s%c%s", cfgdir, dirsep, "mrbig.cfg");
	startup_log("cfgfile = '%s'", cfgfile);
	startup_log("SystemRoot = '%s'", getenv("SystemRoot"));

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-c")) {
			i++;
			if (argv[i] == NULL) {
				fprintf(stderr, "No cfg file\n");
				return EXIT_FAILURE;
			}
		} else if (!strcmp(argv[i], "-d")) {
			debug++;
		} else if (!strcmp(argv[i], "-m")) {
			debug_memory = 1;
		} else if (!strncmp(argv[i], "-i", 2)) {
			if (argv[i][2] == '\0') {
				install_service("MrBig", "Mr Big Monitoring Agent");
			} else {
				install_service(argv[i]+2, argv[i]+2);
			}
			return 0;
		} else if (!strncmp(argv[i], "-u", 2)) {
			if (argv[i][2] == '\0') {
				delete_service("MrBig");
			} else {
				delete_service(argv[i]+2);
			}
			return 0;
		} else if (!strcmp(argv[i], "-t")) {
			standalone = 1;
		} else {
			fprintf(stderr, "Bogus option '%s'\n", argv[i]);
			usage();
		}
	}

	if (standalone) {
		mrbig();
		return 0;
	}

	startup_log("We want to become a service");
	service_main(argc, argv);

	dump_chunks();
	check_chunks("just before exit");
	dump_files();

	return 0;
}
コード例 #8
0
/*
 * kern_return_t
 * bootstrap_register(mach_port_t bootstrap_port,
 *	name_t service_name,
 *	mach_port_t service_port)
 *
 * Registers send rights for the port service_port for the service named by
 * service_name.  Registering a declared service or registering a service for
 * which bootstrap has receive rights via a port backup notification is
 * allowed.
 * The previous service port will be deallocated.  Restarting services wishing
 * to resume service for previous clients must first attempt to checkin to the
 * service.
 *
 * Errors:	Returns appropriate kernel errors on rpc failure.
 *		Returns BOOTSTRAP_NOT_PRIVILEGED, if request directed to
 *			unprivileged bootstrap port.
 *		Returns BOOTSTRAP_SERVICE_ACTIVE, if service has already been
 *			register or checked-in.
 */
kern_return_t
x_bootstrap_register(
	mach_port_t	bootstrap_port,
	name_t	service_name,
	mach_port_t	service_port)
{
	kern_return_t result;
	service_t *servicep;
	server_t *serverp;
	bootstrap_info_t *bootstrap;
	mach_port_t old_port;

	debug("Register attempt for service %s port %x",
	      service_name, service_port);

	/*
	 * Validate the bootstrap.
	 */
	bootstrap = lookup_bootstrap_by_port(bootstrap_port);
	if (!bootstrap || !active_bootstrap(bootstrap))
		return BOOTSTRAP_NOT_PRIVILEGED;
	  
	/*
	 * If this bootstrap port is for a server, or it's an unprivileged
	 * bootstrap can't register the port.
	 */
	serverp = lookup_server_by_port(bootstrap_port);
	servicep = lookup_service_by_name(bootstrap, service_name);
	if (servicep && servicep->server && servicep->server != serverp)
		return BOOTSTRAP_NOT_PRIVILEGED;

	if (servicep == NULL || servicep->bootstrap != bootstrap) {
		servicep = new_service(bootstrap,
				       service_name,
				       service_port,
				       ACTIVE,
				       REGISTERED,
				       NULL_SERVER);
		debug("Registered new service %s", service_name);
	} else {
		if (servicep->isActive) {
			debug("Register: service %s already active, port %x",
		 	      servicep->name, servicep->port);
			ASSERT(!canReceive(servicep->port));
			return BOOTSTRAP_SERVICE_ACTIVE;
		}
		old_port = servicep->port;
		if (servicep->servicetype == DECLARED) {
			servicep->servicetype = REGISTERED;

			if (servicep->server) {
				ASSERT(servicep->server == serverp);
				ASSERT(active_server(serverp));
				servicep->server = NULL_SERVER;
				serverp->activity++;
			}

			result = mach_port_mod_refs(
					mach_task_self(),
					old_port,
					MACH_PORT_RIGHT_RECEIVE, 
					-1);
			if (result != KERN_SUCCESS)
				kern_fatal(result, "mach_port_mod_refs");
		}
		result = mach_port_deallocate(
				mach_task_self(),
				old_port);
		if (result != KERN_SUCCESS)
			kern_fatal(result, "mach_port_mod_refs");
		
		servicep->port = service_port;
		servicep->isActive = TRUE;
		debug("Re-registered inactive service %x bootstrap %x: %s",
			servicep->port, servicep->bootstrap->bootstrap_port, service_name);
	}

	/* detect the new service port going dead */
	result = mach_port_request_notification(
			mach_task_self(),
			service_port,
			MACH_NOTIFY_DEAD_NAME,
			0,
			notify_port,
			MACH_MSG_TYPE_MAKE_SEND_ONCE,
			&old_port);
	if (result != KERN_SUCCESS) {
		debug("Can't request notification on service %x bootstrap %x: %s",
		       service_port, servicep->bootstrap->bootstrap_port, "must be dead");
		delete_service(servicep);
		return BOOTSTRAP_SUCCESS;
	} else if (old_port != MACH_PORT_NULL) {
		debug("deallocating old notification port (%x) for service %x",
		      old_port, service_port);
		result = mach_port_deallocate(
				mach_task_self(),
				old_port);
		if (result != KERN_SUCCESS)
			kern_fatal(result, "mach_port_deallocate");
	}
	info("Registered service %x bootstrap %x: %s",
	     servicep->port, servicep->bootstrap->bootstrap_port, servicep->name);
	return BOOTSTRAP_SUCCESS;
}