Apache2
passwd_common.h
Go to the documentation of this file.
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 #if !defined(WIN32) && !defined(NETWARE)
32 #include "ap_config_auto.h"
33 #endif
34 
35 #define MAX_STRING_LEN 256
36 
37 #define ALG_PLAIN 0
38 #define ALG_CRYPT 1
39 #define ALG_APMD5 2
40 #define ALG_APSHA 3
41 #define ALG_BCRYPT 4
42 #define ALG_CRYPT_SHA256 5
43 #define ALG_CRYPT_SHA512 6
44 
45 #define BCRYPT_DEFAULT_COST 5
46 
47 #define ERR_FILEPERM 1
48 #define ERR_SYNTAX 2
49 #define ERR_PWMISMATCH 3
50 #define ERR_INTERRUPTED 4
51 #define ERR_OVERFLOW 5
52 #define ERR_BADUSER 6
53 #define ERR_INVALID 7
54 #define ERR_RANDOM 8
55 #define ERR_GENERAL 9
56 #define ERR_ALG_NOT_SUPP 10
57 
58 #define NL APR_EOL_STR
59 
60 #if defined(WIN32) || defined(NETWARE)
61 #define CRYPT_ALGO_SUPPORTED 0
62 #define PLAIN_ALGO_SUPPORTED 1
63 #else
64 #define CRYPT_ALGO_SUPPORTED 1
65 #define PLAIN_ALGO_SUPPORTED 0
66 #endif
67 
68 #if APR_VERSION_AT_LEAST(2,0,0) || \
69  (APU_MAJOR_VERSION == 1 && APU_MINOR_VERSION >= 5)
70 #define BCRYPT_ALGO_SUPPORTED 1
71 #else
72 #define BCRYPT_ALGO_SUPPORTED 0
73 #endif
74 
75 #if APR_CHARSET_EBCDIC
76 #undef BCRYPT_ALGO_SUPPORTED
77 #define BCRYPT_ALGO_SUPPORTED 0
78 #endif
79 
80 /*
81  * Must be initialized with apr_file_open_stderr() before using any of the
82  * below functions.
83  */
84 extern apr_file_t *errfile;
85 
86 struct passwd_ctx {
88  const char *errstr;
89  char *out;
91  char *passwd;
92  int alg;
93  int cost; /* cost for bcrypt, rounds for SHA-2 */
94  enum {
95  PW_PROMPT = 0,
100 };
101 
102 
103 /*
104  * To be used as apr_pool_abort_fn
105  */
106 int abort_on_oom(int rc);
107 
108 /*
109  * Write a line to the file. On error, print a message and exit
110  */
111 void putline(apr_file_t *f, const char *l);
112 
113 /*
114  * The following functions return zero on success; otherwise, one of
115  * the ERR_* codes is returned and an error message is stored in ctx->errstr.
116  */
117 
118 /*
119  * Parse the algorithm specific options.
120  */
121 int parse_common_options(struct passwd_ctx *ctx, char opt, const char *opt_arg);
122 
123 /*
124  * Ask for password with verification.
125  */
126 int get_password(struct passwd_ctx *ctx);
127 
128 /*
129  * Make a password record from the given information.
130  */
131 int mkhash(struct passwd_ctx *ctx);
132 
133 #endif /* _PASSWD_COMMON_H */
134 
APR Platform Definitions.
APR Error Codes.
APR File I/O Handling.
APR Miscellaneous library routines.
APR general purpose library routines.
APR Strings library.
APR Versioning Interface.
APR-util Versioning Interface.
size_t apr_size_t
Definition: apr.h:394
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
int get_password(struct passwd_ctx *ctx)
apr_file_t * errfile
int abort_on_oom(int rc)
int mkhash(struct passwd_ctx *ctx)
int parse_common_options(struct passwd_ctx *ctx, char opt, const char *opt_arg)
void putline(apr_file_t *f, const char *l)
Definition: apr_arch_file_io.h:107
Definition: lua_passwd.h:68
char * out
Definition: lua_passwd.h:71
apr_size_t out_len
Definition: lua_passwd.h:72
int cost
Definition: lua_passwd.h:75
char * passwd
Definition: lua_passwd.h:73
int alg
Definition: lua_passwd.h:74
@ PW_ARG
Definition: passwd_common.h:96
@ PW_STDIN
Definition: passwd_common.h:97
@ PW_PROMPT_VERIFY
Definition: passwd_common.h:98
@ PW_PROMPT
Definition: passwd_common.h:95
apr_pool_t * pool
Definition: lua_passwd.h:69
const char * errstr
Definition: lua_passwd.h:70
enum passwd_ctx::@23 passwd_src