示例#1
0
int pbs_stagein(
    
  int   c,
  char *jobid,
  char *location,
  char *extend)

  {
  int                   rc;
  int                   local_errno = 0;

  struct batch_reply   *reply;
  int                   sock;
  struct tcp_chan *chan = NULL;


  if ((jobid == (char *)0) || (*jobid == '\0'))
    return (PBSE_IVALREQ);

  if (location == (char *)0)
    location = (char *)"";

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
    /* send stagein request, a run request with a different id */
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_StageIn, pbs_current_user)) ||
      (rc = encode_DIS_RunJob(chan, jobid, location, 0)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(&local_errno, c);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
  DIS_tcp_cleanup(chan);
  return(rc);
  }
示例#2
0
int PBSD_QueueJob_hash(

    int             connect,     /* I */
    char           *jobid,       /* I */
    char           *destin,
    memmgr        **mm,
    job_data       *job_attr,
    job_data       *res_attr,
    char           *extend,
    char          **job_id,
    char          **msg)

{
    struct batch_reply *reply;
    int                 rc = PBSE_NONE;
    int                 sock;
    int                 tmp_size = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_PROTOCOL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_QueueJob, pbs_current_user)) ||
             (rc = encode_DIS_QueueJob_hash(chan, jobid, destin, mm, job_attr, res_attr)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            if ((rc >= 0) &&
                    (rc <= DIS_INVALID))
                connection[connect].ch_errtxt = memmgr_strdup(mm, (char *)dis_emsg[rc], &tmp_size);
        }
        *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);

        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    if ((rc = DIS_tcp_wflush(chan)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */
    reply = PBSD_rdrpy(&rc, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
        if (rc == PBSE_TIMEOUT)
            rc = PBSE_EXPIRED;
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        rc = PBSE_PROTOCOL;

        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
    }
    else if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
    {
        *msg = memmgr_strdup(mm, reply->brp_un.brp_txt.brp_str, &tmp_size);
    }
    else if (connection[connect].ch_errno == 0)
    {
        *job_id = memmgr_strdup(mm, reply->brp_un.brp_jid, &tmp_size);
    }

    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return rc;
}  /* END PBSD_queuejob() */
示例#3
0
int pbs_rescreserve(
  
  int          c,        /* connection */
  char       **rl,       /* list of resources */
  int          num_resc, /* number of items in list */
  resource_t  *prh)      /* ptr to resource reservation handle */

  {
  int                 rc;
  int                 local_errno = 0;

  struct batch_reply *reply;

  pthread_mutex_lock(connection[c].ch_mutex);

  if (rl == NULL)
    {
    connection[c].ch_errno = PBSE_RMNOPARAM;

    pthread_mutex_unlock(connection[c].ch_mutex);

    return (PBSE_RMNOPARAM);
    }

  if (prh == NULL)
    {
    connection[c].ch_errno = PBSE_RMBADPARAM;

    pthread_mutex_unlock(connection[c].ch_mutex);

    return (PBSE_RMBADPARAM);
    }

  /* send request */

  if ((rc = PBS_resc(c, PBS_BATCH_ReserveResc, rl, num_resc, *prh)) != 0)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    return (rc);
    }

  /*
   * now get reply, if reservation successful, the reservation handle,
   * resource_t, is in the  aux field
   */

  reply = PBSD_rdrpy(&local_errno, c);

  if (((rc = connection[c].ch_errno) == PBSE_NONE) ||
      (rc == PBSE_RMPART))
    {
    *prh = reply->brp_auxcode;
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);

  return (rc);
  } /* END pbs_rescreserve() */
示例#4
0
static int PBSD_scbuf(

    int   c,  /* connection handle     */
    int   reqtype, /* request type */
    int   seq,  /* file chunk sequence number */
    char *buf,  /* file chunk */
    int   len,  /* length of chunk */
    char *jobid,  /* job id (for types 1 and 2 only) */
    enum job_file which) /* standard file type, see libpbs.h */

{

    struct batch_reply *reply;

    int                 rc;
    int                 sock;
    int                 local_errno = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[c].ch_mutex);
    sock = connection[c].ch_socket;
    pthread_mutex_unlock(connection[c].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if (jobid == NULL)
        jobid = ""; /* use null string for null pointer */

    if ((rc = encode_DIS_ReqHdr(chan, reqtype, pbs_current_user)) ||
            (rc = encode_DIS_JobFile(chan, seq, buf, len, jobid, which)) ||
            (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[c].ch_mutex);
        connection[c].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[c].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }
    DIS_tcp_cleanup(chan);

    /* read reply */

    reply = PBSD_rdrpy(&local_errno, c);

    PBSD_FreeReply(reply);

    pthread_mutex_lock(connection[c].ch_mutex);
    rc = connection[c].ch_errno;
    pthread_mutex_unlock(connection[c].ch_mutex);


    return(rc);
}
示例#5
0
char *PBSD_queuejob(

    int             connect,     /* I */
    int            *local_errno, /* O */
    char           *jobid,       /* I */
    char           *destin,
    struct attropl *attrib,
    char           *extend)

