Example #1
0
/**
 * @brief
 * 	-PBS_resc() - internal common code for sending resource requests
 *
 * @par Functionality:
 *	Formats and sends the requests for pbs_rescquery(), pbs_rescreserve(),
 *	and pbs_rescfree().   Note, while the request is overloaded for all
 *	three, each has its own expected reply format.
 *
 * @param[in] c - communication handle
 * @param[in] reqtype - request type
 * @param[in] rescl- pointer to resource list
 * @param[in] ct - count of query strings
 * @param[in] rh - resource handle
 *
 * @return      int
 * @retval      0       success
 * @retval      !0      error
 *
 */
static int
PBS_resc(int c, int reqtype, char **rescl, int ct, pbs_resource_t rh)
{
	int rc;
	int sock;

	sock = connection[c].ch_socket;

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

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, reqtype, pbs_current_user)) ||
		(rc = encode_DIS_Resc(sock, rescl, ct, rh)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		return (pbs_errno);
	}
	if (DIS_tcp_wflush(sock)) {
		return (pbs_errno = PBSE_PROTOCOL);
	}
	return (0);
}
Example #2
0
int
PBSD_py_spawn_put(int c, char *jobid, char **argv, char **envp, int rpp, char **msgid)
{
	int rc = 0;
	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;
	}

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_PySpawn,
		pbs_current_user)) ||
		(rc = encode_DIS_PySpawn(sock, jobid, argv, envp)) ||
		(rc = encode_DIS_ReqExtend(sock, NULL))) {
			return (pbs_errno = PBSE_PROTOCOL);
	}

	if (DIS_wflush(sock, rpp)) {
		pbs_errno = PBSE_PROTOCOL;
		rc = pbs_errno;
	}

	return rc;
}
Example #3
0
int
PBSD_msg_put(int c, char *jobid, int fileopt, char *msg, char *extend, int rpp, char **msgid)
{
	int rc = 0;
	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;
	}

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_MessJob,
		pbs_current_user)) ||
		(rc = encode_DIS_MessageJob(sock, jobid, fileopt, msg)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		return (pbs_errno = PBSE_PROTOCOL);
	}
	if (DIS_wflush(sock, rpp)) {
		pbs_errno = PBSE_PROTOCOL;
		rc	  = pbs_errno;
	}

	return rc;
}
Example #4
0
int
__pbs_orderjob(int c, char *job1, char *job2, char *extend)
{
	struct batch_reply *reply;
	int rc;
	int sock;


	if ((job1 == NULL) || (*job1 == '\0') ||
		(job2 == NULL) || (*job2 == '\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_OrderJob, pbs_current_user)) ||
		(rc = encode_DIS_MoveJob(sock, job1, job2)) ||
		(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;
	}

	/* read reply */

	reply = PBSD_rdrpy(c);

	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;
}
Example #5
0
int PBSD_selectattr_put(

  int             c,
  int             type,
  struct attropl *attropl,
  struct attrl   *attrib,
  char           *extend)

  {
  int rc = PBSE_NONE;
  int sock;
  struct tcp_chan *chan = NULL;
  
  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, type, pbs_current_user)) ||
      (rc = encode_DIS_attropl(chan, attropl)) ||
      (rc = encode_DIS_attrl(chan, attrib)) ||
      (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);
    }

  pthread_mutex_unlock(connection[c].ch_mutex);

  /* write data */

  if (DIS_tcp_wflush(chan))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBSD_selectattr_put() */
