ses: SUN plugin doesn't actually need libnvfru
[unleashed.git] / usr / src / lib / libfsmgt / common / nfs_nfssec.c
blob59fefc2bd682072c57855f817aa8eb01d9da2fc0
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 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <errno.h>
30 #include <sys/types.h>
31 #include <nfs/nfs_sec.h>
32 #include <strings.h>
33 #include "libfsmgt.h"
36 * Public methods
40 * Method: nfssec_free_secmode_list
42 * Description: Frees the space allocated for the security mode list array.
44 * Parameters:
45 * - char **seclist - the array to be freed.
46 * - int num_elements - the number of elements in the array.
48 * Returns:
49 * - Nothing
51 void
52 nfssec_free_secmode_list(char **seclist, int num_elements)
54 fileutil_free_string_array(seclist, num_elements);
55 } /* nfssec_free_secmode_list */
58 * Method: nfssec_get_default_secmode
60 * Description: Retrieves the default security mode for NFS.
62 * Parameters:
63 * - int *errp - the error indicator. This will be set to a non-zero
64 * value upon error.
66 * Returns:
67 * - char * - the NFS security mode name.
68 * - NULL if an error occurred.
70 * Note: Caller must free the space allocated for the return value.
72 char *
73 nfssec_get_default_secmode(int *errp)
75 seconfig_t secp, defsecp;
76 char *ret_val;
77 int err = 0;
79 *errp = 0;
80 err = nfs_getseconfig_default(&secp);
81 if (err != 0) {
82 *errp = err;
83 return (NULL);
86 err = nfs_getseconfig_bynumber(secp.sc_nfsnum, &defsecp);
87 if (err != 0) {
88 *errp = err;
89 return (NULL);
92 ret_val = strdup(defsecp.sc_name);
93 if (ret_val == NULL) {
94 *errp = ENOMEM;
95 return (NULL);
98 return (ret_val);
99 } /* nfssec_get_default_secmode */
102 * Method: nfssec_get_nfs_secmode_list
104 * Description: Retrieves a list of the supported NFS security modes from
105 * /etc/nfssec.conf.
107 * Parameters:
108 * - int *num_elements - integer pointer used to keep track of the number
109 * of elements in the array.
110 * - int *errp - the error indicator. This will be set to a non-zero
111 * value upon error.
113 * Returns:
114 * - char ** - The array containing the supported security mode names as
115 * elements.
116 * - NULL if an error occurred.
118 * Note: The space allocated for the return array must be freed by the caller
119 * using nfssec_free_secmode_list.
121 char **
122 nfssec_get_nfs_secmode_list(int *num_elements, int *errp)
124 FILE *fp;
125 char **seclist = NULL;
126 int err = 0;
128 *errp = 0;
129 if ((fp = fopen(NFSSEC_CONF, "r")) == NULL) {
131 * The opening of nfssec.conf failed.
133 *errp = errno;
134 return (NULL);
137 seclist = fileutil_get_first_column_data(fp, num_elements, &err);
138 (void) fclose(fp);
139 if (seclist == NULL) {
140 *errp = err;
141 return (NULL);
144 return (seclist);
145 } /* nfssec_get_nfs_secmode_list */