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