From: Richard Kettlewell Date: Sun, 20 Apr 2008 17:15:49 +0000 (+0100) Subject: Clients now test whether users.db is readable before blundering in and X-Git-Tag: 4.0~112^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/199c2a23548cf3c89ddbb8a444ccdf2940f89c74 Clients now test whether users.db is readable before blundering in and trying it. They will still fail in all the cases they did before but much more gracefuly. --- diff --git a/CHANGES b/CHANGES index 6d92b62..aff856b 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,8 @@ Builds --without-server should work again. The web interface is a bit more liberal in the cookie value syntax it will accept. +Clients fail more gracefully if no password is available. + * Changes up to version 3.0.1 Debian upgrades from 2.0.x should now work better. diff --git a/lib/client.c b/lib/client.c index 75381c6..4dfd10c 100644 --- a/lib/client.c +++ b/lib/client.c @@ -389,9 +389,8 @@ int disorder_connect(disorder_client *c) { return -1; } password = config->password; - if(!password) { - /* Maybe we can read the database */ - /* TODO failure to open the database should not be fatal */ + /* Maybe we can read the database */ + if(!password && trackdb_readable()) { trackdb_init(TRACKDB_NO_RECOVER|TRACKDB_NO_UPGRADE); trackdb_open(TRACKDB_READ_ONLY); password = trackdb_get_password(username); diff --git a/lib/trackdb-stub.c b/lib/trackdb-stub.c index 22174d3..3b92c97 100644 --- a/lib/trackdb-stub.c +++ b/lib/trackdb-stub.c @@ -44,6 +44,10 @@ void trackdb_open(int attribute((unused)) flags) { void trackdb_init(int attribute((unused)) flags) { } +int trackdb_readable(void) { + return 0; +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/trackdb.c b/lib/trackdb.c index 8945ec3..875acc5 100644 --- a/lib/trackdb.c +++ b/lib/trackdb.c @@ -166,6 +166,16 @@ static int compare(DB attribute((unused)) *db_, return compare_path_raw(a->data, a->size, b->data, b->size); } +/** @brief Test whether the track database can be read + * @return 1 if it can, 0 if it cannot + */ +int trackdb_readable(void) { + char *usersdb; + + byte_xasprintf(&usersdb, "%s/users.db", config->home); + return access(usersdb, R_OK) == 0; +} + /** @brief Open database environment * @param flags Flags word * diff --git a/lib/trackdb.h b/lib/trackdb.h index 804ff5a..e100f25 100644 --- a/lib/trackdb.h +++ b/lib/trackdb.h @@ -171,6 +171,7 @@ int trackdb_edituserinfo(const char *user, char **trackdb_listusers(void); int trackdb_confirm(const char *user, const char *confirmation, rights_type *rightsp); +int trackdb_readable(void); #endif /* TRACKDB_H */