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

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

updated version of anti's patch for feh 1.3.0...

  • feh-1.3.0/src/feh.h

    old new  
    2525 
    2626#ifndef FEH_H 
    2727#define FEH_H 
     28#define _XOPEN_SOURCE 
    2829 
    2930#include "config.h" 
    3031 
     
    4344#include <stdlib.h> 
    4445#include <limits.h> 
    4546#include <unistd.h> 
     47#include <shadow.h> 
    4648#include <ctype.h> 
    4749#include <sys/stat.h> 
    4850#include <pwd.h> 
  • feh-1.3.0/src/keyevents.c

    old new  
    4848  } 
    4949} 
    5050 
     51int 
     52feh_check_passwd( char* pass ) 
     53{ 
     54        char            *cpass = NULL; 
     55         
     56        cpass = crypt( pass, opt.screen_lock_pass ); 
     57//      printf( "DEBUG: Crypted password: %s\n", cpass ); 
     58        if( !strcmp( opt.screen_lock_pass, cpass ) ){ 
     59                return( 1 ); 
     60        } 
     61        return( 0 ); 
     62} 
     63 
    5164void 
    5265feh_event_handle_keypress(XEvent * ev) 
    5366{ 
    5467   int len; 
     68   int tlen; 
    5569   char kbuf[20]; 
    5670   KeySym keysym; 
    5771   XKeyEvent *kev; 
     
    7286   kev = (XKeyEvent *) ev; 
    7387   len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); 
    7488 
     89   if (opt.screen_lock){ 
     90        /* for testing / 
     91        if( keysym == XK_Escape ){ 
     92                winwidget_destroy_all(); 
     93        } 
     94        /* end testing */ 
     95        if( keysym == XK_Return ){ 
     96                if( feh_check_passwd( opt.screen_lock_typed ) ){ 
     97//              if( !strcmp (opt.screen_lock_pass, opt.screen_lock_typed) ) { 
     98                        winwidget_destroy_all(); 
     99                } else { 
     100                        opt.screen_lock_typed[ 0 ] = 0; 
     101                } 
     102                D_RETURN_(4); 
     103        } 
     104            
     105        /* capture keys for password comparison */ 
     106        tlen=strlen(opt.screen_lock_typed); 
     107        if( tlen<15 ){ 
     108                if( isascii( kbuf[0] ) ){ 
     109                        opt.screen_lock_typed[ tlen ] = kbuf[0]; 
     110                        opt.screen_lock_typed[ tlen+1 ] = 0; 
     111                        //         printf( "Key so far: >>%s<<\n", opt.screen_lock_typed ); 
     112                } 
     113        }   
     114        D_RETURN_(4); 
     115   } 
     116    
    75117   /* menus are showing, so this is a menu control keypress */ 
    76118   if (ev->xbutton.window == menu_cover) { 
    77119     selected_item = feh_menu_find_selected_r(menu_root, &selected_menu); 
  • feh-1.3.0/src/main.c

    old new  
    4444 
    4545   init_parse_options(argc, argv); 
    4646 
     47        /* drop root privileges */ 
     48        setuid( getuid( ) );    /* getuid gets the _real_ uid, setuid sets the _effective_ uid */ 
    4749   init_x_and_imlib(); 
    4850 
    4951   feh_event_init(); 
  • feh-1.3.0/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; 
     
    404407      {"action7", 1, 0, 216}, 
    405408      {"action8", 1, 0, 217}, 
    406409      {"action9", 1, 0, 218}, 
     410      {"screen-lock", 1, 0, 219}, 
    407411      {0, 0, 0, 0} 
    408412   }; 
    409413   int optch = 0, cmdx = 0, i = 0; 
     
    719723        case 221: 
    720724           opt.hide_pointer = 1; 
    721725           break; 
     726        case 219: 
     727           opt.screen_lock = atoi(optarg); 
     728                if( opt.screen_lock ){ 
     729                        char            *username = NULL; 
     730                        struct passwd   *pwd = NULL; 
     731                        struct spwd     *pwds = NULL; 
     732                                 
     733                        /* get the username */ 
     734                        username = getenv( "LOGNAME" ); 
     735                        /* get the passwd entry */ 
     736                        pwd = getpwnam( username ); 
     737                        if( !strcmp( pwd->pw_passwd, "x" ) ){ 
     738                                /* system uses shadow passwd */ 
     739                                pwds = getspnam( username ); 
     740                                if( !pwds ){ 
     741                                        /* can't access shadow passwords :( */ 
     742                                        printf( "On systems with shadow passwd, feh needs to be set uid root.\n" ); 
     743                                        /* allow exit without passwd check to keep user from locking himself out of the system */ 
     744                                        exit( 1 ); 
     745                                } 
     746                                opt.screen_lock_pass = pwds->sp_pwdp; 
     747                        }else{ 
     748                                opt.screen_lock_pass = pwd->pw_passwd; 
     749                        } 
     750                         
     751                } 
     752           break; 
    722753        default: 
    723754           break; 
    724755      } 
     
    10021033"                           image windows could become very large, making\n" 
    10031034"                           them unmanageable in certain window managers.\n" 
    10041035"     --hide-pointer        In full screen mode, hide the X mouse pointer.\n" 
     1036"      --screen-lock [0|1]   Enable/disable window locking.\n" 
    10051037" FORMAT SPECIFIERS\n" 
    10061038"                           %%f image path/filename\n" 
    10071039"                           %%n image name\n" 
  • feh-1.3.0/src/options.h

    old new  
    6868   unsigned char screen_clip; 
    6969   unsigned char hide_pointer; 
    7070 
     71   unsigned char screen_lock; 
     72   unsigned char *screen_lock_pass; 
     73   unsigned char screen_lock_typed[16]; 
     74 
    7175   char *output_file; 
    7276   char *output_dir; 
    7377   char *bg_file; 
  • feh-1.3.0/src/winwidget.c

    old new  
    5353  ret->im_angle = 0; 
    5454  ret->bg_pmap = 0; 
    5555  ret->bg_pmap_cache = 0; 
     56  ret->cursor_lock = 0; 
    5657  ret->im = NULL; 
    5758  ret->name = NULL; 
    5859  ret->file = NULL; 
     
    292293  XSetCommand(disp, ret->win, cmdargv, cmdargc); 
    293294 
    294295  winwidget_register(ret); 
     296 
     297  if (opt.screen_lock && !opt.hide_pointer){ 
     298    /* create the cursor used for locking */ 
     299    ret->cursor_lock = XCreateFontCursor(disp, XC_circle);      /* PLAN: use a user supplied icon or hide the cursor */ 
     300    XDefineCursor(disp, ret->win, ret->cursor_lock); 
     301  } 
    295302  D_RETURN_(4); 
    296303} 
    297304 
     
    664671    XFreePixmap(disp, winwid->bg_pmap); 
    665672    winwid->bg_pmap = None; 
    666673  } 
     674  if (opt.screen_lock){ 
     675    XUngrabPointer(disp, CurrentTime ); 
     676    XUngrabKeyboard(disp, CurrentTime ); 
     677  } 
     678  if (winwid->cursor_lock) { 
     679    XFreeCursor(disp, winwid->cursor_lock); 
     680  } 
    667681  D_RETURN_(4); 
    668682} 
    669683 
     
    749763    XMaskEvent(disp, StructureNotifyMask, &ev); 
    750764    D(4, ("Window mapped\n")); 
    751765    winwid->visible = 1; 
     766    if (opt.screen_lock){ 
     767      /* grab the pointer */ 
     768      XGrabPointer(disp, winwid->win, False, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, winwid->win, winwid->cursor_lock, CurrentTime ); 
     769      /* grab the keyboard */ 
     770      XGrabKeyboard(disp, winwid->win, False, GrabModeAsync, GrabModeAsync, CurrentTime ); 
     771    } 
    752772  } 
    753773  D_RETURN_(4); 
    754774} 
     
    10201040  unsigned int c; 
    10211041  Window r; 
    10221042 
     1043  if (opt.screen_lock) { 
     1044        return; 
     1045  } 
    10231046  XQueryPointer(disp, winwid->win, &r, &r, &x, &y, &b, &b, &c); 
    10241047  if (winwid->type == WIN_TYPE_ABOUT) 
    10251048  { 
  • feh-1.3.0/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;