diff options
Diffstat (limited to 'usr/src/cmd/modload')
-rw-r--r-- | usr/src/cmd/modload/add_drv.c | 15 | ||||
-rw-r--r-- | usr/src/cmd/modload/addrem.h | 12 | ||||
-rw-r--r-- | usr/src/cmd/modload/drvsubr.c | 117 | ||||
-rw-r--r-- | usr/src/cmd/modload/errmsg.h | 9 | ||||
-rw-r--r-- | usr/src/cmd/modload/rem_drv.c | 9 | ||||
-rw-r--r-- | usr/src/cmd/modload/update_drv.c | 20 |
6 files changed, 139 insertions, 43 deletions
diff --git a/usr/src/cmd/modload/add_drv.c b/usr/src/cmd/modload/add_drv.c index d40eec2902..62da6d8796 100644 --- a/usr/src/cmd/modload/add_drv.c +++ b/usr/src/cmd/modload/add_drv.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -525,7 +524,7 @@ update_driver_classes( { /* make call to update the classes file */ return (append_to_file(driver_name, classes, driver_classes, - ' ', "\t")); + ' ', "\t", 0)); } static int @@ -533,7 +532,8 @@ update_minor_perm( char *driver_name, char *perm_list) { - return (append_to_file(driver_name, perm_list, minor_perm, ',', ":")); + return (append_to_file(driver_name, perm_list, minor_perm, + ',', ":", 0)); } @@ -567,7 +567,8 @@ update_extra_privs( char *driver_name, char *privlist) { - return (append_to_file(driver_name, privlist, extra_privs, ',', ":")); + return (append_to_file(driver_name, privlist, extra_privs, + ',', ":", 0)); } /* diff --git a/usr/src/cmd/modload/addrem.h b/usr/src/cmd/modload/addrem.h index e4b70bea10..c1763c760d 100644 --- a/usr/src/cmd/modload/addrem.h +++ b/usr/src/cmd/modload/addrem.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -125,9 +124,9 @@ extern int check_name_to_major(int); extern void enter_lock(void); extern void err_exit(void); extern void exit_unlock(void); -extern char *get_entry(char *, char *, char); +extern char *get_entry(char *, char *, char, int); extern int build_filenames(char *); -extern int append_to_file(char *, char *, char *, char, char *); +extern int append_to_file(char *, char *, char *, char, char *, int); extern int get_major_no(char *, char *); extern int get_driver_name(int, char *, char *); extern int delete_entry(char *, char *, char *, char *); @@ -139,6 +138,7 @@ extern int update_name_to_major(char *, major_t *, int); extern int do_the_update(char *, char *); extern int fill_n2m_array(char *, char **, int *); extern int aliases_unique(char *); +extern int aliases_paths_exist(char *); extern int update_driver_aliases(char *, char *); extern int unique_driver_name(char *, char *, int *); extern int unique_drv_alias(char *); diff --git a/usr/src/cmd/modload/drvsubr.c b/usr/src/cmd/modload/drvsubr.c index f1fb38add3..37daeaf6f7 100644 --- a/usr/src/cmd/modload/drvsubr.c +++ b/usr/src/cmd/modload/drvsubr.c @@ -106,7 +106,8 @@ append_to_file( char *entry_list, char *filename, char list_separator, - char *entry_separator) + char *entry_separator, + int quoted) { int i, len; int fpint; @@ -153,12 +154,16 @@ append_to_file( line[i] = 0; current_head = get_entry(previous_head, one_entry, - list_separator); + list_separator, quoted); previous_head = current_head; (void) strcpy(line, driver_name); (void) strcat(line, entry_separator); + if (quoted) + (void) strcat(line, "\""); (void) strcat(line, one_entry); + if (quoted) + (void) strcat(line, "\""); (void) strcat(line, "\n"); if ((fputs(line, fp)) == EOF) { @@ -615,16 +620,20 @@ get_name_to_major_entry(int *major_no, char *driver_name, char *file_name) } /* - * given pointer to member n in space separated list, return pointer - * to member n+1, return member n + * Given pointer to begining of member 'n' in a space (or separator) + * separated list, return pointer to member 'n+1', and establish member 'n' + * in *current_entry. If unquote, then we skip a leading quote and treat + * the trailing quote as a separator (and skip). */ char * get_entry( char *prev_member, char *current_entry, - char separator) + char separator, + int unquote) { - char *ptr; + char *ptr; + int quoted = 0; ptr = prev_member; @@ -632,14 +641,25 @@ get_entry( while (*ptr == '\t' || *ptr == ' ') ptr++; - /* read thru the current entry */ - while (*ptr != separator && *ptr != '\0') { + /* if unquote skip leading quote */ + if (unquote && *ptr == '"') { + quoted++; + ptr++; + } + + /* read thru the current entry looking for end, separator, or unquote */ + while (*ptr && + (*ptr != separator) && + ((separator != ' ') || (*ptr != '\t')) && + (!quoted || (*ptr != '"'))) { *current_entry++ = *ptr++; } *current_entry = '\0'; - if ((separator == ',') && (*ptr == separator)) - ptr++; /* skip over comma */ + if (separator && (*ptr == separator)) + ptr++; /* skip over separator */ + if (quoted && (*ptr == '"')) + ptr++; /* skip over trailing quote */ /* skip white space */ while (*ptr == '\t' || *ptr == ' ') { @@ -1003,7 +1023,7 @@ config_driver( return (ERROR); } current = get_entry(previous, - cmdline[n++], ' '); + cmdline[n++], ' ', 0); previous = current; } while (*current != '\0'); @@ -1395,7 +1415,7 @@ check_perm_opts(char *perm_list) for (i = 0; i <= len; i++) one_entry[i] = 0; - current_head = get_entry(previous_head, one_entry, ','); + current_head = get_entry(previous_head, one_entry, ',', 0); previous_head = current_head; scan_stat = sscanf(one_entry, "%s%s%s%s%s", minor, perm, own, @@ -1453,7 +1473,7 @@ aliases_unique(char *aliases) for (i = 0; i <= len; i++) one_entry[i] = 0; - current_head = get_entry(previous_head, one_entry, ' '); + current_head = get_entry(previous_head, one_entry, ' ', 1); previous_head = current_head; if ((unique_driver_name(one_entry, name_to_major, @@ -1490,14 +1510,66 @@ aliases_unique(char *aliases) } +/* + * check each alias : + * if path-oriented alias, path exists + */ +int +aliases_paths_exist(char *aliases) +{ + char *current_head; + char *previous_head; + char *one_entry; + int i, len; + char path[MAXPATHLEN]; + struct stat buf; + + len = strlen(aliases); + + one_entry = calloc(len + 1, 1); + if (one_entry == NULL) { + (void) fprintf(stderr, gettext(ERR_NO_MEM)); + return (ERROR); + } + + previous_head = aliases; + + do { + for (i = 0; i <= len; i++) + one_entry[i] = 0; + + current_head = get_entry(previous_head, one_entry, ' ', 1); + previous_head = current_head; + + /* if the alias is a path, ensure that the path exists */ + if (*one_entry != '/') + continue; + (void) snprintf(path, sizeof (path), "/devices/%s", one_entry); + if (stat(path, &buf) == 0) + continue; + + /* no device at specified path-oriented alias path */ + (void) fprintf(stderr, gettext(ERR_PATH_ORIENTED_ALIAS), + one_entry); + free(one_entry); + return (ERROR); + + } while (*current_head != '\0'); + + free(one_entry); + + return (NOERR); +} + + int update_driver_aliases( char *driver_name, char *aliases) { /* make call to update the aliases file */ - return (append_to_file(driver_name, aliases, driver_aliases, ' ', " ")); - + return (append_to_file(driver_name, aliases, driver_aliases, + ' ', " ", 1)); } @@ -1508,6 +1580,7 @@ unique_drv_alias(char *drv_alias) char drv[FILENAME_MAX + 1]; char line[MAX_N2M_ALIAS_LINE + 1], *cp; char alias[FILENAME_MAX + 1]; + char *a; int status = NOERR; fp = fopen(driver_aliases, "r"); @@ -1526,8 +1599,16 @@ unique_drv_alias(char *drv_alias) (void) fprintf(stderr, gettext(ERR_BAD_LINE), driver_aliases, line); + /* unquote for compare */ + if ((*alias == '"') && + (*(alias + strlen(alias) - 1) == '"')) { + a = &alias[1]; + alias[strlen(alias) - 1] = '\0'; + } else + a = alias; + if ((strcmp(drv_alias, drv) == 0) || - (strcmp(drv_alias, alias) == 0)) { + (strcmp(drv_alias, a) == 0)) { (void) fprintf(stderr, gettext(ERR_ALIAS_IN_USE), drv_alias); @@ -1656,7 +1737,7 @@ update_name_to_major(char *driver_name, major_t *major_num, int server) "%d", is_unique); if (append_to_file(driver_name, major, - name_to_major, ' ', " ") == ERROR) { + name_to_major, ' ', " ", 0) == ERROR) { (void) fprintf(stderr, gettext(ERR_NO_UPDATE), name_to_major); @@ -1857,7 +1938,7 @@ int do_the_update(char *driver_name, char *major_number) { return (append_to_file(driver_name, major_number, name_to_major, - ' ', " ")); + ' ', " ", 0)); } /* diff --git a/usr/src/cmd/modload/errmsg.h b/usr/src/cmd/modload/errmsg.h index 6412f4d24b..a29f866cd9 100644 --- a/usr/src/cmd/modload/errmsg.h +++ b/usr/src/cmd/modload/errmsg.h @@ -56,8 +56,10 @@ extern "C" { #define ERR_INSTALL_FAIL "Error: Could not install driver (%s).\n" #define ERR_DRVNAME_TOO_LONG "Error: driver name must not exceed (%d)" \ " characters; driver name too long (%s)\n" -#define ERR_ALIAS_IN_NAM_MAJ "Alias (%s) already in use as driver name.\n" -#define ERR_ALIAS_IN_USE "(%s) already in use as a driver or alias.\n" +#define ERR_ALIAS_IN_NAM_MAJ \ +"Alias (\"%s\") already in use as driver name.\n" +#define ERR_ALIAS_IN_USE \ +"(\"%s\") already in use as a driver or alias.\n" #define ERR_CANT_ACCESS_FILE "Cannot access file (%s).\n" #define ERR_BAD_PATH "Bad syntax for pathname : (%s)\n" #define ERR_FORK_FAIL "Fork failed; cannot exec : %s\n" @@ -171,6 +173,9 @@ Use octal escape sequence \"\\040\".\n" #define ERR_REMDRV_CLEANUP \ "post-rem_drv devfs cleanup for driver %s failed (%d)\n" +#define ERR_PATH_ORIENTED_ALIAS \ + "no device at specified path-oriented alias \"%s\"\n" + #ifdef __cplusplus } #endif diff --git a/usr/src/cmd/modload/rem_drv.c b/usr/src/cmd/modload/rem_drv.c index 189cc5e9d9..761c52b60c 100644 --- a/usr/src/cmd/modload/rem_drv.c +++ b/usr/src/cmd/modload/rem_drv.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -169,7 +168,7 @@ main(int argc, char *argv[]) (void) sprintf(maj_num, "%d", found); if (append_to_file(driver_name, maj_num, - rem_name_to_major, ' ', " ") == ERROR) { + rem_name_to_major, ' ', " ", 0) == ERROR) { (void) fprintf(stderr, gettext(ERR_NO_UPDATE), rem_name_to_major); err_exit(); diff --git a/usr/src/cmd/modload/update_drv.c b/usr/src/cmd/modload/update_drv.c index 6b49f43a5f..8efbc6d7e9 100644 --- a/usr/src/cmd/modload/update_drv.c +++ b/usr/src/cmd/modload/update_drv.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * 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. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -270,7 +269,7 @@ main(int argc, char *argv[]) if (priv != NULL) { (void) append_to_file(driver_name, priv, extra_privs, - ',', ":"); + ',', ":", 0); cleanup_flag |= CLEAN_DRV_PRIV; } @@ -306,6 +305,17 @@ main(int argc, char *argv[]) return (error); } + /* + * unless force_flag is specified check that + * path-oriented aliases we are adding exist + */ + if ((force_flag == 0) && + ((error = aliases_paths_exist(aliases)) == ERROR)) { + exit_unlock(); + + return (error); + } + /* update the file */ if ((error = update_driver_aliases(driver_name, aliases)) == ERROR) { |