2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1992-1995, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <security/pam_appl.h>
2N/A#include <string.h>
2N/A#include <stdlib.h>
2N/A#include <malloc.h>
2N/A
2N/A#include "sample_utils.h"
2N/A
2N/A/* ******************************************************************** */
2N/A/* */
2N/A/* Utilities Functions */
2N/A/* */
2N/A/* ******************************************************************** */
2N/A
2N/A/*
2N/A * __free_msg():
2N/A * free storage for messages used in the call back "pam_conv" functions
2N/A */
2N/A
2N/Avoid
2N/A__free_msg(num_msg, msg)
2N/A int num_msg;
2N/A struct pam_message *msg;
2N/A{
2N/A int i;
2N/A struct pam_message *m;
2N/A
2N/A if (msg) {
2N/A m = msg;
2N/A for (i = 0; i < num_msg; i++, m++) {
2N/A if (m->msg)
2N/A free(m->msg);
2N/A }
2N/A free(msg);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * __free_resp():
2N/A * free storage for responses used in the call back "pam_conv" functions
2N/A */
2N/A
2N/Avoid
2N/A__free_resp(num_msg, resp)
2N/A int num_msg;
2N/A struct pam_response *resp;
2N/A{
2N/A int i;
2N/A struct pam_response *r;
2N/A
2N/A if (resp) {
2N/A r = resp;
2N/A for (i = 0; i < num_msg; i++, r++) {
2N/A if (r->resp)
2N/A free(r->resp);
2N/A }
2N/A free(resp);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * __display_errmsg():
2N/A * display error message by calling the call back functions
2N/A * provided by the application through "pam_conv" structure
2N/A */
2N/A
2N/Aint
2N/A__display_errmsg(conv_funp, num_msg, messages, conv_apdp)
2N/A int (*conv_funp)();
2N/A int num_msg;
2N/A char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE];
2N/A void *conv_apdp;
2N/A{
2N/A struct pam_message *msg;
2N/A struct pam_message *m;
2N/A struct pam_response *resp;
2N/A int i;
2N/A int k;
2N/A int retcode;
2N/A
2N/A msg = (struct pam_message *)calloc(num_msg,
2N/A sizeof (struct pam_message));
2N/A if (msg == NULL) {
2N/A return (PAM_CONV_ERR);
2N/A }
2N/A m = msg;
2N/A
2N/A i = 0;
2N/A k = num_msg;
2N/A resp = NULL;
2N/A while (k--) {
2N/A /*
2N/A * fill out the pam_message structure to display error message
2N/A */
2N/A m->msg_style = PAM_ERROR_MSG;
2N/A m->msg = (char *)malloc(PAM_MAX_MSG_SIZE);
2N/A if (m->msg != NULL)
2N/A (void) strcpy(m->msg, (const char *)messages[i]);
2N/A else
2N/A continue;
2N/A m++;
2N/A i++;
2N/A }
2N/A
2N/A /*
2N/A * Call conv function to display the message,
2N/A * ignoring return value for now
2N/A */
2N/A retcode = conv_funp(num_msg, &msg, &resp, conv_apdp);
2N/A __free_msg(num_msg, msg);
2N/A __free_resp(num_msg, resp);
2N/A return (retcode);
2N/A}
2N/A
2N/A/*
2N/A * __get_authtok():
2N/A * get authentication token by calling the call back functions
2N/A * provided by the application through "pam_conv" structure
2N/A */
2N/A
2N/Aint
2N/A__get_authtok(conv_funp, num_msg, messages, conv_apdp, ret_respp)
2N/A int (*conv_funp)();
2N/A int num_msg;
2N/A char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE];
2N/A void *conv_apdp;
2N/A struct pam_response **ret_respp;
2N/A{
2N/A struct pam_message *msg;
2N/A struct pam_message *m;
2N/A int i;
2N/A int k;
2N/A int retcode;
2N/A
2N/A i = 0;
2N/A k = num_msg;
2N/A
2N/A msg = (struct pam_message *)calloc(num_msg,
2N/A sizeof (struct pam_message));
2N/A if (msg == NULL) {
2N/A return (PAM_CONV_ERR);
2N/A }
2N/A m = msg;
2N/A
2N/A while (k--) {
2N/A /*
2N/A * fill out the message structure to display error message
2N/A */
2N/A m->msg_style = PAM_PROMPT_ECHO_OFF;
2N/A m->msg = (char *)malloc(PAM_MAX_MSG_SIZE);
2N/A if (m->msg != NULL)
2N/A (void) strcpy(m->msg, (char *)messages[i]);
2N/A else
2N/A continue;
2N/A m++;
2N/A i++;
2N/A }
2N/A
2N/A /*
2N/A * Call conv function to display the prompt,
2N/A * ignoring return value for now
2N/A */
2N/A retcode = conv_funp(num_msg, &msg, ret_respp, conv_apdp);
2N/A __free_msg(num_msg, msg);
2N/A return (retcode);
2N/A}