Provide default name for login

This commit is contained in:
Richard Frith-Macdonald 2022-06-07 12:04:00 +01:00
parent e32f34a063
commit 2ce70c02e3
3 changed files with 37 additions and 6 deletions

View file

@ -1,3 +1,10 @@
2022-06-07 Richard Frith-Macdonald <rfm@gnu.org>
* GNUMakefile: Fix to supply local flags to build libraries
* EcConsole.m: Use the EffectiveUser default or the name of the
user running the process as the default name to login with.
The user is still allowed to enter a name at the Login prompt.
2022-02-28 Richard Frith-Macdonald <rfm@gnu.org>
* EcCommand.m:

View file

@ -61,6 +61,8 @@ static BOOL commandIsRepeat (NSString *string)
}
}
static NSString *originalUserName = nil;
@interface EcConsole : EcProcess <RunLoopEvents, Console>
{
NSFileHandle *ichan;
@ -759,6 +761,7 @@ static BOOL commandIsRepeat (NSString *string)
- (id) initWithDefaults: (NSDictionary*)defs
{
ASSIGN(originalUserName, NSUserName());
self = [super initWithDefaults: defs];
if (self)
{
@ -1051,9 +1054,20 @@ consoleCompleter(const char *text, int start, int end)
NSString *reject;
char buf[128], *line;
if (nil == (u = [[self cmdDefaults] stringForKey: @"EffectiveUser"]))
{
u = originalUserName;
}
/* read username */
printf("Login: ");
if (u)
{
printf("Login (%s): ", [u UTF8String]);
}
else
{
printf("Login: ");
}
fflush(stdout);
line = fgets(buf, sizeof(buf), stdin);
@ -1064,12 +1078,19 @@ consoleCompleter(const char *text, int start, int end)
}
line[strlen(line) - 1] = '\0';
u = [[NSString stringWithCString: line] stringByTrimmingSpaces];
if ([u length] == 0)
/* If we do not have a system username or if the user entered a value
* we use the username entered (or try again).
*/
if (nil == u || line[0] != '\0')
{
/* user just pressed enter, retry */
continue;
u = [[NSString stringWithCString: line] stringByTrimmingSpaces];
if ([u length] == 0)
{
/* user just pressed enter, retry */
continue;
}
}
if ([u caseInsensitiveCompare: @"quit"] == NSOrderedSame)
{
[self cmdQuit: 0];

View file

@ -74,14 +74,17 @@ TOOL_NAME = \
Command_OBJC_FILES = Command.m EcCommand.m EcClientI.m NSFileHandle+Printf.m
Command_TOOL_LIBS += -lECCL
Command_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
Command_CPPFLAGS += ${ECCL_CPPFLAGS}
Console_OBJC_FILES = Console.m EcConsole.m NSFileHandle+Printf.m
Console_TOOL_LIBS += -lECCL
Console_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
Console_CPPFLAGS += ${ECCL_CPPFLAGS}
Control_OBJC_FILES = Control.m EcControl.m EcClientI.m NSFileHandle+Printf.m
Control_TOOL_LIBS += -lECCL
Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
Control_CPPFLAGS += ${ECCL_CPPFLAGS}
AlarmTool_OBJC_FILES = AlarmTool.m
AlarmTool_TOOL_LIBS += -lECCL