]> granicus.if.org Git - apache/blob - support/passwd_common.h
Start refactoring of htpasswd and htdbm
[apache] / support / passwd_common.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "apr.h"
18 #include "apr_lib.h"
19 #include "apr_strings.h"
20 #include "apr_errno.h"
21 #include "apr_file_io.h"
22 #include "apr_general.h"
23 #include "apr_version.h"
24
25 #define MAX_STRING_LEN 256
26
27 #define ALG_PLAIN 0
28 #define ALG_CRYPT 1
29 #define ALG_APMD5 2
30 #define ALG_APSHA 3
31
32 #define ERR_FILEPERM 1
33 #define ERR_SYNTAX 2
34 #define ERR_PWMISMATCH 3
35 #define ERR_INTERRUPTED 4
36 #define ERR_OVERFLOW 5
37 #define ERR_BADUSER 6
38 #define ERR_INVALID 7
39 #define ERR_RANDOM 8
40 #define ERR_GENERAL 9
41 #define ERR_ALG_NOT_SUPP 10
42
43 #define NL APR_EOL_STR
44
45 #if defined(WIN32) || defined(NETWARE)
46 #define CRYPT_ALGO_SUPPORTED 0
47 #define PLAIN_ALGO_SUPPORTED 1
48 #else
49 #define CRYPT_ALGO_SUPPORTED 1
50 #define PLAIN_ALGO_SUPPORTED 0
51 #endif
52
53 /*
54  * Must be initialized with apr_file_open_stderr() before using any of the
55  * below functions.
56  */
57 extern apr_file_t *errfile;
58
59 struct passwd_ctx {
60     apr_pool_t      *pool;
61     const char      *errstr;
62     char            *out;
63     apr_size_t      out_len;
64     char            *passwd;
65     int             alg;
66     enum {
67         PW_PROMPT = 0,
68         PW_ARG
69     } passwd_src;
70 };
71
72 /*
73  * Write a line to the file. On error, print a message and exit
74  */
75 void putline(apr_file_t *f, const char *l);
76
77 /*
78  * The following functions return zero on success; otherwise, one of
79  * the ERR_* codes is returned and an error message is stored in ctx->errstr.
80  */
81
82 /*
83  * Parse the algorithm specific options.
84  */
85 int parse_common_options(struct passwd_ctx *ctx, char opt, const char *opt_arg);
86
87 /*
88  * Ask for password with verification.
89  */
90 int get_password(struct passwd_ctx *ctx);
91
92 /*
93  * Make a password record from the given information.
94  */
95 int mkhash(struct passwd_ctx *ctx);