{
    struct batch_reply *reply;
    char               *return_jobid = NULL;
    int                 rc;
    int                 sock;
    struct tcp_chan    *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    connection[connect].ch_errno = 0;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(NULL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_QueueJob,pbs_current_user)) ||
             (rc = encode_DIS_QueueJob(chan, jobid, destin, attrib)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);

        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    if (DIS_tcp_wflush(chan))
    {
        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */

    reply = PBSD_rdrpy(local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        *local_errno = PBSE_PROTOCOL;
    }
    else if (connection[connect].ch_errno == 0)
    {
        return_jobid = strdup(reply->brp_un.brp_jid);
    }
    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return(return_jobid);
}  /* END PBSD_queuejob() */
示例#6
0
/**
 * @brief
 *	Makes a PBS_BATCH_Connect request to 'server'.
 *
 * @param[in]   server - the hostname of the pbs server to connect to.
 * @param[in]   extend_data - a string to send as "extend" data.
 *
 * @return int
 * @retval >= 0	index to the internal connection table representing the
 *		connection made.
 * @retval -1	error encountered setting up the connection.
 */
int
__pbs_connect_extend(char *server, char *extend_data)
{
	struct sockaddr_in server_addr;
	struct sockaddr_in my_sockaddr;
	int out;
	int i;
	int f;
	char  *altservers[2];
	int    have_alt = 0;
	struct batch_reply	*reply;
	char server_name[PBS_MAXSERVERNAME+1];
	unsigned int server_port;
	struct sockaddr_in sockname;
	pbs_socklen_t	 socknamelen;
#ifdef WIN32
	struct sockaddr_in to_sock;
	struct sockaddr_in from_sock;
#endif

#ifndef WIN32
	char   pbsrc[_POSIX_PATH_MAX];
	struct stat sb;
	int    using_secondary = 0;
#endif  /* not WIN32 */

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return -1;

	if (pbs_loadconf(0) == 0)
		return -1;

	/* get server host and port	*/

	server = PBS_get_server(server, server_name, &server_port);
	if (server == NULL) {
		pbs_errno = PBSE_NOSERVER;
		return -1;
	}

	if (pbs_conf.pbs_primary && pbs_conf.pbs_secondary) {
		/* failover configuered ...   */
		if (hostnmcmp(server, pbs_conf.pbs_primary) == 0) {
			have_alt = 1;
			/* We want to try the one last seen as "up" first to not   */
			/* have connection delays.   If the primary was up, there  */
			/* is no .pbsrc.NAME file.  If the last command connected  */
			/* to the Secondary, then it created the .pbsrc.USER file. */

			/* see if already seen Primary down */
#ifdef WIN32
			/* due to windows quirks, all try both in same order */
			altservers[0] = pbs_conf.pbs_primary;
			altservers[1] = pbs_conf.pbs_secondary;
#else
			(void)snprintf(pbsrc, _POSIX_PATH_MAX, "%s/.pbsrc.%s", pbs_conf.pbs_tmpdir, pbs_current_user);
			if (stat(pbsrc, &sb) == -1) {
				/* try primary first */
				altservers[0] = pbs_conf.pbs_primary;
				altservers[1] = pbs_conf.pbs_secondary;
				using_secondary = 0;
			} else {
				/* try secondary first */
				altservers[0] = pbs_conf.pbs_secondary;
				altservers[1] = pbs_conf.pbs_primary;
				using_secondary = 1;
			}
#endif
		}
	}

	/* if specific host name declared for the host on which */
	/* this client is running,  get its address */
	if (pbs_conf.pbs_public_host_name) {
		if (get_hostsockaddr(pbs_conf.pbs_public_host_name, &my_sockaddr) != 0)
			return -1; /* pbs_errno was set */
	}

	/* Reserve a connection state record */
	if (pbs_client_thread_lock_conntable() != 0)
		return -1;

	out = -1;
	for (i=1;i<NCONNECTS;i++) {
		if (connection[i].ch_inuse) continue;
		out = i;
		connection[out].ch_errno = 0;
		connection[out].ch_socket= -1;
		connection[out].ch_errtxt = NULL;
		connection[out].ch_inuse = 1; /* reserve the socket */
		break;
	}

	if (pbs_client_thread_unlock_conntable() != 0)
		return -1; /* pbs_errno set by the function */

	if (out < 0) {
		pbs_errno = PBSE_NOCONNECTS;
		return -1;
	}

	/*
	 * connect to server ...
	 * If attempt to connect fails and if Failover configured and
	 *   if attempting to connect to Primary,  try the Secondary
	 *   if attempting to connect to Secondary, try the Primary
	 */
	for (i=0; i<(have_alt+1); ++i) {

		/* get socket	*/

#ifdef WIN32
		/* the following lousy hack is needed since the socket call needs */
		/* SYSTEMROOT env variable properly set! */
		if (getenv("SYSTEMROOT") == NULL) {
			setenv("SYSTEMROOT", "C:\\WINNT", 1);
			setenv("SystemRoot", "C:\\WINNT", 1);
		}
		connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);
		if (connection[out].ch_socket < 0) {
			setenv("SYSTEMROOT", "C:\\WINDOWS", 1);
			setenv("SystemRoot", "C:\\WINDOWS", 1);
			connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);

		}
#else
		connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);
#endif
		if (connection[out].ch_socket < 0) {
			connection[out].ch_inuse = 0;
			pbs_errno = errno;
			return -1;
		}

		/* and connect... */

		if (have_alt) {
			server = altservers[i];
		}
		strcpy(pbs_server, server); /* set for error messages from commands */

		/* If a specific host name is defined which the client should use */

		if (pbs_conf.pbs_public_host_name) {
			/* my address will be in my_sockaddr,  bind the socket to it */
			my_sockaddr.sin_port = 0;
			if (bind(connection[out].ch_socket, (struct sockaddr *)&my_sockaddr, sizeof(my_sockaddr)) != 0) {
				return -1;
			}
		}

		if (get_hostsockaddr(server, &server_addr) != 0)
			return -1;

		server_addr.sin_port = htons(server_port);
		if (connect(connection[out].ch_socket,
			(struct sockaddr *)&server_addr,
			sizeof(struct sockaddr)) == 0) {

				break;
		} else {
			/* connect attempt failed */
			CLOSESOCKET(connection[out].ch_socket);
			pbs_errno = errno;
		}
	}
	if (i >= (have_alt+1)) {
		connection[out].ch_inuse = 0;
		return -1; 		/* cannot connect */
	}

#ifndef WIN32
	if (have_alt && (i == 1)) {
		/* had to use the second listed server ... */
		if (using_secondary == 1) {
			/* remove file that causes trying the Secondary first */
			unlink(pbsrc);
		} else {
			/* create file that causes trying the Primary first   */
			f = open(pbsrc, O_WRONLY|O_CREAT, 0200);
			if (f != -1)
				(void)close(f);
		}
	}
#endif

	/* setup connection level thread context */
	if (pbs_client_thread_init_connect_context(out) != 0) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		/* pbs_errno set by the pbs_connect_init_context routine */
		return -1;
	}

	/*
	 * No need for global lock now on, since rest of the code
	 * is only communication on a connection handle.
	 * But we dont need to lock the connection handle, since this
	 * connection handle is not yet been returned to the client
	 */

	/* The following code was originally  put in for HPUX systems to deal
	 * with the issue where returning from the connect() call doesn't
	 * mean the connection is complete.  However, this has also been
	 * experienced in some Linux ppc64 systems like js-2. Decision was
	 * made to enable this harmless code for all architectures.
	 * FIX: Need to use the socket to send
	 * a message to complete the process.  For IFF authentication there is
	 * no leading authentication message needing to be sent on the client
	 * socket, so will send a "dummy" message and discard the replyback.
	 */

#if !defined(PBS_SECURITY ) || (PBS_SECURITY == STD )

	DIS_tcp_setup(connection[out].ch_socket);
	if ((i = encode_DIS_ReqHdr(connection[out].ch_socket,
		PBS_BATCH_Connect, pbs_current_user)) ||
		(i = encode_DIS_ReqExtend(connection[out].ch_socket,
		extend_data))) {
		pbs_errno = PBSE_SYSTEM;
		return -1;
	}
	if (DIS_tcp_wflush(connection[out].ch_socket)) {
		pbs_errno = PBSE_SYSTEM;
		return -1;
	}

	reply = PBSD_rdrpy(out);
	PBSD_FreeReply(reply);

#endif	/* PBS_SECURITY ... */

	/*do configured authentication (kerberos, pbs_iff, whatever)*/

	/*Get the socket port for engage_authentication() */
	socknamelen = sizeof(sockname);
	if (getsockname(connection[out].ch_socket, (struct sockaddr *)&sockname, &socknamelen))
		return -1;

	if (engage_authentication(connection[out].ch_socket,
		server,
		server_port,
		&sockname) == -1) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		pbs_errno = PBSE_PERM;
		return -1;
	}

	/* setup DIS support routines for following pbs_* calls */

	DIS_tcp_setup(connection[out].ch_socket);
	pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_VLONG;	/* set for 3 hours */

	/*
	 * Disable Nagle's algorithm on the TCP connection to server.
	 * Nagle's algorithm is hurting cmd-server communication.
	 */
	if (pbs_connection_set_nodelay(out) == -1) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		pbs_errno = PBSE_SYSTEM;
		return -1;
	}

	return out;
}
示例#7
0
int PBSD_commit_get_sid(

    int   connect, /* I */
    long *sid,     /* O */
    char *jobid)   /* I */

