pwd.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "klone_conf.h"
00012 #include <u/libu.h>
00013 #include <klone/emb.h>
00014 #include <klone/utils.h>
00015
00016 static int __emb_open (const char *fqn, void **pio);
00017 static char *__emb_load (char *str, int size, void *io);
00018 static void __emb_close (void *io);
00019 static int u_pwd_init_embfs (const char *fqn, u_pwd_hash_cb_t cb_hash,
00020 size_t hash_len, int in_memory, u_pwd_t **ppwd);
00021
00035 int u_pwd_init_agnostic (const char *fqn, int hashed, int in_memory,
00036 u_pwd_t **ppwd)
00037 {
00038 int where;
00039 u_pwd_hash_cb_t hfn = NULL;
00040 size_t hlen = 0;
00041
00042 dbg_return_if (fqn == NULL, ~0);
00043 dbg_return_if (ppwd == NULL, ~0);
00044
00045 dbg_err_if (u_path_where_art_thou(fqn, &where));
00046
00047 if (hashed)
00048 {
00049 hfn = u_md5;
00050 hlen = MD5_DIGEST_BUFSZ;
00051 }
00052
00053 switch (where)
00054 {
00055 case U_PATH_IN_EMBFS:
00056 return u_pwd_init_embfs(fqn, hfn, hlen, in_memory, ppwd);
00057 case U_PATH_IN_FS:
00058 return u_pwd_init_file(fqn, hfn, hlen, in_memory, ppwd);
00059 default:
00060 dbg_err("%s: resource not found !", fqn);
00061 }
00062
00063
00064
00065 err:
00066 return ~0;
00067 }
00068
00069 static int __emb_open (const char *fqn, void **pio)
00070 {
00071 io_t *io = NULL;
00072
00073 dbg_err_if (emb_open(fqn, &io));
00074
00075 *pio = (void *) io;
00076
00077 return 0;
00078 err:
00079 return ~0;
00080 }
00081
00082 static void __emb_close (void *io)
00083 {
00084 dbg_if (io_close((io_t *) io));
00085 return;
00086 }
00087
00088 static char *__emb_load (char *str, int size, void *io)
00089 {
00090 dbg_err_if (io_gets((io_t *) io, str, size) <= 0);
00091
00092 return str;
00093 err:
00094 return NULL;
00095 }
00096
00097 static int u_pwd_init_embfs (const char *fqn, u_pwd_hash_cb_t cb_hash,
00098 size_t hash_len, int in_memory, u_pwd_t **ppwd)
00099 {
00100 return u_pwd_init(fqn, __emb_open, __emb_load, __emb_close, NULL,
00101 cb_hash, hash_len, in_memory, ppwd);
00102 }