* the results to amd_out.
*/
static int
-sun2amd_convert(FILE *sun_in, FILE *amd_out)
-{
+sun2amd_convert(FILE *sun_in, FILE *amd_out)
+{
char line_buff[INFO_MAX_LINE_LEN], *tmp, *key, *entry;
int pos, line = 0, retval = 1;
-
+
/* just to be safe */
memset(line_buff, 0, sizeof(line_buff));
-
+
/* Read the input line by line and do the conversion. */
while ((pos = file_read_line(line_buff, sizeof(line_buff), sun_in))) {
line++;
-
+
/* Make sure we have the whole line. */
if (line_buff[pos - 1] != '\n') {
plog(XLOG_ERROR, "map line %d is too long", line);
goto err;
}
-
+
line_buff[pos - 1] = '\0';
-
+
/* remove comments */
if ((tmp = strchr(line_buff, '#')) != NULL) {
*tmp = '\0';
while (*key != '\0' && isspace((int)*key)) {
key++;
}
-
+
/* ignore blank lines */
if (*key == '\0') {
continue;
}
-
+
/* find the end of the key and NULL terminate */
tmp = key;
while (*tmp != '\0' && isspace((int)*tmp) == 0) {
goto err;
}
*tmp++ = '\0';
- if(*tmp == '\0') {
+ if (*tmp == '\0') {
plog(XLOG_ERROR, "map line %d has no entry", line);
goto err;
}
entry = tmp;
-
+
/* convert the sun entry to an amd entry */
if ((tmp = sun_entry2amd(key, entry)) == NULL) {
goto err;
}
-
+
if (fputs(tmp, amd_out) == EOF) {
plog(XLOG_ERROR, "can't write amd entry on line %d: fputs: %s", line, strerror(errno));
goto err;
}
-
+
/* just to be safe */
memset(line_buff, 0, sizeof(line_buff));
}
err:
return retval;
-}
+}
-/*
- * wrapper open function
+/*
+ * wrapper open function
*/
static FILE *
-sun2amd_open(const char *path, const char *mode)
+sun2amd_open(const char *path, const char *mode)
{
FILE *retval = NULL;
-
+
if ((retval = fopen(path,mode)) == NULL) {
plog(XLOG_ERROR,"could not open file %s",path);
}
-
+
return retval;
}
-/*
- * echo the usage and exit
+/*
+ * echo the usage and exit
*/
static void
-sun2amd_usage(void)
+sun2amd_usage(void)
{
fprintf(stderr,
"usage : sun2amd [-hH] [-i infile] [-o outfile]\n"
"-h\thelp\n"
"-i\tspecify an infile (defaults to stdin)\n"
- "-o\tspecify an outfile (defaults to stdout)\n");
+ "-o\tspecify an outfile (defaults to stdout)\n");
}
/* default in/out to stdin/stdout */
FILE *sun_in = stdin, *amd_out = stdout;
int opt, retval = 1;
-
+
while ((opt = getopt(argc, argv , "i:o:hH")) != -1) {
switch (opt) {
-
+
case 'i':
if ((sun_in = sun2amd_open(optarg,"r")) == NULL) {
goto err;
}
break;
-
+
case 'o':
if ((amd_out = sun2amd_open(optarg,"w")) == NULL) {
goto err;
}
break;
-
+
case 'h':
case 'H':
sun2amd_usage();
goto err;
- }
+ }
}
-
+
retval = sun2amd_convert(sun_in,amd_out);
err:
#define AMD_RHOST_KW "rhost:=" /* remote host */
#define AMD_RFS_KW "rfs:=" /* remote file system */
#define AMD_FS_KW "fs:=" /* local file system */
-#define AMD_TYPE_NFS_KW "type:=nfs;" /* fs type nfs */
+#define AMD_TYPE_NFS_KW "type:=nfs;" /* fs type nfs */
#define AMD_TYPE_AUTO_KW "type:=auto;" /* fs type auto */
#define AMD_MAP_FS_KW "fs:=${map};" /* set the mount map as current map */
#define AMD_MAP_PREF_KW "pref:=${key};" /* set the mount map as current map */
-#define SUN_KEY_SUB "&" /* Sun key subsitution */
+#define SUN_KEY_SUB "&" /* Sun key subsitution */
/* a set a Sun variable substitutions for map entries */
-#define SUN_ARCH "$ARCH" /* host architecture */
+#define SUN_ARCH "$ARCH" /* host architecture */
#define SUN_CPU "$CPU" /* processor type */
#define SUN_HOST "$HOST" /* host name */
#define SUN_OSNAME "$OSNAME" /* OS name */
* return - new string with str substitutions, NULL on error
*/
static char *
-sun_strsub(const char *src, const char *str, const char *sub)
+sun_strsub(const char *src, const char *str, const char *sub)
{
-
+
char *retval = NULL, *str_start, *str_end, *src_end;
size_t total_size, first_half, second_half, sub_size;
-
+
/* assign pointers to the start and end of str */
- if((str_start = strstr(src, str)) == NULL) {
+ if ((str_start = strstr(src, str)) == NULL) {
return retval;
}
str_end = (strlen(str) - 1) + str_start;
/* size from the beginning of src to the start of str */
first_half = (size_t)(str_start - src);
-
+
/* size from the end of str to the end of src */
second_half = (size_t)(src_end - str_end);
-
+
sub_size = strlen(sub);
-
+
total_size = (first_half + sub_size + second_half + 1);
-
+
retval = (char*)xmalloc(total_size);
memset(retval, 0, total_size);
- /*
+ /*
* Put together the string such that the first half is copied
* followed the sub and second half.
*
(void)strncat(retval, sub, sub_size);
(void)strncat(retval, str_end + 1, second_half);
- if((str_start = strstr(retval, str)) != NULL) {
+ if ((str_start = strstr(retval, str)) != NULL) {
/*
* If there is another occurrences of str call this function
* recursively.
*/
char* tmp;
- if((tmp = sun_strsub(retval, str, sub)) != NULL) {
+ if ((tmp = sun_strsub(retval, str, sub)) != NULL) {
XFREE(retval);
retval = tmp;
}
* exist in src or error.
*/
static char *
-sun_expand2amd(const char *str)
+sun_expand2amd(const char *str)
{
-
+
char *retval = NULL, *tmp = NULL, *tmp2 = NULL;
const char *pos;
-
+
/*
* Iterator through the string looking for '$' chars. For each '$'
* found try to replace it with Sun variable substitions. If we
tmp = tmp2;
}
- /*
+ /*
* If a 'replace' does not retuen NULL than a variable was
* successfully subsituted.
*/
if ((tmp2 = sun_strsub(tmp, SUN_OSNAME, AMD_OSNAME)) != NULL) {
continue;
}
- /*
+ /*
* os release - Amd doesn't hava a OS release var just usr os
* version or now.
*/
continue;
}
}
- if(tmp2 == NULL) {
+ if (tmp2 == NULL) {
retval = tmp;
}
else {
retval = tmp2;
- if(tmp != NULL) {
+ if (tmp != NULL) {
XFREE(tmp);
}
}
-
+
return retval;
}
sun_append_str(char *dest,
size_t destlen,
const char *key,
- const char *str)
+ const char *str)
{
char *sub = NULL, *sub2 = NULL, *out = NULL;
/* By default we are going to just write the original string. */
out = (char*)str;
- /*
+ /*
* Resolve variable substititions in two steps; 1) replace any key
* map substitutions with the entry key 2) expand any variable
* substitutions i.e $HOST.
- *
+ *
* Try to replace the key substitution '&'. If this function returns
* with a new string, one or more key subs. where replaced with the
* entry key.
*/
if ((sub = sun_strsub(str, SUN_KEY_SUB, key)) != NULL) {
out = sub;
- /*
+ /*
* Try to convert any variable substitutions. If this function
* returns a new string one or more var subs where expanded.
*/
out = sub2;
}
}
- /*
+ /*
* Try to convert any variable substitutions. If this function
* returns a new string one or more var subs where expanded.
*/
else if ((sub = sun_expand2amd(out)) != NULL) {
out = sub;
}
-
+
if (out != NULL) {
xstrlcat(dest, out, destlen);
}
- if (sub != NULL) {
+ if (sub != NULL) {
XFREE(sub);
}
if (sub2 != NULL) {
* param opt_list - list of Sun mount options
*/
static void
-sun_opts2amd(char *dest,
+sun_opts2amd(char *dest,
size_t destlen,
const char *key,
const struct sun_opt *opt_list)
const struct sun_opt *opt;
xstrlcat(dest, AMD_OPTS_KW, destlen);
-
+
/* Iterate through each option and append it to the buffer. */
for(opt = opt_list; opt != NULL; opt = NEXT(struct sun_opt, opt)) {
sun_append_str(dest, destlen, key, opt->str);
/* If there are more options add some commas. */
- if(NEXT(struct sun_opt, opt) != NULL) {
+ if (NEXT(struct sun_opt, opt) != NULL) {
xstrlcat(dest, ",", destlen);
}
}
* param s_entry - Sun entry
*/
static void
-sun_nfs2amd(char *dest,
- size_t destlen,
+sun_nfs2amd(char *dest,
+ size_t destlen,
const char *key,
const struct sun_entry *s_entry)
{
}
else {
/* multiple NFS mount points */
-
+
/* We need to setup a auto fs Amd automount point. */
xstrlcat(dest, AMD_TYPE_AUTO_KW, destlen);
xstrlcat(dest, AMD_MAP_FS_KW, destlen);
plog(XLOG_ERROR,"could not parse Sun style map");
goto err;
}
-
+
memset(line_buff, 0, sizeof(line_buff));
-
+
if (s_entry_obj->opt_list != NULL) {
/* write the mount options to the buffer */
sun_opts2amd(line_buff, sizeof(line_buff), key, s_entry_obj->opt_list);
plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
s_entry_obj->fstype);
goto err;
-
+
}
else if (NSTREQ(s_entry_obj->fstype, SUN_CACHEFS_TYPE, strlen(SUN_CACHEFS_TYPE))) {
/* CacheFS Type */
entry = CALLOC(struct sun_entry);
/* An fstype may have been defined in the 'options'. */
- if(tmpFsType != NULL) {
+ if (tmpFsType != NULL) {
entry->fstype = tmpFsType;
tmpFsType = NULL;
}
entry = CALLOC(struct sun_entry);
/* An fstype may have been defined in the 'options'. */
- if(tmpFsType != NULL) {
+ if (tmpFsType != NULL) {
entry->fstype = tmpFsType;
tmpFsType = NULL;
}
option : WORD {
char *type;
-
+
/* check if this is an fstype option */
if ((type = strstr($1,SUN_FSTYPE_STR)) != NULL) {
/* parse out the fs type from the Sun fstype keyword */
if ((type = type + strlen(SUN_FSTYPE_STR)) != NULL) {
- /*
+ /*
* This global fstype str will be assigned to the current being
* parsed later in the parsing.
- */
+ */
tmpFsType = strdup(type);
}
}
else {
- /*
+ /*
* If it is not an fstype option allocate an opt struct and assign
- * the value.
+ * the value.
*/
struct sun_opt *opt = CALLOC(struct sun_opt);
opt->str = strdup($1);
* The parser is designed to parse map entries with out the keys. For
* example the entry:
*
- * usr -ro pluto:/usr/local
+ * usr -ro pluto:/usr/local
*
* should be passed to the parser as:
*