update installer: remove unused stuff, allow files (and directories but untested) to be installed with different names)

This commit is contained in:
Steve Checkoway
2004-06-08 09:13:57 +00:00
parent 63bbabc491
commit 3e1efaa68d
4 changed files with 127 additions and 126 deletions
@@ -24,7 +24,8 @@ using namespace std;
#include "Processor.h"
#include "Util.h"
void HandleFile(const CString& file, const CString& dir, const CString& archivePath, bool overwrite)
void HandleFile(const CString& file, const CString& dir,
const CString& archivePath, bool overwrite)
{
static bool archiveMade = false;
char path[] = "/usr/bin/tar";
@@ -44,8 +45,6 @@ void HandleFile(const CString& file, const CString& dir, const CString& archiveP
strcpy(arg4, dir);
strcpy(arg5, file);
/*if (CallTool(path, arg1, arg2, arg3, arg4, arg5, NULL))
exit(-10);*/
int r;
if ((r = CallTool2(true, -1, -1, -1, path, arg1, arg2, arg3, arg4,
arg5, NULL)) != 0)
+11 -65
View File
@@ -6,8 +6,6 @@
// Copyright (c) 2003 Steve Checkoway. All rights reserved.
//
#import <Security/Authorization.h>
#import <Security/AuthorizationTags.h>
#import <sys/types.h>
#import <sys/wait.h>
#import <cstring>
@@ -22,14 +20,14 @@
void Error(const char *fmt, ...);
static id c;
static AuthorizationRef auth;
static BOOL privilegedInstall;
void HandleFile(const CString& file, const CString& dir, const CString& archivePath, bool overwrite)
void HandleFile(const CString& file, const CString& dir,
const CString& archivePath, bool overwrite)
{
NSString *filePath = [NSString stringWithCString:dir];
filePath = [filePath stringByAppendingFormat:@"%s%s", (dir == "/" ? "" : "/"), file.c_str()];
filePath = [filePath stringByAppendingFormat:@"%s%s",
(dir == "/" ? "" : "/"), file.c_str()];
if (!overwrite && DoesFileExist([filePath cString]))
return;
[c postMessage:filePath];
@@ -46,32 +44,11 @@ void HandleFile(const CString& file, const CString& dir, const CString& archiveP
strcpy(d, dir);
strcpy(f, file);
if (privilegedInstall)
{
AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagExtendRights;
AuthorizationItem item = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &item};
OSStatus status = AuthorizationCopyRights(auth, &rights, NULL, flags, NULL);
int fd_dev_null = open("/dev/null", O_RDWR, 0);
if (status != errAuthorizationSuccess)
{
[c postMessage:@"Couldn't authorize"];
return;
}
status = AuthorizationExecuteWithPrivileges(auth, path, kAuthorizationFlagDefaults, arguments+1, NULL);
if (status != errAuthorizationSuccess)
[c postMessage:@"failed"];
wait((int*)&status);
}
else
{
int fd_dev_null = open("/dev/null", O_RDWR, 0);
if (CallTool3(true, -1, fd_dev_null, fileno(stderr), path, arguments))
[c postMessage:@"failed"];
close(fd_dev_null);
}
if (CallTool3(true, -1, fd_dev_null, fileno(stderr), path, arguments))
[c postMessage:@"failed"];
close(fd_dev_null);
}
const CString GetPath(const CString& ID)
@@ -84,8 +61,8 @@ const CString GetPath(const CString& ID)
[panel setAllowsMultipleSelection:NO];
[panel setPrompt:@"Install"];
// Only in 10.3 and above
if ([panel respondsToSelector:@selector(setCanCreatetDirectories:)])
[panel setCanCreateDirectories:YES];
if ([panel respondsToSelector:@selector(setCanCreateDirectories:)])
[panel setCanCreateDirectories:YES];
[panel setTitle:@"Choose a location to install."];
int result = [panel runModalForTypes:[NSArray array]]; // No extensions
@@ -122,16 +99,6 @@ bool AskFunc(const CString& question)
return answer;
}
bool Auth(void)
{
AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights;
AuthorizationItem item = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &item};
OSStatus status = AuthorizationCopyRights(auth, &rights, NULL, flags, NULL);
return status == errAuthorizationSuccess;
}
void Echo(const CString& message, bool loud)
{
if (!loud)
@@ -142,13 +109,7 @@ void Echo(const CString& message, bool loud)
NSBeginCriticalAlertSheet(@"Warning", @"OK", nil, nil, [c window], c, nil, nil, NULL,
[NSString stringWithCString:message.c_str()]);
}
void Priv(bool privileged)
{
privilegedInstall = privileged;
}
}
@implementation Helper
- (id)initWithPath:(NSString *)path
@@ -156,24 +117,11 @@ void Priv(bool privileged)
[super init];
mPath = [path retain];
OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagDefaults, &auth);
if (status != errAuthorizationSuccess)
{
auth = NULL;
[self autorelease];
return nil;
}
privilegedInstall = NO;
return self;
}
- (void)dealloc
{
if (auth)
AuthorizationFree(auth, kAuthorizationFlagDestroyRights);
[mPath autorelease];
[super dealloc];
}
@@ -194,9 +142,7 @@ void Priv(bool privileged)
Processor p(archivePath, HandleFile, GetPath, AskFunc, YES);
p.SetErrorFunc(Error);
p.SetAuthFunc(Auth);
p.SetEchoFunc(Echo);
p.SetPrivFunc(Priv);
[c postMessage:@"Reading from the config file."];
+113 -51
View File
@@ -109,41 +109,121 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
#pragma mark FILE
if (parts[0] == "FILE")
{
if (parts.size() != 3)
goto error;
CString file, dir;
if (parts[1][0] == '/')
{
file = parts[1].substr(1);
dir = "/";
}
else
{
file = parts[1];
dir = mCWD;
}
if (parts.size() == 3)
{
CString file, dir;
if (parts[1][0] == '/')
{
file = parts[1].substr(1);
dir = "/";
}
else
{
file = parts[1];
dir = mCWD;
}
if (mInstalling)
(*mHandleFile)(file, dir, mPath, ResolveConditional(parts[2]));
else
{
CStringArray list, dirs;
if (IsADirectory((dir == "/" ? dir : dir + "/" ) + file))
{
int fd = open(".", O_RDONLY, 0);
if (mInstalling)
(*mHandleFile)(file, dir, mPath, ResolveConditional(parts[2]));
else
{
if (IsADirectory((dir == "/" ? dir : dir + "/" ) + file))
{
CStringArray list, dirs;
int fd = open(".", O_RDONLY, 0);
chdir(dir);
FileListingForDirectoryWithIgnore(file, list, dirs, mIgnore);
fchdir(fd);
close(fd);
if (list.size() == 0) //empty directory or ignored directory
(*mHandleFile)(file, dir, mPath, true);
for (unsigned i=0; i<list.size(); ++i)
(*mHandleFile)(list[i], dir, mPath, true);
}
else
(*mHandleFile)(file, dir, mPath, true);
}
chdir(dir);
FileListingForDirectoryWithIgnore(file, list, dirs,
mIgnore);
fchdir(fd);
close(fd);
if (list.size() == 0) //empty dir or ignored dir
(*mHandleFile)(file, dir, mPath, true);
for (unsigned i=0; i<list.size(); ++i)
(*mHandleFile)(list[i], dir, mPath, true);
}
else
(*mHandleFile)(file, dir, mPath, true);
}
}
else if (parts.size() == 4)
{
CString iFile, iDir, fFile, fDir;
if (parts[1][0] == '/')
{
iFile = parts[1].substr(1);
iDir = "/";
}
else
{
iFile = parts[1];
iDir = mCWD;
}
if (parts[2][0] == '/')
{
fFile = parts[2].substr(1);
fFile = "/";
}
else
{
fFile = parts[2];
fDir = mCWD;
}
if (mInstalling)
(*mHandleFile)(fFile, fDir, mPath,
ResolveConditional(parts[3]));
else
{
// Now the fun part
char temp[] = "/tmp/tmpXXXXXX";
CString dir;
size_t pos = fFile.find_last_of('/');
char arg1[] = "-r";
char tool1[] = "/bin/cp";
char tool2[] = "/bin/rm";
mkdtemp(temp);
dir.Format("%s/%s/%s", temp, fDir == mCWD ? "." : fDir.c_str(),
pos == fFile.npos ? "" :
fFile.substr(0, pos).c_str());
if (mkdir_p(dir))
{
fprintf(stderr, "Couldn't create directory: %s\n",
dir.c_str());
exit(-1);
}
if (CallTool(tool1, arg1, (iDir + "/" + iFile).c_str(),
dir.c_str(), NULL))
{
fprintf(stderr, "Couldn't copy file(s).\n");
exit(-1);
}
if (IsADirectory((iDir == "/" ? iDir : iDir + "/") + iFile))
{
CStringArray list, dirs;
int fd = open(".", O_RDONLY, 0);
chdir(dir + "/" + fDir);
FileListingForDirectoryWithIgnore(fFile, list, dirs,
mIgnore);
fchdir(fd);
close(fd);
if (list.size() == 0)
(*mHandleFile)(fFile, temp, mPath, true);
for (unsigned i=0; i<list.size(); ++i)
(*mHandleFile)(list[i], temp, mPath, true);
}
else
(*mHandleFile)(fFile, temp, mPath, true);
char arg[] = "-rf";
CallTool(tool2, arg, temp, NULL);
}
}
else
goto error;
return;
}
@@ -313,15 +393,6 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return;
}
#pragma mark AUTH
if (parts[0] == "AUTH")
{
if (parts.size() != 2)
goto error;
mConditionals[parts[1]] = (*mAuth)();
return;
}
#pragma mark ECHO
if (parts[0] == "ECHO")
{
@@ -331,15 +402,6 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return;
}
#pragma mark PRIVILEGED
if (parts[0] == "PRIVILEGED")
{
if (parts.size() != 2)
goto error;
(mPriv)(ResolveConditional(parts[1]));
return;
}
error:
(*mError)("%s is an invalid command", line.c_str());
}
+1 -7
View File
@@ -24,9 +24,7 @@ private:
typedef const CString (*getPathFunc)(const CString& ID);
typedef void (*errorFunc)(const char *fmt, ...);
typedef bool (*askFunc)(const CString& question);
typedef bool (*authFunc)(void);
typedef void (*echoFunc)(const CString& message, bool loud);
typedef void (*privFunc)(bool privileged);
stack<unsigned> mReturnStack;
bool mDoGoto;
@@ -41,9 +39,7 @@ private:
getPathFunc mGetPath;
askFunc mAsk;
errorFunc mError;
authFunc mAuth;
echoFunc mEcho;
privFunc mPriv;
echoFunc mEcho;
bool mInstalling;
const CString& ResolveVar(const CString& var);
@@ -54,9 +50,7 @@ public:
~Processor();
void ProcessLine(const CString& line, unsigned& nextLine);
void SetErrorFunc(errorFunc f) { mError = f; }
void SetAuthFunc(authFunc f) { mAuth = f; }
void SetEchoFunc(echoFunc f) { mEcho = f; }
void SetPrivFunc(privFunc f) { mPriv = f; }
};
#endif