Skip to content

Commit

Permalink
Integrated slimlock into slim
Browse files Browse the repository at this point in the history
iwamatsu's final release of SLiM (1.3.6) had integrated slimlock into
the same codebase.  This commit foward-ports the same code from the
1.3.6 release that was on berlios before berlios was discontinued.

Note there might be some other code changes that are not directly
slimlock-related in this commit; it was difficult to separate them out.

The slim-1.3.6 release had a number of inconsistencies related to the
slimlock merge that can cause build and runtime errors, so additionally
this commit addresses those:

- added missing link deps to libslim
- ensured slimlock isn't installed when it isn't built
- install slimlock SUID, as it was in its predecessor
  • Loading branch information
axs-gentoo committed Sep 17, 2015
1 parent 30be199 commit c98f1f3
Show file tree
Hide file tree
Showing 12 changed files with 968 additions and 63 deletions.
95 changes: 86 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,49 @@ set(SLIM_DEFINITIONS ${SLIM_DEFINITIONS} "-DSYSCONFDIR=\"${SYSCONFDIR}\"")
set(slim_srcs
main.cpp
app.cpp
cfg.cpp
image.cpp
numlock.cpp
panel.cpp
switchuser.cpp
util.cpp
log.cpp
png.c
jpeg.c
coord.cpp
)

set(slimlock_srcs
slimlock.cpp
)

set(common_srcs
cfg.cpp
image.cpp
log.cpp
panel.cpp
util.cpp
coord.cpp
)
if(USE_PAM)
set(slim_srcs ${slim_srcs} PAM.cpp)
set(common_srcs ${common_srcs} PAM.cpp)
# for now, only build slimlock if we are using PAM.
set(BUILD_SLIMLOCK 1)
endif(USE_PAM)

# Build common library
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")

if (BUILD_SHARED_LIBS)
message(STATUS "Enable shared library building")
add_library(libslim ${common_srcs})
else(BUILD_SHARED_LIBS)
message(STATUS "Disable shared library building")
add_library(libslim STATIC ${common_srcs})
endif(BUILD_SHARED_LIBS)

if(USE_CONSOLEKIT)
set(slim_srcs ${slim_srcs} Ck.cpp)
endif(USE_CONSOLEKIT)

add_executable(${PROJECT_NAME} ${slim_srcs})
if(BUILD_SLIMLOCK)
add_executable(slimlock ${slimlock_srcs})
endif(BUILD_SLIMLOCK)

#Set the custom CMake module directory where our include/lib finders are
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
Expand All @@ -91,6 +114,8 @@ if(USE_PAM)
message("\tPAM Found")
set(SLIM_DEFINITIONS ${SLIM_DEFINITIONS} "-DUSE_PAM")
target_link_libraries(${PROJECT_NAME} ${PAM_LIBRARY})
target_link_libraries(libslim ${PAM_LIBRARY})
target_link_libraries(slimlock ${PAM_LIBRARY})
include_directories(${PAM_INCLUDE_DIR})
else(PAM_FOUND)
message("\tPAM Not Found")
Expand Down Expand Up @@ -130,6 +155,7 @@ endif(USE_CONSOLEKIT)
find_library(M_LIB m)
find_library(RT_LIB rt)
find_library(CRYPTO_LIB crypt)
find_package(Threads)

add_definitions(${SLIM_DEFINITIONS})

Expand All @@ -138,33 +164,84 @@ include_directories(
${X11_INCLUDE_DIR}
${X11_Xft_INCLUDE_PATH}
${X11_Xrender_INCLUDE_PATH}
${X11_Xrandr_INCLUDE_PATH}
${FREETYPE_INCLUDE_DIRS}
${X11_Xmu_INCLUDE_PATH}
${ZLIB_INCLUDE_DIR}
${JPEG_INCLUDE_DIR}
${PNG_INCLUDE_DIR}
)

#Set up library with all found packages
target_link_libraries(libslim
${RT_LIB}
${X11_Xft_LIB}
${X11_Xrandr_LIB}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
)

#Set up library with all found packages for slim
target_link_libraries(${PROJECT_NAME}
${M_LIB}
${RT_LIB}
${CRYPTO_LIB}
${X11_X11_LIB}
${X11_Xft_LIB}
${X11_Xrender_LIB}
${X11_Xrandr_LIB}
${X11_Xmu_LIB}
${FREETYPE_LIBRARY}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
)
libslim
)

if(BUILD_SLIMLOCK)
#Set up library with all found packages for slimlock
target_link_libraries(slimlock
${M_LIB}
${RT_LIB}
${CRYPTO_LIB}
${X11_X11_LIB}
${X11_Xft_LIB}
${X11_Xrender_LIB}
${X11_Xrandr_LIB}
${X11_Xmu_LIB}
${X11_Xext_LIB}
${FREETYPE_LIBRARY}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
libslim
)
endif(BUILD_SLIMLOCK)

####### install
# slim
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin )
install(TARGETS slimlock RUNTIME DESTINATION bin)

if (BUILD_SHARED_LIBS)
set_target_properties(libslim PROPERTIES
OUTPUT_NAME slim
SOVERSION ${SLIM_VERSION})

install(TARGETS libslim
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
)
endif (BUILD_SHARED_LIBS)

# man file
install(FILES slim.1 DESTINATION ${MANDIR}/man1/)
# configure
install(FILES slim.conf DESTINATION ${SYSCONFDIR})

