4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Traverses /etc/dfs/sharetab in order to find shared file systems
40 #include <sharefs/share.h>
48 static mutex_t sharetab_lock
= DEFAULTMUTEX
;
51 * Private method declarations
53 fs_sharelist_t
*create_sharelist_entry(struct share
*sharetab_entry
,
61 fs_free_share_list(fs_sharelist_t
*headp
)
65 while (headp
!= NULL
) {
68 free(headp
->resource
);
71 free(headp
->description
);
80 * Get a linked list of all the shares on the system from /etc/dfs/dfstab
83 fs_get_share_list(int *errp
)
86 fs_sharelist_t
*headp
;
87 fs_sharelist_t
*tailp
;
93 if ((fp
= fopen(SHARETAB
, "r")) != NULL
) {
94 struct share
*sharetab_entry
;
96 (void) mutex_lock(&sharetab_lock
);
97 while (getshare(fp
, &sharetab_entry
) > 0) {
99 newp
= create_sharelist_entry(sharetab_entry
, errp
);
104 fs_free_share_list(headp
);
105 (void) mutex_unlock(&sharetab_lock
);
118 } /* while (getshare(fp, &sharetab_entry) != 0) */
119 (void) mutex_unlock(&sharetab_lock
);
123 } /* if ((fp = fopen(SHARETAB, "r")) != NULL) */
126 * Caller must free the mount list
129 } /* fs_get_share_list */
133 * fs_parse_opts_for_sec_modes
134 * Get an array of strings of all the security modes of the option string.
136 * char *cmd - The option string from the share command.
137 * int *count - pointer to the number of elements in the returned array.
138 * int *error - error pointer for returning any errors.
141 fs_parse_opts_for_sec_modes(char *cmd
, int *count
, int *error
)
144 char **secstringarray
;
148 strptr
= strdup(cmd
);
149 if (strptr
== NULL
) {
157 (char **)calloc((size_t)SECMODES
, (size_t)(sizeof (char *)));
158 if (secstringarray
== NULL
) {
163 if (strstr(strptr
, "sec=") != NULL
) {
167 while (next_str
!= NULL
) {
168 next_str
= strstr(strptr
, "sec=");
169 if (next_str
!= NULL
) {
170 if (strncmp(strptr
, "sec=", 4) != 0) {
171 *(next_str
- 1) = '\0';
174 next_str
= strstr(strptr
+ 4, "sec=");
175 if (next_str
!= NULL
) {
176 *(next_str
- 1) = '\0';
178 secstringarray
[*count
] = strdup(strptr
);
179 if (secstringarray
[*count
] == NULL
) {
182 fileutil_free_string_array(
183 secstringarray
, *count
);
185 free(secstringarray
);
195 secstringarray
[*count
] = strdup(temp_str
);
196 if (secstringarray
[*count
] == NULL
) {
199 fileutil_free_string_array(
200 secstringarray
, *count
);
202 free(secstringarray
);
210 return (secstringarray
);
214 * fs_create_array_from_accesslist
215 * Takes the colon seperated access list parses the list into an array
216 * containing all the elements of the list. The array created is returned
217 * and count is set to the number of elements in the array.
219 * char *access_list - The string containing the colon sperated access list.
220 * int *count - Will contain the number of elements in the array.
221 * int *err - any errors encountered.
224 fs_create_array_from_accesslist(char *access_list
, int *count
, int *err
)
226 char *delimiter
= ":";
228 char **list_array
= NULL
;
232 if (access_list
!= NULL
) {
233 list_copy
= strdup(access_list
);
234 if (list_copy
!= NULL
) {
235 server_string
= strtok(list_copy
, delimiter
);
236 if (server_string
!= NULL
) {
237 while (server_string
!= NULL
) {
238 if (!fileutil_add_string_to_array(
239 &list_array
, server_string
, count
,
241 fileutil_free_string_array(
247 strtok(NULL
, delimiter
);
251 (char **)calloc(((*count
) + 1),
253 if (list_array
== NULL
) {
258 list_array
[*count
] = strdup(access_list
);
259 if (list_array
[*count
] == NULL
) {
274 } /* fs_create_array_from_accesslist */
282 create_sharelist_entry(struct share
*sharetab_entry
, int *errp
)
285 fs_sharelist_t
*newp
;
287 newp
= (fs_sharelist_t
*)calloc((size_t)1,
288 (size_t)sizeof (fs_sharelist_t
));
298 newp
->path
= strdup(sharetab_entry
->sh_path
);
299 if (newp
->path
== NULL
) {
304 fs_free_share_list(newp
);
308 newp
->resource
= strdup(sharetab_entry
->sh_res
);
309 if (newp
->path
== NULL
) {
314 fs_free_share_list(newp
);
318 newp
->fstype
= strdup(sharetab_entry
->sh_fstype
);
319 if (newp
->fstype
== NULL
) {
324 fs_free_share_list(newp
);
328 newp
->options
= strdup(sharetab_entry
->sh_opts
);
329 if (newp
->options
== NULL
) {
334 fs_free_share_list(newp
);
338 newp
->description
= strdup(sharetab_entry
->sh_descr
);
339 if (newp
->description
== NULL
) {
344 fs_free_share_list(newp
);
350 } /* create_sharelist_entry */