Changeset 55417bb in freewrt
- Timestamp:
- Jun 28, 2007, 7:48:27 PM (18 years ago)
- Children:
- 116879b
- Parents:
- 5986dbb
- Location:
- package/fwwif/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
package/fwwif/src/Makefile
r5986dbb r55417bb 30 30 chpw.o c_chpw.o: c_chpw.h common.h 31 31 md5.o md5hl.o: md5.h common.h 32 md5crypt.o pwd_gensalt.o : md5crypt.h md5.h common.h32 md5crypt.o pwd_gensalt.o c_chpw.o: md5crypt.h md5.h common.h 33 33 34 34 md5hl.c: helper.c -
package/fwwif/src/c_chpw.c
r5986dbb r55417bb 23 23 */ 24 24 25 #define _GNU_SOURCE 25 26 #include "common.h" 27 #include <errno.h> 26 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <string.h> 31 #include <unistd.h> 27 32 #include "c_chpw.h" 33 #include "md5crypt.h" 28 34 29 35 int 30 36 c_chpw(const char *oldpw, const char *newpw) 31 37 { 32 fprintf(stdout, "test: oldpw=<%s>\n", oldpw); 33 fprintf(stderr, "test: newpw=<%s>\n", newpw); 34 return (1); 38 FILE *fi, *fo; 39 char *lp, *cp, *rootline = NULL, *adminline = NULL, *ap; 40 char salt[16]; 41 size_t n; 42 int rv = 1; 43 44 if ((fi = fopen("/etc/passwd", "rb")) == NULL) { 45 printf("Error opening /etc/passwd for reading: %s\n", 46 strerror(errno)); 47 return (1); 48 } 49 if ((fo = fopen("/etc/passwd.new", "wb")) == NULL) { 50 printf("Error opening /etc/passwd.new for writing: %s\n", 51 strerror(errno)); 52 fclose(fi); 53 return (1); 54 } 55 56 lp = NULL; 57 while (getline(&lp, &n, fi) > 0) { 58 if ((cp = strchr(lp, '\n'))) 59 *cp = '\0'; 60 if (!strncmp(lp, "root:", 5)) { 61 if (rootline == NULL) 62 rootline = strdup(lp); 63 } else if (!strncmp(lp, "admin:", 6)) { 64 if (adminline == NULL) 65 adminline = strdup(lp); 66 } else 67 fprintf(fo, "%s\n", lp); 68 } 69 if (lp) 70 free(lp); 71 lp = NULL; 72 73 if (rootline == NULL) { 74 printf("No root account found!\n"); 75 goto out; 76 } 77 lp = rootline + /* "root:" */ 5; 78 cp = strchr(lp, ':'); 79 if (cp == NULL) { 80 printf("No root password found!\n"); 81 goto out; 82 } 83 *cp++ = '\0'; 84 rootline = cp; 85 86 /* lp = root password */ 87 cp = md5crypt(oldpw, lp); 88 if (strcmp(cp, lp)) { 89 printf("root pw mismatch: '%s' != '%s'\n", cp, lp); 90 goto out; 91 } 92 93 /* we are authenticated, now change root and admin password */ 94 if (!pwd_gensalt(salt, sizeof (salt))) 95 strlcpy(salt, lp, sizeof (salt)); 96 cp = md5crypt(newpw, salt); 97 fprintf(fo, "root:%s:%s\n", cp, rootline); 98 if (adminline) 99 if ((ap = strchr(adminline + /* admin: */ 6, ':')) == NULL) { 100 free(adminline); 101 adminline = NULL; 102 } 103 fprintf(fo, "admin:%s:%s\n", cp, adminline ? ap + 1 : 104 "100:100:admin:/tmp:/bin/sh"); 105 106 if (fclose(fo)) { 107 printf("Error closing new password file: %s\n", 108 strerror(errno)); 109 goto out; 110 } 111 fo = NULL; 112 fclose(fi); 113 fi = NULL; 114 if (rename("/etc/passwd", "/etc/passwd.old")) { 115 printf("Error renaming old password file: %s\n", 116 strerror(errno)); 117 goto out; 118 } 119 if (rename("/etc/passwd.new", "/etc/passwd")) { 120 printf("Error renaming new password file: %s\n", 121 strerror(errno)); 122 rename("/etc/passwd.old", "/etc/passwd"); 123 goto out; 124 } 125 rv = 0; 126 127 out: 128 if (adminline) 129 free(adminline); 130 if (lp) 131 free(lp - /* "root:" */ 5); 132 if (fo) { 133 fclose(fo); 134 unlink("/etc/passwd.new"); 135 } 136 if (fi) 137 fclose(fi); 138 139 return (rv); 35 140 } -
package/fwwif/src/chpw.ecpp
r5986dbb r55417bb 40 40 </%cpp> 41 41 <h1>Change Password</h1> 42 <p>You can change the password for your FreeWRT box here. The old password 43 you must enter has to match against the current root password. The new 44 passwords must match each other and will set the new passwords for the 45 root user, the admin user <!-- and the web interface --> to their value.</p> 42 46 <%cpp> 43 47 } else if (newpw1 != newpw2) { … … 55 59 if (i) { 56 60 </%cpp> 57 <form action="/chpw.htm" method=" get">61 <form action="/chpw.htm" method="post"> 58 62 <table> 59 63 <tr>
Note:
See TracChangeset
for help on using the changeset viewer.
