4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1992-1995, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #include <security/pam_appl.h>
32 #include "sample_utils.h"
34 /* ******************************************************************** */
36 /* Utilities Functions */
38 /* ******************************************************************** */
42 * free storage for messages used in the call back "pam_conv" functions
46 __free_msg(num_msg
, msg
)
48 struct pam_message
*msg
;
51 struct pam_message
*m
;
55 for (i
= 0; i
< num_msg
; i
++, m
++) {
64 * free storage for responses used in the call back "pam_conv" functions
68 __free_resp(num_msg
, resp
)
70 struct pam_response
*resp
;
73 struct pam_response
*r
;
77 for (i
= 0; i
< num_msg
; i
++, r
++) {
86 * display error message by calling the call back functions
87 * provided by the application through "pam_conv" structure
91 __display_errmsg(conv_funp
, num_msg
, messages
, conv_apdp
)
94 char messages
[PAM_MAX_NUM_MSG
][PAM_MAX_MSG_SIZE
];
97 struct pam_message
*msg
;
98 struct pam_message
*m
;
99 struct pam_response
*resp
;
104 msg
= (struct pam_message
*)calloc(num_msg
,
105 sizeof (struct pam_message
));
107 return (PAM_CONV_ERR
);
116 * fill out the pam_message structure to display error message
118 m
->msg_style
= PAM_ERROR_MSG
;
119 m
->msg
= (char *)malloc(PAM_MAX_MSG_SIZE
);
121 (void) strcpy(m
->msg
, (const char *)messages
[i
]);
129 * Call conv function to display the message,
130 * ignoring return value for now
132 retcode
= conv_funp(num_msg
, &msg
, &resp
, conv_apdp
);
133 __free_msg(num_msg
, msg
);
134 __free_resp(num_msg
, resp
);
140 * get authentication token by calling the call back functions
141 * provided by the application through "pam_conv" structure
145 __get_authtok(conv_funp
, num_msg
, messages
, conv_apdp
, ret_respp
)
148 char messages
[PAM_MAX_NUM_MSG
][PAM_MAX_MSG_SIZE
];
150 struct pam_response
**ret_respp
;
152 struct pam_message
*msg
;
153 struct pam_message
*m
;
161 msg
= (struct pam_message
*)calloc(num_msg
,
162 sizeof (struct pam_message
));
164 return (PAM_CONV_ERR
);
170 * fill out the message structure to display error message
172 m
->msg_style
= PAM_PROMPT_ECHO_OFF
;
173 m
->msg
= (char *)malloc(PAM_MAX_MSG_SIZE
);
175 (void) strcpy(m
->msg
, (char *)messages
[i
]);
183 * Call conv function to display the prompt,
184 * ignoring return value for now
186 retcode
= conv_funp(num_msg
, &msg
, ret_respp
, conv_apdp
);
187 __free_msg(num_msg
, msg
);