Fix #193: Pidgin Status changes stop working (III)
[siplcs.git] / src / core / sip-sec-ntlm-analyzer.c
blob06facc151ac620fb3cbbcfacef59326a4af32ce8
1 /**
2 * @file sip-sec-ntlm-analyzer.c
4 * pidgin-sipe
6 * Copyright (C) 2013 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Takes Base64-encoded gssapi-data= values from NTLM authentication attempt
25 * on the command line and prints out the NTLM message contents in human readable
26 * format.
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
33 #include <stdlib.h>
34 #include <stdarg.h>
36 #include <glib.h>
37 #include <glib/gprintf.h>
39 #include "sipe-common.h"
40 #define _SIPE_COMPILING_ANALYZER
41 #include "sip-sec-ntlm.c"
43 /* stub functions */
44 void sipe_backend_debug(SIPE_UNUSED_PARAMETER sipe_debug_level level,
45 const gchar *format,
46 ...)
48 va_list ap;
49 va_start(ap, format);
50 vprintf(format, ap);
51 va_end(ap);
54 gboolean sipe_strequal(const gchar *left, const gchar *right)
56 #if GLIB_CHECK_VERSION(2,16,0)
57 return (g_strcmp0(left, right) == 0);
58 #else
59 return ((left == NULL && right == NULL) ||
60 (left != NULL && right != NULL && strcmp(left, right) == 0));
61 #endif
64 /* copied from sipe-utils.c */
65 char *buff_to_hex_str(const guint8 *buff, const size_t buff_len)
67 char *res;
68 size_t i, j;
70 if (!buff) return NULL;
72 res = g_malloc(buff_len * 2 + 1);
73 for (i = 0, j = 0; i < buff_len; i++, j+=2) {
74 sprintf(&res[j], "%02X", buff[i]);
76 res[j] = '\0';
77 return res;
80 int main(int argc, char *argv[])
82 if (argc < 2) {
83 fprintf(stderr, "Usage: %s <gssapi-data> ...\n", argv[0]);
84 return(1);
87 sip_sec_init__ntlm();
89 while (--argc > 0) {
90 const gchar *base64 = *++argv;
91 SipSecBuffer buffer;
93 printf("Base64: %s\n", base64);
94 buffer.value = g_base64_decode(base64, &buffer.length);
95 if (buffer.value && buffer.length) {
96 printf("Decoded %" G_GSIZE_FORMAT " bytes\n", buffer.length);
97 sip_sec_ntlm_message_describe(&buffer, "analyzed");
98 printf("-------------------------------------------------------------------------------\n");
99 g_free(buffer.value);
100 } else {
101 printf("Corrupted Base64 - skipping\n");
105 sip_sec_destroy__ntlm();
107 return(0);
111 Local Variables:
112 mode: c
113 c-file-style: "bsd"
114 indent-tabs-mode: t
115 tab-width: 8
116 End: