]> granicus.if.org Git - apache/blob - support/passwd_common.h
* Lock the worker, not the balancer. We even do not know if we have a balancer
[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 #ifndef _PASSWD_COMMON_H
18 #define _PASSWD_COMMON_H
19
20 #include "apr.h"
21 #include "apr_lib.h"
22 #include "apr_strings.h"
23 #include "apr_errno.h"
24 #include "apr_file_io.h"
25 #include "apr_general.h"
26 #include "apr_version.h"
27 #if !APR_VERSION_AT_LEAST(2,0,0)
28 #include "apu_version.h"
29 #endif
30
31 #include "ap_config_auto.h"
32
33 #define MAX_STRING_LEN 256
34
35 #define ALG_PLAIN 0
36 #define ALG_CRYPT 1
37 #define ALG_APMD5 2
38 #define ALG_APSHA 3
39 #define ALG_BCRYPT 4
40 #define ALG_CRYPT_SHA256 5
41 #define ALG_CRYPT_SHA512 6
42
43 #define BCRYPT_DEFAULT_COST 5
44
45 #define ERR_FILEPERM 1
46 #define ERR_SYNTAX 2
47 #define ERR_PWMISMATCH 3
48 #define ERR_INTERRUPTED 4
49 #define ERR_OVERFLOW 5
50 #define ERR_BADUSER 6
51 #define ERR_INVALID 7
52 #define ERR_RANDOM 8
53 #define ERR_GENERAL 9
54 #define ERR_ALG_NOT_SUPP 10
55
56 #define NL APR_EOL_STR
57
58 #if defined(WIN32) || defined(NETWARE)
59 #define CRYPT_ALGO_SUPPORTED 0
60 #define PLAIN_ALGO_SUPPORTED 1
61 #else
62 #define CRYPT_ALGO_SUPPORTED 1
63 #define PLAIN_ALGO_SUPPORTED 0
64 #endif
65
66 #if APR_VERSION_AT_LEAST(2,0,0) || \
67     (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 5)
68 #define BCRYPT_ALGO_SUPPORTED 1
69 #else
70 #define BCRYPT_ALGO_SUPPORTED 0
71 #endif
72
73 #if APR_CHARSET_EBCDIC
74 #undef BCRYPT_ALGO_SUPPORTED
75 #define BCRYPT_ALGO_SUPPORTED 0
76 #endif
77
78 /*
79  * Must be initialized with apr_file_open_stderr() before using any of the
80  * below functions.
81  */
82 extern apr_file_t *errfile;
83
84 struct passwd_ctx {
85     apr_pool_t      *pool;
86     const char      *errstr;
87     char            *out;
88     apr_size_t      out_len;
89     char            *passwd;
90     int             alg;
91     int             cost; /* cost for bcrypt, rounds for SHA-2 */
92     enum {
93         PW_PROMPT = 0,
94         PW_ARG,
95         PW_STDIN,
96         PW_PROMPT_VERIFY,
97     } passwd_src;
98 };
99
100
101 /*
102  * To be used as apr_pool_abort_fn
103  */
104 int abort_on_oom(int rc);
105
106 /*
107  * Write a line to the file. On error, print a message and exit
108  */
109 void putline(apr_file_t *f, const char *l);
110
111 /*
112  * The following functions return zero on success; otherwise, one of
113  * the ERR_* codes is returned and an error message is stored in ctx->errstr.
114  */
115
116 /*
117  * Parse the algorithm specific options.
118  */
119 int parse_common_options(struct passwd_ctx *ctx, char opt, const char *opt_arg);
120
121 /*
122  * Ask for password with verification.
123  */
124 int get_password(struct passwd_ctx *ctx);
125
126 /*
127  * Make a password record from the given information.
128  */
129 int mkhash(struct passwd_ctx *ctx);
130
131 #endif /* _PASSWD_COMMON_H */
132