xref: /titanic_41/usr/src/cmd/cmd-crypto/cryptoadm/adm_util.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <strings.h>
30 #include "cryptoadm.h"
31 
32 
33 /*
34  * Create one item of type mechlist_t with the mechanism name.  A null is
35  * returned to indicate that the storage space available is insufficient.
36  */
37 mechlist_t *
38 create_mech(char *name)
39 {
40 	mechlist_t *pres = NULL;
41 
42 	if (name == NULL) {
43 		return (NULL);
44 	}
45 
46 	pres = malloc(sizeof (mechlist_t));
47 	if (pres == NULL) {
48 		cryptodebug("out of memory.");
49 		return (NULL);
50 	}
51 
52 	(void) strlcpy(pres->name, name, sizeof (pres->name));
53 	pres->next = NULL;
54 
55 	return (pres);
56 }
57 
58 
59 
60 void
61 free_mechlist(mechlist_t *plist)
62 {
63 	mechlist_t *pnext;
64 
65 	while (plist != NULL) {
66 		pnext = plist->next;
67 		free(plist);
68 		plist = pnext;
69 	}
70 }
71 
72 
73 
74 /*
75  * Check if the mechanism is in the mechanism list.
76  */
77 boolean_t
78 is_in_list(char *mechname, mechlist_t *plist)
79 {
80 	boolean_t found = B_FALSE;
81 
82 	if (mechname == NULL) {
83 		return (B_FALSE);
84 	}
85 
86 	while (plist != NULL) {
87 		if (strcmp(plist->name, mechname) == 0) {
88 			found = B_TRUE;
89 			break;
90 		}
91 		plist = plist->next;
92 	}
93 
94 	return (found);
95 }
96