Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // gcc -Wall -lcrypt -o p p.c
  2. // su && chown root p && chmod u+s p
  3.  
  4. #define _XOPEN_SOURCE
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <strings.h>
  9. #include <unistd.h>
  10.  
  11. #include <sys/types.h>
  12. #include <pwd.h>
  13. #include <shadow.h>
  14.  
  15. #define BUFFSIZE 1024
  16.  
  17. void strip(char *inptstri)
  18. {
  19. int tempsize;
  20.  
  21. tempsize = strlen(inptstri);
  22.  
  23. if (tempsize > 0)
  24. {
  25. inptstri[tempsize - 1] = '\0';
  26. }
  27. }
  28.  
  29. int main(int argc, char **argv)
  30. {
  31. char username[BUFFSIZE], password[BUFFSIZE];
  32. char datepref[BUFFSIZE], datetime[BUFFSIZE];
  33. char *cryppass;
  34. struct spwd *passdata;
  35.  
  36. printf("Username: ");
  37. bzero(username, BUFFSIZE * sizeof(char));
  38. fgets(username, BUFFSIZE - 1, stdin);
  39. strip(username);
  40.  
  41. printf("Password: ");
  42. bzero(password, BUFFSIZE * sizeof(char));
  43. fgets(password, BUFFSIZE - 1, stdin);
  44. strip(password);
  45.  
  46. if ((passdata = getspnam(username)) == NULL)
  47. {
  48. printf("Invalid login!\n");
  49. return 1;
  50. }
  51.  
  52. cryppass = crypt(password, passdata->sp_pwdp);
  53.  
  54. if (strcmp(cryppass, passdata->sp_pwdp) != 0)
  55. {
  56. printf("Invalid login!\n");
  57. return 2;
  58. }
  59.  
  60. printf("Set time [hh:mm]: ");
  61. bzero(datetime, BUFFSIZE * sizeof(char));
  62. fgets(datetime, BUFFSIZE - 1, stdin);
  63. strip(datetime);
  64.  
  65. bzero(datetime, BUFFSIZE * sizeof(char));
  66. strncpy(datepref, "date '+%H:%M' --set='", BUFFSIZE - 1);
  67. strncat(datepref, datetime, BUFFSIZE - 1);
  68. strncat(datepref, "'", BUFFSIZE - 1);
  69.  
  70. system(datetime);
  71. system("date");
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement