Permalink
Browse files

First working version of xlsh. Implemented TTY/X modes, extendable CL…

…I, PAM integration and X daemon.
  • Loading branch information...
1 parent 71ce97a commit b52abc59e441041bb4ac4b77f020dd1843c9ee0e @Nadrin committed Oct 9, 2011
Showing with 989 additions and 3 deletions.
  1. +1 −1 COPYING
  2. +22 −0 Makefile
  3. +7 −2 README
  4. +30 −0 src/config.h
  5. +78 −0 src/libxlsh.c
  6. +30 −0 src/libxlsh.h
  7. +566 −0 src/xlsh.c
  8. +57 −0 src/xlsh.h
  9. +198 −0 src/xlshd.c
View
@@ -1,4 +1,4 @@
-xlsh - X Login Shell
+xlsh - eXtended Login Shell
Copyright (c) 2011 Michał Siejak
This program is free software: you can redistribute it and/or modify
View
@@ -0,0 +1,22 @@
+# xlsh - eXtended Login Shell
+# See COPYING file for license details.
+
+XLSH_SOURCE = src/xlsh.c src/libxlsh.c
+XLSH_HEADERS = src/xlsh.h src/libxlsh.h src/config.h
+XLSH_LIBS = -lreadline -lpam
+
+XLSHD_SOURCE = src/xlshd.c src/libxlsh.c
+XLSHD_HEADERS= src/config.h src/libxlsh.h
+
+all: xlsh xlshd
+
+xlsh: ${XLSH_SOURCE} ${XLSH_HEADERS}
+ ${CC} -g -Wall -o $@ ${XLSH_SOURCE} ${CFLAGS} ${LDFLAGS} ${XLSH_LIBS}
+
+xlshd: ${XLSHD_SOURCE} ${XLSHD_HEADERS}
+ ${CC} -g -Wall -o $@ ${XLSHD_SOURCE} ${CFLAGS} ${LDFLAGS}
+
+clean:
+ rm -f xlsh xlshd
+
+.PHONY: all clean
View
@@ -1,4 +1,9 @@
-xlsh - X Login Shell
+xlsh - eXtended Login Shell
(c) 2011 Michał Siejak
-A very simple, text-based X display manager without XDMCP server component.
+A simple login shell with readline functionality and PAM integration.
+ * When run stand-alone on a virtual console it can replace standard "login" program.
+ * When run in cooperation with X daemon component (xlshd) it can replace XDM/GDM/KDM.
+
+The only build dependencies are: make, a decent C compiler, libreadline and libpam.
+Configuration options can be edited in src/config.h before compiling.
View
@@ -0,0 +1,30 @@
+/* eXtended Login Shell
+ * (c) 2011 Michał Siejak
+ *
+ * See COPYING file for license details.
+ */
+
+#ifndef __XLSH_CONFIG_H
+#define __XLSH_CONFIG_H
+
+// Tweak parameters to suit your needs before compiling.
+
+#define XLSH_EXEC "./.xsession"
+#define XLSH_PROMPT "%s (%s)> "
+#define XLSH_TMPDIR "/tmp"
+#define XLSH_SHELLS "/etc/shells"
+#define XLSH_PATH "/bin:/usr/bin:/usr/local/bin"
+#define XLSH_REBOOT "/sbin/shutdown -r now"
+#define XLSH_HALT "/sbin/shutdown -h now"
+
+#define XLSHD_TMPDIR XLSH_TMPDIR
+#define XLSHD_SHELL "/bin/sh"
+#define XLSHD_PIDFILE "/var/run/xlshd.pid"
+#define XLSHD_XSERVER "/usr/bin/X"
+#define XLSHD_XOPTIONS "-nolisten tcp -noreset"
+#define XLSHD_XDISPLAY ":0"
+#define XLSHD_XLSHRC "/etc/xlsh/xlshrc"
+#define XLSHD_XWAIT 1
+#define XLSHD_XRETRY 2
+
+#endif
View
@@ -0,0 +1,78 @@
+/* eXtended Login Shell
+ * (c) 2011 Michał Siejak
+ *
+ * See COPYING file for license details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "config.h"
+#include "libxlsh.h"
+
+static sigset_t xlsh_default_sigmask;
+
+void libxlsh_sigmask(void)
+{
+ sigprocmask(0, NULL, &xlsh_default_sigmask);
+}
+
+pid_t libxlsh_exec(const char* cmdline, int flags)
+{
+ pid_t pid;
+ int i;
+ char* buffer;
+ char* argv[256];
+
+ pid = fork();
+ if(pid < 0) return -1;
+ if(pid > 0) return pid;
+
+ buffer = strdup(cmdline);
+ i=0;
+ argv[0] = strtok(buffer, " ");
+ do {
+ argv[++i] = strtok(NULL, " ");
+ } while(argv[i] && i<256);
+
+ if(flags & XLSH_DETACH)
+ setsid();
+ sigprocmask(SIG_SETMASK, &xlsh_default_sigmask, NULL);
+ execv(argv[0], argv);
+ exit(EXIT_FAILURE);
+}
+
+pid_t libxlsh_pid_read(const char* filename)
+{
+ pid_t result = 0;
+ FILE* pidfile = fopen(filename, "r");
+ if(!pidfile)
+ return -1;
+ if(fscanf(pidfile, "%d", &result) != 1) {
+ fclose(pidfile);
+ return -1;
+ }
+ fclose(pidfile);
+ return result;
+}
+
+int libxlsh_pid_lock(const char* filename, pid_t pid, int flags)
+{
+ struct stat statbuf;
+ FILE* pidfile;
+
+ if((flags & XLSH_OVERWRITE) && stat(filename, &statbuf) == 0)
+ return XLSH_EFOUND;
+
+ pidfile = fopen(filename, "w");
+ if(!pidfile)
+ return XLSH_ERROR;
+ fprintf(pidfile, "%d", pid);
+ fclose(pidfile);
+ return XLSH_EOK;
+}
View
@@ -0,0 +1,30 @@
+/* eXtended Login Shell
+ * (c) 2011 Michał Siejak
+ *
+ * See COPYING file for license details.
+ */
+
+#ifndef __XLSH_LIBXLSH_H
+#define __XLSH_LIBXLSH_H
+
+#define XLSH_VERSION_API 1
+#define XLSH_VERSION_STRING "0.1.0"
+
+#define XLSH_EOK 0x00
+#define XLSH_EFATAL 0x01
+#define XLSH_EDONE 0x02
+#define XLSH_EARG 0x03
+#define XLSH_ENOTFOUND 0x04
+#define XLSH_EFOUND 0x05
+#define XLSH_ERROR 0xFF
+
+#define XLSH_NORMAL 0x00
+#define XLSH_OVERWRITE 0x01
+#define XLSH_DETACH 0x02
+
+void libxlsh_sigmask(void);
+pid_t libxlsh_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);
+
+#endif
Oops, something went wrong.

0 comments on commit b52abc5

Please sign in to comment.