예제 #1
0
int
encode_DIS_TrackJob(int sock, struct batch_request *preq)
{
	int   rc;

	if ((rc = diswst(sock, preq->rq_ind.rq_track.rq_jid) != 0) ||
		(rc = diswui(sock, preq->rq_ind.rq_track.rq_hopcount) != 0) ||
		(rc = diswst(sock, preq->rq_ind.rq_track.rq_location) != 0) ||
		(rc = diswuc(sock, preq->rq_ind.rq_track.rq_state[0]) != 0))
			return rc;

	return 0;
}
예제 #2
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;
}