Beispiel #1
0
void gw_user_destroy(gw_user_t *user)
{
    int i;
        
    if ( user == NULL )
        return;
    
    gw_log_print("UM",'I',"Removing MADs for user %s (%s).\n",
            GWNSTR(user->name), GWNSTR(user->dn));
            
    if (user->name != NULL )
        free(user->name);

    if (user->proxy_path != NULL )
        free(user->proxy_path);

    if (user->dn != NULL )
        free(user->dn);

    for (i = 0; i< user->em_mads; i++)
        gw_em_mad_finalize(&(user->em_mad[i]));

    for (i = 0; i< user->tm_mads; i++)
        gw_tm_mad_finalize(&(user->tm_mad[i]));

}
Beispiel #2
0
int gw_tm_mad_init(gw_tm_mad_t * tm_mad, 
                   const char *  exe, 
                   const char *  name,
		           const char *  args,
		           const char *  owner)
{
    int rc,length;
	
	if ((name == NULL) || (exe == NULL) || (owner == NULL))
		return -1;
		
	length = strlen(gw_conf.gw_location) + strlen(exe) + 6;
	
    tm_mad->name         = strdup(name);
    tm_mad->owner         = strdup(owner);
    tm_mad->executable   = (char *) malloc(sizeof(char)*length);
    
    sprintf(tm_mad->executable,"%s/bin/%s",gw_conf.gw_location,exe);
    
    if (args != NULL)
		tm_mad->argument = strdup(args);
	else
		tm_mad->argument = NULL;
        
    tm_mad->url          = NULL;
    
    rc = gw_tm_mad_start_mad(tm_mad);
    
    if ( rc == -1 )
        gw_tm_mad_finalize (tm_mad);
        
    return rc;
    
}
Beispiel #3
0
int gw_user_init(gw_user_t *user, const char *name, const char *proxy_path)
{

    int i,j;
    int rc;
    int proxy_var;
    FILE *file;
    char proxy_command[GW_MSG_STRING_LONG], *globus_location;
    char dn[GW_MSG_STRING_LONG], *pline;
 
    if ( user == NULL)
        return -1;
        
    user->name = strdup(name);

    if (user->name == NULL)
        return -1;

    if (strcmp(proxy_path, "") == 0)
    {
#ifdef GWUSERDEBUG
        gw_log_print("UM",'I',"Unsetting X509_USER_PROXY variable.\n");
#endif

        unsetenv("X509_USER_PROXY");
		proxy_var=0;
    }
    else
    {
#ifdef GWUSERDEBUG
        gw_log_print("UM",'I',"Setting X509_USER_PROXY variable to %s.\n",
                proxy_path);
#endif
        proxy_var=1;
        setenv("X509_USER_PROXY", proxy_path, 1);
    }

    user->proxy_path = strdup(proxy_path);
    globus_location = getenv("GLOBUS_LOCATION");

    if (gw_conf.multiuser == GW_TRUE)
        sprintf(proxy_command, "sudo -H -u %s %s/bin/grid-proxy-info -exists", name, globus_location);
    else
        sprintf(proxy_command, "grid-proxy-info -exists");

    if (system(proxy_command) == 0)
    {
        if (gw_conf.multiuser == GW_TRUE)
            sprintf(proxy_command, "sudo -H -u %s %s/bin/grid-proxy-info -identity", name, globus_location);
        else
            sprintf(proxy_command, "grid-proxy-info -identity");

        gw_log_print("UM",'I',"Executing command %s\n", proxy_command);

        file = popen(proxy_command, "r");

        if (file != NULL)
        {
            while( fgets(dn, sizeof(dn), file) != NULL )
            {
                // Keep looping even if we just expect one line
            }
		
            pclose(file);
	  
            if (dn != NULL){
                pline =  strchr(dn, '\n');
            if (pline != NULL)
                *pline = '\0';

            user->dn = strdup(dn);
            gw_log_print("UM",'I',"User proxy info, %s\n", user->dn);
            }
            else
            {
                 gw_log_print("UM",'I',"Error getting identity of user %s.\n",
                         GWNSTR(name));
                user->dn = strdup("Unknown");
            }
        }
        else
        {
            gw_log_print("UM",'I',"Error executing grid-proxy-info -identity for user %s.\n",
                    GWNSTR(name));
            user->dn = strdup("Unknown");
        }
    }
    else
    {
        gw_log_print("UM",'E',"Error executing grid-proxy-info for user %s. Check sudoers.\n",
                GWNSTR(name));
        user->dn = strdup("Unknown"); 
    }

    user->active_jobs  = 0;
    user->running_jobs = 0;
    user->idle         = 0;
    user->em_mads      = 0;
    user->tm_mads      = 0;
    
    gw_log_print("UM",'I',"Loading execution MADs for user %s (%s).\n",
            GWNSTR(name), GWNSTR(user->dn));
    
    i = 0;
    
    while ( ( i < GW_MAX_MADS ) && (gw_conf.em_mads[i][0] != NULL) )
    {
        rc = gw_em_register_mad(user,
                gw_conf.em_mads[i][GW_MAD_EM_PATH_INDEX],
                gw_conf.em_mads[i][GW_MAD_EM_NAME_INDEX],        
                gw_conf.em_mads[i][GW_MAD_EM_ARGS_INDEX],
                gw_conf.em_mads[i][GW_MAD_EM_RSL_INDEX]);

        if (rc != 0)
        {
            gw_log_print("UM",'E',"Could not load execution MAD %s.\n",
                    gw_conf.em_mads[i][GW_MAD_EM_NAME_INDEX]);
        	
            for (j = 0; j< user->em_mads ; j++)
            {
                gw_log_print("UM",'E',"Removing execution MAD %s.\n",
                             user->em_mad[j].name);
                
                gw_em_mad_finalize (&(user->em_mad[j]));
            }
            
            free(user->name);

            return -1;
        }

        i++;
    }
    
    gw_log_print("UM",'I',"Loading transfer MADs for user %s (%s).\n",
            GWNSTR(name), GWNSTR(user->dn));
    
    i = 0;
    while ( ( i < GW_MAX_MADS ) && (gw_conf.tm_mads[i][0] != NULL) )
    {
        rc = gw_tm_register_mad(user,
                gw_conf.tm_mads[i][GW_MAD_TM_PATH_INDEX],
                gw_conf.tm_mads[i][GW_MAD_TM_NAME_INDEX],
                gw_conf.tm_mads[i][GW_MAD_TM_ARGS_INDEX]);

        if ( rc != 0)
        {
            gw_log_print("UM",'E',"Could not load transfer MAD %s.\n",
                    gw_conf.tm_mads[i][GW_MAD_TM_NAME_INDEX]);
        	
            for (j=0; j< user->tm_mads ; j++)
            {  
                gw_log_print("UM",'E',"Removing transfer MAD %s.\n",
                             user->tm_mad[j].name);
            	          	                        
                gw_tm_mad_finalize (&(user->tm_mad[j]));
            }
            
            for (j=0; j< user->em_mads ; j++)
            {
                gw_log_print("UM",'E',"Removing execution MAD %s.\n",
                             user->em_mad[j].name);
                
                gw_em_mad_finalize (&(user->em_mad[j]));
            }

            free(user->name);

            return -1;
        }        
        i++;
    }

    gw_log_print("UM",'I',"User %s (%s) registered.\n",
            GWNSTR(name), GWNSTR(user->dn));
            
    return 0;
}
Beispiel #4
0
int gw_tm_mad_init(gw_tm_mad_t * tm_mad, 
                   const char *  exe, 
                   const char *  name,
		           const char *  args,
		           const char *  owner)
{
    char buf[50];
    char str[GW_TM_MAX_STRING], c;
    char info[GW_TM_MAX_INFO];
    char s_job_id[GW_TM_MAX_JOB_ID];
    char s_cp_xfr_id[5];
    char result[GW_TM_MAX_RESULT];
    char action[GW_TM_MAX_ACTION];
    
    int tm_mad_pipe[2], mad_tm_pipe[2];
    int i, rc;
	int length;
	
	if ((name == NULL) || (exe == NULL) || (owner == NULL))
		return -1;
		
	length = strlen(gw_conf.gw_location) + strlen(exe) + 6;
	
    tm_mad->name        = strdup(name);
    tm_mad->executable  = (char *) malloc(sizeof(char)*length);
    
    sprintf(tm_mad->executable,"%s/bin/%s",gw_conf.gw_location,exe);
    
    if (args != NULL)
		tm_mad->argument = strdup(args);
	else
		tm_mad->argument = NULL;
		
    if ( pipe(tm_mad_pipe) == -1 ||  pipe(mad_tm_pipe) == -1)
    {
        gw_log_print("TM",'E',"Could not create communication pipes: %s.\n",
                strerror(errno));
        return -1;
    }

    tm_mad->pid = fork();

    switch (tm_mad->pid){
        case -1: /* Error */
            gw_log_print("TM",'E',"Could not fork to start transfer MAD %s.\n",name);
            return -1;

        case 0: /* Child process (MAD) */
            close(tm_mad_pipe[1]);
            close(mad_tm_pipe[0]);
			
            /* stdin and stdout redirection */
            if ( dup2(tm_mad_pipe[0], 0) != 0 || dup2(mad_tm_pipe[1], 1) != 1)
            {
                gw_log_print("TM",'E',"Could not duplicate communication pipes: %s\n",
                             strerror(errno));                
                exit(-1);
            }
            
            close(tm_mad_pipe[0]);
            close(mad_tm_pipe[1]);
                  
                        
            if (gw_conf.multiuser == GW_TRUE)            
	            execlp("sudo","sudo","-u",owner,tm_mad->executable,tm_mad->argument,NULL);
	        else
			    execlp(tm_mad->executable,tm_mad->executable,tm_mad->argument,NULL);
			    
    	    /* exec should not return */
            gw_log_print("TM",'E',"Could not execute MAD %s (exec/sudo).\n",tm_mad->executable);
	        
	        exit(-1);

            break;

        default: /* Parent process (GWD) */
            close(tm_mad_pipe[0]);
            close(mad_tm_pipe[1]);

            tm_mad->tm_mad_pipe = tm_mad_pipe[1];
            tm_mad->mad_tm_pipe = mad_tm_pipe[0];

            fcntl(tm_mad->tm_mad_pipe, F_SETFD, FD_CLOEXEC); /* Close pipes in other MADs*/
            fcntl(tm_mad->mad_tm_pipe, F_SETFD, FD_CLOEXEC);
            
            sprintf(buf, "INIT %i - - - -\n",gw_conf.number_of_jobs);
            write(tm_mad->tm_mad_pipe, buf, strlen(buf));

            i = 0;
            
            do
            {
                rc = read(tm_mad->mad_tm_pipe, (void *) &c, sizeof(char));
                str[i++] = c;
            }
            while ( rc > 0 && c != '\n' &&  c != '\0');

            str[i] = '\0';
            
            if (rc <= 0)
            {
                gw_log_print("TM",'E',"\tInitialization failure, reading from MAD %s.\n",tm_mad->name);
              	gw_tm_mad_finalize (tm_mad);
                return -1;
            }

            sscanf(str,"%s %s %s %s %[^\n]", action, s_job_id, s_cp_xfr_id, result, info);
            
            if (strcmp(action, "INIT") == 0)
            {
                if (strcmp(result, "SUCCESS") == 0)
                {
                    if (strcmp(info, "-") == 0)
                        tm_mad->url = NULL;
                    else
                        tm_mad->url = strdup(info);
                }
                else
                {
	                gw_log_print("TM",'E',"\tInitialization failure of MAD %s.\n", tm_mad->name);
                	gw_tm_mad_finalize (tm_mad);
                    return -1;            
                }
            }
            else
            {
                gw_log_print("TM",'E',"\tInitialization failure, bad response from MAD %s.\n", tm_mad->name);
              	gw_tm_mad_finalize (tm_mad);
                return -1;            
            }
                        
            break;               
    }

    return 0;
}