Set a default password file if one is not specified in ocpasswd.

This commit is contained in:
Nikos Mavrogiannopoulos
2014-01-30 19:12:02 +01:00
parent 44cd152f02
commit 2254ba554b
2 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
#include <vpn.h> #include <vpn.h>
#include <tlslib.h> #include <tlslib.h>
#define DEFAULT_CFG_FILE "/etc/ocserv.conf" #define DEFAULT_CFG_FILE "/etc/ocserv/ocserv.conf"
static const char* pid_file = NULL; static const char* pid_file = NULL;
static const char* cfg_file = DEFAULT_CFG_FILE; static const char* cfg_file = DEFAULT_CFG_FILE;
+13 -8
View File
@@ -34,6 +34,8 @@
#include <getpass.h> #include <getpass.h>
#include <minmax.h> #include <minmax.h>
#define DEFAULT_OCPASSWD "/etc/ocserv/ocpasswd"
static const char alphabet[] = static const char alphabet[] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./"; "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";
@@ -102,7 +104,7 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
fd2 = fopen(tmp_passwd, "w"); fd2 = fopen(tmp_passwd, "w");
if (fd2 == NULL) { if (fd2 == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", tmp_passwd); fprintf(stderr, "Cannot open '%s' for writing\n", tmp_passwd);
exit(1); exit(1);
} }
@@ -133,7 +135,11 @@ crypt_int(const char *fpasswd, const char *username, const char *groupname,
fclose(fd2); fclose(fd2);
rename(tmp_passwd, fpasswd); ret = rename(tmp_passwd, fpasswd);
if (ret < 0) {
fprintf(stderr, "Cannot write '%s'\n", fpasswd);
exit(1);
}
free(tmp_passwd); free(tmp_passwd);
} }
@@ -167,7 +173,7 @@ lock_user(const char *fpasswd, const char *username)
fd2 = fopen(tmp_passwd, "w"); fd2 = fopen(tmp_passwd, "w");
if (fd2 == NULL) { if (fd2 == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", tmp_passwd); fprintf(stderr, "Cannot open '%s' for writing\n", tmp_passwd);
exit(1); exit(1);
} }
@@ -231,7 +237,7 @@ unlock_user(const char *fpasswd, const char *username)
fd2 = fopen(tmp_passwd, "w"); fd2 = fopen(tmp_passwd, "w");
if (fd2 == NULL) { if (fd2 == NULL) {
fprintf(stderr, "Cannot open '%s' for write\n", tmp_passwd); fprintf(stderr, "Cannot open '%s' for writing\n", tmp_passwd);
exit(1); exit(1);
} }
@@ -291,11 +297,10 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (HAVE_OPT(PASSWD)) if (HAVE_OPT(PASSWD)) {
fpasswd = OPT_ARG(PASSWD); fpasswd = OPT_ARG(PASSWD);
else { } else {
fprintf(stderr, "Password file was not specified\n"); fpasswd = DEFAULT_OCPASSWD;
exit(1);
} }
if (HAVE_OPT(GROUPNAME)) if (HAVE_OPT(GROUPNAME))