00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "includes.h"
00023
00024 static struct {
00025 char from;
00026 const char *to;
00027 int len;
00028 } weird_table[] = {
00029 {'q', "^q^", 3},
00030 {'Q', "^Q^", 3},
00031 {0, NULL}
00032 };
00033
00034 static size_t weird_pull(void *cd, const char **inbuf, size_t *inbytesleft,
00035 char **outbuf, size_t *outbytesleft)
00036 {
00037 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
00038 int i;
00039 int done = 0;
00040 for (i=0;weird_table[i].from;i++) {
00041 if (strncmp((*inbuf),
00042 weird_table[i].to,
00043 weird_table[i].len) == 0) {
00044 if (*inbytesleft < weird_table[i].len) {
00045 DEBUG(0,("ERROR: truncated weird string\n"));
00046
00047
00048 } else {
00049 (*outbuf)[0] = weird_table[i].from;
00050 (*outbuf)[1] = 0;
00051 (*inbytesleft) -= weird_table[i].len;
00052 (*outbytesleft) -= 2;
00053 (*inbuf) += weird_table[i].len;
00054 (*outbuf) += 2;
00055 done = 1;
00056 break;
00057 }
00058 }
00059 }
00060 if (done) continue;
00061 (*outbuf)[0] = (*inbuf)[0];
00062 (*outbuf)[1] = 0;
00063 (*inbytesleft) -= 1;
00064 (*outbytesleft) -= 2;
00065 (*inbuf) += 1;
00066 (*outbuf) += 2;
00067 }
00068
00069 if (*inbytesleft > 0) {
00070 errno = E2BIG;
00071 return -1;
00072 }
00073
00074 return 0;
00075 }
00076
00077 static size_t weird_push(void *cd, const char **inbuf, size_t *inbytesleft,
00078 char **outbuf, size_t *outbytesleft)
00079 {
00080 int ir_count=0;
00081
00082 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
00083 int i;
00084 int done=0;
00085 for (i=0;weird_table[i].from;i++) {
00086 if ((*inbuf)[0] == weird_table[i].from &&
00087 (*inbuf)[1] == 0) {
00088 if (*outbytesleft < weird_table[i].len) {
00089 DEBUG(0,("No room for weird character\n"));
00090
00091 } else {
00092 memcpy(*outbuf, weird_table[i].to,
00093 weird_table[i].len);
00094 (*inbytesleft) -= 2;
00095 (*outbytesleft) -= weird_table[i].len;
00096 (*inbuf) += 2;
00097 (*outbuf) += weird_table[i].len;
00098 done = 1;
00099 break;
00100 }
00101 }
00102 }
00103 if (done) continue;
00104
00105 (*outbuf)[0] = (*inbuf)[0];
00106 if ((*inbuf)[1]) ir_count++;
00107 (*inbytesleft) -= 2;
00108 (*outbytesleft) -= 1;
00109 (*inbuf) += 2;
00110 (*outbuf) += 1;
00111 }
00112
00113 if (*inbytesleft == 1) {
00114 errno = EINVAL;
00115 return -1;
00116 }
00117
00118 if (*inbytesleft > 1) {
00119 errno = E2BIG;
00120 return -1;
00121 }
00122
00123 return ir_count;
00124 }
00125
00126 struct charset_functions weird_functions = {"WEIRD", weird_pull, weird_push};
00127
00128 NTSTATUS charset_weird_init(void);
00129 NTSTATUS charset_weird_init(void)
00130 {
00131 return smb_register_charset(&weird_functions);
00132 }