-/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as
- * applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
#define ALG_APMD5 1
#define ALG_APSHA 2
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
#define ALG_CRYPT 3
#endif
static apr_status_t htdbm_verify(htdbm_t *htdbm)
{
apr_datum_t key, val;
- char pwd[MAX_STRING_LEN] = {0};
+ char *pwd;
char *rec, *cmnt;
key.dptr = htdbm->username;
rec = apr_pstrndup(htdbm->pool, val.dptr, val.dsize);
cmnt = strchr(rec, ':');
if (cmnt)
- strncpy(pwd, rec, cmnt - rec);
+ pwd = apr_pstrndup(htdbm->pool, rec, cmnt - rec);
else
- strcpy(pwd, rec);
+ pwd = apr_pstrdup(htdbm->pool, rec);
return apr_password_validate(htdbm->userpass, pwd);
}
{
apr_status_t rv;
apr_datum_t key, val;
- char *rec, *cmnt;
- char kb[MAX_STRING_LEN];
+ char *cmnt;
int i = 0;
rv = apr_dbm_firstkey(htdbm->dbm, &key);
fprintf(stderr, "Empty database -- %s\n", htdbm->filename);
return APR_ENOENT;
}
- rec = apr_pcalloc(htdbm->pool, HUGE_STRING_LEN);
-
fprintf(stderr, "Dumping records from database -- %s\n", htdbm->filename);
- fprintf(stderr, " %-32sComment\n", "Username");
+ fprintf(stderr, " %-32s Comment\n", "Username");
while (key.dptr != NULL) {
rv = apr_dbm_fetch(htdbm->dbm, key, &val);
if (rv != APR_SUCCESS) {
fprintf(stderr, "Failed getting data from %s\n", htdbm->filename);
return APR_EGENERAL;
}
- strncpy(kb, key.dptr, key.dsize);
- kb[key.dsize] = '\0';
- fprintf(stderr, " %-32s", kb);
- strncpy(rec, val.dptr, val.dsize);
- rec[val.dsize] = '\0';
- cmnt = strchr(rec, ':');
+ /* Note: we don't store \0-terminators on our dbm data */
+ fprintf(stderr, " %-32.*s", (int)key.dsize, key.dptr);
+ cmnt = memchr(val.dptr, ':', val.dsize);
if (cmnt)
- fprintf(stderr, "%s", cmnt + 1);
+ fprintf(stderr, " %.*s", (int)(val.dptr+val.dsize - (cmnt+1)), cmnt + 1);
fprintf(stderr, "\n");
rv = apr_dbm_nextkey(htdbm->dbm, &key);
if (rv != APR_SUCCESS)
case ALG_PLAIN:
/* XXX this len limitation is not in sync with any HTTPd len. */
apr_cpystrn(cpw,htdbm->userpass,sizeof(cpw));
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
fprintf(stderr, "Warning: Plain text passwords aren't supported by the "
"server on this platform!\n");
#endif
break;
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
case ALG_CRYPT:
(void) srand((int) time((time_t *) NULL));
to64(&salt[0], rand(), 8);
static void htdbm_usage(void)
{
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
#define CRYPT_OPTION "d"
#else
#define CRYPT_OPTION ""
fprintf(stderr, " -c Create a new database.\n");
fprintf(stderr, " -n Don't update database; display results on stdout.\n");
fprintf(stderr, " -m Force MD5 encryption of the password (default).\n");
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
fprintf(stderr, " -d Force CRYPT encryption of the password (now deprecated).\n");
#endif
fprintf(stderr, " -p Do not encrypt the password (plaintext).\n");
case 's':
h->alg = ALG_APSHA;
break;
-#if APR_HAVE_CRYPT_H
+#if (!(defined(WIN32) || defined(NETWARE)))
case 'd':
h->alg = ALG_CRYPT;
break;
switch (cmd) {
case HTDBM_VERIFY:
if ((rv = htdbm_verify(h)) != APR_SUCCESS) {
- if(rv == APR_ENOENT) {
+ if (APR_STATUS_IS_ENOENT(rv)) {
fprintf(stderr, "The user '%s' could not be found in database\n", h->username);
exit(ERR_BADUSER);
}