xref: /onnv-gate/usr/src/lib/pam_modules/authtok_check/packer.h (revision 9798:c54abbfdeb61)
10Sstevel@tonic-gate /*
2*9798SJoep.Vesseur@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate #ifndef _PACKER_H
60Sstevel@tonic-gate #define	_PACKER_H
70Sstevel@tonic-gate 
80Sstevel@tonic-gate #ifdef __cplusplus
90Sstevel@tonic-gate extern "C" {
100Sstevel@tonic-gate #endif
110Sstevel@tonic-gate 
120Sstevel@tonic-gate /*
130Sstevel@tonic-gate  * This program is copyright Alec Muffett 1993. The author disclaims all
140Sstevel@tonic-gate  * responsibility or liability with respect to it's usage or its effect
150Sstevel@tonic-gate  * upon hardware or computer systems, and maintains copyright as set out
160Sstevel@tonic-gate  * in the "LICENCE" document which accompanies distributions of Crack v4.0
170Sstevel@tonic-gate  * and upwards.
180Sstevel@tonic-gate  */
190Sstevel@tonic-gate 
200Sstevel@tonic-gate #include <stdio.h>
210Sstevel@tonic-gate #include <ctype.h>
220Sstevel@tonic-gate #include <string.h>
230Sstevel@tonic-gate #include <unistd.h>
240Sstevel@tonic-gate #include <errno.h>
250Sstevel@tonic-gate #include <stdlib.h>
260Sstevel@tonic-gate #include <limits.h>
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/wait.h>
290Sstevel@tonic-gate #include <sys/stat.h>
300Sstevel@tonic-gate #include <fcntl.h>
310Sstevel@tonic-gate #include <synch.h>
320Sstevel@tonic-gate #include <syslog.h>
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #define	PWADMIN		"/etc/default/passwd"
350Sstevel@tonic-gate #define	TRUNCSTRINGSIZE	(PATH_MAX/4)
360Sstevel@tonic-gate #define	STRINGSIZE	PATH_MAX
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifndef NUMWORDS
390Sstevel@tonic-gate #define	NUMWORDS 	16
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate #define	MAXWORDLEN	32
420Sstevel@tonic-gate #define	MAXBLOCKLEN 	(MAXWORDLEN * NUMWORDS)
430Sstevel@tonic-gate 
440Sstevel@tonic-gate struct pi_header
450Sstevel@tonic-gate {
46*9798SJoep.Vesseur@Sun.COM 	uint32_t pih_magic;
47*9798SJoep.Vesseur@Sun.COM 	uint32_t pih_numwords;
48*9798SJoep.Vesseur@Sun.COM 	uint16_t pih_blocklen;
49*9798SJoep.Vesseur@Sun.COM 	uint16_t pih_pad;
500Sstevel@tonic-gate };
510Sstevel@tonic-gate 
520Sstevel@tonic-gate typedef struct
530Sstevel@tonic-gate {
540Sstevel@tonic-gate 	FILE *ifp;
550Sstevel@tonic-gate 	FILE *dfp;
560Sstevel@tonic-gate 	FILE *wfp;
570Sstevel@tonic-gate 
58*9798SJoep.Vesseur@Sun.COM 	uint32_t flags;
590Sstevel@tonic-gate #define	PFOR_WRITE	0x0001
600Sstevel@tonic-gate #define	PFOR_FLUSH	0x0002
610Sstevel@tonic-gate #define	PFOR_USEHWMS	0x0004
620Sstevel@tonic-gate 
63*9798SJoep.Vesseur@Sun.COM 	uint32_t hwms[256];
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	struct pi_header header;
660Sstevel@tonic-gate 
67*9798SJoep.Vesseur@Sun.COM 	uint32_t count;
680Sstevel@tonic-gate 	char data[NUMWORDS][MAXWORDLEN];
690Sstevel@tonic-gate } PWDICT;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate #define	PW_WORDS(x) ((x)->header.pih_numwords)
72*9798SJoep.Vesseur@Sun.COM #define	PIH_MAGIC 0x70775632
730Sstevel@tonic-gate 
740Sstevel@tonic-gate void PWRemove(char *);
750Sstevel@tonic-gate PWDICT *PWOpen(char *, char *);
760Sstevel@tonic-gate char *Mangle(char *, char *);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate #define	CRACK_TOLOWER(a) 	(isupper(a)?tolower(a):(a))
790Sstevel@tonic-gate #define	CRACK_TOUPPER(a) 	(islower(a)?toupper(a):(a))
800Sstevel@tonic-gate #define	STRCMP(a, b)		strcmp((a), (b))
810Sstevel@tonic-gate 
820Sstevel@tonic-gate char	*Trim(register char *);
83*9798SJoep.Vesseur@Sun.COM uint32_t	FindPW(PWDICT *, char *);
840Sstevel@tonic-gate int	PWClose(PWDICT *);
850Sstevel@tonic-gate int	PutPW(PWDICT *, char *);
860Sstevel@tonic-gate char	Chop(register char *);
870Sstevel@tonic-gate char	Chomp(register char *);
88*9798SJoep.Vesseur@Sun.COM char	*GetPW(PWDICT *, uint32_t);
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	DATABASE_OPEN_FAIL		-1
910Sstevel@tonic-gate #define	DICTIONARY_WORD			2
920Sstevel@tonic-gate #define	REVERSE_DICTIONARY_WORD		3
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /* Dictionary database dir and prefix */
960Sstevel@tonic-gate 
970Sstevel@tonic-gate #define	CRACK_DIR		"/var/passwd"
980Sstevel@tonic-gate #define	CRACK_DICTPATH		"/var/passwd/pw_dict"
990Sstevel@tonic-gate #define	DICT_DATABASE_HWM	"pw_dict.hwm"
1000Sstevel@tonic-gate #define	DICT_DATABASE_PWD	"pw_dict.pwd"
1010Sstevel@tonic-gate #define	DICT_DATABASE_PWI	"pw_dict.pwi"
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate int packer(char *, char *);
1040Sstevel@tonic-gate char *Reverse(char *);
1050Sstevel@tonic-gate char *Lowercase(char *);
1060Sstevel@tonic-gate int DictCheck(char *, char *);
1070Sstevel@tonic-gate int make_dict_database(char *, char *);
1080Sstevel@tonic-gate int build_dict_database(char *, char *);
1090Sstevel@tonic-gate int lock_db(char *);
1100Sstevel@tonic-gate void unlock_db();
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /* Return values for dictionary database checks */
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #define	NO_DICTDATABASE		1
1150Sstevel@tonic-gate #define	UPDATE_DICTDATABASE	2
1160Sstevel@tonic-gate #define	DICTFILE_ERR		-1
1170Sstevel@tonic-gate #define	DICTPATH_ERR		-2
1180Sstevel@tonic-gate #define	DICTDATABASE_BUILD_ERR	-3
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #ifdef __cplusplus
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate #endif
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #endif /* _PACKER_H */
125