{
    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    int                 local_errno = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Commit, pbs_current_user)) ||
             (rc = encode_DIS_JobId(chan, jobid)) ||
             (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    DIS_tcp_cleanup(chan);

    /* PBSD_rdrpy sets connection[connect].ch_errno */
    reply = PBSD_rdrpy(&local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    rc = connection[connect].ch_errno;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if (reply == NULL)
    {
        /* couldn't read a response */
        if (rc == PBSE_NONE)
            rc = PBSE_PROTOCOL;
    }
    else
    {
        /* read the sid if given and no error */
        if (rc == PBSE_NONE)
        {
            if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
            {
                if (sid != NULL)
                    *sid = atol(reply->brp_un.brp_txt.brp_str);
            }
            else
                /* (reply->brp_choice == BATCH_REPLY_CHOICE_NULL) */
            {
                *sid = reply->brp_code;
            }
        }

        PBSD_FreeReply(reply);
    }

    return(rc);
} /* END PBSD_commit_get_sid() */
示例#8
0
/**
 * @brief
 *	 encode a Job Credential Batch Request
 *
 * @param[in] c - socket descriptor
 * @param[in] type - credential type
 * @param[in] buf - credentials
 * @param[in] len - credential length
 * @param[in] rpp - indication for whether to use rpp
 * @param[in] msgid - msg id
 *
 * @return	int
 * @retval	0		success
 * @retval	!0(pbse error)	error
 *
 */
int
PBSD_jcred(int c, int type, char *buf, int len, int rpp, char **msgid)
{
	int			rc;
	struct batch_reply	*reply = NULL;
	int			sock;

	if (!rpp) {
		sock = connection[c].ch_socket;
		DIS_tcp_setup(sock);
	} else {
		sock = c;
		if ((rc = is_compose_cmd(sock, IS_CMD, msgid)) != DIS_SUCCESS)
			return rc;
	}

#ifdef  PBS_CRED_GRIDPROXY
	if (type == PBS_CREDTYPE_GRIDPROXY) {
		OM_uint32		major, minor;
		gss_buffer_desc		input, output;
		/*
		 OM_uint32		flag = GSS_C_CONF_FLAG|GSS_C_DELEG_FLAG;
		 */
		OM_uint32		flag = GSS_C_CONF_FLAG;
		gss_ctx_id_t		context = GSS_C_NO_CONTEXT;
		OM_uint32		life;
		int			ret;

		output.length = 0;
		input.length = 0;

		for (;;) {
			major = gss_init_sec_context(&minor,
				GSS_C_NO_CREDENTIAL, &context,
				GSS_C_NO_NAME, GSS_C_NO_OID, flag, 0,
				GSS_C_NO_CHANNEL_BINDINGS, &input, NULL,
				&output, NULL, NULL);

			if (reply)
				PBSD_FreeReply(reply);

			rc = PBSD_GSS_context(sock, output.value, output.length);
			if (rc) {
				connection[c].ch_errtxt = strdup(dis_emsg[rc]);
				if (connection[c].ch_errtxt == NULL)
					return (pbs_errno = PBSE_SYSTEM);
				return (pbs_errno = PBSE_PROTOCOL);
			}

			if (GSS_ERROR(major)) {
				connection[c].ch_errtxt =
					pbs_gss_error("gss_init_sec_context",
					major, minor);
				return (pbs_errno = PBSE_PROTOCOL);
			}

			reply = PBSD_rdrpy(c);
			if (reply == NULL)
				return (pbs_errno = PBSE_PROTOCOL);
			if (pbs_errno != PBSE_NONE) {
				PBSD_FreeReply(reply);
				return pbs_errno;
			}
			if (reply->brp_choice == BATCH_REPLY_CHOICE_Text) {
				input.length = reply->brp_un.brp_txt.brp_txtlen;
				input.value = reply->brp_un.brp_txt.brp_str;
			}
			else {
				input.length = 0;
				input.value = NULL;
			}
			if (input.length == 0 &&
				(major & GSS_S_CONTINUE_NEEDED) == 0)
				break;
		}
		if (reply)
			PBSD_FreeReply(reply);

		(void)gss_release_buffer(&minor, &output);
		if (major != GSS_S_COMPLETE || context == GSS_C_NO_CONTEXT) {
			connection[c].ch_errtxt =
				strdup("context could not be established");
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
			return (pbs_errno = PBSE_PROTOCOL);
		}

		input.value = buf;
		input.length = len;
		output.length = 0;
		major = gss_seal(&minor, context, 1, GSS_C_QOP_DEFAULT,
			&input, &ret, &output);
		if (major != GSS_S_COMPLETE) {
			connection[c].ch_errtxt =
				pbs_gss_error("gss_seal", major, minor);
			return (pbs_errno = PBSE_PROTOCOL);
		}
		if (ret == 0) {
			connection[c].ch_errtxt =
				strdup("confidentiality not available");
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
			return (pbs_errno = PBSE_PROTOCOL);
		}

		buf = output.value;
		len = output.length;

		output.length = 0;
		major = gss_delete_sec_context(&minor, &context, &output);
		if (major == GSS_S_COMPLETE && output.length > 0) {
			(void)gss_process_context_token(&minor,
				context, &output);
			(void)gss_release_buffer(&minor, &output);
		}
	}
#endif

	if ((rc =encode_DIS_ReqHdr(sock, PBS_BATCH_JobCred, pbs_current_user)) ||
		(rc = encode_DIS_JobCred(sock, type, buf, len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		if (!rpp) {
			connection[c].ch_errtxt = strdup(dis_emsg[rc]);
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
		}
		return (pbs_errno = PBSE_PROTOCOL);
	}

	if (rpp) {
		pbs_errno = PBSE_NONE;
		if (rpp_flush(sock))
			pbs_errno = PBSE_PROTOCOL;

		return (pbs_errno);
	}

	if (DIS_tcp_wflush(sock)) {
		return (pbs_errno = PBSE_PROTOCOL);
	}

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	return connection[c].ch_errno;
}
示例#9
0
int parse_response_svr(

  int          sock,
  std::string &err_msg)

  {
  /*
   * PBS_BATCH_PROT_TYPE
   * PBS_BATCH_PROT_VER
   * reply->brp_code
   * reply->brp_auxcode
   * reply->brp_choice
   * if reply->brp_choice == BATCH_REPLY_CHOICE_Text also read:
   * preq->rq_reply.brp_un.brp_txt.brp_str
   * using
   * preq->rq_reply.brp_un.brp_txt.brp_txtlen
   */
  int rc = PBSE_NONE;
  struct batch_reply *reply = NULL;
  char *tmp_val = NULL;
  struct tcp_chan *chan = NULL;
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    }
  else if ((reply = (struct batch_reply *)calloc(1, sizeof(struct batch_reply))) == NULL)
    {
    }
  else if ((rc = decode_DIS_replyCmd(chan, reply)))
    {
    PBSD_FreeReply(reply);

    if (chan->IsTimeout == TRUE)
      {
      rc = PBSE_TIMEOUT;
      }
    else
      {
      rc = PBSE_PROTOCOL;
      }
    if ((tmp_val = pbs_strerror(rc)) == NULL)
      {
      char err_buf[80];
      snprintf(err_buf, 79, "Error creating error message for code %d", rc);
      err_msg = err_buf;
      }
    else
      err_msg = tmp_val;
    }
  else
    {
    rc = reply->brp_code;
    if (reply->brp_code != PBSE_NONE)
      err_msg = reply->brp_un.brp_txt.brp_str;

    PBSD_FreeReply(reply);
    }

  DIS_tcp_cleanup(chan);

  return(rc);
  } // END parse_response_svr()
示例#10
0
int
__pbs_rerunjob(int c, char *jobid, char *extend)
{
	int	rc;
	struct batch_reply *reply;
	int	sock;
	time_t  old_tcp_timeout;

	if ((jobid == (char *)0) || (*jobid == '\0'))
		return (pbs_errno = PBSE_IVALREQ);

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_Rerun, pbs_current_user)) ||
		(rc = encode_DIS_JobId(sock, jobid)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* write data */

	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* Set timeout value to very long value as rerun request */
	/* goes from Server to Mom and may take a long time      */
	old_tcp_timeout = pbs_tcp_timeout;
	pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_VLONG;

	/* read reply from stream into presentation element */

	reply = PBSD_rdrpy(c);

	/* reset timeout */
	pbs_tcp_timeout = old_tcp_timeout;


	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
示例#11
0
int pbs_orderjob_err(
    
  int   c,
  char *job1,
  char *job2,
  char *extend,
  int  *local_errno)

  {
  struct batch_reply *reply;
  int                 rc;
  int                 sock;
  struct tcp_chan *chan = NULL;


  if ((job1 == (char *)0) || (*job1 == '\0') ||
      (job2 == (char *)0) || (*job2 == '\0'))
    return (PBSE_IVALREQ);
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_OrderJob, pbs_current_user))
      || (rc = encode_DIS_MoveJob(chan, job1, job2))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* read reply */

  reply = PBSD_rdrpy(local_errno, c);

  PBSD_FreeReply(reply);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);

  return(rc);
  } /* END pbs_orderjob_err() */