Example #6
0
int PBSD_rdytocmt(

  int   connect,
  char *jobid)

  {
  int                 rc;

  struct batch_reply *reply;
  int                 sock;
  struct tcp_chan *chan = NULL;
  
  if ((connect < 0) || 
      (connect >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  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_RdytoCommit, 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);

  /* read reply */

  reply = PBSD_rdrpy(&rc, connect);

  PBSD_FreeReply(reply);

  return(rc);
  }
Example #7
0
int PBSD_status_put(

    int           c,
    int           function,
    char         *id,
    struct attrl *attrib,
    char         *extend)

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

    if ((c < 0) ||
            (c >= PBS_NET_MAX_CONNECTIONS))
    {
        return(PBSE_IVALREQ);
    }

    mutex_mgr ch_mutex = mutex_mgr(connection[c].ch_mutex, false);

    sock = connection[c].ch_socket;

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        rc = PBSE_MEM_MALLOC;
        return rc;
    }
    else if ((rc = encode_DIS_ReqHdr(chan, function, pbs_current_user)) ||
             (rc = encode_DIS_Status(chan, id, attrib)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        connection[c].ch_errtxt = strdup(dis_emsg[rc]);

        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    ch_mutex.unlock();

    if (DIS_tcp_wflush(chan))
    {
        rc = PBSE_PROTOCOL;
    }

    /* success */

    DIS_tcp_cleanup(chan);
    return(PBSE_NONE);
}  /* END PBSD_status_put() */
Example #8
0
int
PBSD_ucred(int c, char *user, int type, char *buf, int len)
{
	int			rc;
	struct batch_reply	*reply = NULL;
	int			sock;

	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;

	DIS_tcp_setup(sock);

	if ((rc =encode_DIS_ReqHdr(sock, PBS_BATCH_UserCred, pbs_current_user)) ||
		(rc = encode_DIS_UserCred(sock, user, type, buf, len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		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;
	}

	reply = PBSD_rdrpy(c);

	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;
}
Example #9
0
int pbs_lock(

  int   c,      /* I */
  int   action, /* I */
  char *extend) /* I */

  {

  struct batch_reply *reply;

  int rc = 0;
  int sock;

  /* send request */

  sock = connection[c].ch_socket;

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

  DIS_tcp_setup(sock);

  if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_SchedulerLock, pbs_current_user)) ||
      (rc = encode_DIS_SchedLock(sock, action)) ||
      (rc = encode_DIS_ReqExtend(sock, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

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

    return(pbs_errno);
    }

  /* read in reply */

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

  PBSD_FreeReply(reply);

  return(rc);
  }  /* END pbs_terminate() */
Example #10
0
int PBSD_mgr_put(

  int             c,        /* I */
  int             function, /* I */
  int             command,  /* I */
  int             objtype,  /* I */
  char           *objname,  /* I */
  struct attropl *aoplp,    /* I */
  char           *extend)   /* I */

  {
  int rc = PBSE_NONE;
  int sock;
  struct tcp_chan *chan = NULL;

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  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, function, pbs_current_user)) ||
           (rc = encode_DIS_Manage(chan, command, objtype, objname, aoplp)) ||
           (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);
    rc = PBSE_PROTOCOL; /* We shouldn't be overridding this error!!! */
    return rc;
    }

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

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return rc;
  }  /* END PBSD_mgr_put() */
Example #11
0
int PBSD_commit(

    int   connect,  /* I */
    char *jobid)    /* I */

{

    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    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(&rc, connect);

    PBSD_FreeReply(reply);
    return(rc);
}  /* END PBSD_commit() */
Example #12
0
static int
PBSD_GSS_context(int sock, char *buf, int len)
{
	int			rc;

	if (len == 0)
		return 0;

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_GSS_Context,
		pbs_current_user)) ||
		(rc = diswcs(sock, buf, (size_t)len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		return rc;
	}
	if (DIS_tcp_wflush(sock))
		return DIS_NOCOMMIT;

	return 0;
}
Example #13
0
static int PBS_resc(
    
  int          c,
  int          reqtype, 
  char       **rescl,
  int          ct,
  resource_t   rh)
  {
  int rc;
  int sock;
  struct tcp_chan *chan = NULL;

  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, reqtype, pbs_current_user)) ||
      (rc = encode_DIS_Resc(chan, rescl, ct, rh)) ||
      (rc = encode_DIS_ReqExtend(chan, (char *)0)))
    {
    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))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBS_resc() */
Example #14
0
int PBSD_async_sig_put(

    int   c,
    char *jobid,
    char *signal,
    char *extend)

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

    pthread_mutex_lock(connection[c].ch_mutex);

    sock = connection[c].ch_socket;
    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        rc = PBSE_PROTOCOL;
        return rc;
    }
    else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_SignalJob,pbs_current_user))
             || (rc = encode_DIS_SignalJob(chan,jobid,signal))
             || (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);
    }

    pthread_mutex_unlock(connection[c].ch_mutex);

    if (DIS_tcp_wflush(chan))
    {
        rc = PBSE_PROTOCOL;
    }

    DIS_tcp_cleanup(chan);
    return(rc);
} /* END PBSD_async_sig_put() */
Example #15
0
int PBSD_status_put(

  int           c,
  int           function,
  char         *id,
  struct attrl *attrib,
  char         *extend)

  {
  int rc = 0;
  int sock;

  sock = connection[c].ch_socket;

  DIS_tcp_setup(sock);

  if ((rc = encode_DIS_ReqHdr(sock, function, pbs_current_user)) ||
      (rc = encode_DIS_Status(sock, id, attrib)) ||
      (rc = encode_DIS_ReqExtend(sock, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

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

    return(pbs_errno);
    }

  /* success */

  return(0);
  }  /* END PBSD_status_put() */
Example #16
0
int PBSD_gpu_put(
    
  int   c,
  char *node,
  char *gpuid,
  int   gpumode,
  int   reset_perm,
  int   reset_vol,
  char *extend)
  
  {
  int sock;
  int rc = 0;
  struct tcp_chan *chan = NULL;

  sock = connection[c].ch_socket;
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    return PBSE_PROTOCOL;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_GpuCtrl, pbs_current_user)) ||
      (rc = encode_DIS_GpuCtrl(chan, node, gpuid, gpumode, reset_perm, reset_vol)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    rc = PBSE_PROTOCOL;
    }

  DIS_tcp_cleanup(chan);
  return(rc);
  }
int pbs_asyrunjob_err(

  int   c,
  char *jobid,    /* I */
  char *location,
  char *extend,
  int  *local_errno)

  {
  int                 rc;

  struct batch_reply *reply;
  unsigned int        resch = 0;
  int                 sock;
  struct tcp_chan *chan = NULL;

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

  if (location == NULL)
    location = "";

  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)
    {
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AsyrunJob, pbs_current_user))
      || (rc = encode_DIS_RunJob(chan, jobid, location, resch))
      || (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);
  }  /* END pbs_asyrunjob_err() */
Example #18
0
int pbs_runjob_err(

  int   c,
  char *jobid,
  char *location,
  char *extend,
  int  *rc)

  {
  struct batch_reply   *reply;
  unsigned int          resch = 0;
  int                   sock;
  struct tcp_chan *chan = NULL;

  /* NOTE:  set_task sets WORK_Deferred_Child : request remains until child terminates */

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

  if (location == NULL)
    {
    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 run request */
  else if ((*rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RunJob, pbs_current_user)) ||
           (*rc = encode_DIS_RunJob(chan, jobid, location, resch)) ||
           (*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 ((*rc = DIS_tcp_wflush(chan)) != PBSE_NONE)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    
    DIS_tcp_cleanup(chan);

    return(PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(rc, c);

/*  *rc = connection[c].ch_errno; */

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
    
  DIS_tcp_cleanup(chan);

  return(*rc);
  }  /* END pbs_runjob_err() */
Example #19
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 == NULL) || (*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;
}
Example #20
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc;

  munge_ctx_t         mctx = NULL;
  munge_err_t         mret = EMUNGE_SNAFU;
  char               *mcred = NULL;

  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan    *chan;

  if ((mctx = munge_ctx_create()) == NULL)
    {
    return(-1);
    }

  if ((mret = munge_encode (&mcred, mctx, NULL, 0)) != EMUNGE_SUCCESS)
    {
    const char *merrmsg = NULL;
    if (!(merrmsg = munge_ctx_strerror(mctx)))
      {
      merrmsg = munge_strerror(mret);
      }

    fprintf(stderr, "munge_encode failed: %s (%d)\n", merrmsg, mret);
    munge_ctx_destroy(mctx);
    return(PBSE_MUNGE_NOT_FOUND); /*TODO more fine-grained error codes? */
    }
  
  munge_ctx_destroy(mctx);

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return(-1);
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AltAuthenUser, pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, mcred)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    PBSD_munge_cred_destroy(&mcred);
    /* ERROR */
    return(rc);
    }
  else
    {
    int local_err = PBSE_NONE;
    PBSD_munge_cred_destroy(&mcred);
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_err, handle)) != NULL)
      free(reply);
    
    return(PBSE_NONE);
    }

  return(-1);
  }
Example #21
0
int pbs_original_connect(

  char *server)  /* I (FORMAT:  NULL | '\0' | HOSTNAME | HOSTNAME:PORT )*/

  {
  struct sockaddr_in server_addr;

  struct hostent *hp;
  int out;
  int i;
#ifdef GSSAPI
  int neediff = 0;
#endif
  int auth;

  struct passwd *pw;
  int use_unixsock = 0;
#ifdef ENABLE_UNIX_SOCKETS

  struct sockaddr_un unserver_addr;
  char hnamebuf[256];
#endif

  char  *ptr;

  /* reserve a connection state record */

  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 (out < 0)
    {
    pbs_errno = PBSE_NOCONNECTS;

    if (getenv("PBSDEBUG"))
      fprintf(stderr, "ALERT:  cannot locate free channel\n");

    /* FAILURE */

    return(-1);
    }

  /* get server host and port */

  server = PBS_get_server(server, &server_port);

  if (server == NULL)
    {
    connection[out].ch_inuse = 0;
    pbs_errno = PBSE_NOSERVER;

    if (getenv("PBSDEBUG"))
      fprintf(stderr, "ALERT:  PBS_get_server() failed\n");

    return(-1);
    }

  /* determine who we are */

  pbs_current_uid = getuid();

  if ((pw = getpwuid(pbs_current_uid)) == NULL)
    {
    pbs_errno = PBSE_SYSTEM;

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "ALERT:  cannot get password info for uid %ld\n",
              (long)pbs_current_uid);
      }

    return(-1);
    }

  strcpy(pbs_current_user, pw->pw_name);

  pbs_server = server;    /* set for error messages from commands */


#ifdef ENABLE_UNIX_SOCKETS
  /* determine if we want to use unix domain socket */

  if (!strcmp(server, "localhost"))
    use_unixsock = 1;
  else if ((gethostname(hnamebuf, sizeof(hnamebuf) - 1) == 0) && !strcmp(hnamebuf, server))
    use_unixsock = 1;

  /* NOTE: if any part of using unix domain sockets fails,
   * we just cleanup and try again with inet sockets */

  /* get socket */

  if (use_unixsock)
    {
    connection[out].ch_socket = socket(AF_UNIX, SOCK_STREAM, 0);

    if (connection[out].ch_socket < 0)
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot create socket:  errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      connection[out].ch_inuse = 0;

      pbs_errno = PBSE_PROTOCOL;

      use_unixsock = 0;
      }
    }

  /* and connect... */

  if (use_unixsock)
    {
    unserver_addr.sun_family = AF_UNIX;
    strcpy(unserver_addr.sun_path, TSOCK_PATH);

    if (connect(
          connection[out].ch_socket,
          (struct sockaddr *)&unserver_addr,
          (strlen(unserver_addr.sun_path) + sizeof(unserver_addr.sun_family))) < 0)
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = errno;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server, errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      use_unixsock = 0;  /* will try again with inet socket */
      }
    }

  if (use_unixsock)
    {
    if (!send_unix_creds(connection[out].ch_socket))
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot send unix creds to pbs_server:  errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = PBSE_PROTOCOL;

      use_unixsock = 0;  /* will try again with inet socket */
      }
    }

