10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*991Smcpowers * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 29*991Smcpowers #include <ctype.h> 300Sstevel@tonic-gate #include <strings.h> 310Sstevel@tonic-gate #include "cryptoadm.h" 320Sstevel@tonic-gate 330Sstevel@tonic-gate 340Sstevel@tonic-gate /* 350Sstevel@tonic-gate * Create one item of type mechlist_t with the mechanism name. A null is 360Sstevel@tonic-gate * returned to indicate that the storage space available is insufficient. 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate mechlist_t * 390Sstevel@tonic-gate create_mech(char *name) 400Sstevel@tonic-gate { 410Sstevel@tonic-gate mechlist_t *pres = NULL; 42*991Smcpowers char *first, *last; 430Sstevel@tonic-gate 440Sstevel@tonic-gate if (name == NULL) { 450Sstevel@tonic-gate return (NULL); 460Sstevel@tonic-gate } 470Sstevel@tonic-gate 480Sstevel@tonic-gate pres = malloc(sizeof (mechlist_t)); 490Sstevel@tonic-gate if (pres == NULL) { 500Sstevel@tonic-gate cryptodebug("out of memory."); 510Sstevel@tonic-gate return (NULL); 520Sstevel@tonic-gate } 530Sstevel@tonic-gate 54*991Smcpowers first = name; 55*991Smcpowers while (isspace(*first)) /* nuke leading whitespace */ 56*991Smcpowers first++; 57*991Smcpowers (void) strlcpy(pres->name, first, sizeof (pres->name)); 58*991Smcpowers 59*991Smcpowers last = strrchr(pres->name, '\0'); 60*991Smcpowers last--; 61*991Smcpowers while (isspace(*last)) /* nuke trailing whitespace */ 62*991Smcpowers *last-- = '\0'; 63*991Smcpowers 640Sstevel@tonic-gate pres->next = NULL; 650Sstevel@tonic-gate 660Sstevel@tonic-gate return (pres); 670Sstevel@tonic-gate } 680Sstevel@tonic-gate 690Sstevel@tonic-gate 700Sstevel@tonic-gate 710Sstevel@tonic-gate void 720Sstevel@tonic-gate free_mechlist(mechlist_t *plist) 730Sstevel@tonic-gate { 740Sstevel@tonic-gate mechlist_t *pnext; 750Sstevel@tonic-gate 760Sstevel@tonic-gate while (plist != NULL) { 770Sstevel@tonic-gate pnext = plist->next; 780Sstevel@tonic-gate free(plist); 790Sstevel@tonic-gate plist = pnext; 800Sstevel@tonic-gate } 810Sstevel@tonic-gate } 820Sstevel@tonic-gate 830Sstevel@tonic-gate 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Check if the mechanism is in the mechanism list. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate boolean_t 890Sstevel@tonic-gate is_in_list(char *mechname, mechlist_t *plist) 900Sstevel@tonic-gate { 910Sstevel@tonic-gate boolean_t found = B_FALSE; 920Sstevel@tonic-gate 930Sstevel@tonic-gate if (mechname == NULL) { 940Sstevel@tonic-gate return (B_FALSE); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate while (plist != NULL) { 980Sstevel@tonic-gate if (strcmp(plist->name, mechname) == 0) { 990Sstevel@tonic-gate found = B_TRUE; 1000Sstevel@tonic-gate break; 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate plist = plist->next; 1030Sstevel@tonic-gate } 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate return (found); 1060Sstevel@tonic-gate } 107