Changes in crypting.c [a301379c:43e3368]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
crypting.c
ra301379c r43e3368 29 29 the programs will be built. */ 30 30 31 #ifndef CRYPTING_MAIN 32 #define BITLBEE_CORE 33 #include "bitlbee.h" 34 #include "irc.h" 31 35 #include "md5.h" 32 36 #include "crypting.h" … … 35 39 #include <stdlib.h> 36 40 41 #else 42 43 typedef struct irc 44 { 45 char *password; 46 } irc_t; 47 48 #define set_add( a, b, c, d ) 49 #define set_find( a, b ) NULL 50 51 #include "md5.h" 52 #include "crypting.h" 53 #include <string.h> 54 #include <stdio.h> 55 #include <stdlib.h> 56 57 #define irc_usermsg 58 59 #endif 60 37 61 /*\ 38 62 * [SH] Do _not_ call this if it's not entirely sure that it will not cause … … 41 65 \*/ 42 66 43 int checkpass (const char *pass, const char *md5sum) 44 { 67 /* USE WITH CAUTION! 68 Sets pass without checking */ 69 void setpassnc (irc_t *irc, char *pass) { 70 if (!set_find (irc, "password")) 71 set_add (irc, "password", NULL, passchange); 72 73 if (irc->password) g_free (irc->password); 74 75 if (pass) { 76 irc->password = g_strdup (pass); 77 irc_usermsg (irc, "Password successfully changed"); 78 } else { 79 irc->password = NULL; 80 } 81 } 82 83 char *passchange (irc_t *irc, void *set, char *value) { 84 setpassnc (irc, value); 85 return (NULL); 86 } 87 88 int setpass (irc_t *irc, char *pass, char* md5sum) { 45 89 md5_state_t md5state; 46 90 md5_byte_t digest[16]; … … 59 103 if (digits[1] != md5sum[j + 1]) return (-1); 60 104 } 61 62 return( 0 ); 63 } 64 65 66 char *hashpass (const char *password) 67 { 105 106 /* If pass is correct, we end up here and we set the pass */ 107 setpassnc (irc, pass); 108 109 return (0); 110 } 111 112 char *hashpass (irc_t *irc) { 68 113 md5_state_t md5state; 69 114 md5_byte_t digest[16]; … … 72 117 char *rv; 73 118 74 if (password == NULL) return (NULL); 75 76 rv = g_new0 (char, 33); 119 if (irc->password == NULL) return (NULL); 120 121 rv = (char *)g_malloc (33); 122 memset (rv, 0, 33); 77 123 78 124 md5_init (&md5state); 79 md5_append (&md5state, ( const unsigned char *)password, strlen (password));125 md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password)); 80 126 md5_finish (&md5state, digest); 81 127 … … 89 135 } 90 136 91 char *obfucrypt (char *line, const char *password) 92 { 137 char *obfucrypt (irc_t *irc, char *line) { 93 138 int i, j; 94 139 char *rv; 95 140 96 if (password == NULL) return (NULL); 97 98 rv = g_new0 (char, strlen (line) + 1); 141 if (irc->password == NULL) return (NULL); 142 143 rv = (char *)g_malloc (strlen (line) + 1); 144 memset (rv, '\0', strlen (line) + 1); 99 145 100 146 i = j = 0; … … 102 148 /* Encrypt/obfuscate the line, using the password */ 103 149 if (*(signed char*)line < 0) *line = - (*line); 104 105 rv[j] = *line + password[i]; /* Overflow intended */ 150 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i]; 151 152 rv[j] = *line + irc->password[i]; /* Overflow intended */ 106 153 107 154 line++; 108 if (! password[++i]) i = 0;155 if (!irc->password[++i]) i = 0; 109 156 j++; 110 157 } … … 113 160 } 114 161 115 char *deobfucrypt (char *line, const char *password) 116 { 162 char *deobfucrypt (irc_t *irc, char *line) { 117 163 int i, j; 118 164 char *rv; 119 165 120 if (password == NULL) return (NULL); 121 122 rv = g_new0 (char, strlen (line) + 1); 166 if (irc->password == NULL) return (NULL); 167 168 rv = (char *)g_malloc (strlen (line) + 1); 169 memset (rv, '\0', strlen (line) + 1); 123 170 124 171 i = j = 0; 125 172 while (*line) { 126 173 /* Decrypt/deobfuscate the line, using the pass */ 127 rv[j] = *line - password[i]; /* Overflow intended */174 rv[j] = *line - irc->password[i]; /* Overflow intended */ 128 175 129 176 line++; 130 if (! password[++i]) i = 0;177 if (!irc->password[++i]) i = 0; 131 178 j++; 132 179 } … … 142 189 int main( int argc, char *argv[] ) 143 190 { 191 irc_t *irc = g_malloc( sizeof( irc_t ) ); 144 192 char *hash, *action, line[256]; 145 char* (*func)( char *, constchar * );193 char* (*func)( irc_t *, char * ); 146 194 147 195 if( argc < 2 ) … … 153 201 } 154 202 155 hash = hashpass( argv[1] ); 203 memset( irc, 0, sizeof( irc_t ) ); 204 irc->password = g_strdup( argv[1] ); 205 206 hash = hashpass( irc ); 156 207 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 157 208 … … 185 236 fgetc( stdin ); 186 237 187 out = func( line, argv[1]);238 out = func( irc, line ); 188 239 printf( "%s\n", out ); 189 240 g_free( out );
Note: See TracChangeset
for help on using the changeset viewer.