17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5f4da9be0Scth * Common Development and Distribution License (the "License"). 6f4da9be0Scth * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22dcedc87dSjg * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <stdio.h> 277c478bd9Sstevel@tonic-gate #include <locale.h> 287c478bd9Sstevel@tonic-gate #include <stdlib.h> 297c478bd9Sstevel@tonic-gate #include <unistd.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <string.h> 327c478bd9Sstevel@tonic-gate #include "addrem.h" 337c478bd9Sstevel@tonic-gate #include "errmsg.h" 347c478bd9Sstevel@tonic-gate #include "plcysubr.h" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* function prototypes */ 377c478bd9Sstevel@tonic-gate static void usage(); 387c478bd9Sstevel@tonic-gate static int unload_drv(char *, int, int); 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * try to modunload driver. 437c478bd9Sstevel@tonic-gate * return -1 on failure and 0 on success 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate static int 467c478bd9Sstevel@tonic-gate unload_drv(char *driver_name, int force_flag, int verbose_flag) 477c478bd9Sstevel@tonic-gate { 487c478bd9Sstevel@tonic-gate int modid; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate get_modid(driver_name, &modid); 517c478bd9Sstevel@tonic-gate if (modid != -1) { 527c478bd9Sstevel@tonic-gate if (modctl(MODUNLOAD, modid) < 0) { 537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_MODUN), driver_name); 547c478bd9Sstevel@tonic-gate if (force_flag == 0) { /* no force flag */ 557c478bd9Sstevel@tonic-gate if (verbose_flag) { 567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 577c478bd9Sstevel@tonic-gate gettext(NOUPDATE), driver_name); 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate /* clean up and exit. remove lock file */ 607c478bd9Sstevel@tonic-gate err_exit(); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(FORCE_UPDATE), 637c478bd9Sstevel@tonic-gate driver_name); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate return (-1); 667c478bd9Sstevel@tonic-gate } 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate return (0); 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate static void 747c478bd9Sstevel@tonic-gate usage() 757c478bd9Sstevel@tonic-gate { 767c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(UPD_DRV_USAGE)); 777c478bd9Sstevel@tonic-gate exit(1); 787c478bd9Sstevel@tonic-gate } 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate int 827c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 837c478bd9Sstevel@tonic-gate { 847c478bd9Sstevel@tonic-gate int error, opt, major; 857c478bd9Sstevel@tonic-gate int cleanup_flag = 0; 867c478bd9Sstevel@tonic-gate int update_conf = 1; /* reload driver.conf by default */ 877c478bd9Sstevel@tonic-gate int verbose_flag = 0; /* -v option */ 887c478bd9Sstevel@tonic-gate int force_flag = 0; /* -f option */ 897c478bd9Sstevel@tonic-gate int a_flag = 0; /* -a option */ 907c478bd9Sstevel@tonic-gate int d_flag = 0; /* -d option */ 917c478bd9Sstevel@tonic-gate int i_flag = 0; /* -i option */ 927c478bd9Sstevel@tonic-gate int l_flag = 0; /* -l option */ 937c478bd9Sstevel@tonic-gate int m_flag = 0; /* -m option */ 947c478bd9Sstevel@tonic-gate char *perms = NULL; 95*0013e2d3SJerry Gilliam char *aliases = NULL; 967c478bd9Sstevel@tonic-gate char *basedir = NULL; 977c478bd9Sstevel@tonic-gate char *policy = NULL; 98*0013e2d3SJerry Gilliam char *aliases2 = NULL; 997c478bd9Sstevel@tonic-gate char *priv = NULL; 1007c478bd9Sstevel@tonic-gate char *driver_name; 1017c478bd9Sstevel@tonic-gate int found; 1027c478bd9Sstevel@tonic-gate major_t major_num; 1037c478bd9Sstevel@tonic-gate int rval; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 1067c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 1077c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ 1087c478bd9Sstevel@tonic-gate #endif 1097c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* must be run by root */ 1127c478bd9Sstevel@tonic-gate if (getuid() != 0) { 1137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NOT_ROOT)); 1147c478bd9Sstevel@tonic-gate exit(1); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "m:i:b:p:adlfuvP:")) != EOF) { 1187c478bd9Sstevel@tonic-gate switch (opt) { 1197c478bd9Sstevel@tonic-gate case 'a': 1207c478bd9Sstevel@tonic-gate a_flag++; 1217c478bd9Sstevel@tonic-gate break; 1227c478bd9Sstevel@tonic-gate case 'b': 1237c478bd9Sstevel@tonic-gate update_conf = 0; /* don't update .conf file */ 1247c478bd9Sstevel@tonic-gate basedir = optarg; 1257c478bd9Sstevel@tonic-gate break; 1267c478bd9Sstevel@tonic-gate case 'd': 1277c478bd9Sstevel@tonic-gate d_flag++; 1287c478bd9Sstevel@tonic-gate break; 1297c478bd9Sstevel@tonic-gate case 'f': 1307c478bd9Sstevel@tonic-gate force_flag++; 1317c478bd9Sstevel@tonic-gate break; 1327c478bd9Sstevel@tonic-gate case 'i': 1337c478bd9Sstevel@tonic-gate i_flag++; 1347c478bd9Sstevel@tonic-gate aliases = optarg; 1357c478bd9Sstevel@tonic-gate if (check_space_within_quote(aliases) == ERROR) { 1367c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NO_SPACE), 1373ed242f5Sjg aliases); 1387c478bd9Sstevel@tonic-gate exit(1); 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate break; 1417c478bd9Sstevel@tonic-gate case 'l': /* private option */ 1427c478bd9Sstevel@tonic-gate l_flag++; 1437c478bd9Sstevel@tonic-gate break; 1447c478bd9Sstevel@tonic-gate case 'm': 1457c478bd9Sstevel@tonic-gate m_flag++; 1467c478bd9Sstevel@tonic-gate perms = optarg; 1477c478bd9Sstevel@tonic-gate break; 1487c478bd9Sstevel@tonic-gate case 'p': 1497c478bd9Sstevel@tonic-gate policy = optarg; 1507c478bd9Sstevel@tonic-gate break; 1517c478bd9Sstevel@tonic-gate case 'v': 1527c478bd9Sstevel@tonic-gate verbose_flag++; 1537c478bd9Sstevel@tonic-gate break; 1547c478bd9Sstevel@tonic-gate case 'P': 1557c478bd9Sstevel@tonic-gate priv = optarg; 1567c478bd9Sstevel@tonic-gate break; 1577c478bd9Sstevel@tonic-gate case '?' : 1587c478bd9Sstevel@tonic-gate default: 1597c478bd9Sstevel@tonic-gate usage(); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * check for flags and extra args 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate if ((argv[optind] == NULL) || (optind + 1 != argc)) { 1677c478bd9Sstevel@tonic-gate usage(); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * - cannot be adding and removing at the same time 1727c478bd9Sstevel@tonic-gate * - if -a or -d is specified, it's an error if none of 1737c478bd9Sstevel@tonic-gate * -i/-m/-p/-P is specified. 1747c478bd9Sstevel@tonic-gate */ 1757c478bd9Sstevel@tonic-gate if ((a_flag && d_flag) || 1767c478bd9Sstevel@tonic-gate ((a_flag || d_flag) && 1777c478bd9Sstevel@tonic-gate !m_flag && !i_flag && priv == NULL && policy == NULL)) { 1787c478bd9Sstevel@tonic-gate usage(); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * - with -d option or -a option either -i 'identify_name', 1837c478bd9Sstevel@tonic-gate * -m 'permission', -p 'policy' or -P 'priv' should be specified 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate if (m_flag || i_flag || policy != NULL || priv != NULL) { 1867c478bd9Sstevel@tonic-gate if (!(a_flag || d_flag)) 1877c478bd9Sstevel@tonic-gate usage(); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate driver_name = argv[optind]; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* set up update_drv filenames */ 1937c478bd9Sstevel@tonic-gate if ((build_filenames(basedir)) == ERROR) { 1947c478bd9Sstevel@tonic-gate exit(1); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* no lock is needed for listing minor perm entry */ 1987c478bd9Sstevel@tonic-gate if (l_flag) { 1997c478bd9Sstevel@tonic-gate list_entry(minor_perm, driver_name, ":"); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate return (NOERR); 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* must be only running version of add_drv/update_drv/rem_drv */ 2057c478bd9Sstevel@tonic-gate enter_lock(); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if ((check_perms_aliases(m_flag, i_flag)) == ERROR) { 2087c478bd9Sstevel@tonic-gate err_exit(); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /* update_drv doesn't modify /etc/name_to_major file */ 2127c478bd9Sstevel@tonic-gate if ((check_name_to_major(R_OK)) == ERROR) 2137c478bd9Sstevel@tonic-gate err_exit(); 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate if (priv != NULL && check_priv_entry(priv, a_flag) != 0) 2167c478bd9Sstevel@tonic-gate err_exit(); 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate if (policy != NULL && (policy = check_plcy_entry(policy, driver_name, 2197c478bd9Sstevel@tonic-gate d_flag ? B_TRUE : B_FALSE)) == NULL) 2207c478bd9Sstevel@tonic-gate err_exit(); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate /* 2237c478bd9Sstevel@tonic-gate * ADD: -a option 2247c478bd9Sstevel@tonic-gate * i_flag: update /etc/driver_aliases 2257c478bd9Sstevel@tonic-gate * m_flag: update /etc/minor_perm 2267c478bd9Sstevel@tonic-gate * -p: update /etc/security/device_policy 2277c478bd9Sstevel@tonic-gate * -P: update /etc/security/extra_privs 2287c478bd9Sstevel@tonic-gate * if force_flag is specified continue w/ the next operation 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate if (a_flag) { 2317c478bd9Sstevel@tonic-gate if (m_flag) { 2327c478bd9Sstevel@tonic-gate /* check if the permissions are valid */ 2337c478bd9Sstevel@tonic-gate if ((error = check_perm_opts(perms)) == ERROR) { 2347c478bd9Sstevel@tonic-gate if (force_flag == 0) { /* no force flag */ 2357c478bd9Sstevel@tonic-gate exit_unlock(); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate return (error); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * update the file, if and only if 2437c478bd9Sstevel@tonic-gate * we didn't run into error earlier. 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate if ((error != ERROR) && 2467c478bd9Sstevel@tonic-gate (error = update_minor_entry(driver_name, perms))) { 2477c478bd9Sstevel@tonic-gate if (force_flag == 0) { /* no force flag */ 2487c478bd9Sstevel@tonic-gate exit_unlock(); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate return (error); 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate cleanup_flag |= CLEAN_NAM_MAJ; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * Notify running system of minor perm change 2577c478bd9Sstevel@tonic-gate */ 2587c478bd9Sstevel@tonic-gate if (basedir == NULL || (strcmp(basedir, "/") == 0)) { 2597c478bd9Sstevel@tonic-gate rval = devfs_add_minor_perm(driver_name, 2607c478bd9Sstevel@tonic-gate log_minorperm_error); 2617c478bd9Sstevel@tonic-gate if (rval) { 2627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2637c478bd9Sstevel@tonic-gate gettext(ERR_UPDATE_PERM), 2647c478bd9Sstevel@tonic-gate driver_name); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (priv != NULL) { 2707c478bd9Sstevel@tonic-gate (void) append_to_file(driver_name, priv, extra_privs, 2713ed242f5Sjg ',', ":", 0); 2727c478bd9Sstevel@tonic-gate cleanup_flag |= CLEAN_DRV_PRIV; 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate if (policy != NULL) { 2767c478bd9Sstevel@tonic-gate if ((error = update_device_policy(device_policy, 2777c478bd9Sstevel@tonic-gate policy, B_TRUE)) != 0) { 2787c478bd9Sstevel@tonic-gate exit_unlock(); 2797c478bd9Sstevel@tonic-gate return (error); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate cleanup_flag |= CLEAN_DEV_POLICY; 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate if (i_flag) { 2857c478bd9Sstevel@tonic-gate found = get_major_no(driver_name, name_to_major); 2867c478bd9Sstevel@tonic-gate if (found == ERROR) { 2877c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_MAX_MAJOR), 2887c478bd9Sstevel@tonic-gate name_to_major); 2897c478bd9Sstevel@tonic-gate err_exit(); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate if (found == UNIQUE) { 2937c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2947c478bd9Sstevel@tonic-gate gettext(ERR_NOT_INSTALLED), driver_name); 2957c478bd9Sstevel@tonic-gate err_exit(); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate major_num = (major_t)found; 2997c478bd9Sstevel@tonic-gate 300*0013e2d3SJerry Gilliam /* 301*0013e2d3SJerry Gilliam * To ease the nuisance of using update_drv 302*0013e2d3SJerry Gilliam * in packaging scripts, do not require that 303*0013e2d3SJerry Gilliam * existing driver aliases be trimmed from 304*0013e2d3SJerry Gilliam * the command line. If an invocation asks 305*0013e2d3SJerry Gilliam * to add an alias and it's already there, 306*0013e2d3SJerry Gilliam * drive on. We implement this by removing 307*0013e2d3SJerry Gilliam * duplicates now and add the remainder. 308*0013e2d3SJerry Gilliam */ 309*0013e2d3SJerry Gilliam error = trim_duplicate_aliases(driver_name, 310*0013e2d3SJerry Gilliam aliases, &aliases2); 311*0013e2d3SJerry Gilliam if (error == ERROR) { 312f9e4eebbScth exit_unlock(); 313f9e4eebbScth return (error); 314f9e4eebbScth } 315f9e4eebbScth 316*0013e2d3SJerry Gilliam /* 317*0013e2d3SJerry Gilliam * if the list of aliases to be added is 318*0013e2d3SJerry Gilliam * now empty, we're done. 319*0013e2d3SJerry Gilliam */ 320*0013e2d3SJerry Gilliam if (aliases2 == NULL) 321*0013e2d3SJerry Gilliam goto done; 322*0013e2d3SJerry Gilliam 323f4da9be0Scth /* 324f4da9be0Scth * unless force_flag is specified check that 325f4da9be0Scth * path-oriented aliases we are adding exist 326f4da9be0Scth */ 327*0013e2d3SJerry Gilliam if ((force_flag == 0) && ((error = 328*0013e2d3SJerry Gilliam aliases_paths_exist(aliases2)) == ERROR)) { 329f4da9be0Scth exit_unlock(); 330f4da9be0Scth return (error); 331f4da9be0Scth } 332f4da9be0Scth 333f9e4eebbScth /* update the file */ 334f9e4eebbScth if ((error = update_driver_aliases(driver_name, 335*0013e2d3SJerry Gilliam aliases2)) == ERROR) { 336f9e4eebbScth exit_unlock(); 337f9e4eebbScth return (error); 338f9e4eebbScth } 339f9e4eebbScth 3407c478bd9Sstevel@tonic-gate /* paranoia - if we crash whilst configuring */ 3417c478bd9Sstevel@tonic-gate sync(); 3427c478bd9Sstevel@tonic-gate 3433ed242f5Sjg /* optionally update the running system - not -b */ 3443ed242f5Sjg if (update_conf) { 3453ed242f5Sjg cleanup_flag |= CLEAN_DRV_ALIAS; 3463ed242f5Sjg if (config_driver(driver_name, major_num, 347*0013e2d3SJerry Gilliam aliases2, NULL, cleanup_flag, 3483ed242f5Sjg verbose_flag) == ERROR) { 3493ed242f5Sjg err_exit(); 3503ed242f5Sjg } 3517c478bd9Sstevel@tonic-gate } 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate } 354*0013e2d3SJerry Gilliam 355*0013e2d3SJerry Gilliam done: 356dcedc87dSjg if (update_conf && (i_flag || policy != NULL)) { 3577c478bd9Sstevel@tonic-gate /* load the driver */ 3587c478bd9Sstevel@tonic-gate load_driver(driver_name, verbose_flag); 359dcedc87dSjg } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate exit_unlock(); 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate return (0); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate /* 3687c478bd9Sstevel@tonic-gate * DELETE: -d option 3697c478bd9Sstevel@tonic-gate * i_flag: update /etc/driver_aliases 3707c478bd9Sstevel@tonic-gate * m_flag: update /etc/minor_perm 3717c478bd9Sstevel@tonic-gate * -p: update /etc/security/device_policy 3727c478bd9Sstevel@tonic-gate * -P: update /etc/security/extra_privs 3737c478bd9Sstevel@tonic-gate */ 3747c478bd9Sstevel@tonic-gate if (d_flag) { 3757c478bd9Sstevel@tonic-gate int err = NOERR; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate if (m_flag) { 3787c478bd9Sstevel@tonic-gate /* 3797c478bd9Sstevel@tonic-gate * On a running system, we first need to 3807c478bd9Sstevel@tonic-gate * remove devfs's idea of the minor perms. 3817c478bd9Sstevel@tonic-gate * We don't have any ability to do this singly 3827c478bd9Sstevel@tonic-gate * at this point. 3837c478bd9Sstevel@tonic-gate */ 3847c478bd9Sstevel@tonic-gate if (basedir == NULL || (strcmp(basedir, "/") == 0)) { 3857c478bd9Sstevel@tonic-gate rval = devfs_rm_minor_perm(driver_name, 3867c478bd9Sstevel@tonic-gate log_minorperm_error); 3877c478bd9Sstevel@tonic-gate if (rval) { 3887c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3897c478bd9Sstevel@tonic-gate gettext(ERR_UPDATE_PERM), 3907c478bd9Sstevel@tonic-gate driver_name); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate if ((error = delete_entry(minor_perm, 3957c478bd9Sstevel@tonic-gate driver_name, ":", perms)) != NOERR) { 3967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NO_ENTRY), 3977c478bd9Sstevel@tonic-gate driver_name, minor_perm); 3987c478bd9Sstevel@tonic-gate err = error; 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * Notify running system of new minor perm state 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate if (basedir == NULL || (strcmp(basedir, "/") == 0)) { 4047c478bd9Sstevel@tonic-gate rval = devfs_add_minor_perm(driver_name, 4057c478bd9Sstevel@tonic-gate log_minorperm_error); 4067c478bd9Sstevel@tonic-gate if (rval) { 4077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 4087c478bd9Sstevel@tonic-gate gettext(ERR_UPDATE_PERM), 4097c478bd9Sstevel@tonic-gate driver_name); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate if (i_flag) { 4157c478bd9Sstevel@tonic-gate if ((error = delete_entry(driver_aliases, 4167c478bd9Sstevel@tonic-gate driver_name, ":", aliases)) != NOERR) { 4177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NO_ENTRY), 4187c478bd9Sstevel@tonic-gate driver_name, driver_aliases); 4197c478bd9Sstevel@tonic-gate if (err != NOERR) 4207c478bd9Sstevel@tonic-gate err = error; 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate if (priv != NULL) { 4257c478bd9Sstevel@tonic-gate if ((error = delete_entry(extra_privs, driver_name, ":", 4267c478bd9Sstevel@tonic-gate priv)) != NOERR) { 4277c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NO_ENTRY), 4287c478bd9Sstevel@tonic-gate driver_name, extra_privs); 4297c478bd9Sstevel@tonic-gate if (err != NOERR) 4307c478bd9Sstevel@tonic-gate err = error; 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate if (policy != NULL) { 4357c478bd9Sstevel@tonic-gate if ((error = delete_plcy_entry(device_policy, 4363ed242f5Sjg policy)) != NOERR) { 4377c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_NO_ENTRY), 4387c478bd9Sstevel@tonic-gate driver_name, device_policy); 4397c478bd9Sstevel@tonic-gate if (err != NOERR) 4407c478bd9Sstevel@tonic-gate err = error; 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate } 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate if (err == NOERR && update_conf) { 4457c478bd9Sstevel@tonic-gate if (i_flag || m_flag) { 4467c478bd9Sstevel@tonic-gate /* try to unload the driver */ 4477c478bd9Sstevel@tonic-gate (void) unload_drv(driver_name, 4487c478bd9Sstevel@tonic-gate force_flag, verbose_flag); 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate /* reload the policy */ 4517c478bd9Sstevel@tonic-gate if (policy != NULL) 4527c478bd9Sstevel@tonic-gate load_driver(driver_name, verbose_flag); 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate exit_unlock(); 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate return (err); 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate /* driver name must exist (for update_conf stuff) */ 4607c478bd9Sstevel@tonic-gate major = get_major_no(driver_name, name_to_major); 4617c478bd9Sstevel@tonic-gate if (major == ERROR) { 4627c478bd9Sstevel@tonic-gate err_exit(); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate /* 4667c478bd9Sstevel@tonic-gate * Update driver.conf file: 4677c478bd9Sstevel@tonic-gate * First try to unload driver module. If it fails, there may 4687c478bd9Sstevel@tonic-gate * be attached devices using the old driver.conf properties, 4697c478bd9Sstevel@tonic-gate * so we cannot safely update driver.conf 4707c478bd9Sstevel@tonic-gate * 4717c478bd9Sstevel@tonic-gate * The user may specify -f to force a driver.conf update. 4727c478bd9Sstevel@tonic-gate * In this case, we will update driver.conf cache. All attached 4737c478bd9Sstevel@tonic-gate * devices still reference old driver.conf properties, including 4747c478bd9Sstevel@tonic-gate * driver global properties. Devices attached in the future will 4757c478bd9Sstevel@tonic-gate * referent properties in the updated driver.conf file. 4767c478bd9Sstevel@tonic-gate */ 4777c478bd9Sstevel@tonic-gate if (update_conf) { 4787c478bd9Sstevel@tonic-gate (void) unload_drv(driver_name, force_flag, verbose_flag); 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate if ((modctl(MODUNLOADDRVCONF, major) != 0) || 4817c478bd9Sstevel@tonic-gate (modctl(MODLOADDRVCONF, major) != 0)) { 4827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_DRVCONF), 4837c478bd9Sstevel@tonic-gate driver_name); 4847c478bd9Sstevel@tonic-gate err_exit(); 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate if (verbose_flag) { 4887c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(DRVCONF_UPDATED), 4897c478bd9Sstevel@tonic-gate driver_name); 4907c478bd9Sstevel@tonic-gate } 491dcedc87dSjg load_driver(driver_name, verbose_flag); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate exit_unlock(); 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate return (NOERR); 4977c478bd9Sstevel@tonic-gate } 498