/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
*/
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <nfs/fedfs.h>
/*
* Take an array of 'host:/path' strings and convert it to something
* suitable for nsdb_add().
*/
nsdb_entry_t **
nsdb_parse(int numloc, char **loclist)
{
int i;
char *t;
nsdb_entry_t **locs;
locs = calloc(numloc + 1, sizeof (nsdb_entry_t *));
if (locs == NULL)
return (NULL);
for (i = 0; i < numloc; i++) {
locs[i] = calloc(1, sizeof (nsdb_entry_t));
t = strrchr(loclist[i], ':');
if (t == NULL) {
free(locs);
return (NULL);
}
*t = '\0';
locs[i]->host = strdup(loclist[i]);
locs[i]->path = strdup(t + 1);
*t = ':';
if (locs[i]->host == NULL || locs[i]->path == NULL) {
int j;
for (j = 0; j <= i; j++) {
if (locs[j]->host != NULL)
free(locs[j]->host);
if (locs[j]->path != NULL)
free(locs[j]->path);
free(locs[j]);
}
free(locs);
return (NULL);
}
locs[i]->share = NULL;
locs[i]->annotations = NULL;
}
return (locs);
}