auth.h (1194B)
1 #ifndef __LINKD_UTIL_AUTH_H__ 2 #define __LINKD_UTIL_AUTH_H__ 3 4 #include <stddef.h> 5 6 // Password file, one entry per line: 7 // 8 // user:$pbkdf2-sha256$<iterations>$<salt>$<hash>:role 9 // 10 // role is `full` or `readonly`, and defaults to readonly when omitted. 11 // salt and hash use passlib's adapted base64 ("." for "+", no padding), so 12 // entries generated by passlib or Django interoperate. 13 14 #define AUTH_ROLE_NONE 0 15 #define AUTH_ROLE_READONLY 1 16 #define AUTH_ROLE_FULL 2 17 18 #define AUTH_DEFAULT_ITERATIONS 29000 19 20 // Returns the role granted, or AUTH_ROLE_NONE on any failure. 21 int auth_check(const char *path, const char *user, const char *pass); 22 23 // Verify one `$pbkdf2-sha256$...` string against a password. 24 int auth_verify_hash(const char *stored, const char *pass); 25 26 // Build a hash string. Caller frees. NULL on failure. 27 char *auth_make_hash(const char *pass, unsigned iterations); 28 29 // Refuses a world-writable file; warns when group- or world-readable. 30 int auth_check_permissions(const char *path); 31 32 int ab64_encode(const unsigned char *in, size_t len, char *out, size_t out_sz); 33 size_t ab64_decode(const char *in, unsigned char *out, size_t out_sz); 34 35 #endif // __LINKD_UTIL_AUTH_H__