#slimlock
if(BUILD_SLIMLOCK)
install(TARGETS slimlock RUNTIME DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE SETUID)
install(FILES slimlock.1 DESTINATION ${MANDIR}/man1/)
endif(BUILD_SLIMLOCK)

# themes directory
subdirs(themes)
7 changes: 6 additions & 1 deletion app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ void App::Run() {
Scr = DefaultScreen(Dpy);
Root = RootWindow(Dpy, Scr);

// Intern _XROOTPMAP_ID property
BackgroundPixmapId = XInternAtom(Dpy, "_XROOTPMAP_ID", False);

// for tests we use a standard window
if (testing) {
Window RealRoot = RootWindow(Dpy, Scr);
Expand All @@ -313,7 +316,7 @@ void App::Run() {
HideCursor();

// Create panel
LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir);
LoginPanel = new Panel(Dpy, Scr, Root, cfg, themedir, Panel::Mode_DM);
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";
Expand Down Expand Up @@ -1092,6 +1095,8 @@ void App::setBackground(const string& themedir) {
}
Pixmap p = image->createPixmap(Dpy, Scr, Root);
XSetWindowBackgroundPixmap(Dpy, Root, p);
XChangeProperty(Dpy, Root, BackgroundPixmapId, XA_PIXMAP, 32,
PropModeReplace, (unsigned char *)&p, 1);
}
XClearWindow(Dpy, Root);

Expand Down
2 changes: 2 additions & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define _APP_H_

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -99,6 +100,7 @@ class App {

void blankScreen();
Image* image;
Atom BackgroundPixmapId;
void setBackground(const std::string& themedir);

bool firstlogin;
Expand Down
14 changes: 14 additions & 0 deletions cfg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SLiM - Simple Login Manager
Copyright (C) 2004-06 Simone Rota <[email protected]>
Copyright (C) 2004-06 Johannes Winkelmann <[email protected]>
Copyright (C) 2012-13 Nobuhiro Iwamatsu <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -120,6 +121,19 @@ Cfg::Cfg()
options.insert(option("session_shadow_yoffset", "0"));
options.insert(option("session_shadow_color","#FFFFFF"));

// slimlock-specific options
options.insert(option("dpms_standby_timeout", "60"));
options.insert(option("dpms_off_timeout", "600"));
options.insert(option("wrong_passwd_timeout", "2"));
options.insert(option("passwd_feedback_x", "50%"));
options.insert(option("passwd_feedback_y", "10%"));
options.insert(option("passwd_feedback_msg", "Authentication failed"));
options.insert(option("passwd_feedback_capslock", "Authentication failed (CapsLock is on)"));
options.insert(option("show_username", "1"));
options.insert(option("show_welcome_msg", "0"));
options.insert(option("tty_lock", "1"));
options.insert(option("bell", "1"));

error = "";

}
Expand Down
53 changes: 53 additions & 0 deletions image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,59 @@ void Image::Merge(Image* background, const int x, const int y) {

}

/* Merge the image with a background, taking care of the
* image Alpha transparency. (background alpha is ignored).
* The images is merged on position (x, y) on the
* background, the background must contain the image.
*/
#define IMG_POS_RGB(p, x) (3 * p + x)
void Image::Merge_non_crop(Image* background, const int x, const int y)
{
int bg_w = background->Width();
int bg_h = background->Height();

if (x + width > bg_w || y + height > bg_h)
return;

double tmp;
unsigned char *new_rgb = (unsigned char *)malloc(3 * bg_w * bg_h);
const unsigned char *bg_rgb = background->getRGBData();
int pnl_pos = 0;
int bg_pos = 0;
int pnl_w_end = x + width;
int pnl_h_end = y + height;

memcpy(new_rgb, bg_rgb, 3 * bg_w * bg_h);

for (int j = 0; j < bg_h; j++) {
for (int i = 0; i < bg_w; i++) {
if (j >= y && i >= x && j < pnl_h_end && i < pnl_w_end ) {
for (int k = 0; k < 3; k++) {
if (png_alpha != NULL)
tmp = rgb_data[IMG_POS_RGB(pnl_pos, k)]
* png_alpha[pnl_pos]/255.0
+ bg_rgb[IMG_POS_RGB(bg_pos, k)]
* (1 - png_alpha[pnl_pos]/255.0);
else
tmp = rgb_data[IMG_POS_RGB(pnl_pos, k)];

new_rgb[IMG_POS_RGB(bg_pos, k)] = static_cast<unsigned char>(tmp);
}
pnl_pos++;
}
bg_pos++;
}
}

width = bg_w;
height = bg_h;

free(rgb_data);
free(png_alpha);
rgb_data = new_rgb;
png_alpha = NULL;
}

/* Tile the image growing its size to the minimum entire
* multiple of w * h.
* The new dimensions should be > of the current ones.
Expand Down
1 change: 1 addition & 0 deletions image.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Image {
void Reduce(const int factor);
void Resize(const int w, const int h);
void Merge(Image* background, const int x, const int y);
void Merge_non_crop(Image* background, const int x, const int y);
void Crop(const int x, const int y, const int w, const int h);
void Tile(const int w, const int h);
void Center(const int w, const int h, const char *hex);
Expand Down
Loading

0 comments on commit c98f1f3

Please sign in to comment.