Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added minimal support for issue file, moved xlshrc to /etc, defined X…

… tty name.
  • Loading branch information...
commit 5ba8a1b5d6f72a19044a34f8e0a414208d7d605a 1 parent b52abc5
@Nadrin authored
View
5 src/config.h
@@ -13,9 +13,12 @@
#define XLSH_PROMPT "%s (%s)> "
#define XLSH_TMPDIR "/tmp"
#define XLSH_SHELLS "/etc/shells"
+#define XLSH_ISSUE "/etc/issue"
#define XLSH_PATH "/bin:/usr/bin:/usr/local/bin"
#define XLSH_REBOOT "/sbin/shutdown -r now"
#define XLSH_HALT "/sbin/shutdown -h now"
+#define XLSH_XTTY "/dev/console"
+#define XLSH_XTTY_NAME "X11"
#define XLSHD_TMPDIR XLSH_TMPDIR
#define XLSHD_SHELL "/bin/sh"
@@ -23,7 +26,7 @@
#define XLSHD_XSERVER "/usr/bin/X"
#define XLSHD_XOPTIONS "-nolisten tcp -noreset"
#define XLSHD_XDISPLAY ":0"
-#define XLSHD_XLSHRC "/etc/xlsh/xlshrc"
+#define XLSHD_XLSHRC "/etc/xlshrc"
#define XLSHD_XWAIT 1
#define XLSHD_XRETRY 2
View
35 src/libxlsh.c
@@ -17,12 +17,13 @@
static sigset_t xlsh_default_sigmask;
-void libxlsh_sigmask(void)
+// Process functions
+void libxlsh_proc_sigmask(void)
{
sigprocmask(0, NULL, &xlsh_default_sigmask);
}
-pid_t libxlsh_exec(const char* cmdline, int flags)
+pid_t libxlsh_proc_exec(const char* cmdline, int flags)
{
pid_t pid;
int i;
@@ -47,6 +48,7 @@ pid_t libxlsh_exec(const char* cmdline, int flags)
exit(EXIT_FAILURE);
}
+// Pid read/write functions
pid_t libxlsh_pid_read(const char* filename)
{
pid_t result = 0;
@@ -76,3 +78,32 @@ int libxlsh_pid_lock(const char* filename, pid_t pid, int flags)
fclose(pidfile);
return XLSH_EOK;
}
+
+// File IO functions
+int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize)
+{
+ FILE* file;
+ size_t filesize, bytes_read;
+
+ if(!(file = fopen(filename, "r")))
+ return XLSH_ENOTFOUND;
+
+ fseek(file, 0, SEEK_END);
+ filesize = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ *buffer = malloc(filesize + 1);
+ if(bufsize) *bufsize = filesize + 1;
+ if(!*buffer) {
+ fclose(file);
+ return XLSH_ERROR;
+ }
+ bytes_read = fread(*buffer, 1, filesize, file);
+ fclose(file);
+
+ if(bytes_read != filesize) {
+ free(*buffer);
+ return XLSH_ERROR;
+ }
+ return XLSH_EOK;
+}
View
5 src/libxlsh.h
@@ -22,9 +22,10 @@
#define XLSH_OVERWRITE 0x01
#define XLSH_DETACH 0x02
-void libxlsh_sigmask(void);
-pid_t libxlsh_exec(const char* cmdline, int flags);
+void libxlsh_proc_sigmask(void);
+pid_t libxlsh_proc_exec(const char* cmdline, int flags);
pid_t libxlsh_pid_read(const char* filename);
int libxlsh_pid_lock(const char* filename, pid_t pid, int flags);
+int libxlsh_file_read(const char* filename, char** buffer, size_t* bufsize);
#endif
View
62 src/xlsh.c
@@ -47,6 +47,8 @@ static xlsh_command_t xlsh_commands[] = {
{ NULL, NULL, NULL },
};
+static int xlsh_X = 0;
+
static void xlsh_usage(char* argv0)
{
fprintf(stderr, "eXtended Login Shell, version %s\n", XLSH_VERSION_STRING);
@@ -93,7 +95,7 @@ int xlsh_func_login(int argc, char** argv)
return XLSH_EARG;
}
- if(getenv("DISPLAY")) {
+ if(xlsh_X) {
if(!arg_shell)
arg_shell = xlsh_config[XLSH_ID_EXEC].value;
return xlsh_session_x(arg_user, arg_shell);
@@ -107,7 +109,7 @@ int xlsh_func_reboot(int argc, char** argv)
pid_t xlshd_pid;
printf("Initiating system reboot ...\n");
- if(libxlsh_exec(XLSH_REBOOT, XLSH_DETACH) == -1) {
+ if(libxlsh_proc_exec(XLSH_REBOOT, XLSH_DETACH) == -1) {
fprintf(stderr, "Failed to execute: %s\n", XLSH_REBOOT);
return XLSH_ERROR;
}
@@ -124,7 +126,7 @@ int xlsh_func_shutdown(int argc, char** argv)
pid_t xlshd_pid;
printf("Initiating system shutdown ...\n");
- if(libxlsh_exec(XLSH_HALT, XLSH_DETACH) == -1) {
+ if(libxlsh_proc_exec(XLSH_HALT, XLSH_DETACH) == -1) {
fprintf(stderr, "Failed to execute: %s\n", XLSH_HALT);
return XLSH_ERROR;
}
@@ -171,6 +173,37 @@ static int xlsh_session_conv(int num_msg, const struct pam_message** msg,
}
// Session management
+int xlsh_session_showissue(const char* issuefile)
+{
+ char* buffer;
+ size_t buffer_size;
+ char *curptr, *nextptr, *endptr;
+
+ int errflag;
+ char escflag;
+
+ if((errflag = libxlsh_file_read(issuefile, &buffer, &buffer_size)) != XLSH_EOK)
+ return errflag;
+
+ curptr = buffer;
+ endptr = buffer + buffer_size - 1;
+ do {
+ nextptr = strchr(curptr, '\\');
+ if(nextptr) {
+ *nextptr = 0;
+ escflag = *(++nextptr);
+ curptr += (printf("%s", curptr) + 2);
+ printf("[%c]", escflag);
+ }
+ else
+ curptr += printf("%s", curptr);
+ } while(curptr < endptr);
+
+ fputc('\n', stdout);
+ free(buffer);
+ return XLSH_EOK;
+}
+
char* xlsh_session_getshell(char* buffer, const char* shell, size_t bufsize)
{
char readbuf[bufsize];
@@ -233,7 +266,11 @@ int xlsh_session_open(const char* service, const char* user,
if(pam_start(service, user, &conv, &pam_handle) != PAM_SUCCESS)
return XLSH_ERROR;
- pam_set_item(pam_handle, PAM_TTY, ttyname(0));
+
+ if(xlsh_X)
+ pam_set_item(pam_handle, PAM_TTY, XLSH_XTTY);
+ else
+ pam_set_item(pam_handle, PAM_TTY, ttyname(0));
if(pam_authenticate(pam_handle, 0) != PAM_SUCCESS) {
pam_end(pam_handle, 0);
@@ -431,7 +468,7 @@ int xlsh_session_x(const char* user, const char* shell)
// Configuration
void xlsh_config_init(char* exec_arg)
-{
+{
if(exec_arg)
xlsh_config_set(&xlsh_config[XLSH_ID_EXEC], exec_arg);
else
@@ -494,12 +531,13 @@ int xlsh_cmd_loop(void)
xlsh_command_t* command = NULL;
int retvalue = XLSH_EOK;
- if(ttyname_r(0, sys_ttypath, 64) != 0)
- strcpy(sys_ttypath, "/dev/console");
if(gethostname(sys_hostname, 64) != 0)
strcpy(sys_hostname, "localhost");
+ if(xlsh_X || ttyname_r(0, sys_ttypath, 64) != 0)
+ sys_ttyname = XLSH_XTTY_NAME;
+ else
+ sys_ttyname = sys_ttypath + 5;
- sys_ttyname = sys_ttypath + 5;
snprintf(prompt, 256, xlsh_config[XLSH_ID_PROMPT].value,
sys_hostname, sys_ttyname);
@@ -553,14 +591,20 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
- libxlsh_sigmask();
+ libxlsh_proc_sigmask();
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
sigaddset(&sigmask, SIGHUP);
sigprocmask(SIG_BLOCK, &sigmask, NULL);
+
+ if(getenv("DISPLAY"))
+ xlsh_X = 1;
xlsh_config_init(opt_exec);
+ xlsh_session_showissue(XLSH_ISSUE);
+
retvalue = xlsh_cmd_loop();
+
xlsh_config_free();
return retvalue;
}
View
6 src/xlshd.c
@@ -126,7 +126,7 @@ int main(int argc, char** argv)
libxlsh_pid_lock(XLSHD_PIDFILE, getpid(), XLSH_OVERWRITE);
}
- libxlsh_sigmask();
+ libxlsh_proc_sigmask();
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGHUP);
@@ -146,7 +146,7 @@ int main(int argc, char** argv)
xrc_pid = 0;
snprintf(buffer, PATH_MAX, "%s %s %s", XLSHD_XSERVER, XLSHD_XOPTIONS, opt_display);
- if((xserver_pid = libxlsh_exec(buffer, 0)) < 0) {
+ if((xserver_pid = libxlsh_proc_exec(buffer, 0)) < 0) {
retval = EXIT_FAILURE;
break;
}
@@ -155,7 +155,7 @@ int main(int argc, char** argv)
sleep(XLSHD_XWAIT);
snprintf(buffer, PATH_MAX, "%s %s", XLSHD_SHELL, XLSHD_XLSHRC);
- if((xrc_pid = libxlsh_exec(buffer, 0)) < 0) {
+ if((xrc_pid = libxlsh_proc_exec(buffer, 0)) < 0) {
kill(xserver_pid, SIGTERM);
retval = EXIT_FAILURE;
break;
Please sign in to comment.
Something went wrong with that request. Please try again.