示例#12
0
int pbs_rerunjob_err(
    
  int   c,
  char *jobid,
  char *extend,
  int  *local_errno)

  {
  int                 rc;

  struct batch_reply *reply;
  int                 sock;
  struct tcp_chan *chan = NULL;

  if ((jobid == (char *)0) || (*jobid == '\0'))
    return (PBSE_IVALREQ);

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Rerun, pbs_current_user)) ||
      (rc = encode_DIS_JobId(chan, jobid)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* write data */

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* read reply from stream into presentation element */

  reply = PBSD_rdrpy(local_errno, c);

  PBSD_FreeReply(reply);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return(rc);
  } /* END pbs_rerunjob_err() */
示例#13
0
int
pbs_rescquery(int c, char **resclist, int num_resc,
	int *available, int *allocated, int *reserved, int *down)
{
	int i;
	struct batch_reply *reply;
	int rc = 0;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	if (resclist == 0) {
		pbs_errno = connection[c].ch_errno = PBSE_RMNOPARAM;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* send request */

	if ((rc = PBS_resc(c, PBS_BATCH_Rescq, resclist,
		num_resc, (pbs_resource_t)0)) != 0) {
		(void)pbs_client_thread_unlock_connection(c);
		return rc;
	}

	/* read in reply */

	reply = PBSD_rdrpy(c);
	if ((rc = connection[c].ch_errno) == PBSE_NONE &&
		reply->brp_choice == BATCH_REPLY_CHOICE_RescQuery) {
		struct	brp_rescq	*resq = &reply->brp_un.brp_rescq;

		if (resq == NULL || num_resc != resq->brq_number) {
			rc = pbs_errno = connection[c].ch_errno =
				PBSE_IRESVE;
			goto done;
		}

		/* copy in available and allocated numbers */

		for (i=0; i<num_resc; i++) {
			available[i] = resq->brq_avail[i];
			allocated[i] = resq->brq_alloc[i];
			reserved[i]  = resq->brq_resvd[i];
			down[i]	     = resq->brq_down[i];
		}
	}

done:
	PBSD_FreeReply(reply);

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return (rc);
}
示例#14
0
/**
 * @brief
 *	Open a connection with a pbs server.
 *	Do not allow TCP to block us if Server host is down
 *	At this point, this does not attempt to find a fail_over Server
 *
 * @param[in]   server - specifies the server to which to connect
 * @param[in]   tout - timeout value for select
 *
 * @return int
 * @retval >= 0	index to the internal connection table representing the
 *		connection made.
 * @retval -1	error encountered in getting index
 */
int
pbs_connect_noblk(char *server, int tout)
{
	int out;
	int i;
	pbs_socklen_t l;
	int n;
	struct timeval tv;
	fd_set fdset;
	struct batch_reply *reply;
	char server_name[PBS_MAXSERVERNAME+1];
	unsigned int server_port;
	struct addrinfo *aip, *pai;
	struct addrinfo hints;
	struct sockaddr_in *inp;
	short int connect_err = 0;

	struct sockaddr_in sockname;
	pbs_socklen_t	 socknamelen;

#ifdef WIN32
	int     non_block = 1;
	struct sockaddr_in to_sock;
	struct sockaddr_in from_sock;
#endif

#ifndef WIN32
	int nflg;
	int oflg;
#endif

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return -1;

	if (pbs_loadconf(0) == 0)
		return -1;

	/* get server host and port	*/

	server = PBS_get_server(server, server_name, &server_port);
	if (server == NULL) {
		pbs_errno = PBSE_NOSERVER;
		return -1;
	}

	/* Reserve a connection state record */
	if (pbs_client_thread_lock_conntable() != 0)
		return -1;

	out = -1;
	for (i=1;i<NCONNECTS;i++) {
		if (connection[i].ch_inuse) continue;
		out = i;
		connection[out].ch_inuse = 1;
		connection[out].ch_errno = 0;
		connection[out].ch_socket= -1;
		connection[out].ch_errtxt = NULL;
		break;
	}

	if (pbs_client_thread_unlock_conntable() != 0)
		return -1; /* pbs_errno set by the function */

	if (out < 0) {
		pbs_errno = PBSE_NOCONNECTS;
		return -1;
	}


	/* get socket	*/

#ifdef WIN32
	/* the following lousy hack is needed since the socket call needs */
	/* SYSTEMROOT env variable properly set! */
	if (getenv("SYSTEMROOT") == NULL) {
		setenv("SYSTEMROOT", "C:\\WINNT", 1);
		setenv("SystemRoot", "C:\\WINNT", 1);
	}
	connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);
	if (connection[out].ch_socket < 0) {
		setenv("SYSTEMROOT", "C:\\WINDOWS", 1);
		setenv("SystemRoot", "C:\\WINDOWS", 1);
		connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);
	}