#endif /* END ENABLE_UNIX_SOCKETS */

  if (!use_unixsock)
    {

    /* at this point, either using unix sockets failed, or we determined not to
     * try */

    connection[out].ch_socket = socket(AF_INET, SOCK_STREAM, 0);

    if (connection[out].ch_socket < 0)
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server \"%s\", errno=%d (%s)\n",
                server,
                errno,
                strerror(errno));
        }

      connection[out].ch_inuse = 0;

      pbs_errno = PBSE_PROTOCOL;

      return(-1);
      }

    /* connection succeeded re-mark as used */
    connection[out].ch_inuse = 1;

    server_addr.sin_family = AF_INET;

    hp = NULL;
    hp = gethostbyname(server);
  /* setup DIS support routines for following pbs_* calls */

    if (hp == NULL)
      {
      close(connection[out].ch_socket);
      connection[out].ch_inuse = 0;
      pbs_errno = PBSE_BADHOST;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot get servername (%s) errno=%d (%s)\n",
                (server != NULL) ? server : "NULL",
                errno,
                strerror(errno));
        }

      return(-1);
      }

    memcpy((char *)&server_addr.sin_addr, hp->h_addr_list[0], hp->h_length);

    server_addr.sin_port = htons(server_port);

    if (connect(
          connection[out].ch_socket,
          (struct sockaddr *)&server_addr,
          sizeof(server_addr)) < 0)
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;
      pbs_errno = errno;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot connect to server, errno=%d (%s)\n",
                errno,
                strerror(errno));
        }

      return(-1);
      }

  DIS_tcp_setup(connection[out].ch_socket);

  if ((ptr = getenv("PBSAPITIMEOUT")) != NULL)
    {
    pbs_tcp_timeout = strtol(ptr,NULL,0);	

    if (pbs_tcp_timeout <= 0)
      {
      pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
      }
    }
  else
    {
    pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
    }


  /* If we have GSSAPI, then try gssapi authentication first.  If that fails, fall back to iff.
     If there's no GSSAPI, then just use iff.
   */
#ifdef GSSAPI
  if (!getenv("TORQUE_IGNORE_KERBEROS") &&
      !ignore_kerberos_for_connection &&
      pbsgss_can_get_creds())
    {
    if (encode_DIS_ReqHdr(connection[out].ch_socket, PBS_BATCH_GSSAuthenUser, pbs_current_user) ||
        encode_DIS_ReqExtend(connection[out].ch_socket,0))
      {
      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr,"ERROR:  cannot authenticate connection with gssapi, errno=%d (%s)\n", errno, strerror(errno));
        }
      neediff = 1;
      }
    else
      {
      DIS_tcp_wflush(connection[out].ch_socket);
      if (pbsgss_client_authenticate(server,connection[out].ch_socket,1,1) != 0)
        {
        neediff = 1;
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr,"ERROR:  cannot authenticate connection, errno=%d (%s)\n", errno, strerror(errno));
          }
        }
      }
    }
  else
    {
    neediff = 1;
    }

  if (neediff)
    {
#endif

    /* FIXME: is this necessary?  Contributed by one user that fixes a problem,
       but doesn't fix the same problem for another user! */
#if 0
#if defined(__hpux)
    /*HP-UX : avoiding socket caching */
    send(connection[out].ch_socket, '?', 1, MSG_OOB);

#endif
#endif

    /* Have pbs_iff authenticate connection */

    if ((ENABLE_TRUSTED_AUTH == FALSE) && ((auth = PBSD_authenticate(connection[out].ch_socket)) != 0))
      {
      close(connection[out].ch_socket);

      connection[out].ch_inuse = 0;

      if (auth == ENOENT)
        {
        pbs_errno = ENOENT;
        
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "ERROR:  cannot find pbs_iif executable\n");
          }
        }
      else
        {
      pbs_errno = PBSE_PERM;

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "ERROR:  cannot authenticate connection to server \"%s\", errno=%d (%s)\n",
                server,
                errno,
                strerror(errno));
        }
        }

      return(-1);
      }
