553f11a8f542196fd02498006338dd33c64045c3fuankg/* Licensed to the Apache Software Foundation (ASF) under one or more
553f11a8f542196fd02498006338dd33c64045c3fuankg * contributor license agreements. See the NOTICE file distributed with
553f11a8f542196fd02498006338dd33c64045c3fuankg * this work for additional information regarding copyright ownership.
553f11a8f542196fd02498006338dd33c64045c3fuankg * The ASF licenses this file to You under the Apache License, Version 2.0
553f11a8f542196fd02498006338dd33c64045c3fuankg * (the "License"); you may not use this file except in compliance with
553f11a8f542196fd02498006338dd33c64045c3fuankg * the License. You may obtain a copy of the License at
553f11a8f542196fd02498006338dd33c64045c3fuankg *
553f11a8f542196fd02498006338dd33c64045c3fuankg * http://www.apache.org/licenses/LICENSE-2.0
553f11a8f542196fd02498006338dd33c64045c3fuankg *
553f11a8f542196fd02498006338dd33c64045c3fuankg * Unless required by applicable law or agreed to in writing, software
553f11a8f542196fd02498006338dd33c64045c3fuankg * distributed under the License is distributed on an "AS IS" BASIS,
553f11a8f542196fd02498006338dd33c64045c3fuankg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
553f11a8f542196fd02498006338dd33c64045c3fuankg * See the License for the specific language governing permissions and
553f11a8f542196fd02498006338dd33c64045c3fuankg * limitations under the License.
553f11a8f542196fd02498006338dd33c64045c3fuankg */
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#ifndef _LUA_PASSWD_H
553f11a8f542196fd02498006338dd33c64045c3fuankg#define _LUA_PASSWD_H
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_lib.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_strings.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_errno.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_file_io.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_general.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apr_version.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#if !APR_VERSION_AT_LEAST(2,0,0)
553f11a8f542196fd02498006338dd33c64045c3fuankg#include "apu_version.h"
553f11a8f542196fd02498006338dd33c64045c3fuankg#endif
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#define MAX_PASSWD_LEN 256
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ALG_APMD5 0
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ALG_APSHA 1
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ALG_BCRYPT 2
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ALG_CRYPT 3
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#define BCRYPT_DEFAULT_COST 5
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_FILEPERM 1
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_SYNTAX 2
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_PWMISMATCH 3
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_INTERRUPTED 4
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_OVERFLOW 5
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_BADUSER 6
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_INVALID 7
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_RANDOM 8
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_GENERAL 9
553f11a8f542196fd02498006338dd33c64045c3fuankg#define ERR_ALG_NOT_SUPP 10
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#if defined(WIN32) || defined(NETWARE)
553f11a8f542196fd02498006338dd33c64045c3fuankg#define CRYPT_ALGO_SUPPORTED 0
553f11a8f542196fd02498006338dd33c64045c3fuankg#define PLAIN_ALGO_SUPPORTED 1
553f11a8f542196fd02498006338dd33c64045c3fuankg#else
553f11a8f542196fd02498006338dd33c64045c3fuankg#define CRYPT_ALGO_SUPPORTED 1
553f11a8f542196fd02498006338dd33c64045c3fuankg#define PLAIN_ALGO_SUPPORTED 0
553f11a8f542196fd02498006338dd33c64045c3fuankg#endif
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#if APR_VERSION_AT_LEAST(2,0,0) || \
553f11a8f542196fd02498006338dd33c64045c3fuankg (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 5)
553f11a8f542196fd02498006338dd33c64045c3fuankg#define BCRYPT_ALGO_SUPPORTED 1
553f11a8f542196fd02498006338dd33c64045c3fuankg#else
553f11a8f542196fd02498006338dd33c64045c3fuankg#define BCRYPT_ALGO_SUPPORTED 0
553f11a8f542196fd02498006338dd33c64045c3fuankg#endif
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankgtypedef struct passwd_ctx passwd_ctx;
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankgstruct passwd_ctx {
553f11a8f542196fd02498006338dd33c64045c3fuankg apr_pool_t *pool;
553f11a8f542196fd02498006338dd33c64045c3fuankg const char *errstr;
553f11a8f542196fd02498006338dd33c64045c3fuankg char *out;
553f11a8f542196fd02498006338dd33c64045c3fuankg apr_size_t out_len;
553f11a8f542196fd02498006338dd33c64045c3fuankg char *passwd;
553f11a8f542196fd02498006338dd33c64045c3fuankg int alg;
553f11a8f542196fd02498006338dd33c64045c3fuankg int cost;
553f11a8f542196fd02498006338dd33c64045c3fuankg};
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg/*
553f11a8f542196fd02498006338dd33c64045c3fuankg * The following functions return zero on success; otherwise, one of
553f11a8f542196fd02498006338dd33c64045c3fuankg * the ERR_* codes is returned and an error message is stored in ctx->errstr.
553f11a8f542196fd02498006338dd33c64045c3fuankg */
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg/*
553f11a8f542196fd02498006338dd33c64045c3fuankg * Make a password record from the given information.
553f11a8f542196fd02498006338dd33c64045c3fuankg */
553f11a8f542196fd02498006338dd33c64045c3fuankgint mk_password_hash(passwd_ctx *ctx);
553f11a8f542196fd02498006338dd33c64045c3fuankg
553f11a8f542196fd02498006338dd33c64045c3fuankg#endif /* _LUA_PASSWD_H */
553f11a8f542196fd02498006338dd33c64045c3fuankg