static void setdefaults (void) { int n; char *confpath, *localHost; struct config_param acctdir[] = { {"LSF_RES_ACCTDIR", NULL}, {NULL, NULL} }; struct stat statBuf; char lsfUserName[MAX_LOGIN + 1]; details = 0; if ((confpath = getenv ("LSF_ENVDIR")) == NULL) confpath = "/etc"; ls_readconfenv (acctdir, confpath); if (acctdir[0].paramValue == NULL || stat (acctdir[0].paramValue, &statBuf) == -1) acctdir[0].paramValue = "/tmp"; strcpy (logfile, acctdir[0].paramValue); n = strlen (logfile); strncat (logfile, "/lsf.acct.", MAX_PATH - n); if ((localHost = ls_getmyhostname ()) == NULL) { ls_perror ("ls_getmyhostname"); return; } n = strlen (logfile); strncat (logfile, localHost, MAX_PATH - n); if (getLSFUser_ (lsfUserName, MAX_LOGIN + 1) != 0) { ls_perror ("getLSFUser_"); return; } strcpy (mylogin, lsfUserName); users[0] = mylogin; users[1] = NULL; hosts[0] = NULL; eternity = mkinterval (mktime (&creation), mktime (&destruction)); start = complete = eternity; }
void lsfExecLog(const char *cmd) { static char fname[] = "lsfExecLog"; char lsfUserName[MAXLSFNAMELEN]; if (genParams_[LSF_MLS_LOG].paramValue && ((genParams_[LSF_MLS_LOG].paramValue[0] == 'y') || (genParams_[LSF_MLS_LOG].paramValue[0] == 'Y'))) { getLSFUser_(lsfUserName, sizeof(lsfUserName)); syslog(LOG_INFO, I18N(6259,"%s: user - %s cmd - '%s'"), /* catgets 6259 */ fname, lsfUserName, cmd); } }
int setLockOnOff_(int on, time_t duration, char *hname) { struct limLock lockReq; char *host = hname; if (initenv_(NULL, NULL) <0) return -1; lockReq.on = on; lockReq.uid = getuid(); if (getLSFUser_(lockReq.lsfUserName, sizeof(lockReq.lsfUserName)) < 0) { return -1; } if (duration == 0) lockReq.time = 77760000; else lockReq.time = duration; if (host == NULL) host = ls_getmyhostname(); if (callLim_(LIM_LOCK_HOST, &lockReq, xdr_limLock, NULL, NULL, host, 0, NULL) < 0) return -1; return 0; }
static void remoteOutput (int fidx, char **disOut, char *exHost, char *fname, char *execUsername, char **envp) { char buf[MAXFILENAMELEN]; char *args[MAX_PEEK_ARGS + 4]; char lsfUserName[MAXLINELEN]; # define RSHCMD "rsh" if ((getLSFUser_ (lsfUserName, MAXLINELEN) == 0) && strcmp (lsfUserName, execUsername)) { if (useTmp (exHost, fname)) { sprintf (buf, "/tmp/.lsbtmp%d/%s", (int) getuid (), fname); disOut[fidx] = buf; } else { disOut[fidx] = fname; } args[0] = RSHCMD; args[1] = exHost; args[2] = "-l"; args[3] = execUsername; if (fidx == 2) { args[4] = disOut[0]; args[5] = disOut[1]; args[6] = disOut[2]; args[7] = NULL; } else { args[4] = disOut[0]; args[5] = disOut[1]; args[6] = NULL; } lsfExecvp (RSHCMD, args); fprintf (stderr, I18N_FUNC_S_S_FAIL_S, "execvp", args[0], strerror (errno)); return; } if (useTmp (exHost, fname)) { sprintf (buf, "/tmp/.lsbtmp%d/%s", (int) getuid (), fname); disOut[fidx] = buf; } else disOut[fidx] = fname; if (ls_initrex (1, 0) < 0) { ls_perror ("ls_initrex"); return; } ls_rfcontrol (RF_CMD_RXFLAGS, REXF_CLNTDIR); ls_rexecve (exHost, disOut, REXF_CLNTDIR, envp); fprintf (stderr, I18N_FUNC_S_S_FAIL_S, "ls_rexecv", disOut[0], ls_sysmsg ()); }
struct userInfoEnt * lsb_userinfo (char **users, int *numUsers) { mbdReqType mbdReqtype; XDR xdrs; struct LSFHeader hdr; char *reply_buf; char *request_buf; struct userInfoReply userInfoReply, *reply; static struct infoReq userInfoReq; int i, cc = 0, numReq = -1; char lsfUserName[MAXLINELEN]; if (numUsers) { numReq = *numUsers; *numUsers = 0; } if (numReq < 0) { lsberrno = LSBE_BAD_ARG; return (NULL); } if (userInfoReq.names) free (userInfoReq.names); if (numUsers == NULL || numReq == 0) { userInfoReq.numNames = 0; if ((userInfoReq.names = (char **) malloc (sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.names[0] = ""; cc = 1; } else if (numReq == 1 && users == NULL) { if (getLSFUser_ (lsfUserName, MAXLINELEN) != 0) { return (NULL); } userInfoReq.numNames = 1; if ((userInfoReq.names = (char **) malloc (sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.names[0] = lsfUserName; cc = 1; } else { if ((userInfoReq.names = (char **) calloc (numReq, sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.numNames = numReq; for (i = 0; i < numReq; i++) { if (users[i] && strlen (users[i]) + 1 < MAXHOSTNAMELEN) userInfoReq.names[i] = users[i]; else { free (userInfoReq.names); lsberrno = LSBE_BAD_USER; *numUsers = i; return (NULL); } } cc = numReq; } userInfoReq.resReq = ""; mbdReqtype = BATCH_USER_INFO; cc = sizeof (struct infoReq) + cc * MAXHOSTNAMELEN + cc + 100; if ((request_buf = malloc (cc)) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } xdrmem_create (&xdrs, request_buf, cc, XDR_ENCODE); initLSFHeader_ (&hdr); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg (&xdrs, (char *) &userInfoReq, &hdr, xdr_infoReq, 0, NULL)) { xdr_destroy (&xdrs); free (request_buf); lsberrno = LSBE_XDR; return (NULL); } if ((cc = callmbd (NULL, request_buf, XDR_GETPOS (&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy (&xdrs); free (request_buf); return (NULL); } xdr_destroy (&xdrs); free (request_buf); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_BAD_USER) { xdrmem_create (&xdrs, reply_buf, XDR_DECODE_SIZE_ (cc), XDR_DECODE); reply = &userInfoReply; if (!xdr_userInfoReply (&xdrs, reply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy (&xdrs); if (cc) free (reply_buf); return (NULL); } xdr_destroy (&xdrs); if (cc) free (reply_buf); if (lsberrno == LSBE_BAD_USER) { *numUsers = reply->badUser; return (NULL); } *numUsers = reply->numUsers; return (reply->users); } if (cc) free (reply_buf); return (NULL); }
struct jobInfoHead * lsb_openjobinfo_a (LS_LONG_INT jobId, char *jobName, char *userName, char *queueName, char *hostName, int options) { static int first = TRUE; static struct jobInfoReq jobInfoReq; static struct jobInfoHead jobInfoHead; mbdReqType mbdReqtype; XDR xdrs, xdrs2; char request_buf[MSGSIZE]; char *reply_buf, *clusterName = NULL; int cc, aa; struct LSFHeader hdr; char lsfUserName[MAXLINELEN]; if (first) { if ( !(jobInfoReq.jobName = (char *) malloc(MAX_CMD_DESC_LEN)) || !(jobInfoReq.queue = (char *) malloc(MAX_LSB_NAME_LEN)) || !(jobInfoReq.userName = (char *) malloc(MAX_LSB_NAME_LEN)) || !(jobInfoReq.host = (char *) malloc(MAXHOSTNAMELEN))) { lsberrno = LSBE_SYS_CALL; return(NULL); } first = FALSE; } if (queueName == NULL) jobInfoReq.queue[0] = '\0'; else { if (strlen (queueName) >= MAX_LSB_NAME_LEN - 1) { lsberrno = LSBE_BAD_QUEUE; return(NULL); } TIMEIT(1, strcpy(jobInfoReq.queue, queueName), "strcpy"); } if (hostName == NULL) jobInfoReq.host[0] = '\0'; else { if (ls_isclustername(hostName) > 0) { jobInfoReq.host[0] = '\0'; clusterName = hostName; } else { struct hostent *hp; TIMEIT(0, (hp = Gethostbyname_(hostName)), "getHostOfficialByName_"); if (hp != NULL) { struct hostInfo *hostinfo; char officialNameBuf[MAXHOSTNAMELEN]; strcpy(officialNameBuf, hp->h_name); hostinfo = ls_gethostinfo("-", NULL, (char **)&hp->h_name, 1, LOCAL_ONLY); if (hostinfo == NULL) { strcpy(jobInfoReq.host, hostName); } else { strcpy(jobInfoReq.host, officialNameBuf); } } else { if (strlen (hostName) >= MAXHOSTNAMELEN - 1) { lsberrno = LSBE_BAD_HOST; return(NULL); } strcpy(jobInfoReq.host, hostName); } } } if (jobName == NULL) jobInfoReq.jobName[0] = '\0'; else { if (strlen (jobName) >= MAX_CMD_DESC_LEN - 1) { lsberrno = LSBE_BAD_JOB; return(NULL); } strcpy(jobInfoReq.jobName, jobName); } if (userName == NULL ) { TIMEIT(0, (cc = getLSFUser_(lsfUserName, MAXLINELEN)), "getLSFUser_"); if (cc != 0) { return (NULL); } TIMEIT(1, strcpy(jobInfoReq.userName, lsfUserName), "strcpy"); } else { if (strlen (userName) >= MAX_LSB_NAME_LEN - 1) { lsberrno = LSBE_BAD_USER; return(NULL); } strcpy(jobInfoReq.userName, userName); } if ((options & ~(JOBID_ONLY | JOBID_ONLY_ALL | HOST_NAME | NO_PEND_REASONS)) == 0) jobInfoReq.options = CUR_JOB; else jobInfoReq.options = options; if (jobId < 0) { lsberrno = LSBE_BAD_ARG; return(NULL); } jobInfoReq.jobId = jobId; mbdReqtype = BATCH_JOB_INFO; xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); hdr.opCode = mbdReqtype; TIMEIT(1, (aa = xdr_encodeMsg(&xdrs, (char *) &jobInfoReq , &hdr, xdr_jobInfoReq, 0, NULL)), "xdr_encodeMsg"); if (aa == FALSE) { lsberrno = LSBE_XDR; return(NULL); } TIMEIT(0, (cc = callmbd (clusterName, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, &mbdSock, NULL, NULL)), "callmbd"); if (cc == -1) { xdr_destroy(&xdrs); return (NULL); } xdr_destroy(&xdrs); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR) { xdrmem_create(&xdrs2, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (! xdr_jobInfoHead (&xdrs2, &jobInfoHead, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs2); if (cc) free(reply_buf); return(NULL); } xdr_destroy(&xdrs2); if (cc) free(reply_buf); return (&jobInfoHead); } if (cc) free(reply_buf); return(NULL); }