#ifdef GSSAPI
    } /* END if neediff */
#endif

    } /* END !useunix */

  DIS_tcp_setup(connection[out].ch_socket);

  if ((ptr = getenv("PBSAPITIMEOUT")) != NULL)
    {
    pbs_tcp_timeout = strtol(ptr, NULL, 0);

    if (pbs_tcp_timeout <= 0)
      {
      pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
      }
    }
  else
    {
    pbs_tcp_timeout = 10800;      /* set for 3 hour time out */
    }

  return(out);
  }  /* END pbs_original_connect() */
Example #22
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() */
Example #23
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);
}
Example #24
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() */
Example #25
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);
  }
Example #26
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() */
Example #27
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc = PBSE_NONE;

  int                 fd;
  FILE               *munge_pipe;
  char                munge_buf[MUNGE_SIZE];
  char                munge_command[MUNGE_SIZE];
  char               *ptr; /* pointer to the current place to copy data into munge_buf */
  int                 bytes_read;
  int                 total_bytes_read = 0;
  int                 local_errno = 0;
  
  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan *chan = NULL;

  snprintf(munge_command,sizeof(munge_command),
    "munge -n 2>/dev/null");

  memset(munge_buf, 0, MUNGE_SIZE);
  ptr = munge_buf; 

  if ((munge_pipe = popen(munge_command,"r")) == NULL)
    {
    /* FAILURE */
    return(-1);
    }

  fd = fileno(munge_pipe);

  while ((bytes_read = read_ac_socket(fd, ptr, MUNGE_SIZE - total_bytes_read)) > 0)
    {
    total_bytes_read += bytes_read;
    ptr += bytes_read;
    }

  pclose(munge_pipe);

  if (bytes_read == -1)
    {
    /* read failed */
    local_errno = errno;
    log_err(local_errno, __func__, "error reading pipe in PBSD_munge_authenticate");
    return -1;
    }
  
  /* if we got no bytes back then Munge may not be installed etc. */
  if (total_bytes_read == 0)
    {
    return(PBSE_MUNGE_NOT_FOUND);
    }

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();  
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return rc;
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    rc = PBSE_MEM_MALLOC;
    }
  else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_AltAuthenUser,pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, munge_buf)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    /* ERROR */
    }
  else
    {
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_errno, handle)) != NULL)
      free(reply);

    rc = PBSE_NONE;
    }
  if (chan != NULL)
    DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBSD_munge_authenticate() */
