Advertisement
Guest User

Untitled

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