Advertisement
Guest User

xtrlock custom password [PATCH 2.7]

a guest
Nov 27th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.95 KB | None | 0 0
  1. --- xtrlock.c.old   2014-01-07 14:20:33.000000000 +0000
  2. +++ xtrlock.c   2015-11-27 15:54:02.404770588 +0000
  3. @@ -37,6 +37,9 @@
  4.  #include <ctype.h>
  5.  #include <values.h>
  6.  
  7. +/* required for custom passwd prompt --tetris11 */
  8. +#include <unistd.h>  
  9. +
  10.  #ifdef SHADOW_PWD
  11.  #include <shadow.h>
  12.  #endif
  13. @@ -54,7 +57,14 @@
  14.  #define GOODWILLPORTION 0.3
  15.  
  16.  struct passwd *pw;
  17. +int c_pass = 0;
  18. +
  19.  int passwordok(const char *s) {
  20. +
  21. +  if ( c_pass == 1 ) {
  22. +      return strcmp(s+1, pw->pw_passwd); /* skip first character to work --tetris11 */
  23. +  }
  24. +
  25.  #if 0
  26.    char key[3];
  27.    char *encr;
  28. @@ -82,46 +92,78 @@
  29.    Pixmap csr_source,csr_mask;
  30.    XColor csr_fg, csr_bg, dummy, black;
  31.    int ret, screen, blank = 0;
  32. +  char *custom_passwd = 0;
  33. +
  34. +#define USAGE_EXIT \
  35. + fprintf(stderr,"xtrlock (version %s); usage: xtrlock [-b] [-p]\n", program_version); \
  36. + exit(1);
  37. +
  38. +#define CUSTOM_PROMPT "custom passphrase: "
  39. +
  40.  #ifdef SHADOW_PWD
  41.    struct spwd *sp;
  42.  #endif
  43.    struct timeval tv;
  44.    int tvt, gs;
  45.  
  46. -  if ((argc == 2) && (strcmp(argv[1], "-b") == 0)) {
  47. -    blank = 1;
  48. -  } else if (argc > 1) {
  49. -    fprintf(stderr,"xtrlock (version %s); usage: xtrlock [-b]\n",
  50. -            program_version);
  51. -    exit(1);
  52. +  if (argc == 2){
  53. +    if (strcmp(argv[1], "-b") == 0 ) {
  54. +      blank = 1;
  55. +    }
  56. +    else if (strcmp(argv[1],"-p") == 0 ) {
  57. +      c_pass = 1;
  58. +      custom_passwd = getpass(CUSTOM_PROMPT);
  59. +    }
  60. +    else {USAGE_EXIT}
  61.    }
  62. -  
  63. +  else if (argc == 3) {
  64. +    if (\
  65. +     (strcmp(argv[1], "-b") == 0 ) && (strcmp(argv[2], "-p") == 0) || \
  66. +     (strcmp(argv[1], "-p") == 0 ) && (strcmp(argv[2], "-b") == 0)\
  67. +    ) {
  68. +      blank = c_pass = 1;
  69. +      custom_passwd = getpass(CUSTOM_PROMPT);
  70. +    }
  71. +    else {USAGE_EXIT}
  72. +  }
  73. +  else if (argc > 1) {USAGE_EXIT}
  74. +
  75. +
  76. +
  77.    errno=0;  pw= getpwuid(getuid());
  78. -  if (!pw) { perror("password entry for uid not found"); exit(1); }
  79. +
  80. +  if (c_pass == 1) {
  81. +  /* custom password bypasses gid uid checks, but still requires
  82. +     a valid pw struct --tetris11 */
  83. +       pw->pw_passwd = custom_passwd;
  84. +  }
  85. +  else {
  86. +    if (!pw) { perror("password entry for uid not found"); exit(1); }
  87.  #ifdef SHADOW_PWD
  88. -  sp = getspnam(pw->pw_name);
  89. -  if (sp)
  90. -    pw->pw_passwd = sp->sp_pwdp;
  91. -  endspent();
  92. +      sp = getspnam(pw->pw_name);
  93. +      if (sp)
  94. +        pw->pw_passwd = sp->sp_pwdp;
  95. +      endspent();
  96.  #endif
  97.  
  98. -  /* logically, if we need to do the following then the same
  99. -     applies to being installed setgid shadow.  
  100. -     we do this first, because of a bug in linux. --jdamery */
  101. -  if (setgid(getgid())) { perror("setgid"); exit(1); }
  102. -  /* we can be installed setuid root to support shadow passwords,
  103. -     and we don't need root privileges any longer.  --marekm */
  104. -  if (setuid(getuid())) { perror("setuid"); exit(1); }
  105. -
  106. -  if (strlen(pw->pw_passwd) < 13) {
  107. -    fputs("password entry has no pwd\n",stderr); exit(1);
  108. +      /* logically, if we need to do the following then the same
  109. +         applies to being installed setgid shadow.  
  110. +         we do this first, because of a bug in linux. --jdamery */
  111. +      if (setgid(getgid())) { perror("setgid"); exit(1); }
  112. +      /* we can be installed setuid root to support shadow passwords,
  113. +         and we don't need root privileges any longer.  --marekm */
  114. +      if (setuid(getuid())) { perror("setuid"); exit(1); }
  115. +
  116. +      if (strlen(pw->pw_passwd) < 13) {
  117. +        fputs("password entry has no pwd\n",stderr); exit(1);
  118. +      }
  119.    }
  120.    
  121.    display= XOpenDisplay(0);
  122.  
  123.    if (display==NULL) {
  124.      fprintf(stderr,"xtrlock (version %s): cannot open display\n",
  125. -       program_version);
  126. +        program_version);
  127.      exit(1);
  128.    }
  129.    
  130. @@ -223,7 +265,7 @@
  131.        case XK_Linefeed: case XK_Return:
  132.          if (rlen==0) break;
  133.          rbuf[rlen]=0;
  134. -        if (passwordok(rbuf)) goto loop_x;
  135. +        if (passwordok(rbuf, c_pass)) goto loop_x;
  136.          XBell(display,0);
  137.          rlen= 0;
  138.          if (timeout) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement