xref: /titanic_41/usr/src/lib/pam_modules/authtok_check/packer.h (revision dd49f125507979bb2ab505a8daf2a46d1be27051)
1 /*
2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 #ifndef _PACKER_H
6 #define	_PACKER_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /*
13  * This program is copyright Alec Muffett 1993. The author disclaims all
14  * responsibility or liability with respect to it's usage or its effect
15  * upon hardware or computer systems, and maintains copyright as set out
16  * in the "LICENCE" document which accompanies distributions of Crack v4.0
17  * and upwards.
18  */
19 
20 #include <stdio.h>
21 #include <ctype.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <synch.h>
32 #include <syslog.h>
33 
34 #define	PWADMIN		"/etc/default/passwd"
35 #define	TRUNCSTRINGSIZE	(PATH_MAX/4)
36 #define	STRINGSIZE	PATH_MAX
37 
38 #ifndef NUMWORDS
39 #define	NUMWORDS 	16
40 #endif
41 #define	MAXWORDLEN	32
42 #define	MAXBLOCKLEN 	(MAXWORDLEN * NUMWORDS)
43 
44 struct pi_header
45 {
46 	uint32_t pih_magic;
47 	uint32_t pih_numwords;
48 	uint16_t pih_blocklen;
49 	uint16_t pih_pad;
50 };
51 
52 typedef struct
53 {
54 	FILE *ifp;
55 	FILE *dfp;
56 	FILE *wfp;
57 
58 	uint32_t flags;
59 #define	PFOR_WRITE	0x0001
60 #define	PFOR_FLUSH	0x0002
61 #define	PFOR_USEHWMS	0x0004
62 
63 	uint32_t hwms[256];
64 
65 	struct pi_header header;
66 
67 	uint32_t count;
68 	char data[NUMWORDS][MAXWORDLEN];
69 } PWDICT;
70 
71 #define	PW_WORDS(x) ((x)->header.pih_numwords)
72 #define	PIH_MAGIC 0x70775632
73 
74 void PWRemove(char *);
75 PWDICT *PWOpen(char *, char *);
76 char *Mangle(char *, char *);
77 
78 #define	CRACK_TOLOWER(a) 	(isupper(a)?tolower(a):(a))
79 #define	CRACK_TOUPPER(a) 	(islower(a)?toupper(a):(a))
80 #define	STRCMP(a, b)		strcmp((a), (b))
81 
82 char	*Trim(register char *);
83 uint32_t	FindPW(PWDICT *, char *);
84 int	PWClose(PWDICT *);
85 int	PutPW(PWDICT *, char *);
86 char	Chop(register char *);
87 char	Chomp(register char *);
88 char	*GetPW(PWDICT *, uint32_t);
89 
90 #define	DATABASE_OPEN_FAIL		-1
91 #define	DICTIONARY_WORD			2
92 #define	REVERSE_DICTIONARY_WORD		3
93 
94 
95 /* Dictionary database dir and prefix */
96 
97 #define	CRACK_DIR		"/var/passwd"
98 #define	CRACK_DICTPATH		"/var/passwd/pw_dict"
99 #define	DICT_DATABASE_HWM	"pw_dict.hwm"
100 #define	DICT_DATABASE_PWD	"pw_dict.pwd"
101 #define	DICT_DATABASE_PWI	"pw_dict.pwi"
102 
103 int packer(char *, char *);
104 char *Reverse(char *);
105 char *Lowercase(char *);
106 int DictCheck(char *, char *);
107 int make_dict_database(char *, char *);
108 int build_dict_database(char *, char *);
109 int lock_db(char *);
110 void unlock_db();
111 
112 /* Return values for dictionary database checks */
113 
114 #define	NO_DICTDATABASE		1
115 #define	UPDATE_DICTDATABASE	2
116 #define	DICTFILE_ERR		-1
117 #define	DICTPATH_ERR		-2
118 #define	DICTDATABASE_BUILD_ERR	-3
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* _PACKER_H */
125