#else
	connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);
#endif
	if (connection[out].ch_socket < 0) {
		connection[out].ch_inuse = 0;
		pbs_errno = ERRORNO;
		return -1;
	}

	/* set socket non-blocking */

#ifdef WIN32
	if (ioctlsocket(connection[out].ch_socket, FIONBIO, &non_block) == SOCKET_ERROR)
#else
	oflg = fcntl(connection[out].ch_socket, F_GETFL) & ~O_ACCMODE;
	nflg = oflg | O_NONBLOCK;
	if (fcntl(connection[out].ch_socket, F_SETFL, nflg) == -1)
#endif
		goto err;

	/* and connect... */

	strcpy(pbs_server, server);    /* set for error messages from commands */
	memset(&hints, 0, sizeof(struct addrinfo));
	/*
	 *      Why do we use AF_UNSPEC rather than AF_INET?  Some
	 *      implementations of getaddrinfo() will take an IPv6
	 *      address and map it to an IPv4 one if we ask for AF_INET
	 *      only.  We don't want that - we want only the addresses
	 *      that are genuinely, natively, IPv4 so we start with
	 *      AF_UNSPEC and filter ai_family below.
	 */
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	if (getaddrinfo(server, NULL, &hints, &pai) != 0) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		pbs_errno = PBSE_BADHOST;
		return -1;
	}
	for (aip = pai; aip != NULL; aip = aip->ai_next) {
		/* skip non-IPv4 addresses */
		if (aip->ai_family == AF_INET) {
			inp = (struct sockaddr_in *) aip->ai_addr;
			break;
		}
	}
	if (aip == NULL) {
		/* treat no IPv4 addresses as getaddrinfo() failure */
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		pbs_errno = PBSE_BADHOST;
		freeaddrinfo(pai);
		return -1;
	} else
		inp->sin_port = htons(server_port);
	if (connect(connection[out].ch_socket,
		aip->ai_addr,
		aip->ai_addrlen) < 0) {
		connect_err = 1;
	}
	if (connect_err == 1)
	{
		/* connect attempt failed */
		pbs_errno = ERRORNO;
		switch (pbs_errno) {
#ifdef WIN32
			case WSAEWOULDBLOCK:
#else
			case EINPROGRESS:
			case EWOULDBLOCK:
#endif
				while (1) {
					FD_ZERO(&fdset);
					FD_SET(connection[out].ch_socket, &fdset);
					tv.tv_sec = tout;
					tv.tv_usec = 0;
					n = select(connection[out].ch_socket+1, NULL, &fdset, NULL, &tv);
					if (n > 0) {
						pbs_errno = 0;
						l = sizeof(pbs_errno);
						(void)getsockopt(connection[out].ch_socket,
							SOL_SOCKET, SO_ERROR,
							&pbs_errno, &l);
						if (pbs_errno == 0)
							break;
						else
							goto err;
					} if ((n < 0) &&
#ifdef WIN32
						(ERRORNO == WSAEINTR)
#else
						(ERRORNO == EINTR)
#endif
						) {
						continue;
					} else {
						goto err;
					}
				}
				break;

			default:
err:
				CLOSESOCKET(connection[out].ch_socket);
				connection[out].ch_inuse = 0;
				freeaddrinfo(pai);
				return -1;	/* cannot connect */

		}
	}
	freeaddrinfo(pai);

	/* reset socket blocking */
