sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / pam_modules / sample / sample_utils.c
blob9431ce3c695d1b72ece7dee2ba508249bb26c8d5
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1992-1995, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #include <security/pam_appl.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <malloc.h>
32 #include "sample_utils.h"
34 /* ******************************************************************** */
35 /* */
36 /* Utilities Functions */
37 /* */
38 /* ******************************************************************** */
41 * __free_msg():
42 * free storage for messages used in the call back "pam_conv" functions
45 void
46 __free_msg(num_msg, msg)
47 int num_msg;
48 struct pam_message *msg;
50 int i;
51 struct pam_message *m;
53 if (msg) {
54 m = msg;
55 for (i = 0; i < num_msg; i++, m++) {
56 free(m->msg);
58 free(msg);
63 * __free_resp():
64 * free storage for responses used in the call back "pam_conv" functions
67 void
68 __free_resp(num_msg, resp)
69 int num_msg;
70 struct pam_response *resp;
72 int i;
73 struct pam_response *r;
75 if (resp) {
76 r = resp;
77 for (i = 0; i < num_msg; i++, r++) {
78 free(r->resp);
80 free(resp);
85 * __display_errmsg():
86 * display error message by calling the call back functions
87 * provided by the application through "pam_conv" structure
90 int
91 __display_errmsg(conv_funp, num_msg, messages, conv_apdp)
92 int (*conv_funp)();
93 int num_msg;
94 char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE];
95 void *conv_apdp;
97 struct pam_message *msg;
98 struct pam_message *m;
99 struct pam_response *resp;
100 int i;
101 int k;
102 int retcode;
104 msg = (struct pam_message *)calloc(num_msg,
105 sizeof (struct pam_message));
106 if (msg == NULL) {
107 return (PAM_CONV_ERR);
109 m = msg;
111 i = 0;
112 k = num_msg;
113 resp = NULL;
114 while (k--) {
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);
120 if (m->msg != NULL)
121 (void) strcpy(m->msg, (const char *)messages[i]);
122 else
123 continue;
124 m++;
125 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);
135 return (retcode);
139 * __get_authtok():
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)
146 int (*conv_funp)();
147 int num_msg;
148 char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE];
149 void *conv_apdp;
150 struct pam_response **ret_respp;
152 struct pam_message *msg;
153 struct pam_message *m;
154 int i;
155 int k;
156 int retcode;
158 i = 0;
159 k = num_msg;
161 msg = (struct pam_message *)calloc(num_msg,
162 sizeof (struct pam_message));
163 if (msg == NULL) {
164 return (PAM_CONV_ERR);
166 m = msg;
168 while (k--) {
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);
174 if (m->msg != NULL)
175 (void) strcpy(m->msg, (char *)messages[i]);
176 else
177 continue;
178 m++;
179 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);
188 return (retcode);