Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • crypting.c

    ra301379c r43e3368  
    2929   the programs will be built. */
    3030
     31#ifndef CRYPTING_MAIN
     32#define BITLBEE_CORE
     33#include "bitlbee.h"
     34#include "irc.h"
    3135#include "md5.h"
    3236#include "crypting.h"
     
    3539#include <stdlib.h>
    3640
     41#else
     42
     43typedef 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
    3761/*\
    3862 * [SH] Do _not_ call this if it's not entirely sure that it will not cause
     
    4165\*/
    4266
    43 int checkpass (const char *pass, const char *md5sum)
    44 {
     67/* USE WITH CAUTION!
     68   Sets pass without checking */
     69void 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
     83char *passchange (irc_t *irc, void *set, char *value) {
     84        setpassnc (irc, value);
     85        return (NULL);
     86}
     87
     88int setpass (irc_t *irc, char *pass, char* md5sum) {
    4589        md5_state_t md5state;
    4690        md5_byte_t digest[16];
     
    59103                if (digits[1] != md5sum[j + 1]) return (-1);
    60104        }
    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
     112char *hashpass (irc_t *irc) {
    68113        md5_state_t md5state;
    69114        md5_byte_t digest[16];
     
    72117        char *rv;
    73118       
    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);
    77123       
    78124        md5_init (&md5state);
    79         md5_append (&md5state, (const unsigned char *)password, strlen (password));
     125        md5_append (&md5state, (unsigned char *)irc->password, strlen (irc->password));
    80126        md5_finish (&md5state, digest);
    81127       
     
    89135}
    90136
    91 char *obfucrypt (char *line, const char *password)
    92 {
     137char *obfucrypt (irc_t *irc, char *line) {
    93138        int i, j;
    94139        char *rv;
    95140       
    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);
    99145       
    100146        i = j = 0;
     
    102148                /* Encrypt/obfuscate the line, using the password */
    103149                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 */
    106153               
    107154                line++;
    108                 if (!password[++i]) i = 0;
     155                if (!irc->password[++i]) i = 0;
    109156                j++;
    110157        }
     
    113160}
    114161
    115 char *deobfucrypt (char *line, const char *password)
    116 {
     162char *deobfucrypt (irc_t *irc, char *line) {
    117163        int i, j;
    118164        char *rv;
    119165       
    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);
    123170       
    124171        i = j = 0;
    125172        while (*line) {
    126173                /* Decrypt/deobfuscate the line, using the pass */
    127                 rv[j] = *line - password[i]; /* Overflow intended */
     174                rv[j] = *line - irc->password[i]; /* Overflow intended */
    128175               
    129176                line++;
    130                 if (!password[++i]) i = 0;
     177                if (!irc->password[++i]) i = 0;
    131178                j++;
    132179        }
     
    142189int main( int argc, char *argv[] )
    143190{
     191        irc_t *irc = g_malloc( sizeof( irc_t ) );
    144192        char *hash, *action, line[256];
    145         char* (*func)( char *, const char * );
     193        char* (*func)( irc_t *, char * );
    146194       
    147195        if( argc < 2 )
     
    153201        }
    154202       
    155         hash = hashpass( argv[1] );
     203        memset( irc, 0, sizeof( irc_t ) );
     204        irc->password = g_strdup( argv[1] );
     205       
     206        hash = hashpass( irc );
    156207        action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    157208       
     
    185236                fgetc( stdin );
    186237               
    187                 out = func( line, argv[1] );
     238                out = func( irc, line );
    188239                printf( "%s\n", out );
    189240                g_free( out );
Note: See TracChangeset for help on using the changeset viewer.