3 * This file is part of httpd.
5 * 07/07/1996 Initial Release Michael Temari <Michael@TemWare.Com>
6 * 12/29/2002 Michael Temari <Michael@TemWare.Com>
18 #include <minix/minlib.h>
21 #define STD_PASSWD_FILE "/etc/passwd"
25 static char buffer
[1024];
30 _PROTOTYPE(static int getuser
, (char *pwdfile
, char *user
));
32 static int getuser(pwdfile
, user
)
40 if((fp
= fopen(pwdfile
, "r")) == (FILE *)NULL
)
43 for(i
= 0; i
< 4; i
++) pwde
[i
] = "";
46 if(fgets(buffer
, sizeof(buffer
), fp
) == (char *)NULL
) {
52 while(*p
&& *p
!= ':') p
++;
53 if(*p
!= ':') continue;
55 if(strcmp(pwduser
, user
)) continue;
57 while(*p
&& *p
!= ':' && *p
!= '\r' && *p
!= '\n') p
++;
64 for(i
= 0; i
< 4; i
++) {
66 while(*p
&& *p
!= ':' && *p
!= '\r' && *p
!= '\n') p
++;
85 if(!strcmp(pwdfile
, STD_PASSWD_FILE
))
88 if((fp
= fopen(pwdfile
, "r")) == (FILE *)NULL
)
96 int passuser(pwdfile
, user
)
100 if(!strcmp(pwdfile
, STD_PASSWD_FILE
))
101 if(getpwnam(user
) == (struct passwd
*)NULL
)
106 return(getuser(pwdfile
, user
));
109 int passnone(pwdfile
, user
)
115 if(!strcmp(pwdfile
, STD_PASSWD_FILE
))
116 if((pwd
= getpwnam(user
)) == (struct passwd
*)NULL
)
119 if(!strcmp(pwd
->pw_passwd
, crypt("", pwd
->pw_passwd
)))
124 if(getuser(pwdfile
, user
))
127 if(!strcmp(pwdpass
, crypt("", pwdpass
)))
133 int passpass(pwdfile
, user
, pass
)
140 if(!strcmp(pwdfile
, STD_PASSWD_FILE
))
141 if((pwd
= getpwnam(user
)) == (struct passwd
*)NULL
)
144 if(strcmp(pwd
->pw_passwd
, crypt(pass
, pwd
->pw_passwd
)))
149 if(getuser(pwdfile
, user
))
152 if(strcmp(pwdpass
, crypt(pass
, pwdpass
)))
158 int passadd(pwdfile
, user
, pass
, e1
, e2
, e3
, e4
)
177 if(pwdfile
== (char *)NULL
||
178 user
== (char *)NULL
||
179 pass
== (char *)NULL
)
182 if(!strcmp(pwdfile
, STD_PASSWD_FILE
))
185 if(!getuser(pwdfile
, user
))
186 return(PASS_USEREXISTS
);
189 sl
[0] = (salt
& 077) + '.';
190 sl
[1] = ((salt
>> 6) & 077) + '.';
191 for (cn
= 0; cn
< 2; cn
++) {
192 if (sl
[cn
] > '9') sl
[cn
] += 7;
193 if (sl
[cn
] > 'Z') sl
[cn
] += 6;
196 if(e1
== (char *)NULL
) ee1
= ""; else ee1
= e1
;
197 if(e2
== (char *)NULL
) ee2
= ""; else ee2
= e2
;
198 if(e3
== (char *)NULL
) ee3
= ""; else ee3
= e3
;
199 if(e4
== (char *)NULL
) ee4
= ""; else ee4
= e4
;
201 /* XXX need to add locking mechanics to add new user */
203 if((fp
= fopen(pwdfile
, "a")) == (FILE *)NULL
)
206 fprintf(fp
, "%s:%s:%s:%s:%s:%s\n", user
, crypt(pass
, sl
), ee1
, ee2
, ee3
, ee4
);
210 /* XXX need to add unlocking mechanics to add new user */