Lines Matching defs:htdbm

18  * htdbm.c: simple program for manipulating DBM
89 static void htdbm_terminate(htdbm_t *htdbm)
91 if (htdbm->dbm)
92 apr_dbm_close(htdbm->dbm);
93 htdbm->dbm = NULL;
101 fprintf(stderr, "htdbm Interrupted !\n");
144 static apr_status_t htdbm_open(htdbm_t *htdbm)
146 if (htdbm->create)
147 return apr_dbm_open_ex(&htdbm->dbm, htdbm->type, htdbm->filename, APR_DBM_RWCREATE,
148 APR_OS_DEFAULT, htdbm->ctx.pool);
150 return apr_dbm_open_ex(&htdbm->dbm, htdbm->type, htdbm->filename,
151 htdbm->rdonly ? APR_DBM_READONLY : APR_DBM_READWRITE,
152 APR_OS_DEFAULT, htdbm->ctx.pool);
155 static apr_status_t htdbm_save(htdbm_t *htdbm, int *changed)
159 if (!htdbm->username)
162 key.dptr = htdbm->username;
163 key.dsize = strlen(htdbm->username);
164 if (apr_dbm_exists(htdbm->dbm, key))
167 val.dsize = strlen(htdbm->ctx.passwd);
168 if (!htdbm->comment)
169 val.dptr = htdbm->ctx.passwd;
171 val.dptr = apr_pstrcat(htdbm->ctx.pool, htdbm->ctx.passwd, ":",
172 htdbm->comment, NULL);
173 val.dsize += (strlen(htdbm->comment) + 1);
175 return apr_dbm_store(htdbm->dbm, key, val);
178 static apr_status_t htdbm_del(htdbm_t *htdbm)
182 key.dptr = htdbm->username;
183 key.dsize = strlen(htdbm->username);
184 if (!apr_dbm_exists(htdbm->dbm, key))
187 return apr_dbm_delete(htdbm->dbm, key);
190 static apr_status_t htdbm_verify(htdbm_t *htdbm)
196 key.dptr = htdbm->username;
197 key.dsize = strlen(htdbm->username);
198 if (!apr_dbm_exists(htdbm->dbm, key))
200 if (apr_dbm_fetch(htdbm->dbm, key, &val) != APR_SUCCESS)
202 rec = apr_pstrndup(htdbm->ctx.pool, val.dptr, val.dsize);
205 pwd = apr_pstrndup(htdbm->ctx.pool, rec, cmnt - rec);
207 pwd = apr_pstrdup(htdbm->ctx.pool, rec);
208 return apr_password_validate(htdbm->ctx.passwd, pwd);
211 static apr_status_t htdbm_list(htdbm_t *htdbm)
218 rv = apr_dbm_firstkey(htdbm->dbm, &key);
220 fprintf(stderr, "Empty database -- %s\n", htdbm->filename);
223 fprintf(stderr, "Dumping records from database -- %s\n", htdbm->filename);
226 rv = apr_dbm_fetch(htdbm->dbm, key, &val);
228 fprintf(stderr, "Failed getting data from %s\n", htdbm->filename);
237 rv = apr_dbm_nextkey(htdbm->dbm, &key);
247 static int htdbm_make(htdbm_t *htdbm)
252 htdbm->ctx.out = cpw;
253 htdbm->ctx.out_len = sizeof(cpw);
254 ret = mkhash(&htdbm->ctx);
256 fprintf(stderr, "Error: %s\n", htdbm->ctx.errstr);
259 htdbm->ctx.passwd = apr_pstrdup(htdbm->ctx.pool, cpw);
263 static apr_status_t htdbm_valid_username(htdbm_t *htdbm)
265 if (!htdbm->username || (strlen(htdbm->username) > 64) || (strlen(htdbm->username) < 1)) {
269 if (strchr(htdbm->username, ':')) {
279 "htdbm -- program for manipulating DBM password databases.\n\n"
280 "Usage: htdbm [-cimBdpstvx] [-C cost] [-TDBTYPE] database username\n"
331 fprintf(stderr, "Unable to initialize htdbm terminating!\n");