Esempio n. 1
0
/**
 * @brief read a batch reply from the given connecction index
 *
 * @param[in] c - The connection index to read from
 *
 * @return DIS error code
 * @retval   DIS_SUCCESS  - Success
 * @retval  !DIS_SUCCESS  - Failure
 */
struct batch_reply *
PBSD_rdrpy(int c)
{
	int rc;
	struct batch_reply *reply;
	int sock;
	time_t old_timeout;

	/* clear any prior error message */

	if (connection[c].ch_errtxt != (char *)NULL) {
		free(connection[c].ch_errtxt);
		connection[c].ch_errtxt = (char *)NULL;
	}

	sock = connection[c].ch_socket;
	reply = PBSD_rdrpy_sock(sock, &rc);
	if (reply == NULL) {
		connection[c].ch_errno = PBSE_PROTOCOL;
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL)
			pbs_errno = PBSE_SYSTEM;
		return (struct batch_reply *) NULL;
	}

	connection[c].ch_errno = reply->brp_code;
	pbs_errno = reply->brp_code;

	if (reply->brp_choice == BATCH_REPLY_CHOICE_Text) {
		if (reply->brp_un.brp_txt.brp_str != NULL) {

			/*No memory leak, see beginning of function*/
			connection[c].ch_errtxt = strdup(reply->brp_un.brp_txt.brp_str);
			if (connection[c].ch_errtxt == NULL) {
				pbs_errno = PBSE_SYSTEM;
				return (struct batch_reply *)NULL;
			}
		}
	}
	return reply;
}
Esempio n. 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;
}