Ticket #2: feh-1.2.6-an-screenlock.patch

File feh-1.2.6-an-screenlock.patch, 8.4 kB (added by giblet, 3 years ago)

second version of anti's patch (system passwords but must setuid feh)

  • feh-1.2.6/src/Makefile.am

    old new  
    1616utils.c utils.h keyevents.c timers.c timers.h list.c collage.c debug.h \ 
    1717events.c events.h support.c support.h \ 
    1818thumbnail.c thumbnail.h ipc.c ipc.h 
    19 feh_LDADD         = -lX11 @IMLIB_LIBS@ @GIBLIB_LIBS@ 
     19feh_LDADD         = -lX11 @IMLIB_LIBS@ @GIBLIB_LIBS@ -lcrypt 
    2020 
    2121images_DATA = about.png menubg_default.png menubg_sky.png \ 
    2222menubg_chrome.png menubg_brushed.png \ 
  • feh-1.2.6/src/feh.h

    old new  
    5757#include <sys/wait.h> 
    5858#include <math.h> 
    5959 
     60 
     61#define _XOPEN_SOURCE 
     62#include <unistd.h> 
     63#include <shadow.h> 
     64 
     65 
    6066#include <Imlib2.h> 
    6167#include <giblib/giblib.h> 
    6268 
  • feh-1.2.6/src/keyevents.c

    old new  
    2929#include "winwidget.h" 
    3030#include "options.h" 
    3131 
     32int 
     33feh_check_passwd( char* pass ) 
     34{ 
     35        char            *cpass = NULL; 
     36         
     37        cpass = crypt( pass, opt.screen_lock_pass ); 
     38//      printf( "DEBUG: Crypted password: %s\n", cpass ); 
     39        if( !strcmp( opt.screen_lock_pass, cpass ) ){ 
     40                return( 1 ); 
     41        } 
     42        return( 0 ); 
     43} 
     44 
    3245void 
    3346feh_event_handle_keypress(XEvent * ev) 
    3447{ 
    3548   int len; 
     49   int tlen; 
    3650   char kbuf[20]; 
    3751   KeySym keysym; 
    3852   XKeyEvent *kev; 
     
    5367   kev = (XKeyEvent *) ev; 
    5468   len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); 
    5569 
     70   if (opt.screen_lock){ 
     71        /* for testing / 
     72        if( keysym == XK_Escape ){ 
     73                winwidget_destroy_all(); 
     74        } 
     75        /* end testing */ 
     76        if( keysym == XK_Return ){ 
     77                if( feh_check_passwd( opt.screen_lock_typed ) ){ 
     78//              if( !strcmp (opt.screen_lock_pass, opt.screen_lock_typed) ) { 
     79                        winwidget_destroy_all(); 
     80                } else { 
     81                        opt.screen_lock_typed[ 0 ] = 0; 
     82                } 
     83                D_RETURN_(4); 
     84        } 
     85            
     86        /* capture keys for password comparison */ 
     87        tlen=strlen(opt.screen_lock_typed); 
     88        if( tlen<15 ){ 
     89                if( isascii( kbuf[0] ) ){ 
     90                        opt.screen_lock_typed[ tlen ] = kbuf[0]; 
     91                        opt.screen_lock_typed[ tlen+1 ] = 0; 
     92                        //         printf( "Key so far: >>%s<<\n", opt.screen_lock_typed ); 
     93                } 
     94        }   
     95        D_RETURN_(4); 
     96   } 
     97    
    5698   /* menus are showing, so this is a menu control keypress */ 
    5799   if (ev->xbutton.window == menu_cover) { 
    58100     selected_item = feh_menu_find_selected_r(menu_root, &selected_menu); 
     
    160202     D_RETURN_(4); 
    161203   } 
    162204    
    163     
     205 
    164206   switch (keysym) 
    165207   { 
    166208     case XK_Left: 
  • feh-1.2.6/src/main.c

    old new  
    4343 
    4444   init_parse_options(argc, argv); 
    4545 
     46        /* drop root privileges */ 
     47        setuid( getuid( ) );    /* getuid gets the _real_ uid, setuid sets the _effective_ uid */ 
    4648   init_x_and_imlib(); 
    4749 
    4850   feh_event_init(); 
  • feh-1.2.6/src/options.c

    old new  
    7676 
    7777   opt.xinerama = 0; 
    7878   opt.screen_clip = 1; 
     79   opt.screen_lock = 0; 
     80   opt.screen_lock_pass = "qPfnQ7bvq2/zg"; 
     81   opt.screen_lock_typed[0] = 0; 
    7982#ifdef HAVE_LIBXINERAMA 
    8083   /* if we're using xinerama, then enable it by default */ 
    8184   opt.xinerama = 1; 
     
    393396      {"menu-border", 1, 0, 208}, 
    394397      {"caption-path", 1, 0, 209}, 
    395398      {"no-jump-on-resort",0,0,210}, 
     399      {"screen-lock", 1, 0, 211},       /* CHECK: assign a different number ? */ 
    396400      {0, 0, 0, 0} 
    397401   }; 
    398402   int optch = 0, cmdx = 0, i = 0; 
     
    679683        case 210: 
    680684           opt.no_jump_on_resort = 1; 
    681685           break; 
     686        case 211: 
     687           opt.screen_lock = atoi(optarg); 
     688                if( opt.screen_lock ){ 
     689                        char            *username = NULL; 
     690                        struct passwd   *pwd = NULL; 
     691                        struct spwd     *pwds = NULL; 
     692                                 
     693                        /* get the username */ 
     694                        username = getenv( "LOGNAME" ); 
     695                        /* get the passwd entry */ 
     696                        pwd = getpwnam( username ); 
     697                        if( !strcmp( pwd->pw_passwd, "x" ) ){ 
     698                                /* system uses shadow passwd */ 
     699                                pwds = getspnam( username ); 
     700                                if( !pwds ){ 
     701                                        /* can't access shadow passwords :( */ 
     702                                        printf( "On systems with shadow passwd, feh needs to be set uid root.\n" ); 
     703                                        /* allow exit without passwd check to keep user from locking himself out of the system */ 
     704                                        exit( 1 ); 
     705                                } 
     706                                opt.screen_lock_pass = pwds->sp_pwdp; 
     707                        }else{ 
     708                                opt.screen_lock_pass = pwd->pw_passwd; 
     709                        } 
     710                         
     711                } 
     712           break; 
    682713        default: 
    683714           break; 
    684715      } 
     
    958989           "                            size.  WARNING: with this option disabled,\n" 
    959990           "                            image windows could become very large, making\n" 
    960991           "                            them unmanageable in certain window managers.\n." 
     992           "      --screen-lock [0|1]   Enable/disable window locking.\n" 
    961993           " FORMAT SPECIFIERS\n" 
    962994           "                            %%f image path/filename\n" 
    963995           "                            %%n image name\n" 
  • feh-1.2.6/src/options.h

    old new  
    6666   unsigned char bgmode; 
    6767   unsigned char xinerama; 
    6868   unsigned char screen_clip; 
     69   unsigned char screen_lock; 
     70   unsigned char *screen_lock_pass; 
     71   unsigned char screen_lock_typed[16]; 
    6972 
    7073   char *output_file; 
    7174   char *output_dir; 
  • feh-1.2.6/src/winwidget.c

    old new  
    5252  ret->im_angle = 0; 
    5353  ret->bg_pmap = 0; 
    5454  ret->bg_pmap_cache = 0; 
     55  ret->cursor_lock = 0; 
    5556  ret->im = NULL; 
    5657  ret->name = NULL; 
    5758  ret->file = NULL; 
     
    261262  XSetCommand(disp, ret->win, cmdargv, cmdargc); 
    262263 
    263264  winwidget_register(ret); 
     265 
     266  if (opt.screen_lock){ 
     267    /* create the cursor used for locking */ 
     268    ret->cursor_lock = XCreateFontCursor(disp, XC_circle);      /* PLAN: use a user supplied icon or hide the cursor */ 
     269    XDefineCursor(disp, ret->win, ret->cursor_lock); 
     270  } 
    264271  D_RETURN_(4); 
    265272} 
    266273 
     
    634641    XFreePixmap(disp, winwid->bg_pmap); 
    635642    winwid->bg_pmap = None; 
    636643  } 
     644  if (opt.screen_lock){ 
     645    XUngrabPointer(disp, CurrentTime ); 
     646    XUngrabKeyboard(disp, CurrentTime ); 
     647  } 
     648  if (winwid->cursor_lock) { 
     649    XFreeCursor(disp, winwid->cursor_lock); 
     650  } 
    637651  D_RETURN_(4); 
    638652} 
    639653 
     
    719733    XMaskEvent(disp, StructureNotifyMask, &ev); 
    720734    D(4, ("Window mapped\n")); 
    721735    winwid->visible = 1; 
     736    if (opt.screen_lock){ 
     737      /* grab the pointer */ 
     738      XGrabPointer(disp, winwid->win, False, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, winwid->win, winwid->cursor_lock, CurrentTime ); 
     739      /* grab the keyboard */ 
     740      XGrabKeyboard(disp, winwid->win, False, GrabModeAsync, GrabModeAsync, CurrentTime ); 
     741    } 
    722742  } 
    723743  D_RETURN_(4); 
    724744} 
     
    9901010  unsigned int c; 
    9911011  Window r; 
    9921012 
     1013  if (opt.screen_lock) { 
     1014        return; 
     1015  } 
    9931016  XQueryPointer(disp, winwid->win, &r, &r, &x, &y, &b, &b, &c); 
    9941017  if (winwid->type == WIN_TYPE_ABOUT) 
    9951018  { 
  • feh-1.2.6/src/winwidget.h

    old new  
    3030 
    3131# include <X11/X.h> 
    3232# include <X11/Xproto.h> 
     33# include <X11/cursorfont.h> 
    3334 
    3435/* Motif window hints */ 
    3536#define MWM_HINTS_FUNCTIONS     (1L << 0) 
     
    9192   GC gc; 
    9293   Pixmap bg_pmap; 
    9394   Pixmap bg_pmap_cache; 
     95   Cursor       cursor_lock; 
    9496   char *name; 
    9597   gib_list *file; 
    9698   unsigned char visible;