xref: /titanic_51/usr/src/lib/pam_modules/authtok_check/packer.h (revision c7402f0767d7a0360fabd0bd449c6baf9b282074)
17c478bd9Sstevel@tonic-gate /*
2*c7402f07SJoep Vesseur  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate #ifndef _PACKER_H
67c478bd9Sstevel@tonic-gate #define	_PACKER_H
77c478bd9Sstevel@tonic-gate 
87c478bd9Sstevel@tonic-gate #ifdef __cplusplus
97c478bd9Sstevel@tonic-gate extern "C" {
107c478bd9Sstevel@tonic-gate #endif
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate /*
137c478bd9Sstevel@tonic-gate  * This program is copyright Alec Muffett 1993. The author disclaims all
147c478bd9Sstevel@tonic-gate  * responsibility or liability with respect to it's usage or its effect
157c478bd9Sstevel@tonic-gate  * upon hardware or computer systems, and maintains copyright as set out
167c478bd9Sstevel@tonic-gate  * in the "LICENCE" document which accompanies distributions of Crack v4.0
177c478bd9Sstevel@tonic-gate  * and upwards.
187c478bd9Sstevel@tonic-gate  */
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include <stdio.h>
217c478bd9Sstevel@tonic-gate #include <ctype.h>
227c478bd9Sstevel@tonic-gate #include <string.h>
237c478bd9Sstevel@tonic-gate #include <unistd.h>
247c478bd9Sstevel@tonic-gate #include <errno.h>
257c478bd9Sstevel@tonic-gate #include <stdlib.h>
267c478bd9Sstevel@tonic-gate #include <limits.h>
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/wait.h>
297c478bd9Sstevel@tonic-gate #include <sys/stat.h>
307c478bd9Sstevel@tonic-gate #include <fcntl.h>
317c478bd9Sstevel@tonic-gate #include <synch.h>
327c478bd9Sstevel@tonic-gate #include <syslog.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #define	PWADMIN		"/etc/default/passwd"
357c478bd9Sstevel@tonic-gate #define	TRUNCSTRINGSIZE	(PATH_MAX/4)
367c478bd9Sstevel@tonic-gate #define	STRINGSIZE	PATH_MAX
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef NUMWORDS
397c478bd9Sstevel@tonic-gate #define	NUMWORDS 	16
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate #define	MAXWORDLEN	32
427c478bd9Sstevel@tonic-gate #define	MAXBLOCKLEN 	(MAXWORDLEN * NUMWORDS)
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate struct pi_header
457c478bd9Sstevel@tonic-gate {
46*c7402f07SJoep Vesseur 	uint32_t pih_magic;
47*c7402f07SJoep Vesseur 	uint32_t pih_numwords;
48*c7402f07SJoep Vesseur 	uint16_t pih_blocklen;
49*c7402f07SJoep Vesseur 	uint16_t pih_pad;
507c478bd9Sstevel@tonic-gate };
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef struct
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	FILE *ifp;
557c478bd9Sstevel@tonic-gate 	FILE *dfp;
567c478bd9Sstevel@tonic-gate 	FILE *wfp;
577c478bd9Sstevel@tonic-gate 
58*c7402f07SJoep Vesseur 	uint32_t flags;
597c478bd9Sstevel@tonic-gate #define	PFOR_WRITE	0x0001
607c478bd9Sstevel@tonic-gate #define	PFOR_FLUSH	0x0002
617c478bd9Sstevel@tonic-gate #define	PFOR_USEHWMS	0x0004
627c478bd9Sstevel@tonic-gate 
63*c7402f07SJoep Vesseur 	uint32_t hwms[256];
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	struct pi_header header;
667c478bd9Sstevel@tonic-gate 
67*c7402f07SJoep Vesseur 	uint32_t count;
687c478bd9Sstevel@tonic-gate 	char data[NUMWORDS][MAXWORDLEN];
697c478bd9Sstevel@tonic-gate } PWDICT;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #define	PW_WORDS(x) ((x)->header.pih_numwords)
72*c7402f07SJoep Vesseur #define	PIH_MAGIC 0x70775632
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate void PWRemove(char *);
757c478bd9Sstevel@tonic-gate PWDICT *PWOpen(char *, char *);
767c478bd9Sstevel@tonic-gate char *Mangle(char *, char *);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	CRACK_TOLOWER(a) 	(isupper(a)?tolower(a):(a))
797c478bd9Sstevel@tonic-gate #define	CRACK_TOUPPER(a) 	(islower(a)?toupper(a):(a))
807c478bd9Sstevel@tonic-gate #define	STRCMP(a, b)		strcmp((a), (b))
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate char	*Trim(register char *);
83*c7402f07SJoep Vesseur uint32_t	FindPW(PWDICT *, char *);
847c478bd9Sstevel@tonic-gate int	PWClose(PWDICT *);
857c478bd9Sstevel@tonic-gate int	PutPW(PWDICT *, char *);
867c478bd9Sstevel@tonic-gate char	Chop(register char *);
877c478bd9Sstevel@tonic-gate char	Chomp(register char *);
88*c7402f07SJoep Vesseur char	*GetPW(PWDICT *, uint32_t);
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	DATABASE_OPEN_FAIL		-1
917c478bd9Sstevel@tonic-gate #define	DICTIONARY_WORD			2
927c478bd9Sstevel@tonic-gate #define	REVERSE_DICTIONARY_WORD		3
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* Dictionary database dir and prefix */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	CRACK_DIR		"/var/passwd"
987c478bd9Sstevel@tonic-gate #define	CRACK_DICTPATH		"/var/passwd/pw_dict"
997c478bd9Sstevel@tonic-gate #define	DICT_DATABASE_HWM	"pw_dict.hwm"
1007c478bd9Sstevel@tonic-gate #define	DICT_DATABASE_PWD	"pw_dict.pwd"
1017c478bd9Sstevel@tonic-gate #define	DICT_DATABASE_PWI	"pw_dict.pwi"
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate int packer(char *, char *);
1047c478bd9Sstevel@tonic-gate char *Reverse(char *);
1057c478bd9Sstevel@tonic-gate char *Lowercase(char *);
1067c478bd9Sstevel@tonic-gate int DictCheck(char *, char *);
1077c478bd9Sstevel@tonic-gate int make_dict_database(char *, char *);
1087c478bd9Sstevel@tonic-gate int build_dict_database(char *, char *);
1097c478bd9Sstevel@tonic-gate int lock_db(char *);
1107c478bd9Sstevel@tonic-gate void unlock_db();
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /* Return values for dictionary database checks */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	NO_DICTDATABASE		1
1157c478bd9Sstevel@tonic-gate #define	UPDATE_DICTDATABASE	2
1167c478bd9Sstevel@tonic-gate #define	DICTFILE_ERR		-1
1177c478bd9Sstevel@tonic-gate #define	DICTPATH_ERR		-2
1187c478bd9Sstevel@tonic-gate #define	DICTDATABASE_BUILD_ERR	-3
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate #endif
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #endif /* _PACKER_H */
125