version 1.1, 2014/03/17 12:49:13 |
version 1.2, 2014/03/17 12:51:58 |
|
|
FILE *in, *out; |
FILE *in, *out; |
size_t linesize; |
size_t linesize; |
ssize_t linelen; |
ssize_t linelen; |
|
mode_t old_umask; |
int fd, loginlen; |
int fd, loginlen; |
char hash[_PASSWORD_LEN], *file, *line, *login, pass[1024], pass2[1024]; |
char hash[_PASSWORD_LEN], *file, *line, *login, pass[1024], pass2[1024]; |
char salt[_PASSWORD_LEN], tmpl[sizeof("/tmp/htpasswd-XXXXXXXXXX")]; |
char salt[_PASSWORD_LEN], tmpl[sizeof("/tmp/htpasswd-XXXXXXXXXX")]; |
|
|
else { |
else { |
if ((in = fopen(file, "r+")) == NULL) { |
if ((in = fopen(file, "r+")) == NULL) { |
if (errno == ENOENT) { |
if (errno == ENOENT) { |
|
old_umask = umask(S_IXUSR| |
|
S_IWGRP|S_IRGRP|S_IXGRP| |
|
S_IWOTH|S_IROTH|S_IXOTH); |
if ((out = fopen(file, "w")) == NULL) |
if ((out = fopen(file, "w")) == NULL) |
err(1, "cannot open password file for" |
err(1, "cannot open password file for" |
" reading or writing"); |
" reading or writing"); |
if (fchmod(fileno(out), S_IRUSR | S_IWUSR) |
umask(old_umask); |
== -1) |
|
err(1, "cannot chmod new password" |
|
" file"); |
|
} else |
} else |
err(1, "cannot open password file for reading"); |
err(1, "cannot open password file for reading"); |
} |
} |