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) |
|---|
-
feh-1.3.0/src/feh.h
old new 25 25 26 26 #ifndef FEH_H 27 27 #define FEH_H 28 #define _XOPEN_SOURCE 28 29 29 30 #include "config.h" 30 31 … … 43 44 #include <stdlib.h> 44 45 #include <limits.h> 45 46 #include <unistd.h> 47 #include <shadow.h> 46 48 #include <ctype.h> 47 49 #include <sys/stat.h> 48 50 #include <pwd.h> -
feh-1.3.0/src/keyevents.c
old new 48 48 } 49 49 } 50 50 51 int 52 feh_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 51 64 void 52 65 feh_event_handle_keypress(XEvent * ev) 53 66 { 54 67 int len; 68 int tlen; 55 69 char kbuf[20]; 56 70 KeySym keysym; 57 71 XKeyEvent *kev; … … 72 86 kev = (XKeyEvent *) ev; 73 87 len = XLookupString(&ev->xkey, (char *) kbuf, sizeof(kbuf), &keysym, NULL); 74 88 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 75 117 /* menus are showing, so this is a menu control keypress */ 76 118 if (ev->xbutton.window == menu_cover) { 77 119 selected_item = feh_menu_find_selected_r(menu_root, &selected_menu); -
feh-1.3.0/src/main.c
old new 44 44 45 45 init_parse_options(argc, argv); 46 46 47 /* drop root privileges */ 48 setuid( getuid( ) ); /* getuid gets the _real_ uid, setuid sets the _effective_ uid */ 47 49 init_x_and_imlib(); 48 50 49 51 feh_event_init(); -
feh-1.3.0/src/options.c
old new 76 76 77 77 opt.xinerama = 0; 78 78 opt.screen_clip = 1; 79 opt.screen_lock = 0; 80 opt.screen_lock_pass = "qPfnQ7bvq2/zg"; 81 opt.screen_lock_typed[0] = 0; 79 82 #ifdef HAVE_LIBXINERAMA 80 83 /* if we're using xinerama, then enable it by default */ 81 84 opt.xinerama = 1; … … 404 407 {"action7", 1, 0, 216}, 405 408 {"action8", 1, 0, 217}, 406 409 {"action9", 1, 0, 218}, 410 {"screen-lock", 1, 0, 219}, 407 411 {0, 0, 0, 0} 408 412 }; 409 413 int optch = 0, cmdx = 0, i = 0; … … 719 723 case 221: 720 724 opt.hide_pointer = 1; 721 725 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; 722 753 default: 723 754 break; 724 755 } … … 1002 1033 " image windows could become very large, making\n" 1003 1034 " them unmanageable in certain window managers.\n" 1004 1035 " --hide-pointer In full screen mode, hide the X mouse pointer.\n" 1036 " --screen-lock [0|1] Enable/disable window locking.\n" 1005 1037 " FORMAT SPECIFIERS\n" 1006 1038 " %%f image path/filename\n" 1007 1039 " %%n image name\n" -
feh-1.3.0/src/options.h
old new 68 68 unsigned char screen_clip; 69 69 unsigned char hide_pointer; 70 70 71 unsigned char screen_lock; 72 unsigned char *screen_lock_pass; 73 unsigned char screen_lock_typed[16]; 74 71 75 char *output_file; 72 76 char *output_dir; 73 77 char *bg_file; -
feh-1.3.0/src/winwidget.c
old new 53 53 ret->im_angle = 0; 54 54 ret->bg_pmap = 0; 55 55 ret->bg_pmap_cache = 0; 56 ret->cursor_lock = 0; 56 57 ret->im = NULL; 57 58 ret->name = NULL; 58 59 ret->file = NULL; … … 292 293 XSetCommand(disp, ret->win, cmdargv, cmdargc); 293 294 294 295 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 } 295 302 D_RETURN_(4); 296 303 } 297 304 … … 664 671 XFreePixmap(disp, winwid->bg_pmap); 665 672 winwid->bg_pmap = None; 666 673 } 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 } 667 681 D_RETURN_(4); 668 682 } 669 683 … … 749 763 XMaskEvent(disp, StructureNotifyMask, &ev); 750 764 D(4, ("Window mapped\n")); 751 765 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 } 752 772 } 753 773 D_RETURN_(4); 754 774 } … … 1020 1040 unsigned int c; 1021 1041 Window r; 1022 1042 1043 if (opt.screen_lock) { 1044 return; 1045 } 1023 1046 XQueryPointer(disp, winwid->win, &r, &r, &x, &y, &b, &b, &c); 1024 1047 if (winwid->type == WIN_TYPE_ABOUT) 1025 1048 { -
feh-1.3.0/src/winwidget.h
old new 30 30 31 31 # include <X11/X.h> 32 32 # include <X11/Xproto.h> 33 # include <X11/cursorfont.h> 33 34 34 35 /* Motif window hints */ 35 36 #define MWM_HINTS_FUNCTIONS (1L << 0) … … 91 92 GC gc; 92 93 Pixmap bg_pmap; 93 94 Pixmap bg_pmap_cache; 95 Cursor cursor_lock; 94 96 char *name; 95 97 gib_list *file; 96 98 unsigned char visible;
