Browse Source

Fix coding style

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@224 7c53e7cc-98ea-0310-8f1f-a0b24da60408
iwamatsu 8 years ago
parent
commit
b7a2dbdc6d
23 changed files with 3517 additions and 3545 deletions
  1. 77 77
      Ck.cpp
  2. 13 13
      Ck.h
  3. 245 247
      PAM.cpp
  4. 65 65
      PAM.h
  5. 976 994
      app.cpp
  6. 62 64
      app.h
  7. 234 235
      cfg.cpp
  8. 23 23
      cfg.h
  9. 17 19
      const.h
  10. 767 769
      image.cpp
  11. 45 45
      image.h
  12. 83 83
      jpeg.c
  13. 22 22
      log.h
  14. 6 5
      main.cpp
  15. 42 42
      numlock.cpp
  16. 1 1
      numlock.h
  17. 535 535
      panel.cpp
  18. 117 119
      panel.h
  19. 142 142
      png.c
  20. 25 25
      switchuser.cpp
  21. 15 15
      switchuser.h
  22. 1 1
      util.cpp
  23. 4 4
      util.h

+ 77 - 77
Ck.cpp

@@ -19,126 +19,126 @@
 
 namespace Ck {
   Exception::Exception(const std::string &func,
-                       const std::string &errstr):
-    func(func),
-    errstr(errstr)
+					   const std::string &errstr):
+	func(func),
+	errstr(errstr)
   {}
 
   dbus_bool_t Session::ck_connector_open_graphic_session(const std::string &display,
-                                                         uid_t uid)
+														 uid_t uid)
   {
-    dbus_bool_t local        = true;
-    const char *session_type = "x11";
-    const char *x11_display  = display.c_str();
-    const char *x11_device   = get_x11_device(display);
-    const char *remote_host  = "";
-    const char *display_dev  = "";
-
-    return ck_connector_open_session_with_parameters(ckc, &error,
-                                                     "unix-user", &uid,
-                                                     "session-type", &session_type,
-                                                     "x11-display", &x11_display,
-                                                     "x11-display-device", &x11_device,
-                                                     "display-device", &display_dev,
-                                                     "remote-host-name", &remote_host,
-                                                     "is-local", &local,
-                                                     NULL);
+	dbus_bool_t local		= true;
+	const char *session_type = "x11";
+	const char *x11_display  = display.c_str();
+	const char *x11_device   = get_x11_device(display);
+	const char *remote_host  = "";
+	const char *display_dev  = "";
+
+	return ck_connector_open_session_with_parameters(ckc, &error,
+													 "unix-user", &uid,
+													 "session-type", &session_type,
+													 "x11-display", &x11_display,
+													 "x11-display-device", &x11_device,
+													 "display-device", &display_dev,
+													 "remote-host-name", &remote_host,
+													 "is-local", &local,
+													 NULL);
   }
 
   const char * Session::get_x11_device(const std::string &display)
   {
-    static char device[32];
+	static char device[32];
 
-    Display *xdisplay = XOpenDisplay(display.c_str());
+	Display *xdisplay = XOpenDisplay(display.c_str());
 
-    if(!xdisplay)
-      throw Exception(__func__, "cannot open display");
+	if(!xdisplay)
+	  throw Exception(__func__, "cannot open display");
 
-    Window root;
-    Atom xfree86_vt_atom;
-    Atom return_type_atom;
-    int return_format;
-    unsigned long return_count;
-    unsigned long bytes_left;
-    unsigned char *return_value;
-    long vt;
+	Window root;
+	Atom xfree86_vt_atom;
+	Atom return_type_atom;
+	int return_format;
+	unsigned long return_count;
+	unsigned long bytes_left;
+	unsigned char *return_value;
+	long vt;
 
-    xfree86_vt_atom = XInternAtom(xdisplay, "XFree86_VT", true);
+	xfree86_vt_atom = XInternAtom(xdisplay, "XFree86_VT", true);
 
-    if(xfree86_vt_atom == None)
-      throw Exception(__func__, "cannot get XFree86_VT");
+	if(xfree86_vt_atom == None)
+	  throw Exception(__func__, "cannot get XFree86_VT");
 
-    root = DefaultRootWindow(xdisplay);
+	root = DefaultRootWindow(xdisplay);
 
-    if(XGetWindowProperty(xdisplay, root, xfree86_vt_atom,
-                          0L, 1L, false, XA_INTEGER,
-                          &return_type_atom, &return_format,
-                          &return_count, &bytes_left,
-                          &return_value) != Success)
-      throw Exception(__func__, "cannot get root window property");
+	if(XGetWindowProperty(xdisplay, root, xfree86_vt_atom,
+						  0L, 1L, false, XA_INTEGER,
+						  &return_type_atom, &return_format,
+						  &return_count, &bytes_left,
+						  &return_value) != Success)
+	  throw Exception(__func__, "cannot get root window property");
 
-    if(return_type_atom != XA_INTEGER)
-      throw Exception(__func__, "bad atom type");
+	if(return_type_atom != XA_INTEGER)
+	  throw Exception(__func__, "bad atom type");
 
-    if(return_format != 32)
-      throw Exception(__func__, "invalid return format");
+	if(return_format != 32)
+	  throw Exception(__func__, "invalid return format");
 
-    if(return_count != 1)
-      throw Exception(__func__, "invalid count");
+	if(return_count != 1)
+	  throw Exception(__func__, "invalid count");
 
-    if(bytes_left != 0)
-      throw Exception(__func__, "invalid bytes left");
+	if(bytes_left != 0)
+	  throw Exception(__func__, "invalid bytes left");
 
-    vt = *((long *)return_value);
+	vt = *((long *)return_value);
 
-    std::snprintf(device, 32, "/dev/tty%ld", vt);
+	std::snprintf(device, 32, "/dev/tty%ld", vt);
 
-    if(return_value)
-      XFree(return_value);
+	if(return_value)
+	  XFree(return_value);
 
-    return device;
+	return device;
   }
 
   void Session::open_session(const std::string &display, uid_t uid)
   {
-    ckc = ck_connector_new();
-
-    if(!ckc)
-      throw Exception(__func__, "error setting up connection to ConsoleKit");
-
-    if(!ck_connector_open_graphic_session(display, uid)) {
-      if(dbus_error_is_set(&error))
-        throw Exception(__func__, error.message);
-      else
-        throw Exception(__func__, "cannot open ConsoleKit session: OOM, DBus system bus "
-                        " not available or insufficient privileges");
-    }
+	ckc = ck_connector_new();
+
+	if(!ckc)
+	  throw Exception(__func__, "error setting up connection to ConsoleKit");
+
+	if(!ck_connector_open_graphic_session(display, uid)) {
+	  if(dbus_error_is_set(&error))
+		throw Exception(__func__, error.message);
+	  else
+		throw Exception(__func__, "cannot open ConsoleKit session: OOM, DBus system bus "
+						" not available or insufficient privileges");
+	}
   }
 
   const char * Session::get_xdg_session_cookie()
   {
-    return ck_connector_get_cookie(ckc);
+	return ck_connector_get_cookie(ckc);
   }
 
   void Session::close_session()
   {
-    if(!ck_connector_close_session(ckc, &error)) {
-      if(dbus_error_is_set(&error))
-        throw Exception(__func__, error.message);
-      else
-        throw Exception(__func__, "cannot close ConsoleKit session: OOM, DBus system bus "
-                        " not available or insufficient privileges");
-    }
+	if(!ck_connector_close_session(ckc, &error)) {
+	  if(dbus_error_is_set(&error))
+		throw Exception(__func__, error.message);
+	  else
+		throw Exception(__func__, "cannot close ConsoleKit session: OOM, DBus system bus "
+						" not available or insufficient privileges");
+	}
   }
 
   Session::Session()
   {
-    dbus_error_init(&error);
+	dbus_error_init(&error);
   }
 
   Session::~Session()
   {
-    dbus_error_free(&error);
+	dbus_error_free(&error);
   }
 };
 

+ 13 - 13
Ck.h

@@ -18,26 +18,26 @@
 namespace Ck {
   class Exception {
   public:
-    std::string func;
-    std::string errstr;
-    Exception(const std::string &func, const std::string &errstr);
+	std::string func;
+	std::string errstr;
+	Exception(const std::string &func, const std::string &errstr);
   };
 
   class Session {
   private:
-    CkConnector *ckc;
-    DBusError error;
+	CkConnector *ckc;
+	DBusError error;
 
-    const char * get_x11_device(const std::string &display);
-    dbus_bool_t ck_connector_open_graphic_session(const std::string &display,
-                                                  uid_t uid);
+	const char * get_x11_device(const std::string &display);
+	dbus_bool_t ck_connector_open_graphic_session(const std::string &display,
+												  uid_t uid);
   public:
-    const char * get_xdg_session_cookie();
-    void open_session(const std::string &display, uid_t uid);
-    void close_session();
+	const char * get_xdg_session_cookie();
+	void open_session(const std::string &display, uid_t uid);
+	void close_session();
 
-    Session();
-    ~Session();
+	Session();
+	~Session();
   };
 };
 

+ 245 - 247
PAM.cpp