#ifdef WIN32
	non_block = 0;
	if (ioctlsocket(connection[out].ch_socket, FIONBIO, &non_block) == SOCKET_ERROR)
#else
	if (fcntl(connection[out].ch_socket, F_SETFL, oflg) < 0)
#endif
		goto err;

	/*
	 * multiple threads cant get the same connection id above,
	 * so no need to lock this piece of code
	 */
	/* setup connection level thread context */
	if (pbs_client_thread_init_connect_context(out) != 0) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		/* pbs_errno set by the pbs_connect_init_context routine */
		return -1;
	}
	/*
	 * even though the following is communication with server on
	 * a connection handle, it does not need to be lock since
	 * this connection handle has not be returned back yet to the client
	 * so others threads cannot use it
	 */

	/* send "dummy" connect message */
	DIS_tcp_setup(connection[out].ch_socket);
	if ((i = encode_DIS_ReqHdr(connection[out].ch_socket,
		PBS_BATCH_Connect, pbs_current_user)) ||
		(i = encode_DIS_ReqExtend(connection[out].ch_socket,
		NULL))) {
		pbs_errno = PBSE_SYSTEM;
		return -1;
	}
	if (DIS_tcp_wflush(connection[out].ch_socket)) {
		pbs_errno = PBSE_SYSTEM;
		return -1;
	}
	reply = PBSD_rdrpy(out);
	PBSD_FreeReply(reply);

	/*do configured authentication (kerberos, pbs_iff, whatever)*/

	/*Get the socket port for engage_authentication()*/
	socknamelen = sizeof(sockname);
	if (getsockname(connection[out].ch_socket, (struct sockaddr *)&sockname, &socknamelen))
		return -1;
	if (engage_authentication(connection[out].ch_socket,
		server,
		server_port,
		&sockname) == -1) {
		CLOSESOCKET(connection[out].ch_socket);
		connection[out].ch_inuse = 0;
		pbs_errno = PBSE_PERM;
		return -1;
	}

	/* setup DIS support routines for following pbs_* calls */
	DIS_tcp_setup(connection[out].ch_socket);
	pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_VLONG;	/* set for 3 hours */

	return out;
}
示例#15
0
char *pbs_locjob_err(
    
  int   c,
  char *jobid,
  char *extend,
  int  *local_errno)

  {
  int rc;

  struct batch_reply *reply;
  char       *ploc = (char *)0;
  int sock;
  struct tcp_chan *chan = NULL;

  if ((jobid == (char *)0) || (*jobid == '\0'))
    {
    *local_errno = PBSE_IVALREQ;
    return(NULL);
    }
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(NULL);
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    return NULL;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_LocateJob, pbs_current_user))
      || (rc = encode_DIS_JobId(chan, jobid))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* write data over tcp stream */

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* read reply from stream */

  reply = PBSD_rdrpy(local_errno,c);

  if (reply == NULL)
    {
    *local_errno = PBSE_PROTOCOL;
    }
  else if (reply->brp_choice != BATCH_REPLY_CHOICE_NULL &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Locate)
    {
#ifndef NDEBUG
    fprintf(stderr, "advise: pbs_locjob\tUnexpected reply choice\n\n");
#endif /* NDEBUG */
    *local_errno = PBSE_PROTOCOL;
    }
  else if (connection[c].ch_errno == 0)
    {
    ploc = strdup(reply->brp_un.brp_locate);
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return(ploc);
  } /* END pbs_locjob_err() */
示例#16
0
/**
 * @brief
 * 		process the reply received for a request issued to
 *		  another server via issue_request()
 *
 * 		Reads the reply from the RPP stream and executes the work task associated
 * 		with the RPP reply message. The RPP request for which this reply arrived
 * 		is matched by comparing the msgid of the reply with the msgid of the work
 * 		tasks stored in the msr_deferred_cmds list of the mom for this stream.
 *
 * @param[in] handle - RPP handle on which reply/close arrived
 *
 * @return void
 */
