Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // gcc -Wall -lcrypt -o p p.c
- // su && chown root p && chmod u+s p
- #define _XOPEN_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <strings.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <pwd.h>
- #include <shadow.h>
- #define BUFFSIZE 1024
- void strip(char *inptstri)
- {
- int tempsize;
- tempsize = strlen(inptstri);
- if (tempsize > 0)
- {
- inptstri[tempsize - 1] = '\0';
- }
- }
- int main(int argc, char **argv)
- {
- char username[BUFFSIZE], password[BUFFSIZE];
- char datepref[BUFFSIZE], datetime[BUFFSIZE];
- char *cryppass;
- struct spwd *passdata;
- printf("Username: ");
- bzero(username, BUFFSIZE * sizeof(char));
- fgets(username, BUFFSIZE - 1, stdin);
- strip(username);
- printf("Password: ");
- bzero(password, BUFFSIZE * sizeof(char));
- fgets(password, BUFFSIZE - 1, stdin);
- strip(password);
- if ((passdata = getspnam(username)) == NULL)
- {
- printf("Invalid login!\n");
- return 1;
- }
- cryppass = crypt(password, passdata->sp_pwdp);
- if (strcmp(cryppass, passdata->sp_pwdp) != 0)
- {
- printf("Invalid login!\n");
- return 2;
- }
- printf("Set time [hh:mm]: ");
- bzero(datetime, BUFFSIZE * sizeof(char));
- fgets(datetime, BUFFSIZE - 1, stdin);
- strip(datetime);
- bzero(datepref, BUFFSIZE * sizeof(char));
- strncpy(datepref, "date '+%H:%M' --set='", BUFFSIZE - 1);
- strncat(datepref, datetime, BUFFSIZE - 1);
- strncat(datepref, "'", BUFFSIZE - 1);
- system(datepref);
- system("date");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement