Skip to content

Commit

Permalink
Login: fixed sessionLog var memory allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
trunkmaster committed Aug 11, 2024
1 parent d7fb60d commit bdfab10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
5 changes: 3 additions & 2 deletions Applications/Login/Controller.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)openSessionForUser:(NSString *)user
@autoreleasepool {
while (aSession.isRunning != NO) {
[aSession launchSessionScript];
NSLog(@"Session Log (openSessionForUser:) - %@", aSession.sessionLog);
[self performSelectorOnMainThread:@selector(userSessionWillClose:)
withObject:aSession
waitUntilDone:YES];
Expand Down Expand Up @@ -103,7 +104,7 @@ - (NSInteger)runAlertPanelForSession:(UserSession *)session
[alert setButtonsTarget:self];
[alert setButtonsAction:@selector(alertButtonPressed:)];

consoleLogPath = [session.sessionLog copy];
consoleLogPath = session.sessionLog;
NSLog(@"Console log for %@ - %@", session.userName, session.sessionLog);

[alert show];
Expand Down Expand Up @@ -166,7 +167,7 @@ - (void)userSessionWillClose:(UserSession *)session
// "Do you want to restart or cleanup session?\n"
// "Note: \"Cleanup\" will kill all running applications.",
// @"Restart", @"Cleanup", nil);
choice = [self runAlertPanelForSession:session];
choice = [self runAlertPanelForSession:session];
if (choice == NSAlertAlternateReturn) {
[self closeAllXClients];
}
Expand Down
45 changes: 19 additions & 26 deletions Applications/Login/UserSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,18 @@
@implementation UserSession

// Log file for session use
- (void)_setupSessionLog
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *logDir;
NSString *logPath;
BOOL isDir;

logDir = [NSString stringWithFormat:@"/tmp/GNUstepSecure%u",
getpwnam([_userName cString])->pw_uid];

if (![fm fileExistsAtPath:logDir isDirectory:&isDir]) {
[fm createDirectoryAtPath:logDir
withIntermediateDirectories:YES
attributes:@{NSFilePosixPermissions:@"700"}
error:0];
}
if (_sessionLog != nil) {
[_sessionLog release];
}
logPath = [logDir stringByAppendingPathComponent:@"console.log"];
_sessionLog = [[NSString alloc] initWithString:logPath];
NSLog(@"Session log for %@ - %@", _userName, _sessionLog);
}
// - (NSString *)_sessionLogPath
// {
// struct passwd *user;
// NSString *logPath;

// user = getpwnam([_userName cString]);
// if (user) {
// logPath = [[NSString alloc] initWithFormat:@"/tmp/GNUstepSecure%u/console.log", user->pw_uid];
// }

// return logPath;
// }

// Called for every launched command (launchCommand:)
- (BOOL)_setUserEnvironment
Expand Down Expand Up @@ -102,8 +91,8 @@ - (BOOL)_setUserEnvironment

// Create user GNUstep directory in /tmp.
[[NSFileManager defaultManager]
createDirectoryAtPath:[NSString stringWithFormat:@"/tmp/GNUstepSecure%d", user->pw_uid]
attributes:@{@"NSFilePosixPermissions":[NSNumber numberWithShort:0700]}];
createDirectoryAtPath:[NSString stringWithFormat:@"/tmp/GNUstepSecure%d", user->pw_uid]
attributes:@{@"NSFilePosixPermissions" : [NSNumber numberWithShort:0700]}];

// General environment variables
setenv("USER", user->pw_name, 1);
Expand All @@ -126,7 +115,7 @@ - (BOOL)_setUserEnvironment
// For CoreFoundation dynamic loading of CFNetwork
setenv("CFNETWORK_LIBRARY_PATH", "/usr/NextSpace/lib/libCFNetwork.so", 1);

[self _setupSessionLog];
// [self _setupSessionLog];
setenv("NS_LOGFILE", [_sessionLog cString], 1);

return YES;
Expand Down Expand Up @@ -162,6 +151,10 @@ - (id)initWithOwner:(Controller *)controller

_userName = [[NSString alloc] initWithString:name];

// _sessionLog = [self _sessionLogPath];
_sessionLog = [[NSString alloc]
initWithFormat:@"/tmp/GNUstepSecure%u/console.log", getpwnam([_userName cString])->pw_uid];

return self;
}

Expand Down

0 comments on commit bdfab10

Please sign in to comment.