@@ -11,265 +11,263 @@
 #include "PAM.h"
 
 namespace PAM {
-    Exception::Exception(pam_handle_t* _pam_handle,
-               const std::string& _func_name,
-               int _errnum):
-        errnum(_errnum),
-        errstr(pam_strerror(_pam_handle, _errnum)),
-        func_name(_func_name)
-        {}
-
-    Exception::~Exception(void){}
-
-    Auth_Exception::Auth_Exception(pam_handle_t* _pam_handle,
-                                   const std::string& _func_name,
-                                   int _errnum):
-        Exception(_pam_handle, _func_name, _errnum){}
-
-    Cred_Exception::Cred_Exception(pam_handle_t* _pam_handle,
-                                   const std::string& _func_name,
-                                   int _errnum):
-        Exception(_pam_handle, _func_name, _errnum){}
-
-    int Authenticator::_end(void){
-        int result=pam_end(pam_handle, last_result);
-        pam_handle=0;
-        return result;
-    }
-
-    Authenticator::Authenticator(conversation* conv, void* data):
-        pam_handle(0),
-        last_result(PAM_SUCCESS)
-    {
-        pam_conversation.conv=conv;
-        pam_conversation.appdata_ptr=data;
-    }
-
-    Authenticator::~Authenticator(void){
-        if (pam_handle) _end();
-    }
-
-    void Authenticator::start(const std::string& service){
-        switch((last_result=pam_start(service.c_str(), NULL, &pam_conversation, &pam_handle))){
-            default:
-                throw Exception(pam_handle, "pam_start()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    void Authenticator::end(void){
-        switch((last_result=_end())){
-            default:
-                throw Exception(pam_handle, "pam_end()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-
-        }
-        return;
-    }
-
-    void Authenticator::set_item(const Authenticator::ItemType item, const void* value){
-        switch((last_result=pam_set_item(pam_handle, item, value))){
-            default:
-            _end();
-                throw Exception(pam_handle, "pam_set_item()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    const void* Authenticator::get_item(const Authenticator::ItemType item){
-        const void* data;
-        switch ((last_result=pam_get_item(pam_handle, item, &data))){
-            default:
-            case PAM_SYSTEM_ERR:
+	Exception::Exception(pam_handle_t* _pam_handle,
+			   const std::string& _func_name,
+			   int _errnum):
+		errnum(_errnum),
+		errstr(pam_strerror(_pam_handle, _errnum)),
+		func_name(_func_name)
+		{}
+
+	Exception::~Exception(void){}
+
+	Auth_Exception::Auth_Exception(pam_handle_t* _pam_handle,
+								   const std::string& _func_name,
+								   int _errnum):
+		Exception(_pam_handle, _func_name, _errnum){}
+
+	Cred_Exception::Cred_Exception(pam_handle_t* _pam_handle,
+								   const std::string& _func_name,
+								   int _errnum):
+		Exception(_pam_handle, _func_name, _errnum){}
+
+	int Authenticator::_end(void){
+		int result=pam_end(pam_handle, last_result);
+		pam_handle=0;
+		return result;
+	}
+
+	Authenticator::Authenticator(conversation* conv, void* data):
+		pam_handle(0),
+		last_result(PAM_SUCCESS)
+	{
+		pam_conversation.conv=conv;
+		pam_conversation.appdata_ptr=data;
+	}
+
+	Authenticator::~Authenticator(void){
+		if (pam_handle) _end();
+	}
+
+	void Authenticator::start(const std::string& service){
+		switch((last_result=pam_start(service.c_str(), NULL, &pam_conversation, &pam_handle))){
+			default:
+				throw Exception(pam_handle, "pam_start()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::end(void){
+		switch((last_result=_end())){
+			default:
+				throw Exception(pam_handle, "pam_end()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::set_item(const Authenticator::ItemType item, const void* value){
+		switch((last_result=pam_set_item(pam_handle, item, value))){
+			default:
+			_end();
+				throw Exception(pam_handle, "pam_set_item()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	const void* Authenticator::get_item(const Authenticator::ItemType item){
+		const void* data;
+		switch ((last_result=pam_get_item(pam_handle, item, &data))){
+			default:
+			case PAM_SYSTEM_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_get_item()", last_result);
+				_end();
+				throw Exception(pam_handle, "pam_get_item()", last_result);
 
-            case PAM_PERM_DENIED: // The value of item was NULL
-            case PAM_SUCCESS:
-                break;
-        }
-        return data;
-    }
+			case PAM_PERM_DENIED: /* The value of item was NULL */
+			case PAM_SUCCESS:
+				break;
+		}
+		return data;
+	}
 
 #ifdef __LIBPAM_VERSION
-    void Authenticator::fail_delay(const unsigned int micro_sec){
-        switch((last_result=pam_fail_delay(pam_handle, micro_sec))){
-            default:
-                _end();
-                throw Exception(pam_handle, "fail_delay()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
+	void Authenticator::fail_delay(const unsigned int micro_sec){
+		switch((last_result=pam_fail_delay(pam_handle, micro_sec))){
+			default:
+				_end();
+				throw Exception(pam_handle, "fail_delay()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
 #endif
 
-    void Authenticator::authenticate(void){
-        switch((last_result=pam_authenticate(pam_handle, 0))){
-            default:
-            case PAM_ABORT:
-            case PAM_AUTHINFO_UNAVAIL:
-                _end();
-                throw Exception(pam_handle, "pam_authenticate()", last_result);
-
-            case PAM_USER_UNKNOWN:
-            case PAM_MAXTRIES:
-            case PAM_CRED_INSUFFICIENT:
-            case PAM_AUTH_ERR:
-                throw Auth_Exception(pam_handle, "pam_authentication()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-
-        switch((last_result=pam_acct_mgmt(pam_handle, PAM_SILENT))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_NEW_AUTHTOKEN_REQD is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_NEW_AUTHTOKEN_REQD:
-            case PAM_ACCT_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                _end();
-                throw Exception(pam_handle, "pam_acct_mgmt()", last_result);
-                
-            case PAM_AUTH_ERR:
-            case PAM_PERM_DENIED:
-                throw Auth_Exception(pam_handle, "pam_acct_mgmt()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::open_session(void){
-        switch((last_result=pam_setcred(pam_handle, PAM_ESTABLISH_CRED))){
-            default:
-            case PAM_CRED_ERR:
-            case PAM_CRED_UNAVAIL:
-                _end();
-                throw Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_CRED_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                throw Cred_Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-
-        switch((last_result=pam_open_session(pam_handle, 0))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_SESSION_ERROR is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_SESSION_ERROR:
-                pam_setcred(pam_handle, PAM_DELETE_CRED);
-                _end();
-                throw Exception(pam_handle, "pam_open_session()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::close_session(void){
-        switch((last_result=pam_close_session(pam_handle, 0))){
-            // The documentation and implementation of Linux PAM differs:
-            // PAM_SESSION_ERROR is described in the documentation but
-            // don't exists in the actual implementation. This issue needs
-            // to be fixes at some point.
-
-            default:
-            //case PAM_SESSION_ERROR:
-                pam_setcred(pam_handle, PAM_DELETE_CRED);
-                _end();
-                throw Exception(pam_handle, "pam_close_session", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        switch((last_result=pam_setcred(pam_handle, PAM_DELETE_CRED))){
-            default:
-            case PAM_CRED_ERR:
-            case PAM_CRED_UNAVAIL:
-            case PAM_CRED_EXPIRED:
-            case PAM_USER_UNKNOWN:
-                _end();
-                throw Exception(pam_handle, "pam_setcred()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        }
-        return;
-    }
-
-    void Authenticator::setenv(const std::string& key, const std::string& value){
-        std::string name_value = key+"="+value;
-        switch((last_result=pam_putenv(pam_handle, name_value.c_str()))){
-            default:
-            case PAM_PERM_DENIED:
-            case PAM_ABORT:
-            case PAM_BUF_ERR:
+	void Authenticator::authenticate(void){
+		switch((last_result=pam_authenticate(pam_handle, 0))){
+			default:
+			case PAM_ABORT:
+			case PAM_AUTHINFO_UNAVAIL:
+				_end();
+				throw Exception(pam_handle, "pam_authenticate()", last_result);
+
+			case PAM_USER_UNKNOWN:
+			case PAM_MAXTRIES:
+			case PAM_CRED_INSUFFICIENT:
+			case PAM_AUTH_ERR:
+				throw Auth_Exception(pam_handle, "pam_authentication()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+
+		switch((last_result=pam_acct_mgmt(pam_handle, PAM_SILENT))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_NEW_AUTHTOKEN_REQD is described in the documentation but
+			   don't exists in the actual implementation. This issue needs
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_NEW_AUTHTOKEN_REQD: */
+			case PAM_ACCT_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				_end();
+				throw Exception(pam_handle, "pam_acct_mgmt()", last_result);
+				
+			case PAM_AUTH_ERR:
+			case PAM_PERM_DENIED:
+				throw Auth_Exception(pam_handle, "pam_acct_mgmt()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::open_session(void){
+		switch((last_result=pam_setcred(pam_handle, PAM_ESTABLISH_CRED))){
+			default:
+			case PAM_CRED_ERR:
+			case PAM_CRED_UNAVAIL:
+				_end();
+				throw Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_CRED_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				throw Cred_Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+
+		switch((last_result=pam_open_session(pam_handle, 0))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_SESSION_ERROR is described in the documentation but 
+			   don't exists in the actual implementation. This issue needs 
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_SESSION_ERROR: */
+				pam_setcred(pam_handle, PAM_DELETE_CRED);
+				_end();
+				throw Exception(pam_handle, "pam_open_session()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::close_session(void){
+		switch((last_result=pam_close_session(pam_handle, 0))){
+			/* The documentation and implementation of Linux PAM differs:
+			   PAM_SESSION_ERROR is described in the documentation but
+			   don't exists in the actual implementation. This issue needs
+			   to be fixes at some point. */
+
+			default:
+			/* case PAM_SESSION_ERROR: */
+				pam_setcred(pam_handle, PAM_DELETE_CRED);
+				_end();
+				throw Exception(pam_handle, "pam_close_session", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		switch((last_result=pam_setcred(pam_handle, PAM_DELETE_CRED))){
+			default:
+			case PAM_CRED_ERR:
+			case PAM_CRED_UNAVAIL:
+			case PAM_CRED_EXPIRED:
+			case PAM_USER_UNKNOWN:
+				_end();
+				throw Exception(pam_handle, "pam_setcred()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		}
+		return;
+	}
+
+	void Authenticator::setenv(const std::string& key, const std::string& value){
+		std::string name_value = key+"="+value;
+		switch((last_result=pam_putenv(pam_handle, name_value.c_str()))){
+			default:
+			case PAM_PERM_DENIED:
+			case PAM_ABORT:
+			case PAM_BUF_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_putenv()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    void Authenticator::delenv(const std::string& key){
-        switch((last_result=pam_putenv(pam_handle, key.c_str()))){
-            default:
-            case PAM_PERM_DENIED:
-            case PAM_ABORT:
-            case PAM_BUF_ERR:
+				_end();
+				throw Exception(pam_handle, "pam_putenv()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	void Authenticator::delenv(const std::string& key){
+		switch((last_result=pam_putenv(pam_handle, key.c_str()))){
+			default:
+			case PAM_PERM_DENIED:
+			case PAM_ABORT:
+			case PAM_BUF_ERR:
 #ifdef __LIBPAM_VERSION
-            case PAM_BAD_ITEM:
+			case PAM_BAD_ITEM:
 #endif
-                _end();
-                throw Exception(pam_handle, "pam_putenv()", last_result);
-
-            case PAM_SUCCESS:
-                break;
-        };
-        return;
-    }
-
-    const char* Authenticator::getenv(const std::string& key){
-        return pam_getenv(pam_handle, key.c_str());
-    }
-
-    char** Authenticator::getenvlist(void){
-        return pam_getenvlist(pam_handle);
-    }
-
+				_end();
+				throw Exception(pam_handle, "pam_putenv()", last_result);
+
+			case PAM_SUCCESS:
+				break;
+		};
+		return;
+	}
+
+	const char* Authenticator::getenv(const std::string& key){
+		return pam_getenv(pam_handle, key.c_str());
+	}
+
+	char** Authenticator::getenvlist(void){
+		return pam_getenvlist(pam_handle);
+	}
 };
 
 std::ostream& operator<<( std::ostream& os, const PAM::Exception& e){
-    os << e.func_name << ": " << e.errstr;
-    return os;
+	os << e.func_name << ": " << e.errstr;
+	return os;
 }

+ 65 - 65
PAM.h

@@ -17,83 +17,83 @@
 #endif
 
 namespace PAM {
-    class Exception{
-    public:
-        int errnum;
-        std::string errstr;
-        std::string func_name;
-        Exception(pam_handle_t* _pam_handle,
-                  const std::string& _func_name,
-                  int _errnum);
-        virtual ~Exception(void);
-    };
+	class Exception{
+	public:
+		int errnum;
+		std::string errstr;
+		std::string func_name;
+		Exception(pam_handle_t* _pam_handle,
+				  const std::string& _func_name,
+				  int _errnum);
+		virtual ~Exception(void);
+	};
 
-    class Auth_Exception: public Exception{
-    public:
-        Auth_Exception(pam_handle_t* _pam_handle,
-                       const std::string& _func_name,
-                       int _errnum);
-    };
+	class Auth_Exception: public Exception{
+	public:
+		Auth_Exception(pam_handle_t* _pam_handle,
+					   const std::string& _func_name,
+					   int _errnum);
+	};
 
-    class Cred_Exception: public Exception{
-    public:
-        Cred_Exception(pam_handle_t* _pam_handle,
-                       const std::string& _func_name,
-                       int _errnum);
-    };
+	class Cred_Exception: public Exception{
+	public:
+		Cred_Exception(pam_handle_t* _pam_handle,
+					   const std::string& _func_name,
+					   int _errnum);
+	};
 
 
-    class Authenticator{
-    private:
-        struct pam_conv pam_conversation;
-        pam_handle_t* pam_handle;
-        int last_result;
+	class Authenticator{
+	private:
+		struct pam_conv pam_conversation;
+		pam_handle_t* pam_handle;
+		int last_result;
 
-        int _end(void);
-    public:
-        typedef int (conversation)(int num_msg,
-                           const struct pam_message **msg,
-                           struct pam_response **resp,
-                           void *appdata_ptr);
+		int _end(void);
+	public:
+		typedef int (conversation)(int num_msg,
+						   const struct pam_message **msg,
+						   struct pam_response **resp,
+						   void *appdata_ptr);
 
-        enum ItemType {
-            Service     = PAM_SERVICE,
-            User        = PAM_USER,
-            User_Prompt = PAM_USER_PROMPT,
-            TTY         = PAM_TTY,
-            Requestor   = PAM_RUSER,
-            Host        = PAM_RHOST,
-            Conv        = PAM_CONV,
+		enum ItemType {
+			Service	 = PAM_SERVICE,
+			User		= PAM_USER,
+			User_Prompt = PAM_USER_PROMPT,
+			TTY		 = PAM_TTY,
+			Requestor   = PAM_RUSER,
+			Host		= PAM_RHOST,
+			Conv		= PAM_CONV,
 #ifdef __LIBPAM_VERSION
-            //Fail_Delay  = PAM_FAIL_DELAY
+			/* Fail_Delay  = PAM_FAIL_DELAY */
 #endif
-        };
+		};
 
-    public:
-        Authenticator(conversation* conv, void* data=0);
-        ~Authenticator(void);
-        
-        void start(const std::string& service);
-        void end(void);
-        void set_item(const ItemType item, const void* value);
-        const void* get_item(const ItemType item);
+	public:
+		Authenticator(conversation* conv, void* data=0);
+		~Authenticator(void);
+		
+		void start(const std::string& service);
+		void end(void);
+		void set_item(const ItemType item, const void* value);
+		const void* get_item(const ItemType item);
 #ifdef __LIBPAM_VERSION
-        void fail_delay(const unsigned int micro_sec);
+		void fail_delay(const unsigned int micro_sec);
 #endif
-        void authenticate(void);
-        void open_session(void);
-        void close_session(void);
-        void setenv(const std::string& key, const std::string& value);
-        void delenv(const std::string& key);
-        const char* getenv(const std::string& key);
-        char** getenvlist(void);
+		void authenticate(void);
+		void open_session(void);
+		void close_session(void);
+		void setenv(const std::string& key, const std::string& value);
+		void delenv(const std::string& key);
+		const char* getenv(const std::string& key);
+		char** getenvlist(void);
 
-    private:
-        // Explicitly disable copy constructor and copy assignment
-        Authenticator(const PAM::Authenticator&);
-        Authenticator& operator=(const PAM::Authenticator&);
-    };
+	private:
+		/* Explicitly disable copy constructor and copy assignment */
+		Authenticator(const PAM::Authenticator&);
+		Authenticator& operator=(const PAM::Authenticator&);
+	};
 };
 
 std::ostream& operator<<( std::ostream& os, const PAM::Exception& e);
-#endif
+#endif /* _PAM_H_ */

+ 976 - 994
app.cpp

@@ -9,7 +9,6 @@
    (at your option) any later version.
 */
 
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -27,7 +26,6 @@
 #include "numlock.h"
 #include "util.h"
 
-
 #ifdef HAVE_SHADOW
 #include <shadow.h>
 #endif
@@ -38,67 +36,67 @@ using namespace std;
 #include <string>
 
 int conv(int num_msg, const struct pam_message **msg,
-         struct pam_response **resp, void *appdata_ptr){
-    *resp = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
-    Panel* panel = *static_cast<Panel**>(appdata_ptr);
-    int result = PAM_SUCCESS;
-    for (int i=0; i<num_msg; i++){
-        (*resp)[i].resp=0;
-        (*resp)[i].resp_retcode=0;
-        switch(msg[i]->msg_style){
-            case PAM_PROMPT_ECHO_ON:
-                // We assume PAM is asking for the username
-                panel->EventHandler(Panel::Get_Name);
-                switch(panel->getAction()){
-                    case Panel::Suspend:
-                    case Panel::Halt:
-                    case Panel::Reboot:
-                        (*resp)[i].resp=strdup("root");
-                        break;
-
-                    case Panel::Console:
-                    case Panel::Exit:
-                    case Panel::Login:
-                        (*resp)[i].resp=strdup(panel->GetName().c_str());
-                        break;
-                }
-                break;
-
-            case PAM_PROMPT_ECHO_OFF:
-                // We assume PAM is asking for the password
-                switch(panel->getAction()){
-                    case Panel::Console:
-                    case Panel::Exit:
-                        // We should leave now!
-                        result=PAM_CONV_ERR;
-                        break;
-
-                    default:
-                        panel->EventHandler(Panel::Get_Passwd);
-                        (*resp)[i].resp=strdup(panel->GetPasswd().c_str());
-                        break;
-                }
-                break;
-
-            case PAM_ERROR_MSG:
-            case PAM_TEXT_INFO:
-                // We simply write these to the log
-                // TODO: Maybe we should simply ignore them
-                logStream << APPNAME << ": " << msg[i]->msg << endl;
-                break;
-        }
-        if (result!=PAM_SUCCESS) break;
-    }
-    if (result!=PAM_SUCCESS){
-        for (int i=0; i<num_msg; i++){
-            if ((*resp)[i].resp==0) continue;
-            free((*resp)[i].resp);
-            (*resp)[i].resp=0;
-        };
-        free(*resp);
-        *resp=0;
-    };
-    return result;
+		 struct pam_response **resp, void *appdata_ptr){
+	*resp = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
+	Panel* panel = *static_cast<Panel**>(appdata_ptr);
+	int result = PAM_SUCCESS;
+	for (int i=0; i<num_msg; i++){
+		(*resp)[i].resp=0;
+		(*resp)[i].resp_retcode=0;
+		switch(msg[i]->msg_style){
+			case PAM_PROMPT_ECHO_ON:
+				/* We assume PAM is asking for the username */
+				panel->EventHandler(Panel::Get_Name);
+				switch(panel->getAction()){
+					case Panel::Suspend:
+					case Panel::Halt:
+					case Panel::Reboot:
+						(*resp)[i].resp=strdup("root");
+						break;
+
+					case Panel::Console:
+					case Panel::Exit:
+					case Panel::Login:
+						(*resp)[i].resp=strdup(panel->GetName().c_str());
+						break;
+				}
+				break;
+
+			case PAM_PROMPT_ECHO_OFF:
+				/* We assume PAM is asking for the password */
+				switch(panel->getAction()){
+					case Panel::Console:
+					case Panel::Exit:
+						/* We should leave now! */
+						result=PAM_CONV_ERR;
+						break;
+
+					default:
+						panel->EventHandler(Panel::Get_Passwd);
+						(*resp)[i].resp=strdup(panel->GetPasswd().c_str());
+						break;
+				}
+				break;
+
+			case PAM_ERROR_MSG:
+			case PAM_TEXT_INFO:
+				/* We simply write these to the log
+				   TODO: Maybe we should simply ignore them */
+				logStream << APPNAME << ": " << msg[i]->msg << endl;
+				break;
+		}
+		if (result!=PAM_SUCCESS) break;
+	}
+	if (result!=PAM_SUCCESS){
+		for (int i=0; i<num_msg; i++){
+			if ((*resp)[i].resp==0) continue;
+			free((*resp)[i].resp);
+			(*resp)[i].resp=0;
+		};
+		free(*resp);
+		*resp=0;
+	};
+	return result;
 }
 #endif
 
@@ -106,24 +104,23 @@ extern App* LoginApp;
 
 int xioerror(Display *disp) {
 	LoginApp->RestartServer();
-    return 0;
+	return 0;
 }
 
 void CatchSignal(int sig) {
-    logStream << APPNAME << ": unexpected signal " << sig << endl;
+	logStream << APPNAME << ": unexpected signal " << sig << endl;
 
-    if (LoginApp->isServerStarted())
-        LoginApp->StopServer();
+	if (LoginApp->isServerStarted())
+		LoginApp->StopServer();
 
-    LoginApp->RemoveLock();
-    exit(ERR_EXIT);
+	LoginApp->RemoveLock();
+	exit(ERR_EXIT);
 }
 
 void User1Signal(int sig) {
-    signal(sig, User1Signal);
+	signal(sig, User1Signal);
 }
 
-
 #ifdef USE_PAM
 App::App(int argc, char** argv)
   : pam(conv, static_cast<void*>(&LoginPanel)),
@@ -131,1126 +128,1111 @@ App::App(int argc, char** argv)
 App::App(int argc, char** argv)
   :
 #endif
-    mcookiesize(32)		// Must be divisible by 4
+	mcookiesize(32)		/* Must be divisible by 4 */
 {
-    int tmp;
-    ServerPID = -1;
-    testing = false;
-    serverStarted = false;
-    mcookie = string(App::mcookiesize, 'a');
-    daemonmode = false;
-    force_nodaemon = false;
-    firstlogin = true;
-    Dpy = NULL;
-
-    // Parse command line
-    // Note: we force a option for nodaemon switch to handle "-nodaemon"
-    while((tmp = getopt(argc, argv, "vhp:n:d?")) != EOF) {
-        switch (tmp) {
-        case 'p':    // Test theme
-            testtheme = optarg;
-            testing = true;
-            if (testtheme == NULL) {
-                logStream << "The -p option requires an argument" << endl;
-                exit(ERR_EXIT);
-            }
-            break;
-        case 'd':    // Daemon mode
-            daemonmode = true;
-            break;
-        case 'n':    // Daemon mode
-            daemonmode = false;
-            force_nodaemon = true;
-            break;
-        case 'v':    // Version
-            std::cout << APPNAME << " version " << VERSION << endl;
-            exit(OK_EXIT);
-            break;
-        case '?':    // Illegal
-            logStream << endl;
-        case 'h':   // Help
-            logStream << "usage:  " << APPNAME << " [option ...]" << endl
-            << "options:" << endl
-            << "    -d: daemon mode" << endl
-            << "    -nodaemon: no-daemon mode" << endl
-            << "    -v: show version" << endl
-            << "    -p /path/to/theme/dir: preview theme" << endl;
-            exit(OK_EXIT);
-            break;
-        }
-    }
+	int tmp;
+	ServerPID = -1;
+	testing = false;
+	serverStarted = false;
+	mcookie = string(App::mcookiesize, 'a');
+	daemonmode = false;
+	force_nodaemon = false;
+	firstlogin = true;
+	Dpy = NULL;
+
+	/* Parse command line
+	   Note: we force a option for nodaemon switch to handle "-nodaemon" */
+	while((tmp = getopt(argc, argv, "vhp:n:d?")) != EOF) {
+		switch (tmp) {
+		case 'p':	/* Test theme */
+			testtheme = optarg;
+			testing = true;
+			if (testtheme == NULL) {
+				logStream << "The -p option requires an argument" << endl;
+				exit(ERR_EXIT);
+			}
+			break;
+		case 'd':	/* Daemon mode */
+			daemonmode = true;
+			break;
+		case 'n':	/* Daemon mode */
+			daemonmode = false;
+			force_nodaemon = true;
+			break;
+		case 'v':	/* Version */
+			std::cout << APPNAME << " version " << VERSION << endl;
+			exit(OK_EXIT);
+			break;
+		case '?':	/* Illegal */
+			logStream << endl;
+		case 'h':   /* Help */
+			logStream << "usage:  " << APPNAME << " [option ...]" << endl
+			<< "options:" << endl
+			<< "	-d: daemon mode" << endl
+			<< "	-nodaemon: no-daemon mode" << endl
+			<< "	-v: show version" << endl
+			<< "	-p /path/to/theme/dir: preview theme" << endl;
+			exit(OK_EXIT);
+			break;
+		}
+	}
 #ifndef XNEST_DEBUG 
-    if (getuid() != 0 && !testing) {
-        logStream << APPNAME << ": only root can run this program" << endl;
-        exit(ERR_EXIT);
-    }
+	if (getuid() != 0 && !testing) {
+		logStream << APPNAME << ": only root can run this program" << endl;
+		exit(ERR_EXIT);
+	}
 #endif /* XNEST_DEBUG */
 
 }
 
-
 void App::Run() {
-    DisplayName = DISPLAY;
+	DisplayName = DISPLAY;
 
 #ifdef XNEST_DEBUG
-    char* p = getenv("DISPLAY");
-    if (p && p[0]) {
-        DisplayName = p;
-        cout << "Using display name " << DisplayName << endl;
-    }
+	char* p = getenv("DISPLAY");
+	if (p && p[0]) {
+		DisplayName = p;
+		cout << "Using display name " << DisplayName << endl;
+	}
 #endif
 
-
-    // Read configuration and theme
-    cfg = new Cfg;
-    cfg->readConf(CFGFILE);
-    string themebase = "";
-    string themefile = "";
-    string themedir = "";
-    themeName = "";
-    if (testing) {
-        themeName = testtheme;
-    } else {
-        themebase = string(THEMESDIR) + "/";
-        themeName = cfg->getOption("current_theme");
-        string::size_type pos;
-        if ((pos = themeName.find(",")) != string::npos) {
-            // input is a set
-            themeName = findValidRandomTheme(themeName);
-            if (themeName == "") {
-                themeName = "default";
-            }
-        }
-    }
+	/* Read configuration and theme */
+	cfg = new Cfg;
+	cfg->readConf(CFGFILE);
+	string themebase = "";
+	string themefile = "";
+	string themedir = "";
+	themeName = "";
+	if (testing) {
+		themeName = testtheme;
+	} else {
+		themebase = string(THEMESDIR) + "/";
+		themeName = cfg->getOption("current_theme");
+		string::size_type pos;
+		if ((pos = themeName.find(",")) != string::npos) {
+			/* input is a set */
+			themeName = findValidRandomTheme(themeName);
+			if (themeName == "") {
+				themeName = "default";
+			}
+		}
+	}
 
 #ifdef USE_PAM
-    try{
-        pam.start("slim");
-        pam.set_item(PAM::Authenticator::TTY, DisplayName);
-        pam.set_item(PAM::Authenticator::Requestor, "root");
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
+	try{
+		pam.start("slim");
+		pam.set_item(PAM::Authenticator::TTY, DisplayName);
+		pam.set_item(PAM::Authenticator::Requestor, "root");
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
 #endif
 
-    bool loaded = false;
-    while (!loaded) {
-        themedir =  themebase + themeName;
-        themefile = themedir + THEMESFILE;
-        if (!cfg->readConf(themefile)) {
-            if (themeName == "default") {
-                logStream << APPNAME << ": Failed to open default theme file "
-                     << themefile << endl;
-                exit(ERR_EXIT);
-            } else {
-                logStream << APPNAME << ": Invalid theme in config: "
-                     << themeName << endl;
-                themeName = "default";
-            }
-        } else {
-            loaded = true;
-        }
-    }
-
-    if (!testing) {
-        // Create lock file
-        LoginApp->GetLock();
-
-        // Start x-server
-        setenv("DISPLAY", DisplayName, 1);
-        signal(SIGQUIT, CatchSignal);
-        signal(SIGTERM, CatchSignal);
-        signal(SIGKILL, CatchSignal);
-        signal(SIGINT, CatchSignal);
-        signal(SIGHUP, CatchSignal);
-        signal(SIGPIPE, CatchSignal);
-        signal(SIGUSR1, User1Signal);
+	bool loaded = false;
+	while (!loaded) {
+		themedir =  themebase + themeName;
+		themefile = themedir + THEMESFILE;
+		if (!cfg->readConf(themefile)) {
+			if (themeName == "default") {
+				logStream << APPNAME << ": Failed to open default theme file "
+					 << themefile << endl;
+				exit(ERR_EXIT);
+			} else {
+				logStream << APPNAME << ": Invalid theme in config: "
+					 << themeName << endl;
+				themeName = "default";
+			}
+		} else {
+			loaded = true;
+		}
+	}
+
+	if (!testing) {
+		/* Create lock file */
+		LoginApp->GetLock();
+
+		/* Start x-server */
+		setenv("DISPLAY", DisplayName, 1);
+		signal(SIGQUIT, CatchSignal);
+		signal(SIGTERM, CatchSignal);
+		signal(SIGKILL, CatchSignal);
+		signal(SIGINT, CatchSignal);
+		signal(SIGHUP, CatchSignal);
+		signal(SIGPIPE, CatchSignal);
+		signal(SIGUSR1, User1Signal);
 
 #ifndef XNEST_DEBUG
-        if (!force_nodaemon && cfg->getOption("daemon") == "yes") {
-            daemonmode = true;
-        }
+		if (!force_nodaemon && cfg->getOption("daemon") == "yes") {
+			daemonmode = true;
+		}
 
-        // Daemonize
-        if (daemonmode) {
-            if (daemon(0, 0) == -1) {
-                logStream << APPNAME << ": " << strerror(errno) << endl;
-                exit(ERR_EXIT);
-            }
-        }
+		/* Daemonize */
+		if (daemonmode) {
+			if (daemon(0, 0) == -1) {
+				logStream << APPNAME << ": " << strerror(errno) << endl;
+				exit(ERR_EXIT);
+			}
+		}
 
-        OpenLog();
+		OpenLog();
 
-        if (daemonmode)
-            UpdatePid();
+		if (daemonmode)
+			UpdatePid();
 
-        CreateServerAuth();
-        StartServer();
+		CreateServerAuth();
+		StartServer();
 #endif
 
-    }
-
-    // Open display
-    if((Dpy = XOpenDisplay(DisplayName)) == 0) {
-        logStream << APPNAME << ": could not open display '"
-             << DisplayName << "'" << endl;
-        if (!testing) StopServer();
-        exit(ERR_EXIT);
-    }
-
-    // Get screen and root window
-    Scr = DefaultScreen(Dpy);
-    Root = RootWindow(Dpy, Scr);
-
-    // for tests we use a standard window
-    if (testing) {
-        Window RealRoot = RootWindow(Dpy, Scr);
-        Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 1280, 1024, 0, 0, 0);
-        XMapWindow(Dpy, Root);
-        XFlush(Dpy);
-    } else {
-        blankScreen();
-    }
-
-    HideCursor();
-
-    // Create panel
-    LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir);
-    bool firstloop = true; // 1st time panel is shown (for automatic username)
-    bool focuspass = cfg->getOption("focus_password")=="yes";
-    bool autologin = cfg->getOption("auto_login")=="yes";
-    
-    if (firstlogin && cfg->getOption("default_user") != "") {
-        LoginPanel->SetName(cfg->getOption("default_user") );
-        #ifdef USE_PAM
-	pam.set_item(PAM::Authenticator::User, cfg->getOption("default_user").c_str());
-	#endif
-        firstlogin = false;
-        if (autologin) {
-            Login();
-        }
-    }
-
-    // Set NumLock
-    string numlock = cfg->getOption("numlock");
-    if (numlock == "on") {
-        NumLock::setOn(Dpy);
-    } else if (numlock == "off") {
-        NumLock::setOff(Dpy);
-    }
-    
-    // Start looping
-    int panelclosed = 1;
-    Panel::ActionType Action;
-
-    while(1) {
-        if(panelclosed) {
-            // Init root
-            setBackground(themedir);
-
-            // Close all clients
-            if (!testing) {
-                KillAllClients(False);
-                KillAllClients(True);
-            }
-
-            // Show panel
-            LoginPanel->OpenPanel();
-        }
-
-        LoginPanel->Reset();
+	}
+
+	/* Open display */
+	if((Dpy = XOpenDisplay(DisplayName)) == 0) {
+		logStream << APPNAME << ": could not open display '"
+			 << DisplayName << "'" << endl;
+		if (!testing) StopServer();
+		exit(ERR_EXIT);
+	}
+
+	/* Get screen and root window */
+	Scr = DefaultScreen(Dpy);
+	Root = RootWindow(Dpy, Scr);
+
+	/* for tests we use a standard window */
+	if (testing) {
+		Window RealRoot = RootWindow(Dpy, Scr);
+		Root = XCreateSimpleWindow(Dpy, RealRoot, 0, 0, 1280, 1024, 0, 0, 0);
+		XMapWindow(Dpy, Root);
+		XFlush(Dpy);
+	} else {
+		blankScreen();
+	}
+
+	HideCursor();
+
+	/* Create panel */
+	LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir);
+	bool firstloop = true; /* 1st time panel is shown (for automatic username) */
+	bool focuspass = cfg->getOption("focus_password")=="yes";
+	bool autologin = cfg->getOption("auto_login")=="yes";
 	
+	if (firstlogin && cfg->getOption("default_user") != "") {
+		LoginPanel->SetName(cfg->getOption("default_user") );
+#ifdef USE_PAM
+	pam.set_item(PAM::Authenticator::User, cfg->getOption("default_user").c_str());
+#endif
+		firstlogin = false;
+		if (autologin) {
+			Login();
+		}
+	}
+
+	/* Set NumLock */
+	string numlock = cfg->getOption("numlock");
+	if (numlock == "on") {
+		NumLock::setOn(Dpy);
+	} else if (numlock == "off") {
+		NumLock::setOff(Dpy);
+	}
 	
-        if (firstloop && cfg->getOption("default_user") != "") {
-            LoginPanel->SetName(cfg->getOption("default_user") );
-        }
-
-
-        if (!AuthenticateUser(focuspass && firstloop)){
-            panelclosed = 0;
-            firstloop = false;
-            LoginPanel->ClearPanel();
-            XBell(Dpy, 100);
-            continue;
-        }
+	/* Start looping */
+	int panelclosed = 1;
+	Panel::ActionType Action;
+
+	while(1) {
+		if(panelclosed) {
+			/* Init root */
+			setBackground(themedir);
+
+			/* Close all clients */
+			if (!testing) {
+				KillAllClients(False);
+				KillAllClients(True);
+			}
+
+			/* Show panel */
+			LoginPanel->OpenPanel();
+		}
+
+		LoginPanel->Reset();
+
+		if (firstloop && cfg->getOption("default_user") != "") {
+			LoginPanel->SetName(cfg->getOption("default_user") );
+		}
+
+
+		if (!AuthenticateUser(focuspass && firstloop)){
+			panelclosed = 0;
+			firstloop = false;
+			LoginPanel->ClearPanel();
+			XBell(Dpy, 100);
+			continue;
+		}
 	
-	firstloop = false;
-
-        Action = LoginPanel->getAction();
-        // for themes test we just quit
-        if (testing) {
-            Action = Panel::Exit;
-        }
-        panelclosed = 1;
-        LoginPanel->ClosePanel();
-
-        switch(Action) {
-            case Panel::Login:
-                Login();
-                break;
-            case Panel::Console:
-                Console();
-                break;
-            case Panel::Reboot:
-                Reboot();
-                break;
-            case Panel::Halt:
-                Halt();
-                break;
-            case Panel::Suspend:
-                Suspend();
-                break;
-            case Panel::Exit:
-                Exit();
-                break;
-        }
-    }
+		firstloop = false;
+
+		Action = LoginPanel->getAction();
+		/* for themes test we just quit */
+		if (testing) {
+			Action = Panel::Exit;
+		}
+		panelclosed = 1;
+		LoginPanel->ClosePanel();
+
+		switch(Action) {
+			case Panel::Login:
+				Login();
+				break;
+			case Panel::Console:
+				Console();
+				break;
+			case Panel::Reboot:
+				Reboot();
+				break;
+			case Panel::Halt:
+				Halt();
+				break;
+			case Panel::Suspend:
+				Suspend();
+				break;
+			case Panel::Exit:
+				Exit();
+				break;
+		}
+	}
 }
 
 #ifdef USE_PAM
 bool App::AuthenticateUser(bool focuspass){
-    // Reset the username
-    try{
-        if (!focuspass)
-		    pam.set_item(PAM::Authenticator::User, 0);
-        pam.authenticate();
-    }
-    catch(PAM::Auth_Exception& e){
-        switch(LoginPanel->getAction()){
-            case Panel::Exit:
-            case Panel::Console:
-                return true; // <--- This is simply fake!
-            default:
-                break;
-        };
-        logStream << APPNAME << ": " << e << endl;
-        return false;
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
-    return true;
+	/* Reset the username */
+	try{
+		if (!focuspass)
+			pam.set_item(PAM::Authenticator::User, 0);
+		pam.authenticate();
+	}
+	catch(PAM::Auth_Exception& e){
+		switch(LoginPanel->getAction()){
+			case Panel::Exit:
+			case Panel::Console:
+				return true; /* <--- This is simply fake! */
+			default:
+				break;
+		};
+		logStream << APPNAME << ": " << e << endl;
+		return false;
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
+	return true;
 }
 #else
 bool App::AuthenticateUser(bool focuspass){
-    if (!focuspass){
-        LoginPanel->EventHandler(Panel::Get_Name);
-        switch(LoginPanel->getAction()){
-            case Panel::Exit:
-            case Panel::Console:
-                logStream << APPNAME << ": Got a special command (" << LoginPanel->GetName() << ")" << endl;
-                return true; // <--- This is simply fake!
-            default:
-                break;
-        }
-    }
-    LoginPanel->EventHandler(Panel::Get_Passwd);
-    
-    char *encrypted, *correct;
-    struct passwd *pw;
-
-    switch(LoginPanel->getAction()){
-        case Panel::Suspend:
-        case Panel::Halt:
-        case Panel::Reboot:
-            pw = getpwnam("root");
-            break;
-        case Panel::Console:
-        case Panel::Exit:
-        case Panel::Login:
-            pw = getpwnam(LoginPanel->GetName().c_str());
-            break;
-    }
-    endpwent();
-    if(pw == 0)
-        return false;
+	if (!focuspass){
+		LoginPanel->EventHandler(Panel::Get_Name);
+		switch(LoginPanel->getAction()){
+			case Panel::Exit:
+			case Panel::Console:
+				logStream << APPNAME << ": Got a special command (" << LoginPanel->GetName() << ")" << endl;
+				return true; /* <--- This is simply fake! */
+			default:
+				break;
+		}
+	}
+	LoginPanel->EventHandler(Panel::Get_Passwd);
+	
+	char *encrypted, *correct;
+	struct passwd *pw;
+
+	switch(LoginPanel->getAction()){
+		case Panel::Suspend:
+		case Panel::Halt:
+		case Panel::Reboot:
+			pw = getpwnam("root");
+			break;
+		case Panel::Console:
+		case Panel::Exit:
+		case Panel::Login:
+			pw = getpwnam(LoginPanel->GetName().c_str());
+			break;
+	}
+	endpwent();
+	if(pw == 0)
+		return false;
 
 #ifdef HAVE_SHADOW
-    struct spwd *sp = getspnam(pw->pw_name);    
-    endspent();
-    if(sp)
-        correct = sp->sp_pwdp;
-    else
-#endif        // HAVE_SHADOW
-        correct = pw->pw_passwd;
-
-    if(correct == 0 || correct[0] == '\0')
-        return true;
-
-    encrypted = crypt(LoginPanel->GetPasswd().c_str(), correct);
-    return ((strcmp(encrypted, correct) == 0) ? true : false);
+	struct spwd *sp = getspnam(pw->pw_name);	
+	endspent();
+	if(sp)
+		correct = sp->sp_pwdp;
+	else
+#endif		/* HAVE_SHADOW */
+		correct = pw->pw_passwd;
+
+	if(correct == 0 || correct[0] == '\0')
+		return true;
+
+	encrypted = crypt(LoginPanel->GetPasswd().c_str(), correct);
+	return ((strcmp(encrypted, correct) == 0) ? true : false);
 }
 #endif
 
-
 int App::GetServerPID() {
-    return ServerPID;
+	return ServerPID;
 }
 
-// Hide the cursor
+/* Hide the cursor */
 void App::HideCursor() {
-    if (cfg->getOption("hidecursor") == "true") {
-        XColor            black;
-        char            cursordata[1];
-        Pixmap            cursorpixmap;
-        Cursor            cursor;
-        cursordata[0]=0;
-        cursorpixmap=XCreateBitmapFromData(Dpy,Root,cursordata,1,1);
-        black.red=0;
-        black.green=0;
-        black.blue=0;
-        cursor=XCreatePixmapCursor(Dpy,cursorpixmap,cursorpixmap,&black,&black,0,0);
-        XDefineCursor(Dpy,Root,cursor);
-    }
+	if (cfg->getOption("hidecursor") == "true") {
+		XColor			black;
+		char			cursordata[1];
+		Pixmap			cursorpixmap;
+		Cursor			cursor;
+		cursordata[0]=0;
+		cursorpixmap=XCreateBitmapFromData(Dpy,Root,cursordata,1,1);
+		black.red=0;
+		black.green=0;
+		black.blue=0;
+		cursor=XCreatePixmapCursor(Dpy,cursorpixmap,cursorpixmap,&black,&black,0,0);
+		XDefineCursor(Dpy,Root,cursor);
+	}
 }
 
 void App::Login() {
-    struct passwd *pw;
-    pid_t pid;
+	struct passwd *pw;
+	pid_t pid;
 
 #ifdef USE_PAM
-    try{
-        pam.open_session();
-        pw = getpwnam(static_cast<const char*>(pam.get_item(PAM::Authenticator::User)));
-    }
-    catch(PAM::Cred_Exception& e){
-        // Credentials couldn't be established
-        logStream << APPNAME << ": " << e << endl;
-        return;
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    };
+	try{
+		pam.open_session();
+		pw = getpwnam(static_cast<const char*>(pam.get_item(PAM::Authenticator::User)));
+	}
+	catch(PAM::Cred_Exception& e){
+		/* Credentials couldn't be established */
+		logStream << APPNAME << ": " << e << endl;
+		return;
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	};
 #else
-    pw = getpwnam(LoginPanel->GetName().c_str());
+	pw = getpwnam(LoginPanel->GetName().c_str());
 #endif
-    endpwent();
-    if(pw == 0)
-        return;
-    if (pw->pw_shell[0] == '\0') {
-        setusershell();
-        strcpy(pw->pw_shell, getusershell());
-        endusershell();
-    }
-
-    // Setup the environment
-    char* term = getenv("TERM");
-    string maildir = _PATH_MAILDIR;
-    maildir.append("/");
-    maildir.append(pw->pw_name);
-    string xauthority = pw->pw_dir;
-    xauthority.append("/.Xauthority");
-    
+	endpwent();
+	if(pw == 0)
+		return;
+	if (pw->pw_shell[0] == '\0') {
+		setusershell();
+		strcpy(pw->pw_shell, getusershell());
+		endusershell();
+	}
+
+	/* Setup the environment */
+	char* term = getenv("TERM");
+	string maildir = _PATH_MAILDIR;
+	maildir.append("/");
+	maildir.append(pw->pw_name);
+	string xauthority = pw->pw_dir;
+	xauthority.append("/.Xauthority");
+	
 #ifdef USE_PAM
-    // Setup the PAM environment
-    try{
-        if(term) pam.setenv("TERM", term);
-        pam.setenv("HOME", pw->pw_dir);
-        pam.setenv("PWD", pw->pw_dir);
-        pam.setenv("SHELL", pw->pw_shell);
-        pam.setenv("USER", pw->pw_name);
-        pam.setenv("LOGNAME", pw->pw_name);
-        pam.setenv("PATH", cfg->getOption("default_path").c_str());
-        pam.setenv("DISPLAY", DisplayName);
-        pam.setenv("MAIL", maildir.c_str());
-        pam.setenv("XAUTHORITY", xauthority.c_str());
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    }
+	/* Setup the PAM environment */
+	try{
+		if(term) pam.setenv("TERM", term);
+		pam.setenv("HOME", pw->pw_dir);
+		pam.setenv("PWD", pw->pw_dir);
+		pam.setenv("SHELL", pw->pw_shell);
+		pam.setenv("USER", pw->pw_name);
+		pam.setenv("LOGNAME", pw->pw_name);
+		pam.setenv("PATH", cfg->getOption("default_path").c_str());
+		pam.setenv("DISPLAY", DisplayName);
+		pam.setenv("MAIL", maildir.c_str());
+		pam.setenv("XAUTHORITY", xauthority.c_str());
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	}
 #endif
 
 #ifdef USE_CONSOLEKIT
-    // Setup the ConsoleKit session
-    try {
-        ck.open_session(DisplayName, pw->pw_uid);
-    }
-    catch(Ck::Exception &e) {
-        logStream << APPNAME << ": " << e << endl;
-        exit(ERR_EXIT);
-    }
+	/* Setup the ConsoleKit session */
+	try {
+		ck.open_session(DisplayName, pw->pw_uid);
+	}
+	catch(Ck::Exception &e) {
+		logStream << APPNAME << ": " << e << endl;
+		exit(ERR_EXIT);
+	}
 #endif
 
-    // Create new process
-    pid = fork();
-    if(pid == 0) {
+	/* Create new process */
+	pid = fork();
+	if(pid == 0) {
 #ifdef USE_PAM
-        // Get a copy of the environment and close the child's copy
-        // of the PAM-handle.
-        char** child_env = pam.getenvlist();
+		/* Get a copy of the environment and close the child's copy */
+		/* of the PAM-handle. */
+		char** child_env = pam.getenvlist();
 
 # ifdef USE_CONSOLEKIT
-        char** old_env = child_env;
+		char** old_env = child_env;
 
-        // Grow the copy of the environment for the session cookie
-        int n;
-        for(n = 0; child_env[n] != NULL ; n++);
+		/* Grow the copy of the environment for the session cookie */
+		int n;
+		for(n = 0; child_env[n] != NULL ; n++);
 
-        n++;
+		n++;
 
-        child_env = static_cast<char**>(malloc(sizeof(char*)*n));
-        memcpy(child_env, old_env, sizeof(char*)*n);
-        child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
-        child_env[n] = NULL;
+		child_env = static_cast<char**>(malloc(sizeof(char*)*n));
+		memcpy(child_env, old_env, sizeof(char*)*n);
+		child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
+		child_env[n] = NULL;
 # endif /* USE_CONSOLEKIT */
 
-        pam.end();
+		pam.end();
 #else
 
 # ifdef USE_CONSOLEKIT
-        const int Num_Of_Variables = 12; // Number of env. variables + 1
+		const int Num_Of_Variables = 12; /* Number of env. variables + 1 */
 # else
-        const int Num_Of_Variables = 11; // Number of env. variables + 1
+		const int Num_Of_Variables = 11; /* Number of env. variables + 1 */
 # endif /* USE_CONSOLEKIT */
-        char** child_env = static_cast<char**>(malloc(sizeof(char*)*Num_Of_Variables));
-        int n = 0;
-        if(term) child_env[n++]=StrConcat("TERM=", term);
-        child_env[n++]=StrConcat("HOME=", pw->pw_dir);
-        child_env[n++]=StrConcat("PWD=", pw->pw_dir);
-        child_env[n++]=StrConcat("SHELL=", pw->pw_shell);
-        child_env[n++]=StrConcat("USER=", pw->pw_name);
-        child_env[n++]=StrConcat("LOGNAME=", pw->pw_name);
-        child_env[n++]=StrConcat("PATH=", cfg->getOption("default_path").c_str());
-        child_env[n++]=StrConcat("DISPLAY=", DisplayName);
-        child_env[n++]=StrConcat("MAIL=", maildir.c_str());
-        child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
+		char** child_env = static_cast<char**>(malloc(sizeof(char*)*Num_Of_Variables));
+		int n = 0;
+		if(term) child_env[n++]=StrConcat("TERM=", term);
+		child_env[n++]=StrConcat("HOME=", pw->pw_dir);
+		child_env[n++]=StrConcat("PWD=", pw->pw_dir);
+		child_env[n++]=StrConcat("SHELL=", pw->pw_shell);
+		child_env[n++]=StrConcat("USER=", pw->pw_name);
+		child_env[n++]=StrConcat("LOGNAME=", pw->pw_name);
+		child_env[n++]=StrConcat("PATH=", cfg->getOption("default_path").c_str());
+		child_env[n++]=StrConcat("DISPLAY=", DisplayName);
+		child_env[n++]=StrConcat("MAIL=", maildir.c_str());
+		child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
 # ifdef USE_CONSOLEKIT
-        child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
+		child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
 # endif /* USE_CONSOLEKIT */
-        child_env[n++]=0;
+		child_env[n++]=0;
 
 #endif
 
-        // Login process starts here
-        SwitchUser Su(pw, cfg, DisplayName, child_env);
-        string session = LoginPanel->getSession();
-        string loginCommand = cfg->getOption("login_cmd");
-        replaceVariables(loginCommand, SESSION_VAR, session);
-        replaceVariables(loginCommand, THEME_VAR, themeName);
-        string sessStart = cfg->getOption("sessionstart_cmd");
-        if (sessStart != "") {
-            replaceVariables(sessStart, USER_VAR, pw->pw_name);
-            system(sessStart.c_str());
-        }
-        Su.Login(loginCommand.c_str(), mcookie.c_str());
-        _exit(OK_EXIT);
-    }
+		/* Login process starts here */
+		SwitchUser Su(pw, cfg, DisplayName, child_env);
+		string session = LoginPanel->getSession();
+		string loginCommand = cfg->getOption("login_cmd");
+		replaceVariables(loginCommand, SESSION_VAR, session);
+		replaceVariables(loginCommand, THEME_VAR, themeName);
+		string sessStart = cfg->getOption("sessionstart_cmd");
+		if (sessStart != "") {
+			replaceVariables(sessStart, USER_VAR, pw->pw_name);
+			system(sessStart.c_str());
+		}
+		Su.Login(loginCommand.c_str(), mcookie.c_str());
+		_exit(OK_EXIT);
+	}
 
 #ifndef XNEST_DEBUG
-    CloseLog();
+	CloseLog();
 #endif
 
-    // Wait until user is logging out (login process terminates)
-    pid_t wpid = -1;
-    int status;
-    while (wpid != pid) {
-        wpid = wait(&status);
+	/* Wait until user is logging out (login process terminates) */
+	pid_t wpid = -1;
+	int status;
+	while (wpid != pid) {
+		wpid = wait(&status);
 		if (wpid == ServerPID)
-			xioerror(Dpy);	// Server died, simulate IO error
-    }
-    if (WIFEXITED(status) && WEXITSTATUS(status)) {
-        LoginPanel->Message("Failed to execute login command");
-        sleep(3);
-    } else {
-         string sessStop = cfg->getOption("sessionstop_cmd");
-         if (sessStop != "") {
-            replaceVariables(sessStop, USER_VAR, pw->pw_name);
-            system(sessStop.c_str());
-        }
-    }
+			xioerror(Dpy);	/* Server died, simulate IO error */
+	}
+	if (WIFEXITED(status) && WEXITSTATUS(status)) {
+		LoginPanel->Message("Failed to execute login command");
+		sleep(3);
+	} else {
+		 string sessStop = cfg->getOption("sessionstop_cmd");
+		 if (sessStop != "") {
+			replaceVariables(sessStop, USER_VAR, pw->pw_name);
+			system(sessStop.c_str());
+		}
+	}
 
 #ifdef USE_CONSOLEKIT
-    try {
-        ck.close_session();
-    }
-    catch(Ck::Exception &e) {
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try {
+		ck.close_session();
+	}
+	catch(Ck::Exception &e) {
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
 #ifdef USE_PAM
-    try{
-        pam.close_session();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.close_session();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-// Close all clients
-    KillAllClients(False);
-    KillAllClients(True);
+/* Close all clients */
+	KillAllClients(False);
+	KillAllClients(True);
 
-    // Send HUP signal to clientgroup
-    killpg(pid, SIGHUP);
+	/* Send HUP signal to clientgroup */
+	killpg(pid, SIGHUP);
 
-    // Send TERM signal to clientgroup, if error send KILL
-    if(killpg(pid, SIGTERM))
-    killpg(pid, SIGKILL);
+	/* Send TERM signal to clientgroup, if error send KILL */
+	if(killpg(pid, SIGTERM))
+	killpg(pid, SIGKILL);
 
-    HideCursor();
+	HideCursor();
 
 #ifndef XNEST_DEBUG
-    // Re-activate log file
-    OpenLog();
-    RestartServer();
+	/* Re-activate log file */
+	OpenLog();
+	RestartServer();
 #endif
 
-
 }
 
-
 void App::Reboot() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    // Write message
-    LoginPanel->Message((char*)cfg->getOption("reboot_msg").c_str());
-    sleep(3);
+	/* Write message */
+	LoginPanel->Message((char*)cfg->getOption("reboot_msg").c_str());
+	sleep(3);
 
-    // Stop server and reboot
-    StopServer();
-    RemoveLock();
-    system(cfg->getOption("reboot_cmd").c_str());
-    exit(OK_EXIT);
+	/* Stop server and reboot */
+	StopServer();
+	RemoveLock();
+	system(cfg->getOption("reboot_cmd").c_str());
+	exit(OK_EXIT);
 }
 
 
 void App::Halt() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    // Write message
-    LoginPanel->Message((char*)cfg->getOption("shutdown_msg").c_str());
-    sleep(3);
+	/* Write message */
+	LoginPanel->Message((char*)cfg->getOption("shutdown_msg").c_str());
+	sleep(3);
 
-    // Stop server and halt
-    StopServer();
-    RemoveLock();
-    system(cfg->getOption("halt_cmd").c_str());
-    exit(OK_EXIT);
+	/* Stop server and halt */
+	StopServer();
+	RemoveLock();
+	system(cfg->getOption("halt_cmd").c_str());
+	exit(OK_EXIT);
 }
 
 void App::Suspend() {
-    sleep(1);
-    system(cfg->getOption("suspend_cmd").c_str());
+	sleep(1);
+	system(cfg->getOption("suspend_cmd").c_str());
 }
 
 
 void App::Console() {
-    int posx = 40;
-    int posy = 40;
-    int fontx = 9;
-    int fonty = 15;
-    int width = (XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posx * 2)) / fontx;
-    int height = (XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posy * 2)) / fonty;
-
-    // Execute console
-    const char* cmd = cfg->getOption("console_cmd").c_str();
-    char *tmp = new char[strlen(cmd) + 60];
-    sprintf(tmp, cmd, width, height, posx, posy, fontx, fonty);
-    system(tmp);
-    delete [] tmp;
+	int posx = 40;
+	int posy = 40;
+	int fontx = 9;
+	int fonty = 15;
+	int width = (XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posx * 2)) / fontx;
+	int height = (XHeightOfScreen(ScreenOfDisplay(Dpy, Scr)) - (posy * 2)) / fonty;
+
+	/* Execute console */
+	const char* cmd = cfg->getOption("console_cmd").c_str();
+	char *tmp = new char[strlen(cmd) + 60];
+	sprintf(tmp, cmd, width, height, posx, posy, fontx, fonty);
+	system(tmp);
+	delete [] tmp;
 }
 
 
 void App::Exit() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    if (testing) {
-        const char* testmsg = "This is a test message :-)";
-        LoginPanel->Message(testmsg);
-        sleep(3);
-        delete LoginPanel;
-        XCloseDisplay(Dpy);
-    } else {
-        delete LoginPanel;
-        StopServer();
-        RemoveLock();
-    }
-    delete cfg;
-    exit(OK_EXIT);
+	if (testing) {
+		const char* testmsg = "This is a test message :-)";
+		LoginPanel->Message(testmsg);
+		sleep(3);
+		delete LoginPanel;
+		XCloseDisplay(Dpy);
+	} else {
+		delete LoginPanel;
+		StopServer();
+		RemoveLock();
+	}
+	delete cfg;
+	exit(OK_EXIT);
 }
 
-
 int CatchErrors(Display *dpy, XErrorEvent *ev) {
-    return 0;
+	return 0;
 }
 
 void App::RestartServer() {
 #ifdef USE_PAM
-    try{
-        pam.end();
-    }
-    catch(PAM::Exception& e){
-        logStream << APPNAME << ": " << e << endl;
-    };
+	try{
+		pam.end();
+	}
+	catch(PAM::Exception& e){
+		logStream << APPNAME << ": " << e << endl;
+	};
 #endif
 
-    StopServer(); 
-    RemoveLock();
-	while (waitpid(-1, NULL, WNOHANG) > 0); // Collects all dead childrens
-    Run();
+	StopServer(); 
+	RemoveLock();
+	while (waitpid(-1, NULL, WNOHANG) > 0); /* Collects all dead childrens */
+	Run();
 } 
 
 void App::KillAllClients(Bool top) {
-    Window dummywindow;
-    Window *children;
-    unsigned int nchildren;
-    unsigned int i;
-    XWindowAttributes attr;
-
-    XSync(Dpy, 0);
-    XSetErrorHandler(CatchErrors);
-
-    nchildren = 0;
-    XQueryTree(Dpy, Root, &dummywindow, &dummywindow, &children, &nchildren);
-    if(!top) {
-        for(i=0; i<nchildren; i++) {
-            if(XGetWindowAttributes(Dpy, children[i], &attr) && (attr.map_state == IsViewable))
-                children[i] = XmuClientWindow(Dpy, children[i]);
-            else
-                children[i] = 0;
-        }
-    }
-
-    for(i=0; i<nchildren; i++) {
-        if(children[i])
-            XKillClient(Dpy, children[i]);
-    }
-    XFree((char *)children);
-
-    XSync(Dpy, 0);
-    XSetErrorHandler(NULL);
+	Window dummywindow;
+	Window *children;
+	unsigned int nchildren;
+	unsigned int i;
+	XWindowAttributes attr;
+
+	XSync(Dpy, 0);
+	XSetErrorHandler(CatchErrors);
+
+	nchildren = 0;
+	XQueryTree(Dpy, Root, &dummywindow, &dummywindow, &children, &nchildren);
+	if(!top) {
+		for(i=0; i<nchildren; i++) {
+			if(XGetWindowAttributes(Dpy, children[i], &attr) && (attr.map_state == IsViewable))
+				children[i] = XmuClientWindow(Dpy, children[i]);
+			else
+				children[i] = 0;
+		}
+	}
+
+	for(i=0; i<nchildren; i++) {
+		if(children[i])
+			XKillClient(Dpy, children[i]);
+	}
+	XFree((char *)children);
+
+	XSync(Dpy, 0);
+	XSetErrorHandler(NULL);
 }
 
 
 int App::ServerTimeout(int timeout, char* text) {
-    int    i = 0;
-    int pidfound = -1;
-    static char    *lasttext;
-
-    for(;;) {
-        pidfound = waitpid(ServerPID, NULL, WNOHANG);
-        if(pidfound == ServerPID)
-            break;
-        if(timeout) {
-            if(i == 0 && text != lasttext)
-                logStream << endl << APPNAME << ": waiting for " << text;
-            else
-                logStream << ".";
-        }
-        if(timeout)
-            sleep(1);
-        if(++i > timeout)
-            break;
-    }
-
-    if(i > 0)
-        logStream << endl;
-    lasttext = text;
-
-    return (ServerPID != pidfound);
+	int	i = 0;
+	int pidfound = -1;
+	static char	*lasttext;
+
+	for(;;) {
+		pidfound = waitpid(ServerPID, NULL, WNOHANG);
+		if(pidfound == ServerPID)
+			break;
+		if(timeout) {
+			if(i == 0 && text != lasttext)
+				logStream << endl << APPNAME << ": waiting for " << text;
+			else
+				logStream << ".";
+		}
+		if(timeout)
+			sleep(1);
+		if(++i > timeout)
+			break;
+	}
+
+	if(i > 0)
+		logStream << endl;
+	lasttext = text;
+
+	return (ServerPID != pidfound);
 }
 
 
 int App::WaitForServer() {
-    int    ncycles     = 120;
-    int    cycles;
-
-    for(cycles = 0; cycles < ncycles; cycles++) {
-        if((Dpy = XOpenDisplay(DisplayName))) {
-            XSetIOErrorHandler(xioerror);
-            return 1;
-        } else {
-            if(!ServerTimeout(1, (char *) "X server to begin accepting connections"))
-                break;
-        }
-    }
-
-    logStream << "Giving up." << endl;
-
-    return 0;
+	int	ncycles	 = 120;
+	int	cycles;
+
+	for(cycles = 0; cycles < ncycles; cycles++) {
+		if((Dpy = XOpenDisplay(DisplayName))) {
+			XSetIOErrorHandler(xioerror);
+			return 1;
+		} else {
+			if(!ServerTimeout(1, (char *) "X server to begin accepting connections"))
+				break;
+		}
+	}
+
+	logStream << "Giving up." << endl;
+
+	return 0;
 }
 
 
 int App::StartServer() {
-    ServerPID = fork();
-
-    static const int MAX_XSERVER_ARGS = 256;
-    static char* server[MAX_XSERVER_ARGS+2] = { NULL };
-    server[0] = (char *)cfg->getOption("default_xserver").c_str();
-    string argOption = cfg->getOption("xserver_arguments");
-    /* Add mandatory -xauth option */
-    argOption = argOption + " -auth " + cfg->getOption("authfile");
-    char* args = new char[argOption.length()+2]; // NULL plus vt
-    strcpy(args, argOption.c_str());
-
-    serverStarted = false;
-
-    int argc = 1;
-    int pos = 0;
-    bool hasVtSet = false;
-    while (args[pos] != '\0') {
-        if (args[pos] == ' ' || args[pos] == '\t') {
-            *(args+pos) = '\0';
-            server[argc++] = args+pos+1;
-        } else if (pos == 0) {
-            server[argc++] = args+pos;
-        }
-        ++pos;
-
-        if (argc+1 >= MAX_XSERVER_ARGS) {
-            // ignore _all_ arguments to make sure the server starts at
-            // all
-            argc = 1;
-            break;
-        }
-    }
-
-    for (int i=0; i<argc; i++) {
-        if (server[i][0] == 'v' && server[i][1] == 't') {
-            bool ok = false;
-            Cfg::string2int(server[i]+2, &ok);
-            if (ok) {
-                hasVtSet = true;
-            }
-        }
-    }
-
-    if (!hasVtSet && daemonmode) {
-        server[argc++] = (char*)"vt07";
-    }
-    server[argc] = NULL;
-
-    switch(ServerPID) {
-    case 0:
-        signal(SIGTTIN, SIG_IGN);
-        signal(SIGTTOU, SIG_IGN);
-        signal(SIGUSR1, SIG_IGN);
-        setpgid(0,getpid());
-
-
-        execvp(server[0], server);
-        logStream << APPNAME << ": X server could not be started" << endl;
-        exit(ERR_EXIT);
-        break;
-
-    case -1:
-        break;
-
-    default:
-        errno = 0;
-        if(!ServerTimeout(0, (char *)"")) {
-            ServerPID = -1;
-            break;
-        }
-
-        // Wait for server to start up
-        if(WaitForServer() == 0) {
-            logStream << APPNAME << ": unable to connect to X server" << endl;
-            StopServer();
-            ServerPID = -1;
-            exit(ERR_EXIT);
-        }
-        break;
-    }
-
-    delete args;
-
-    serverStarted = true;
-
-    return ServerPID;
+	ServerPID = fork();
+
+	static const int MAX_XSERVER_ARGS = 256;
+	static char* server[MAX_XSERVER_ARGS+2] = { NULL };
+	server[0] = (char *)cfg->getOption("default_xserver").c_str();
+	string argOption = cfg->getOption("xserver_arguments");
+	/* Add mandatory -xauth option */
+	argOption = argOption + " -auth " + cfg->getOption("authfile");
+	char* args = new char[argOption.length()+2]; /* NULL plus vt */
+	strcpy(args, argOption.c_str());
+
+	serverStarted = false;
+
+	int argc = 1;
+	int pos = 0;
+	bool hasVtSet = false;
+	while (args[pos] != '\0') {
+		if (args[pos] == ' ' || args[pos] == '\t') {
+			*(args+pos) = '\0';
+			server[argc++] = args+pos+1;
+		} else if (pos == 0) {
+			server[argc++] = args+pos;
+		}
+		++pos;
+
+		if (argc+1 >= MAX_XSERVER_ARGS) {
+			/* ignore _all_ arguments to make sure the server starts at */
+			/* all */
+			argc = 1;
+			break;
+		}
+	}
+
+	for (int i=0; i<argc; i++) {
+		if (server[i][0] == 'v' && server[i][1] == 't') {
+			bool ok = false;
+			Cfg::string2int(server[i]+2, &ok);
+			if (ok) {
+				hasVtSet = true;
+			}
+		}
+	}
+
+	if (!hasVtSet && daemonmode) {
+		server[argc++] = (char*)"vt07";
+	}
+	server[argc] = NULL;
+
+	switch(ServerPID) {
+	case 0:
+		signal(SIGTTIN, SIG_IGN);
+		signal(SIGTTOU, SIG_IGN);
+		signal(SIGUSR1, SIG_IGN);
+		setpgid(0,getpid());
+
+		execvp(server[0], server);
+		logStream << APPNAME << ": X server could not be started" << endl;
+		exit(ERR_EXIT);
+		break;
+
+	case -1:
+		break;
+
+	default:
+		errno = 0;
+		if(!ServerTimeout(0, (char *)"")) {
+			ServerPID = -1;
+			break;
+		}
+
+		/* Wait for server to start up */
+		if(WaitForServer() == 0) {
+			logStream << APPNAME << ": unable to connect to X server" << endl;
+			StopServer();
+			ServerPID = -1;
+			exit(ERR_EXIT);
+		}
+		break;
+	}
+
+	delete args;
+
+	serverStarted = true;
+
+	return ServerPID;
 }
 
-
 jmp_buf CloseEnv;
 int IgnoreXIO(Display *d) {
-    logStream << APPNAME << ": connection to X server lost." << endl;
-    longjmp(CloseEnv, 1);
+	logStream << APPNAME << ": connection to X server lost." << endl;
+	longjmp(CloseEnv, 1);
 }
 
-
 void App::StopServer() {
-    signal(SIGQUIT, SIG_IGN);
-    signal(SIGINT, SIG_IGN);
-    signal(SIGHUP, SIG_IGN);
-    signal(SIGPIPE, SIG_IGN);
-    signal(SIGTERM, SIG_DFL);
-    signal(SIGKILL, SIG_DFL);
-
-    // Catch X error
-    XSetIOErrorHandler(IgnoreXIO);
-    if(!setjmp(CloseEnv) && Dpy)
-        XCloseDisplay(Dpy);
-
-    // Send HUP to process group
-    errno = 0;
-    if((killpg(getpid(), SIGHUP) != 0) && (errno != ESRCH))
-        logStream << APPNAME << ": can't send HUP to process group " << getpid() << endl;
-
-    // Send TERM to server
-    if(ServerPID < 0)
-        return;
-    errno = 0;
-    if(killpg(ServerPID, SIGTERM) < 0) {
-        if(errno == EPERM) {
-            logStream << APPNAME << ": can't kill X server" << endl;
-            exit(ERR_EXIT);
-        }
-        if(errno == ESRCH)
-            return;
-    }
-
-    // Wait for server to shut down
-    if(!ServerTimeout(10, (char *)"X server to shut down")) {
-        logStream << endl;
-        return;
-    }
-
-    logStream << endl << APPNAME << ":  X server slow to shut down, sending KILL signal." << endl;
-
-    // Send KILL to server
-    errno = 0;
-    if(killpg(ServerPID, SIGKILL) < 0) {
-        if(errno == ESRCH)
-            return;
-    }
-
-    // Wait for server to die
-    if(ServerTimeout(3, (char*)"server to die")) {
-        logStream << endl << APPNAME << ": can't kill server" << endl;
-        exit(ERR_EXIT);
-    }
-    logStream << endl;
+	signal(SIGQUIT, SIG_IGN);
+	signal(SIGINT, SIG_IGN);
+	signal(SIGHUP, SIG_IGN);
+	signal(SIGPIPE, SIG_IGN);
+	signal(SIGTERM, SIG_DFL);
+	signal(SIGKILL, SIG_DFL);
+
+	/* Catch X error */
+	XSetIOErrorHandler(IgnoreXIO);
+	if(!setjmp(CloseEnv) && Dpy)
+		XCloseDisplay(Dpy);
+
+	/* Send HUP to process group */
+	errno = 0;
+	if((killpg(getpid(), SIGHUP) != 0) && (errno != ESRCH))
+		logStream << APPNAME << ": can't send HUP to process group " << getpid() << endl;
+
+	/* Send TERM to server */
+	if(ServerPID < 0)
+		return;
+	errno = 0;
+	if(killpg(ServerPID, SIGTERM) < 0) {
+		if(errno == EPERM) {
+			logStream << APPNAME << ": can't kill X server" << endl;
+			exit(ERR_EXIT);
+		}
+		if(errno == ESRCH)
+			return;
+	}
+
+	/* Wait for server to shut down */
+	if(!ServerTimeout(10, (char *)"X server to shut down")) {
+		logStream << endl;
+		return;
+	}
+
+	logStream << endl << APPNAME << ":  X server slow to shut down, sending KILL signal." << endl;
+
+	/* Send KILL to server */
+	errno = 0;
+	if(killpg(ServerPID, SIGKILL) < 0) {
+		if(errno == ESRCH)
+			return;
+	}
+
+	/* Wait for server to die */
+	if(ServerTimeout(3, (char*)"server to die")) {
+		logStream << endl << APPNAME << ": can't kill server" << endl;
+		exit(ERR_EXIT);
+	}
+	logStream << endl;
 }
 
-
 void App::blankScreen()
 {
-    GC gc = XCreateGC(Dpy, Root, 0, 0);
-    XSetForeground(Dpy, gc, BlackPixel(Dpy, Scr));
-    XFillRectangle(Dpy, Root, gc, 0, 0,
-                   XWidthOfScreen(ScreenOfDisplay(Dpy, Scr)),