Example #28
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;
}
Example #29
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() */
int send_request_to_remote_server(
    
  int            conn,
  batch_request *request)

  {
  struct attropl   *patrl;

  struct svrattrl  *psvratl;
  int               rc = PBSE_NONE;
  int               tmp_rc = PBSE_NONE;
  int               sock = 0;
  char              log_buf[LOCAL_LOG_BUF_SIZE];
  struct tcp_chan  *chan = NULL;
    
  pthread_mutex_lock(connection[conn].ch_mutex);
  sock = connection[conn].ch_socket;
  pthread_mutex_unlock(connection[conn].ch_mutex);
  
  request->rq_conn = sock;
  
  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    log_err(PBSE_MEM_MALLOC, __func__,
      "Could not allocate memory for socket buffer");
    close_conn(sock, FALSE);
    return(PBSE_MEM_MALLOC);
    }
  /* the request is bound to another server, encode/send the request */
  switch (request->rq_type)
    {
    case PBS_BATCH_DeleteJob:
 
      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_DeleteJob,
             MGR_CMD_DELETE,
             MGR_OBJ_JOB,
             request->rq_ind.rq_delete.rq_objname,
             NULL,
             NULL);

      break;

    case PBS_BATCH_HoldJob:

      attrl_fixlink(&request->rq_ind.rq_hold.rq_orig.rq_attr);

      psvratl = (struct svrattrl *)GET_NEXT(request->rq_ind.rq_hold.rq_orig.rq_attr);

      patrl = &psvratl->al_atopl;

      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_HoldJob,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_hold.rq_orig.rq_objname,
             patrl,
             NULL);

      break;

    case PBS_BATCH_CheckpointJob:

      rc = PBSD_mgr_put(
             conn,
             PBS_BATCH_CheckpointJob,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_hold.rq_orig.rq_objname,
             NULL,
             NULL);

      break;

    case PBS_BATCH_GpuCtrl:

      rc = PBSD_gpu_put(
             conn,
             request->rq_ind.rq_gpuctrl.rq_momnode,
             request->rq_ind.rq_gpuctrl.rq_gpuid,
             request->rq_ind.rq_gpuctrl.rq_gpumode,
             request->rq_ind.rq_gpuctrl.rq_reset_perm,
             request->rq_ind.rq_gpuctrl.rq_reset_vol,
             NULL);

      break;

    case PBS_BATCH_MessJob:

      rc = PBSD_msg_put(
             conn,
             request->rq_ind.rq_message.rq_jid,
             request->rq_ind.rq_message.rq_file,
             request->rq_ind.rq_message.rq_text,
             NULL);

      break;

    case PBS_BATCH_ModifyJob:

    case PBS_BATCH_AsyModifyJob:

      attrl_fixlink(&request->rq_ind.rq_modify.rq_attr);

      patrl = (struct attropl *) & ((struct svrattrl *)GET_NEXT(
                                      request->rq_ind.rq_modify.rq_attr))->al_atopl;

      rc = PBSD_mgr_put(
             conn,
             request->rq_type,
             MGR_CMD_SET,
             MGR_OBJ_JOB,
             request->rq_ind.rq_modify.rq_objname,
             patrl,
             NULL);

      break;

    case PBS_BATCH_Rerun:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Rerun, msg_daemonname)))
        break;

      if ((rc = encode_DIS_JobId(chan, request->rq_ind.rq_rerun)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_RegistDep:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RegistDep, msg_daemonname)))
        break;

      if ((rc = encode_DIS_Register(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_AsySignalJob:

    case PBS_BATCH_SignalJob:

      rc = PBSD_sig_put(
             conn,
             request->rq_ind.rq_signal.rq_jid,
             request->rq_ind.rq_signal.rq_signame,
             request->rq_extra);

      break;

    case PBS_BATCH_StatusJob:

      rc = PBSD_status_put(
             conn,
             PBS_BATCH_StatusJob,
             request->rq_ind.rq_status.rq_id,
             NULL,
             NULL);

      break;

    case PBS_BATCH_TrackJob:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_TrackJob, msg_daemonname)))
        break;

      if ((rc = encode_DIS_TrackJob(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_ReturnFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_ReturnFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_ReturnFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_CopyFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_CopyFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_CopyFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_DelFiles:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DelFiles, msg_daemonname)))
        break;

      if ((rc = encode_DIS_CopyFiles(chan, request)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, 0)))
        break;

      rc = DIS_tcp_wflush(chan);

      break;

    case PBS_BATCH_DeleteReservation:

      if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_DeleteReservation, msg_daemonname)))
        break;

      if ((rc = encode_DIS_ReqExtend(chan, request->rq_extend)))
        break;

      rc = DIS_tcp_wflush(chan);
      
      break;

    default:

      sprintf(log_buf, msg_issuebad, request->rq_type);

      log_err(-1, __func__, log_buf);

      rc = -1;

      break;
    }  /* END switch (request->rq_type) */

  if ((tmp_rc = DIS_reply_read(chan, &request->rq_reply)) != 0)
    {
    sprintf(log_buf, "DIS_reply_read failed: %d", tmp_rc);
    log_record(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, log_buf);
    request->rq_reply.brp_code = tmp_rc;
    request->rq_reply.brp_choice = BATCH_REPLY_CHOICE_NULL;
    }  
  DIS_tcp_cleanup(chan);
  svr_disconnect(conn);

  return(rc);
  } /* END send_request_to_remote_server() */