2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************
24 ** (c) Copyright Hewlett-Packard Company, 1990, 1991, 1992, 1993.
25 ** All rights are reserved. Copying or other reproduction of this
26 ** program except for archival purposes is prohibited without prior
27 ** written consent of Hewlett-Packard Company.
28 ********************************************************************
29 ****************************<+>*************************************/
30 /*******************************************************************
34 * Purpose: Create the Application Manager
35 * the desktop components.
37 * Description: dtappgather is invoked by the Xsession file at
38 * user login. It collects the application groups
39 * and subdirectories that are to appear in the
40 * user's Application Manager view.
42 * It is also invoked by the "ReloadApps" action.
44 * Product: @(#)Common Desktop Environment 1.0
46 * Revision: $TOG: dtappgather.C /main/9 1998/12/14 17:38:54 mgreess $
48 ********************************************************************/
50 /********************************************************************
52 * Environment variables used by this utility
55 * Default may be vendor specific: /nfs
58 * Default: $HOME/.dt,/etc/dt/appconfig,/usr/dt/appconfig
59 * Set at login by the dtsearchpath utility.
63 * Set by the dtlogin program.
67 * Set by the dtlogin program.
70 * Default: /var/dt/appconfig/appmanager/$DTUSERSESSION
71 * Set within this utility.
73 ****************************************************************************/
75 #include "dtappgather.h"
76 #include "DirIterator.h"
78 #if defined(linux) || defined(CSRG_BASED) || defined(sun)
92 // For now, remove the old ApplicationManager subdirectory
93 // so that we don't leave old CDE users with extra baggage
96 CString targetAppmanDir (user->HOME() + ".dt/ApplicationManager");
98 if (user->OS()->isDirectory(targetAppmanDir) &&
99 0 == user->OS()->isLink(targetAppmanDir)) {
101 user->OS()->changePermissions(targetAppmanDir,0777);
102 user->OS()->removeDirectory(targetAppmanDir);
106 AppManagerDirectory::AppManagerDirectory
108 CDEEnvironment * user,
114 // Set the users Application Manager subdirectory
116 CString userhostdir = user->UserHostDir();
118 if (userhostdir.isNull())
119 userhostdir = "generic-display-0";
121 // else if dir is non-NULL and there is a / in DTUSERSESSION,
122 // dtappgather creates /var/dt/appconfig/appmanager/DTUSERSESSION.
123 // This is a possible security hole, so
124 // prevent creation of directories of the form
125 // /var/dt/appconfig/appmanager/directory1/directory2
128 else if ((char *)strstr(userhostdir.data(),"/"))
129 userhostdir = "generic-display-0";
131 dirname_ = "/var/dt/appconfig/appmanager/";
132 dirname_ += userhostdir;
134 if (user->OS()->isDirectory(dirname_) &&
135 0 == user->OS()->isLink(dirname_)) {
137 user->OS()->changeOwnerGroup(dirname_,"","");
138 user->OS()->changePermissions(dirname_,0755);
140 user->OS()->removeFiles(dirname_, ".~*");
142 user->OS()->removeFiles(dirname_, "[.]~*");
144 user->OS()->removeDeadLinks(dirname_);
145 if (!options->Retain())
147 user->OS()->removeFiles(dirname_,"*");
149 user->OS()->removeFiles(dirname_,"[.]*");
154 // Make /var/dt/appconfig/appmanager directories if not present
156 // Make user session subdirectory under /var/dt/appconfig/appmanager
158 CString dir(dirname_);
159 dir.replace("/" + userhostdir,"");
160 if (!user->OS()->isDirectory(dir)) { // does appmanager exist?
161 dir.replace("/appmanager","");
162 if (!user->OS()->isDirectory(dir)) { // does appconfig exist?
163 dir.replace("/appconfig","");
164 if (!user->OS()->isDirectory(dir)) { // does dt exist?
165 dir.replace("/dt","");
166 if (!user->OS()->isDirectory(dir)) { // does /var exist?
167 user->OS()->MakeDirectory(dir,0755);
168 user->OS()->changeOwnerGroup(dir,"root","other");
169 user->OS()->changePermissions(dir,0755);
172 user->OS()->MakeDirectory(dir,0755);
173 user->OS()->changeOwnerGroup(dir,"root","other");
174 user->OS()->changePermissions(dir,0755);
177 user->OS()->MakeDirectory(dir,0755);
178 user->OS()->changeOwnerGroup(dir,"bin","bin");
179 user->OS()->changePermissions(dir,0755);
181 dir += "/appmanager";
182 user->OS()->MakeDirectory(dir,0755);
183 user->OS()->changeOwnerGroup(dir,"bin","bin");
184 user->OS()->changePermissions(dir,0755);
186 user->OS()->MakeDirectory(dirname_,0755);
187 user->OS()->changeOwnerGroup(dirname_,"","");
190 // Make /var/dt/tmp directory if not present
192 CString tmp("/var/dt/tmp/");
193 if (!user->OS()->isDirectory(tmp)) { // does tmp exist?
194 user->OS()->MakeDirectory(tmp,0755);
195 user->OS()->changeOwnerGroup(tmp,"root","other");
196 user->OS()->changePermissions(tmp,0755);
200 if (!user->OS()->isDirectory(tmp)) { // does tmp/$DTUSERSESSION exist?
201 user->OS()->MakeDirectory(tmp, 0755);
202 user->OS()->changeOwnerGroup(tmp,"","");
203 user->OS()->changePermissions(tmp,0755);
208 /********************************************************************
212 * Parse a given search path, using comma (,) and colon (:) as
213 * delimiters. Pass each path element to another function.
214 ********************************************************************/
216 void AppManagerDirectory::TraversePath()
218 if (!appsp_.isNull()) {
219 CTokenizedString subpath(appsp_,":");
220 CString dir = subpath.next();
221 while (!dir.isNull()) {
222 GatherAppsFromASearchElement (dir);
223 dir = subpath.next();
224 if (langVersionFound && dir == "/usr/dt/appconfig/appmanager/C")
225 dir = subpath.next();
230 /********************************************************************
234 * Ignore '.' and '..' and make sure file doesn't exist.
236 ********************************************************************/
238 int AppManagerDirectory::goodFile
240 const CString & path,
241 const CString & fname
244 if (fname == "." || fname == "..")
247 CString filnam(path + "/" + fname);
249 if (user_->OS()->FileExists(filnam))
256 /*********************************************************************
258 * GatherAppsFromASearchElement()
260 * Given search path element (host name or path name), construct
261 * the appropriate path for the various desktop subsystems.
263 * A path is constructed so that each element is appended to
265 *********************************************************************/
266 void AppManagerDirectory::GatherAppsFromASearchElement
272 CString source(path);
273 if (source.contains("/%L")) {
274 if (user_->OS()->LANG() != "C") {
275 source.replace("%L",user_->OS()->LANG());
276 if (!user_->OS()->isDirectory(source))
278 if (source.contains("/usr/dt/appconfig/appmanager/"))
279 langVersionFound = 1;
285 else if (!user_->OS()->isDirectory(source))
288 DirectoryIterator iter (source);
289 struct dirent * direntry;
291 user_->OS()->setUserId();
293 while (direntry = iter()) {
294 CString dname(direntry->d_name);
295 if (user_->OS()->isDirectory(source + "/" + dname)
296 || user_->OS()->isFile(source + "/" + dname))
297 if (goodFile(dirname_, dname))
298 user_->OS()->symbolicLink (source + "/" + dname,
299 dirname_ + "/" + dname);
302 user_->OS()->setUserId();
306 int main (int argc, char **argv)
308 options = new Options(argc, argv);
310 UnixEnvironment * os = new UnixEnvironment;
312 CDEEnvironment * user = new CDEEnvironment(0, os);
316 CString app(getenv("DTAPPSEARCHPATH"));
318 AppManagerDirectory * appman = new AppManagerDirectory(user, app);
319 appman->TraversePath();
321 user->OS()->changePermissions((*appman)(),0555);