Advertisement
Guest User

xtrlock custom password [PATCH 2.7]

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