update_drv.c revision f4da9be01648d6afa604495d9b9956dddeb92a8c
/*
* 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
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "addrem.h"
#include "errmsg.h"
#include "plcysubr.h"
/* function prototypes */
static void usage();
static int unload_drv(char *, int, int);
/*
* try to modunload driver.
* return -1 on failure and 0 on success
*/
static int
{
int modid;
if (modid != -1) {
if (force_flag == 0) { /* no force flag */
if (verbose_flag) {
}
/* clean up and exit. remove lock file */
err_exit();
}
return (-1);
}
}
return (0);
}
static void
usage()
{
exit(1);
}
int
{
int cleanup_flag = 0;
int verbose_flag = 0; /* -v option */
int force_flag = 0; /* -f option */
int a_flag = 0; /* -a option */
int d_flag = 0; /* -d option */
int i_flag = 0; /* -i option */
int l_flag = 0; /* -l option */
int m_flag = 0; /* -m option */
char *aliases = 0;
char *driver_name;
int found;
int rval;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* must be run by root */
if (getuid() != 0) {
exit(1);
}
switch (opt) {
case 'a':
a_flag++;
break;
case 'b':
update_conf = 0; /* don't update .conf file */
break;
case 'd':
d_flag++;
break;
case 'f':
force_flag++;
break;
case 'i':
i_flag++;
aliases);
exit(1);
}
break;
case 'l': /* private option */
l_flag++;
break;
case 'm':
m_flag++;
break;
case 'p':
break;
case 'v':
verbose_flag++;
break;
case 'P':
break;
case '?' :
default:
usage();
}
}
/*
* check for flags and extra args
*/
usage();
}
/*
* - cannot be adding and removing at the same time
* - if -a or -d is specified, it's an error if none of
* -i/-m/-p/-P is specified.
*/
usage();
}
/*
* - with -d option or -a option either -i 'identify_name',
* -m 'permission', -p 'policy' or -P 'priv' should be specified
*/
usage();
}
/* set up update_drv filenames */
exit(1);
}
/* no lock is needed for listing minor perm entry */
if (l_flag) {
return (NOERR);
}
/* must be only running version of add_drv/update_drv/rem_drv */
enter_lock();
err_exit();
}
/* update_drv doesn't modify /etc/name_to_major file */
err_exit();
err_exit();
err_exit();
/*
* ADD: -a option
* i_flag: update /etc/driver_aliases
* m_flag: update /etc/minor_perm
* -p: update /etc/security/device_policy
* -P: update /etc/security/extra_privs
* if force_flag is specified continue w/ the next operation
*/
if (a_flag) {
if (m_flag) {
/* check if the permissions are valid */
if (force_flag == 0) { /* no force flag */
exit_unlock();
return (error);
}
}
/*
* update the file, if and only if
* we didn't run into error earlier.
*/
if (force_flag == 0) { /* no force flag */
exit_unlock();
return (error);
}
}
/*
* Notify running system of minor perm change
*/
if (rval) {
}
}
}
',', ":", 0);
}
exit_unlock();
return (error);
}
}
if (i_flag) {
err_exit();
}
err_exit();
}
/* check if the alias is unique */
exit_unlock();
return (error);
}
/*
* unless force_flag is specified check that
* path-oriented aliases we are adding exist
*/
if ((force_flag == 0) &&
exit_unlock();
return (error);
}
/* update the file */
exit_unlock();
return (error);
}
/* paranoia - if we crash whilst configuring */
sync();
err_exit();
}
}
/* load the driver */
exit_unlock();
return (0);
}
/*
* DELETE: -d option
* i_flag: update /etc/driver_aliases
* m_flag: update /etc/minor_perm
* -p: update /etc/security/device_policy
* -P: update /etc/security/extra_privs
*/
if (d_flag) {
if (m_flag) {
/*
* On a running system, we first need to
* remove devfs's idea of the minor perms.
* We don't have any ability to do this singly
* at this point.
*/
if (rval) {
}
}
}
/*
* Notify running system of new minor perm state
*/
if (rval) {
}
}
}
if (i_flag) {
}
}
}
}
}
}
/* try to unload the driver */
(void) unload_drv(driver_name,
}
/* reload the policy */
}
exit_unlock();
return (err);
}
/* driver name must exist (for update_conf stuff) */
err_exit();
}
/*
* Update driver.conf file:
* First try to unload driver module. If it fails, there may
* be attached devices using the old driver.conf properties,
* so we cannot safely update driver.conf
*
* The user may specify -f to force a driver.conf update.
* In this case, we will update driver.conf cache. All attached
* devices still reference old driver.conf properties, including
* driver global properties. Devices attached in the future will
* referent properties in the updated driver.conf file.
*/
if (update_conf) {
err_exit();
}
if (verbose_flag) {
}
}
/* rebuild /devices & /dev */
exit_unlock();
return (NOERR);
}