1996-05-28 21:25:46 +00:00
|
|
|
/* Implementation of login-related functions for GNUstep
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Created: May 1996
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1996-05-28 21:25:46 +00:00
|
|
|
*/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/preface.h>
|
2000-10-31 16:17:33 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1996-09-02 13:23:43 +00:00
|
|
|
#include <Foundation/NSPathUtilities.h>
|
1999-02-20 21:19:15 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSFileManager.h>
|
1998-12-17 09:16:26 +00:00
|
|
|
#include <Foundation/NSProcessInfo.h>
|
2000-03-25 10:59:07 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
2000-05-04 18:10:02 +00:00
|
|
|
#include <Foundation/NSLock.h>
|
1999-02-20 21:19:15 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
1998-12-15 19:11:58 +00:00
|
|
|
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <stdlib.h> // for getenv()
|
1999-05-11 09:21:38 +00:00
|
|
|
#if !defined(__WIN32__)
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <unistd.h> // for getlogin()
|
1999-04-13 20:37:04 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_PWD_H
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <pwd.h> // for getpwnam()
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif
|
1996-05-28 21:25:46 +00:00
|
|
|
#include <sys/types.h>
|
1999-06-29 11:54:03 +00:00
|
|
|
#include <stdio.h>
|
1996-05-28 21:25:46 +00:00
|
|
|
|
1999-02-20 21:19:15 +00:00
|
|
|
static NSString *theUserName = nil;
|
|
|
|
|
|
|
|
void
|
|
|
|
GSSetUserName(NSString* name)
|
|
|
|
{
|
|
|
|
if (theUserName == nil)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
theUserName = RETAIN(name);
|
|
|
|
}
|
1999-02-20 21:19:15 +00:00
|
|
|
else if ([theUserName isEqualToString: name] == NO)
|
|
|
|
{
|
|
|
|
ASSIGN(theUserName, name);
|
|
|
|
[NSUserDefaults resetUserDefaults];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the caller's login name as an NSString object.
|
|
|
|
* The 'LOGNAME' environment variable is our primary source, but we use
|
|
|
|
* other system-dependent sources if LOGNAME is not set.
|
|
|
|
*/
|
1996-05-28 21:25:46 +00:00
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSUserName(void)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
1999-02-20 21:19:15 +00:00
|
|
|
if (theUserName == nil)
|
|
|
|
{
|
|
|
|
const char *login_name = 0;
|
1999-05-11 09:21:38 +00:00
|
|
|
#if defined(__WIN32__)
|
1999-02-20 21:19:15 +00:00
|
|
|
/* The GetUserName function returns the current user name */
|
|
|
|
char buf[1024];
|
|
|
|
DWORD n = 1024;
|
1997-01-09 16:24:07 +00:00
|
|
|
|
1999-03-03 06:04:33 +00:00
|
|
|
if (GetEnvironmentVariable("LOGNAME", buf, 1024))
|
1999-02-20 21:19:15 +00:00
|
|
|
login_name = buf;
|
|
|
|
else if (GetUserName(buf, &n))
|
|
|
|
login_name = buf;
|
1996-10-31 19:05:14 +00:00
|
|
|
#else
|
1999-02-20 21:19:15 +00:00
|
|
|
login_name = getenv("LOGNAME");
|
2001-04-02 09:59:30 +00:00
|
|
|
#if HAVE_GETPWNAM
|
|
|
|
/*
|
|
|
|
* Check that LOGNAME contained legal name.
|
|
|
|
*/
|
|
|
|
if (login_name != 0 && getpwnam(login_name) == 0)
|
1999-02-20 21:19:15 +00:00
|
|
|
{
|
2001-04-02 09:59:30 +00:00
|
|
|
login_name = 0;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_GETPWNAM */
|
|
|
|
#if HAVE_GETLOGIN
|
|
|
|
/*
|
|
|
|
* Try getlogin() if LOGNAME environmentm variable didn't work.
|
|
|
|
*/
|
|
|
|
if (login_name == 0)
|
|
|
|
{
|
|
|
|
login_name = getlogin();
|
|
|
|
}
|
|
|
|
#endif /* HAVE_GETLOGIN */
|
|
|
|
#if HAVE_GETPWUID
|
|
|
|
/*
|
|
|
|
* Try getting the name of the effective user as a last resort.
|
|
|
|
*/
|
|
|
|
if (login_name == 0)
|
|
|
|
{
|
|
|
|
#if HAVE_GETEUID
|
|
|
|
int uid = geteuid();
|
|
|
|
#else
|
|
|
|
int uid = getuid();
|
|
|
|
#endif /* HAVE_GETEUID */
|
1999-02-20 21:19:15 +00:00
|
|
|
struct passwd *pwent = getpwuid (uid);
|
|
|
|
login_name = pwent->pw_name;
|
|
|
|
}
|
2001-04-02 09:59:30 +00:00
|
|
|
#endif /* HAVE_GETPWUID */
|
1996-10-31 19:05:14 +00:00
|
|
|
#endif
|
1999-02-20 21:19:15 +00:00
|
|
|
if (login_name)
|
|
|
|
GSSetUserName([NSString stringWithCString: login_name]);
|
|
|
|
else
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"Unable to determine curren user name"];
|
|
|
|
}
|
|
|
|
return theUserName;
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the caller's home directory as an NSString object. */
|
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSHomeDirectory(void)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
1996-09-02 13:20:20 +00:00
|
|
|
return NSHomeDirectoryForUser (NSUserName ());
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return LOGIN_NAME's home directory as an NSString object. */
|
|
|
|
NSString *
|
1999-07-13 15:59:50 +00:00
|
|
|
NSHomeDirectoryForUser(NSString *login_name)
|
1996-05-28 21:25:46 +00:00
|
|
|
{
|
2000-06-12 05:17:41 +00:00
|
|
|
#if !defined(__MINGW__)
|
1996-05-28 21:25:46 +00:00
|
|
|
struct passwd *pw;
|
2000-05-04 18:10:02 +00:00
|
|
|
|
|
|
|
[gnustep_global_lock lock];
|
1998-09-30 07:42:38 +00:00
|
|
|
pw = getpwnam ([login_name cString]);
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock unlock];
|
1996-05-28 21:25:46 +00:00
|
|
|
return [NSString stringWithCString: pw->pw_dir];
|
1996-07-15 18:41:44 +00:00
|
|
|
#else
|
1997-01-09 16:24:07 +00:00
|
|
|
/* Then environment variable HOMEPATH holds the home directory
|
|
|
|
for the user on Windows NT; Win95 has no concept of home. */
|
|
|
|
char buf[1024], *nb;
|
|
|
|
DWORD n;
|
|
|
|
NSString *s;
|
|
|
|
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock lock];
|
1997-01-09 16:24:07 +00:00
|
|
|
n = GetEnvironmentVariable("HOMEPATH", buf, 1024);
|
|
|
|
if (n > 1024)
|
|
|
|
{
|
|
|
|
/* Buffer not big enough, so dynamically allocate it */
|
1999-09-28 11:10:34 +00:00
|
|
|
nb = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)*(n+1));
|
1997-01-09 16:24:07 +00:00
|
|
|
n = GetEnvironmentVariable("HOMEPATH", nb, n+1);
|
|
|
|
nb[n] = '\0';
|
|
|
|
s = [NSString stringWithCString: nb];
|
1999-09-28 11:10:34 +00:00
|
|
|
NSZoneFree(NSDefaultMallocZone(), nb);
|
1997-01-09 16:24:07 +00:00
|
|
|
}
|
2000-06-12 05:17:41 +00:00
|
|
|
else if (n > 0)
|
1997-01-09 16:24:07 +00:00
|
|
|
{
|
|
|
|
/* null terminate it and return the string */
|
|
|
|
buf[n] = '\0';
|
2000-05-04 18:10:02 +00:00
|
|
|
s = [NSString stringWithCString: buf];
|
1997-01-09 16:24:07 +00:00
|
|
|
}
|
2000-06-12 05:17:41 +00:00
|
|
|
else
|
2001-03-03 09:14:56 +00:00
|
|
|
{
|
|
|
|
s = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s != nil)
|
|
|
|
{
|
|
|
|
n = GetEnvironmentVariable("HOMEDRIVE", buf, 1024);
|
|
|
|
buf[n] = '\0';
|
|
|
|
s = [[NSString stringWithCString: buf] stringByAppendingString: s];
|
|
|
|
}
|
2000-05-04 18:10:02 +00:00
|
|
|
[gnustep_global_lock unlock];
|
|
|
|
return s;
|
1996-07-15 18:41:44 +00:00
|
|
|
#endif
|
1996-05-28 21:25:46 +00:00
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSFullUserName(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
1999-04-13 20:37:04 +00:00
|
|
|
#if HAVE_PWD_H
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
pw = getpwnam([NSUserName() cString]);
|
|
|
|
return [NSString stringWithCString: pw->pw_gecos];
|
|
|
|
#else
|
1998-12-15 19:11:58 +00:00
|
|
|
NSLog(@"Warning: NSFullUserName not implemented\n");
|
|
|
|
return NSUserName();
|
1999-04-13 20:37:04 +00:00
|
|
|
#endif
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSArray *
|
|
|
|
GSStandardPathPrefixes(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
1999-07-13 15:59:50 +00:00
|
|
|
NSDictionary *env;
|
|
|
|
NSString *prefixes;
|
|
|
|
NSArray *prefixArray;
|
|
|
|
|
|
|
|
env = [[NSProcessInfo processInfo] environment];
|
|
|
|
prefixes = [env objectForKey: @"GNUSTEP_PATHPREFIX_LIST"];
|
2001-04-02 09:59:30 +00:00
|
|
|
if (prefixes != 0)
|
1999-07-13 15:59:50 +00:00
|
|
|
{
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
prefixArray = [prefixes componentsSeparatedByString: @";"];
|
|
|
|
#else
|
|
|
|
prefixArray = [prefixes componentsSeparatedByString: @":"];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *strings[4];
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *str;
|
|
|
|
unsigned count = 0;
|
|
|
|
|
|
|
|
str = [env objectForKey: @"GNUSTEP_USER_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
|
|
|
str = [env objectForKey: @"GNUSTEP_LOCAL_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
2001-01-28 12:16:44 +00:00
|
|
|
str = [env objectForKey: @"GNUSTEP_NETWORK_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
str = [env objectForKey: @"GNUSTEP_SYSTEM_ROOT"];
|
|
|
|
if (str != nil)
|
|
|
|
strings[count++] = str;
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
prefixArray = [NSArray arrayWithObjects: strings count: count];
|
|
|
|
else
|
|
|
|
prefixArray = [NSArray array];
|
|
|
|
}
|
|
|
|
return prefixArray;
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSArray *
|
|
|
|
NSStandardApplicationPaths(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
2001-03-26 23:09:44 +00:00
|
|
|
return NSSearchPathForDirectoriesInDomains(NSAllApplicationsDirectory,
|
|
|
|
NSAllDomainsMask, YES);
|
1999-07-13 15:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *
|
|
|
|
NSStandardLibraryPaths(void)
|
|
|
|
{
|
2001-03-26 23:09:44 +00:00
|
|
|
return NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory,
|
|
|
|
NSAllDomainsMask, YES);
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSTemporaryDirectory(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
2001-04-05 12:42:28 +00:00
|
|
|
NSFileManager *manager;
|
|
|
|
NSString *tempDirName;
|
|
|
|
NSString *baseTempDirName = nil;
|
|
|
|
NSDictionary *attr;
|
|
|
|
int perm;
|
|
|
|
BOOL flag;
|
1999-05-11 09:21:38 +00:00
|
|
|
#if defined(__WIN32__)
|
1998-12-15 19:11:58 +00:00
|
|
|
char buffer[1024];
|
2001-04-05 12:42:28 +00:00
|
|
|
|
1998-12-15 19:11:58 +00:00
|
|
|
if (GetTempPath(1024, buffer))
|
2001-04-05 12:42:28 +00:00
|
|
|
{
|
|
|
|
baseTempDirName = [NSString stringWithCString: buffer];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user has supplied a directory name in the TEMP or TMP
|
|
|
|
* environment variable, attempt to use that unless we already
|
|
|
|
* have a tem porary directory specified.
|
|
|
|
*/
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
|
|
|
NSDictionary *env = [[NSProcessInfo processInfo] environment];
|
|
|
|
|
|
|
|
baseTempDirName = [env objectForKey: @"TEMP"];
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
|
|
|
baseTempDirName = [env objectForKey: @"TMP"];
|
|
|
|
if (baseTempDirName == nil)
|
|
|
|
{
|
|
|
|
#if defined(__WIN32__)
|
|
|
|
baseTempDirName = @"C:\\";
|
1998-12-15 19:11:58 +00:00
|
|
|
#else
|
2001-04-05 12:42:28 +00:00
|
|
|
baseTempDirName = @"/tmp";
|
1998-12-15 19:11:58 +00:00
|
|
|
#endif
|
2001-04-05 12:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
|
2001-04-05 12:42:28 +00:00
|
|
|
/*
|
|
|
|
* Check that the base directory exists ... if it doesn't we can't
|
|
|
|
* go any further.
|
|
|
|
*/
|
|
|
|
tempDirName = baseTempDirName;
|
1998-12-15 19:11:58 +00:00
|
|
|
manager = [NSFileManager defaultManager];
|
2001-04-05 12:42:28 +00:00
|
|
|
if ([manager fileExistsAtPath: tempDirName isDirectory: &flag] == NO
|
|
|
|
|| flag == NO)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
2001-04-05 12:42:28 +00:00
|
|
|
NSLog(@"Temporary directory (%@) does not seem to exist", tempDirName);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the directory owner (presumably us) has access to it,
|
|
|
|
* and nobody else. If other people have access, try to create a
|
|
|
|
* secure subdirectory.
|
|
|
|
*/
|
|
|
|
attr = [manager fileAttributesAtPath: tempDirName traverseLink: YES];
|
|
|
|
perm = [[attr objectForKey: NSFilePosixPermissions] intValue];
|
|
|
|
perm = perm & 0777;
|
|
|
|
if (perm != 0700 && perm != 0600)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
NSLog(@"Temporary directory (%@) may be insecure ... attempting to "
|
|
|
|
@"add secure subdirectory", tempDirName);
|
|
|
|
*/
|
2000-02-24 09:26:19 +00:00
|
|
|
|
2001-04-05 12:42:28 +00:00
|
|
|
tempDirName
|
|
|
|
= [baseTempDirName stringByAppendingPathComponent: NSUserName()];
|
|
|
|
if ([manager fileExistsAtPath: tempDirName] == NO)
|
|
|
|
{
|
|
|
|
NSNumber *p = [NSNumber numberWithInt: 0700];
|
|
|
|
|
|
|
|
attr = [NSDictionary dictionaryWithObject: p
|
|
|
|
forKey: NSFilePosixPermissions];
|
|
|
|
if ([manager createDirectoryAtPath: tempDirName
|
|
|
|
attributes: attr] == NO)
|
|
|
|
{
|
|
|
|
tempDirName = baseTempDirName;
|
|
|
|
NSLog(@"Temporary directory (%@) may be insecure", tempDirName);
|
|
|
|
}
|
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
2001-04-05 12:42:28 +00:00
|
|
|
if ([manager isWritableFileAtPath: tempDirName] == NO)
|
|
|
|
{
|
|
|
|
NSLog(@"Temporary directory (%@) is not writable", tempDirName);
|
|
|
|
return nil;
|
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
return tempDirName;
|
|
|
|
}
|
|
|
|
|
1999-07-13 15:59:50 +00:00
|
|
|
NSString *
|
|
|
|
NSOpenStepRootDirectory(void)
|
1998-12-15 19:11:58 +00:00
|
|
|
{
|
2000-02-24 09:26:19 +00:00
|
|
|
NSString *root = [[[NSProcessInfo processInfo] environment]
|
|
|
|
objectForKey: @"GNUSTEP_ROOT"];
|
1998-12-16 22:30:56 +00:00
|
|
|
|
2000-02-24 09:26:19 +00:00
|
|
|
if (root == nil)
|
2000-06-12 05:17:41 +00:00
|
|
|
#if defined(__MINGW__)
|
1998-12-16 22:30:56 +00:00
|
|
|
root = @"C:\\";
|
1998-12-15 19:11:58 +00:00
|
|
|
#else
|
1998-12-16 22:30:56 +00:00
|
|
|
root = @"/";
|
1998-12-15 19:11:58 +00:00
|
|
|
#endif
|
1998-12-16 22:30:56 +00:00
|
|
|
return root;
|
1998-12-15 19:11:58 +00:00
|
|
|
}
|
|
|
|
|
2000-03-25 10:59:07 +00:00
|
|
|
NSArray *
|
|
|
|
NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory directoryKey,
|
|
|
|
NSSearchPathDomainMask domainMask,
|
|
|
|
BOOL expandTilde)
|
|
|
|
{
|
|
|
|
NSDictionary *env;
|
|
|
|
NSString *gnustep_user_root;
|
|
|
|
NSString *gnustep_local_root;
|
|
|
|
NSString *gnustep_network_root;
|
|
|
|
NSString *gnustep_system_root;
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *adminDir = @"Administrator";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *appsDir = @"Apps";
|
2001-03-26 23:09:44 +00:00
|
|
|
NSString *demosDir = @"Demos";
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *devDir = @"Developer";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *libraryDir = @"Library";
|
2001-01-28 12:16:44 +00:00
|
|
|
NSString *libsDir = @"Libraries";
|
2000-03-25 10:59:07 +00:00
|
|
|
NSString *docDir = @"Documentation";
|
|
|
|
NSMutableArray *paths = [NSMutableArray new];
|
|
|
|
NSString *path;
|
|
|
|
NSFileManager *fm;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
env = [[NSProcessInfo processInfo] environment];
|
2000-03-28 13:02:01 +00:00
|
|
|
gnustep_user_root = [env objectForKey: @"GNUSTEP_USER_ROOT"];
|
|
|
|
gnustep_local_root = [env objectForKey: @"GNUSTEP_LOCAL_ROOT"];
|
|
|
|
gnustep_network_root = [env objectForKey: @"GNUSTEP_NETWORK_ROOT"];
|
|
|
|
gnustep_system_root = [env objectForKey: @"GNUSTEP_SYSTEM_ROOT"];
|
2000-03-25 10:59:07 +00:00
|
|
|
|
|
|
|
if (directoryKey == NSApplicationDirectory
|
2000-03-28 13:02:01 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_user_root stringByAppendingPathComponent: appsDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: appsDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: appsDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: appsDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
|
|
|
if (directoryKey == NSDemoApplicationDirectory
|
2001-04-02 09:59:30 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory); /* FIXME */
|
2001-03-26 23:09:44 +00:00
|
|
|
{
|
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-03-26 23:09:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_system_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, demosDir, nil]]];
|
|
|
|
}
|
2001-03-26 23:09:44 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSDeveloperApplicationDirectory
|
2001-01-28 12:16:44 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
|
|
|
{
|
2001-04-02 09:59:30 +00:00
|
|
|
if (domainMask & NSUserDomainMask); /* FIXME */
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_local_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_network_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_system_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, appsDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSAdminApplicationDirectory
|
2001-01-28 12:16:44 +00:00
|
|
|
|| directoryKey == NSAllApplicationsDirectory)
|
|
|
|
{
|
2001-04-02 09:59:30 +00:00
|
|
|
if (domainMask & NSUserDomainMask); /* FIXME */
|
2001-01-28 12:16:44 +00:00
|
|
|
/* users have no Administrator directory */
|
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_local_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_network_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSString pathWithComponents:
|
2001-01-28 12:16:44 +00:00
|
|
|
[NSArray arrayWithObjects: gnustep_system_root,
|
2001-04-02 09:59:30 +00:00
|
|
|
devDir, adminDir, nil]]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (directoryKey == NSLibraryDirectory
|
2000-03-28 13:02:01 +00:00
|
|
|
|| directoryKey == NSAllLibrariesDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_user_root stringByAppendingPathComponent: libraryDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: libraryDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: libraryDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: libraryDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (directoryKey == NSDeveloperDirectory)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
2001-04-02 09:59:30 +00:00
|
|
|
if (domainMask & NSUserDomainMask); /* FIXME */
|
2001-01-28 12:16:44 +00:00
|
|
|
/* users have no Developer directory */
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
2001-01-28 12:16:44 +00:00
|
|
|
[gnustep_local_root stringByAppendingPathComponent: devDir]];
|
2001-04-02 09:59:30 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
2001-01-28 12:16:44 +00:00
|
|
|
[gnustep_network_root stringByAppendingPathComponent: devDir]];
|
2001-04-02 09:59:30 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
2001-01-28 12:16:44 +00:00
|
|
|
[gnustep_system_root stringByAppendingPathComponent: devDir]];
|
2001-04-02 09:59:30 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
|
|
|
if (directoryKey == NSUserDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject: [NSHomeDirectory()
|
|
|
|
stringByAppendingPathComponent: @"GNUstep"]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
|
|
|
if (directoryKey == NSDocumentationDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_user_root stringByAppendingPathComponent: docDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: docDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: docDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: docDir]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (directoryKey == GSLibrariesDirectory)
|
|
|
|
{
|
|
|
|
if (domainMask & NSUserDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_user_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSLocalDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_local_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSNetworkDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_network_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
if (domainMask & NSSystemDomainMask)
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths addObject:
|
|
|
|
[gnustep_system_root stringByAppendingPathComponent: libsDir]];
|
|
|
|
}
|
2001-01-28 12:16:44 +00:00
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
|
|
|
|
fm = [NSFileManager defaultManager];
|
|
|
|
for (i = 0; i < [paths count]; i++)
|
|
|
|
{
|
|
|
|
path = [paths objectAtIndex: i];
|
|
|
|
// remove bad paths
|
2001-04-02 09:59:30 +00:00
|
|
|
if ([fm fileExistsAtPath: path] == NO)
|
2000-03-25 10:59:07 +00:00
|
|
|
{
|
2001-04-02 09:59:30 +00:00
|
|
|
[paths removeObjectAtIndex: i--];
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
2001-04-02 09:59:30 +00:00
|
|
|
/*
|
|
|
|
* this may look like a performance hit at first glance, but if these
|
|
|
|
* string methods don't alter the string, they return the receiver
|
|
|
|
*/
|
|
|
|
else if (expandTilde == YES)
|
|
|
|
{
|
|
|
|
[paths replaceObjectAtIndex: i
|
|
|
|
withObject: [path stringByExpandingTildeInPath]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
else
|
2001-04-02 09:59:30 +00:00
|
|
|
{
|
|
|
|
[paths replaceObjectAtIndex: i
|
|
|
|
withObject: [path stringByAbbreviatingWithTildeInPath]];
|
|
|
|
}
|
2000-03-25 10:59:07 +00:00
|
|
|
}
|
1998-12-15 19:11:58 +00:00
|
|
|
|
2000-03-25 10:59:07 +00:00
|
|
|
return paths;
|
|
|
|
}
|