changeset 10585:e59699fcc4b6

6818386 devfsadm generates error messages inside a native non-global zone
author Dhanaraj M <Dhanaraj.M@Sun.COM>
date Fri, 18 Sep 2009 21:31:59 -0700
parents b6eb77b5edec
children 252cfb0aebde
files usr/src/cmd/autopush/autopush.c usr/src/cmd/devfsadm/devfsadm.c usr/src/cmd/devfsadm/message.h usr/src/cmd/modload/add_drv.c usr/src/cmd/modload/errmsg.h usr/src/cmd/modload/modload.c usr/src/cmd/modload/modunload.c usr/src/cmd/modload/rem_drv.c
diffstat 8 files changed, 55 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/autopush/autopush.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/autopush/autopush.c	Fri Sep 18 21:31:59 2009 -0700
@@ -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 1999-2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -28,8 +27,6 @@
 /*	  All Rights Reserved  	*/
 
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * autopush(1) is the command interface to the STREAMS autopush
  * mechanism.  The autopush command can be used to configure autopush
@@ -74,6 +71,7 @@
 #include <string.h>
 #include <locale.h>
 #include <sys/stat.h>
+#include <zone.h>
 
 #define	OPTIONS	"M:f:gm:r"	/* command line options for getopt(3C) */
 #define	COMMENT	'#'
@@ -207,6 +205,13 @@
 		usage();
 		exit(1);
 	}
+
+	if (getzoneid() != GLOBAL_ZONEID) {
+		(void) fprintf(stderr, gettext("autopush "
+		    "can only be run from the global zone.\n"));
+		exit(1);
+	}
+
 	if (fflag)
 		exitcode = set_info(filenamep);
 	else if (rflag)
--- a/usr/src/cmd/devfsadm/devfsadm.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/devfsadm/devfsadm.c	Fri Sep 18 21:31:59 2009 -0700
@@ -42,6 +42,7 @@
 #include <utime.h>
 #include <sys/param.h>
 #include <bsm/libbsm.h>
+#include <zone.h>
 #include "devfsadm_impl.h"
 
 /* externs from devalloc.c */
@@ -267,6 +268,11 @@
 		/*NOTREACHED*/
 	}
 
+	if (getzoneid() != GLOBAL_ZONEID) {
+		err_print(MUST_BE_GLOBAL_ZONE);
+		devfsadm_exit(1);
+	}
+
 	/*
 	 * Close all files except stdin/stdout/stderr
 	 */
--- a/usr/src/cmd/devfsadm/message.h	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/devfsadm/message.h	Fri Sep 18 21:31:59 2009 -0700
@@ -255,6 +255,9 @@
 #define	ZONE_PATHCHECK \
     gettext("cannot manage root path '%s': path is part of zone '%s'\n")
 
+#define	MUST_BE_GLOBAL_ZONE \
+    gettext("can only be run from the global zone\n")
+
 #define	DEVNAME_CONTACT_FAILED \
     gettext("cannot talk to devname fs %s: %s\n")
 
--- a/usr/src/cmd/modload/add_drv.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/modload/add_drv.c	Fri Sep 18 21:31:59 2009 -0700
@@ -42,6 +42,7 @@
 #include <libdevinfo.h>
 #include <sys/sysmacros.h>
 #include <fcntl.h>
+#include <zone.h>
 #include "addrem.h"
 #include "errmsg.h"
 #include "plcysubr.h"
@@ -200,6 +201,11 @@
 		exit(1);
 	}
 
+	if (getzoneid() != GLOBAL_ZONEID) {
+		(void) fprintf(stderr, gettext(ERR_NOT_GLOBAL_ZONE));
+		exit(1);
+	}
+
 	/*
 	 * Fail if add_drv was invoked with a pathname prepended to the
 	 * driver_name argument.
--- a/usr/src/cmd/modload/errmsg.h	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/modload/errmsg.h	Fri Sep 18 21:31:59 2009 -0700
@@ -63,6 +63,8 @@
 #define	ERR_FORK_FAIL	"Fork failed; cannot exec : %s\n"
 #define	ERR_PROG_IN_USE	"add_drv/rem_drv currently busy; try later\n"
 #define	ERR_NOT_ROOT	"You must be root to run this program.\n"
+#define	ERR_NOT_GLOBAL_ZONE	\
+"add_drv/rem_drv can only be run from the global zone.\n"
 #define	ERR_BAD_LINE	"Bad line in file %s : %s\n"
 #define	ERR_CANNOT_OPEN	"Cannot open (%s): %s.\n"
 #define	ERR_MIS_TOK	"Option (%s) : missing token: (%s)\n"
--- a/usr/src/cmd/modload/modload.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/modload/modload.c	Fri Sep 18 21:31:59 2009 -0700
@@ -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,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/param.h>
@@ -37,6 +34,7 @@
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <zone.h>
 
 void	l_exec_userfile(char *execfile, int id, char **envp);
 void	l_usage();
@@ -75,6 +73,11 @@
 			l_usage();
 		}
 	}
+
+	if (getzoneid() != GLOBAL_ZONEID) {
+		fatal("modload can only be run from the global zone\n");
+	}
+
 	modpath = argv[optind];
 
 	if (modpath == NULL) {
--- a/usr/src/cmd/modload/modunload.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/modload/modunload.c	Fri Sep 18 21:31:59 2009 -0700
@@ -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,12 +19,10 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -36,6 +33,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/modctl.h>
+#include <zone.h>
 
 void	usage();
 void	exec_userfile(char *execfile, int id, char **envp);
@@ -70,6 +68,10 @@
 		}
 	}
 
+	if (getzoneid() != GLOBAL_ZONEID) {
+		fatal("modunload can only be run from the global zone\n");
+	}
+
 	if (execfile) {
 		child = fork();
 		if (child == -1)
@@ -90,10 +92,10 @@
 	 * Unload the module.
 	 */
 	if (modctl(MODUNLOAD, id) < 0) {
-	    if (errno == EPERM)
-		fatal("Insufficient privileges to unload a module\n");
-	    else if (id != 0)
-		error("can't unload the module");
+		if (errno == EPERM)
+			fatal("Insufficient privileges to unload a module\n");
+		else if (id != 0)
+			error("can't unload the module");
 	}
 
 	return (0);			/* success */
--- a/usr/src/cmd/modload/rem_drv.c	Fri Sep 18 15:55:18 2009 -0700
+++ b/usr/src/cmd/modload/rem_drv.c	Fri Sep 18 21:31:59 2009 -0700
@@ -42,6 +42,7 @@
 #include <sys/modctl.h>
 #include <sys/instance.h>
 #include <libdevinfo.h>
+#include <zone.h>
 
 #include "addrem.h"
 #include "errmsg.h"
@@ -120,6 +121,11 @@
 		exit(1);
 	}
 
+	if (getzoneid() != GLOBAL_ZONEID) {
+		(void) fprintf(stderr, gettext(ERR_NOT_GLOBAL_ZONE));
+		exit(1);
+	}
+
 	/* set up add_drv filenames */
 	if ((build_filenames(basedir)) == ERROR) {
 		exit(1);