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