--- a/dav/pwd.h Sat Sep 15 11:58:17 2018 +0200 +++ b/dav/pwd.h Thu Sep 20 13:07:38 2018 +0200 @@ -40,21 +40,24 @@ extern "C" { #endif -#define PWDSTORE_MAX_LEN 1024 +#define PWDSTORE_MAX_LEN 4096 /* * File Format: * * file = header, enc_content - * header = magic, version, enc, pwfunc, salt + * header = magic, version, enc, pwfunc, salt, indexlen * magic = 1 byte * version = 1 byte * enc = 1 byte * pwfunc = 1 byte * salt = 16 bytes + * indexlen = uint32 * content = { entry } - * entry = length username length password - * length = uint16 + * entry = length id length location length username length password + * length = uint32 + * id = string + * location = string * username = string * password = string * @@ -64,18 +67,24 @@ * All integers are big endian */ -#define PWDS_HEADER_SIZE 20 +#define PWDS_HEADER_SIZE 24 typedef struct PwdStore PwdStore; typedef struct PwdEntry PwdEntry; struct PwdStore { /* - * map of all usernames and passwords + * map of all credentials * key is the username * value is PwdEntry* */ - UcxMap *pwds; + UcxMap *ids; + + /* + * list of all credentials with location + * value is PwdEntry* + */ + UcxList *locations; /* * a buffer containing the complete file content @@ -88,6 +97,11 @@ DavKey *key; /* + * start offset of the encrypted buffer + */ + uint32_t encoffset; + + /* * indicates if the PwdStore is decrypted with pwdstore_decrypt */ uint8_t isdecrypted; @@ -101,6 +115,8 @@ #define PWDS_MAGIC_CHAR 'P' struct PwdEntry { + char *id; + char *location; char *user; char *password; }; @@ -124,12 +140,18 @@ void pwdstore_free(PwdStore* p); -PwdEntry* pwdstore_get(PwdStore *p, const char *username); +int pwdstore_has_id(PwdStore *s, const char *id); +int pwdstore_has_location(PwdStore *s, const char *location); -void pwdstore_put(PwdStore *p, const char *username, const char *password); +PwdEntry* pwdstore_get(PwdStore *p, const char *id); + +void pwdstore_put(PwdStore *p, const char *id, const char *location, const char *username, const char *password); int pwdstore_store(PwdStore *p, const char *file); +/* private */ +int pwdstore_getindex(PwdStore *s); + #ifdef __cplusplus } #endif