![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Edit/update an /etc/group database entry (c/c++) | mekos | UNIX and Linux Applications | 1 | 06-02-2008 04:10 PM |
| Interpreting the encrypted shadow password? | keelba | Linux | 5 | 03-12-2008 05:13 PM |
| shadow file after a password reset | progressdll | UNIX for Dummies Questions & Answers | 0 | 10-31-2007 01:18 AM |
| I want to append password in /etc/shadow file | modgil | Shell Programming and Scripting | 5 | 03-21-2006 08:08 PM |
| remove shadow password | gizaa | UNIX for Dummies Questions & Answers | 2 | 08-03-2004 04:30 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
/etc/shadow update password entry! ( getspent? )
Hi i just whant to update an password entry in /etc/shadow.
But dosen't get it to work. Something is wrong! in this code. What i try do do is if user kalle exist in shadow. I whant it to update it's password for just that entry. #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> #include <pwd.h> #include <grp.h> #include <string.h> #include <shadow.h> //#include <userpw.h> int main() { // -------------------------- // // ------- passwd file ------ // // -------------------------- // FILE* fp; struct passwd *p; memset(&p, 0, sizeof(p)); if (!(fp = fopen("/etc/passwd", "a"))) { perror("Problem "); return(1); } // --------------------------- // // ----- Password Crypt ------ // // --------------------------- // char salt[2]; char password[8] = "password"; char t[11]; salt[0] = 'W'; salt[1] = 'M'; strcpy(t,(char *)crypt(password, salt)); // --------------------------- // // ------ shadow file -------- // // --------------------------- // FILE* fps; struct spwd *sp; memset(&sp, 0, sizeof(sp)); if (!(fps = fopen("/etc/shadow", "rw"))) { perror("Problem"); return(1); } char user[20] = "kalle"; /* Loop thru passwd file */ while ((p = getpwent()) != NULL) { printf("%s\n",p->pw_name); //IF user found if (strcmp(p->pw_name, user) == 0 ) { if(!(sp=getspnam(p->pw_name))){ printf("user missing in shadow file"); } else { strcpy(sp->sp_pwdp,t); prinf("run the train %s\n",sp->sp_pwdp); putspent(sp,fps); } } } fclose(fps); return( EXIT_SUCCESS ); } |
| Forum Sponsor | ||
|
|
|
|||
|
Now i got a bit thurder. But have a differnet problem.
In end of the shadow file it writes "GjgGToqZ1:14063:0:99999:7:" dont understand why! #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> #include <pwd.h> #include <grp.h> #include <string.h> #include <shadow.h> //#include <userpw.h> int main() { // -------------------------- // // ------- passwd file ------ // // -------------------------- // FILE* fp; struct passwd *p; memset(&p, 0, sizeof(p)); if (!(fp = fopen("/etc/passwd", "r"))) { perror("Problem "); return(1); } // --------------------------- // // ------ shadow file -------- // // --------------------------- // FILE* fps; struct spwd *sp; //char currpass[255]; memset(&sp, 0, sizeof(sp)); //memset(&currpass, 0, sizeof(currpass)); if (!(fps = fopen("/etc/shadow", "r+"))) { perror("Problem"); return(1); } char user[20] = "kalle"; //strcpy(sp->sp_pwdp,t); //char password[10] = "password"; /* Loop thru passwd file */ while ((sp = getspent()) != NULL) { if (strcmp(sp->sp_namp,user) == 0 ) { //if(!(sp=getspnam(sp->sp_namp))) { // printf("that user does not exist in shadow file\n"); //} else { strcpy(sp->sp_pwdp,"testpass"); putspent(sp, fps); } else { //strcpy(sp->sp_pwdp,"temp"); putspent(sp,fps); } } fclose(fp); fclose(fps); return( EXIT_SUCCESS ); } exit(0); |