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