KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > nodes > CheckSuperuser


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Tue Jan 26 19:55:32 GMT 1999
21
//
22
// RCS HEADER ``CheckSuperuser.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.nodes;
31
32 import java.io.*;
33 import java.util.*;
34 import java.awt.*;
35 import java.awt.event.*;
36
37 import javax.swing.*; // for JTree
38
import javax.swing.event.*; // for events
39
import javax.swing.tree.*; // MutableTreeNode
40

41 import ixenon.free.swing.*; // for `ResetProgressBar' & `UpdateProgressBar'
42
import ixenon.free.install.*; // for FreeInstallerApplication
43

44 /**
45  * A <code>Installable</code> node that checks for superuser permissions
46  * For UNIX users this would `root'
47  * For NT this would be `Administrator"
48  */

49 public class CheckSuperuser extends AbstractInstallable
50 implements Installable
51 {
52     /**
53      * Construct a installable
54      *
55      * @param nodeName the name of the installable node
56      */

57     public CheckSuperuser ( String JavaDoc nodeName )
58     {
59     super( nodeName, null, true /*allowsChildren*/ );
60     }
61     
62     /**
63      * create or retrieve the visual component of the installable
64      * if one exists. Otherwise return null.
65      */

66     public Component getVisualComponent()
67     {
68     return (null);
69     }
70
71     
72     /**
73      * create or retrieve the configurable component of the installable
74      * if one exists. Otherwise return null object.
75      */

76     public Component getConfigurableComponent()
77     {
78     return (null);
79     }
80
81     /**
82      * method to install by copying files from the source
83      * directory to target directory
84      *
85      * @exception <code>InstallException</code> if there is an
86      * problem trying to install the entity.
87      */

88     public void install() throws InstallException
89     {
90     FreeInstallerApplication theApp =
91         FreeInstallerApplication.getInstance();
92
93     String JavaDoc osname = System.getProperty("os.name");
94
95     // I suppose we could do a more rigorous check for UNIX
96
// like execute the `/usr/bin/id'
97
String JavaDoc username = System.getProperty("user.name");
98     
99     if ( osname.startsWith("Windows 95") ||
100          osname.startsWith("Windows 98") ||
101          osname.startsWith("OS/2") ) {
102         // Checking a superuser does not make sense for these OS
103
// *PLEASE* add any other such operating system here.
104
theApp.printWarning( "CheckSuperuser can perform a security check for "+osname );
105     }
106     else if ( osname.startsWith("Windows NT") ||
107          osname.startsWith("Windows 2000")) {
108         // For windows NT check
109
if ( !osname.equals("Adminstrator") &&
110          !osname.equals("adminstrator") )
111         throw new InstallException(
112             "Regrettably, to install the software package:"+
113             theApp.getProductName()+
114             " you must be NT `administrator' user." );
115     }
116     else {
117         // Assume anything is UNIX system
118
if ( !osname.equals("root") )
119         throw new InstallException(
120             "Regrettably, to install the software package:"+
121             theApp.getProductName()+
122             " you must be `root' user." );
123     }
124     // If we get here, we must be a superuser!
125
}
126     
127     /**
128      * method to perform the uninstallation of content
129      */

130     public void uninstall() throws InstallException
131     {
132     // empty
133
}
134     
135     /**
136      * method to perform the cleanup of content if cancelled, or aborted
137      */

138     public void cleanup() throws InstallException
139     {
140     // empty
141
}
142 }
143
144 // fini
145

146     
147
Popular Tags