summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-03-30 17:49:01 +1100
committerAndrew Bartlett <abartlet@samba.org>2011-03-30 12:17:05 +0200
commita64958a8805b6ef1758293697e63309d3ddbe4ae (patch)
tree325ced3f0b6910c7761a2ddd9a6500493c2c0a87 /source3
parent48d0abe0b50b4e0414f5dcb46aae2a4b5bfaac7e (diff)
downloadsamba-a64958a8805b6ef1758293697e63309d3ddbe4ae.tar.gz
samba-a64958a8805b6ef1758293697e63309d3ddbe4ae.tar.bz2
samba-a64958a8805b6ef1758293697e63309d3ddbe4ae.zip
lib/util Move base64 functions into lib/util/base64.c
Andrew Bartlett
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/proto.h3
-rw-r--r--source3/lib/util_str.c115
3 files changed, 1 insertions, 119 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 15279ee039..05843efd63 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -450,7 +450,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
lib/access.o lib/smbrun.o \
lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
lib/wins_srv.o \
- lib/util_str.o lib/util_sid.o \
+ lib/util_str.o ../lib/util/base64.o lib/util_sid.o \
lib/util_unistr.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
lib/util.o lib/util_names.o \
lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
diff --git a/source3/include/proto.h b/source3/include/proto.h
index a565f93462..91ff45d7b9 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1026,9 +1026,6 @@ char *ipstr_list_make(char **ipstr_list,
int ip_count);
int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list);
void ipstr_list_free(char* ipstr_list);
-DATA_BLOB base64_decode_data_blob(const char *s);
-void base64_decode_inplace(char *s);
-char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data);
uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr);
SMB_OFF_T conv_str_size(const char * str);
void string_append(char **left, const char *right);
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 7b50717463..0f75f45bf1 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -1515,121 +1515,6 @@ void ipstr_list_free(char* ipstr_list)
SAFE_FREE(ipstr_list);
}
-static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-/**
- * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
- **/
-DATA_BLOB base64_decode_data_blob(const char *s)
-{
- int bit_offset, byte_offset, idx, i, n;
- DATA_BLOB decoded = data_blob(s, strlen(s)+1);
- unsigned char *d = decoded.data;
- char *p;
-
- n=i=0;
-
- while (*s && (p=strchr_m(b64,*s))) {
- idx = (int)(p - b64);
- byte_offset = (i*6)/8;
- bit_offset = (i*6)%8;
- d[byte_offset] &= ~((1<<(8-bit_offset))-1);
- if (bit_offset < 3) {
- d[byte_offset] |= (idx << (2-bit_offset));
- n = byte_offset+1;
- } else {
- d[byte_offset] |= (idx >> (bit_offset-2));
- d[byte_offset+1] = 0;
- d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
- n = byte_offset+2;
- }
- s++; i++;
- }
-
- if ((n > 0) && (*s == '=')) {
- n -= 1;
- }
-
- /* fix up length */
- decoded.length = n;
- return decoded;
-}
-
-/**
- * Decode a base64 string in-place - wrapper for the above
- **/
-void base64_decode_inplace(char *s)
-{
- DATA_BLOB decoded = base64_decode_data_blob(s);
-
- if ( decoded.length != 0 ) {
- memcpy(s, decoded.data, decoded.length);
-
- /* null terminate */
- s[decoded.length] = '\0';
- } else {
- *s = '\0';
- }
-
- data_blob_free(&decoded);
-}
-
-/**
- * Encode a base64 string into a talloc()ed string caller to free.
- *
- * From SQUID: adopted from http://ftp.sunet.se/pub2/gnu/vm/base64-encode.c
- * with adjustments
- **/
-
-char *base64_encode_data_blob(TALLOC_CTX *mem_ctx, DATA_BLOB data)
-{
- int bits = 0;
- int char_count = 0;
- size_t out_cnt, len, output_len;
- char *result;
-
- if (!data.length || !data.data)
- return NULL;
-
- out_cnt = 0;
- len = data.length;
- output_len = data.length * 2 + 4; /* Account for closing bytes. 4 is
- * random but should be enough for
- * the = and \0 */
- result = TALLOC_ARRAY(mem_ctx, char, output_len); /* get us plenty of space */
- SMB_ASSERT(result != NULL);
-
- while (len--) {
- int c = (unsigned char) *(data.data++);
- bits += c;
- char_count++;
- if (char_count == 3) {
- result[out_cnt++] = b64[bits >> 18];
- result[out_cnt++] = b64[(bits >> 12) & 0x3f];
- result[out_cnt++] = b64[(bits >> 6) & 0x3f];
- result[out_cnt++] = b64[bits & 0x3f];
- bits = 0;
- char_count = 0;
- } else {
- bits <<= 8;
- }
- }
- if (char_count != 0) {
- bits <<= 16 - (8 * char_count);
- result[out_cnt++] = b64[bits >> 18];
- result[out_cnt++] = b64[(bits >> 12) & 0x3f];
- if (char_count == 1) {
- result[out_cnt++] = '=';
- result[out_cnt++] = '=';
- } else {
- result[out_cnt++] = b64[(bits >> 6) & 0x3f];
- result[out_cnt++] = '=';
- }
- }
- result[out_cnt] = '\0'; /* terminate */
- return result;
-}
-
/* read a SMB_BIG_UINT from a string */
uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr)
{