Пример #1
0
static int pwrap_echo_conv(int num_msg,
			   const struct pam_message **msgm,
			   struct pam_response **response,
			   void *appdata_ptr)
{
	int i;
	struct pam_response *reply;
	int *resp_array = appdata_ptr;

	reply = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
	if (reply == NULL) {
		return PAM_CONV_ERR;
	}

	for (i=0; i < num_msg; i++) {
		switch (msgm[i]->msg_style) {
		case PAM_PROMPT_ECHO_OFF:
			add_to_reply(&reply[i], "echo off: ", msgm[i]->msg);
			break;
		case PAM_PROMPT_ECHO_ON:
			add_to_reply(&reply[i], "echo on: ", msgm[i]->msg);
			break;
		case PAM_TEXT_INFO:
			resp_array[0] = 1;
			break;
		case PAM_ERROR_MSG:
			resp_array[1] = 1;
			break;
		default:
			break;
		}
	}

	*response = reply;
	return PAM_SUCCESS;
}
Пример #2
0
static int pamtest_simple_conv(int num_msg,
			       const struct pam_message **msgm,
			       struct pam_response **response,
			       void *appdata_ptr)
{
	int i, ri = 0;
	int ret;
	struct pam_response *reply = NULL;
	const char *prompt;
	struct pamtest_conv_ctx *cctx = \
				    (struct pamtest_conv_ctx *) appdata_ptr;

	if (cctx == NULL) {
		return PAM_CONV_ERR;
	}

	if (response) {
		reply = (struct pam_response *) calloc(num_msg,
						sizeof(struct pam_response));
		if (reply == NULL) {
			return PAM_CONV_ERR;
		}
	}

	for (i=0; i < num_msg; i++) {
		switch (msgm[i]->msg_style) {
		case PAM_PROMPT_ECHO_OFF:
			prompt = (const char *) \
				   cctx->data->in_echo_off[cctx->echo_off_idx];

			if (reply != NULL) {
				if (prompt != NULL) {
					ret = add_to_reply(&reply[ri], prompt);
					if (ret != PAM_SUCCESS) {
						free_reply(reply, num_msg);
						return ret;
					}
				} else {
					reply[ri].resp = NULL;
				}
				ri++;
			}

			cctx->echo_off_idx++;
			break;
		case PAM_PROMPT_ECHO_ON:
			prompt = (const char *) \
				   cctx->data->in_echo_on[cctx->echo_on_idx];
			if (prompt == NULL) {
				free_reply(reply, num_msg);
				return PAM_CONV_ERR;
			}

			if (reply != NULL) {
				if (prompt != NULL) {
					ret = add_to_reply(&reply[ri], prompt);
					if (ret != PAM_SUCCESS) {
						free_reply(reply, num_msg);
						return ret;
					}
				}
				ri++;
			}

			cctx->echo_on_idx++;
			break;
		case PAM_ERROR_MSG:
			if (cctx->data->out_err != NULL) {
				memcpy(cctx->data->out_err[cctx->err_idx],
				       msgm[i]->msg,
				       MIN(strlen(msgm[i]->msg),
					   PAM_MAX_MSG_SIZE));
				cctx->err_idx++;
			}
			break;
		case PAM_TEXT_INFO:
			if (cctx->data->out_info != NULL) {
				memcpy(cctx->data->out_info[cctx->info_idx],
				       msgm[i]->msg,
				       MIN(strlen(msgm[i]->msg),
					   PAM_MAX_MSG_SIZE));
				cctx->info_idx++;
			}
			break;
		default:
			continue;
		}
	}

	if (response && ri > 0) {
		*response = reply;
	} else {
		free(reply);
	}

	return PAM_SUCCESS;
}