void
process_DreplyRPP(int handle)
{
	struct work_task	*ptask;
	int			 rc;
	struct batch_request	*request;
	struct batch_reply *reply;
	char 		*msgid = NULL;
	mominfo_t *pmom = 0;

	if ((pmom = tfind2((u_long) handle, 0, &streams)) == NULL)
		return;

	DIS_rpp_reset();

	/* find the work task for the socket, it will point us to the request */
	msgid = disrst(handle, &rc);

	if (!msgid || rc) { /* rpp connection actually broke, cull all pending requests */
		while ((ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds)))) {
			/* no need to compare wt_event with handle, since the
			 * task list is for this mom and so it will always match
			 */
			if (ptask->wt_type == WORK_Deferred_Reply) {
				request = ptask->wt_parm1;
				if (request) {
					request->rq_reply.brp_code = rc;
					request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL;
				}
			}

			ptask->wt_aux = PBSE_NORELYMOM;
			pbs_errno = PBSE_NORELYMOM;

			if (ptask->wt_event2)
				free(ptask->wt_event2);

			dispatch_task(ptask);
		}
	} else {
		/* we read msgid fine, so proceed to match it and process the respective task */

		/* get the task list */
		ptask = (struct work_task *)GET_NEXT((((mom_svrinfo_t *) (pmom->mi_data))->msr_deferred_cmds));

		while (ptask) {

			char *cmd_msgid = ptask->wt_event2;

			if (strcmp(cmd_msgid, msgid) == 0) {

				if (ptask->wt_type == WORK_Deferred_Reply)
					request = ptask->wt_parm1;
				else
					request = NULL;

				if (!request) {
					if ((reply = (struct batch_reply *) malloc(sizeof(struct batch_reply))) == 0) {
						delete_task(ptask);
						free(cmd_msgid);
						log_err(errno, msg_daemonname, "Out of memory creating batch reply");
						return;
					}
					(void) memset(reply, 0, sizeof(struct batch_reply));
				} else {
					reply = &request->rq_reply;
				}

				/* read and decode the reply */
				if ((rc = DIS_reply_read(handle, reply, 1)) != 0) {
					reply->brp_code = rc;
					reply->brp_choice = BATCH_REPLY_CHOICE_NULL;
					ptask->wt_aux = PBSE_NORELYMOM;
					pbs_errno = PBSE_NORELYMOM;
				} else {
					ptask->wt_aux = reply->brp_code;
					pbs_errno = reply->brp_code;
				}

				ptask->wt_parm3 = reply; /* set the reply in case callback fn uses without having a preq */

				dispatch_task(ptask);

				if (!request)
					PBSD_FreeReply(reply);

				free(cmd_msgid);

				break;
			}
			ptask = (struct work_task *) GET_NEXT(ptask->wt_linkobj2);
		}
		free(msgid); /* the msgid read should be free after use in matching */
	}
}
示例#17
0
/**
 * @brief
 *	-send async run job batch request.
 *
 * @param[in] c - connection handle
 * @param[in] jobid- job identifier
 * @param[in] location - string of vnodes/resources to be allocated to the job 
 * @param[in] extend - extend string for encoding req
 *
 * @return      int
 * @retval      0       success
 * @retval      !0      error
 *
 */
int
pbs_asyrunjob(int c, char *jobid, char *location, char *extend)
{
	int	rc;
	struct batch_reply   *reply;
	unsigned long resch = 0;
	int	sock;

	if ((jobid == (char *)0) || (*jobid == '\0'))
		return (pbs_errno = PBSE_IVALREQ);
	if (location == (char *)0)
		location = "";

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	/* send run request */

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_AsyrunJob,
		pbs_current_user)) ||
		(rc = encode_DIS_Run(sock, jobid, location, resch)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* get reply */

	reply = PBSD_rdrpy(c);
	rc = connection[c].ch_errno;

	PBSD_FreeReply(reply);

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
示例#18
0
/**
 * @brief
 *      Generate munge key specific to the user and send PBS batch request
 *      (PBS_BATCH_AuthExternal)to PBS server to authenticate user.
 *
 * @param[in] sock - socket fd
 * @param[in] auth_type - Authentication type (Munge/AMS etc)
 * @param[in] fromsvr - connection initiated from server?
 *
 * @return  int
 * @retval   0 on success
 * @retval  -1 on failure
 * @retval  -2 on unsupported auth_type
 *
 */
int
engage_external_authentication(int sock, int auth_type, int fromsvr, char *ebuf, int ebufsz)
{
	int cred_len = 0, rc = 0, ret = 0;
	char *cred = NULL;
	struct batch_reply *reply = NULL;

	switch (auth_type) {
#ifndef WIN32
		case AUTH_MUNGE:
			ebuf[0] = '\0';
			cred = pbs_get_munge_auth_data(fromsvr, ebuf, ebufsz);
			if (!cred)
				goto err;
			break;
#endif
		default:
			snprintf(ebuf, ebufsz, "Authentication type not supported");
			ret = -2;
	}

	if (cred) {
		ret = -1;
		cred_len = strlen(cred);
		DIS_tcp_setup(sock);
		if (encode_DIS_ReqHdr(sock, PBS_BATCH_AuthExternal, pbs_current_user) ||
				diswuc(sock, auth_type) || /* authentication_type */
				diswsi(sock, cred_len) ||       /* credential length */
				diswcs(sock, cred, cred_len) || /* credential data */
				encode_DIS_ReqExtend(sock, NULL)) {
			pbs_errno = PBSE_SYSTEM;
			goto err;
		}

		if (DIS_tcp_wflush(sock)) {
			pbs_errno = PBSE_SYSTEM;
			goto err;
		}

		memset(cred, 0, cred_len);

		reply = PBSD_rdrpy_sock(sock, &rc);
		if ((reply != NULL) && (reply->brp_code != 0)) {
			pbs_errno = PBSE_BADCRED;
			PBSD_FreeReply(reply);
			goto err;
		}

		PBSD_FreeReply(reply);
		free(cred);
		return 0;
	}

	/* else fall through */

err:
	if (ebuf[0] != '\0') {
		fprintf(stderr, "%s\n", ebuf);
		cs_logerr(-1, __func__, ebuf);
	}
	free(cred);
	return ret;
}