summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1998-11-10 19:05:00 +0000
committerLuke Leighton <lkcl@samba.org>1998-11-10 19:05:00 +0000
commit1e1c2ec93c204e6fd3ebba6dfb11e4fbc136e10c (patch)
tree1bf71664960c671d6447a085a5087ce13bb14fea /source3/lib
parent313d8ef27df81118b57f3d214db75be25e38b612 (diff)
downloadsamba-1e1c2ec93c204e6fd3ebba6dfb11e4fbc136e10c.tar.gz
samba-1e1c2ec93c204e6fd3ebba6dfb11e4fbc136e10c.tar.bz2
samba-1e1c2ec93c204e6fd3ebba6dfb11e4fbc136e10c.zip
rpcclient registry commands.
(This used to be commit 36fcb4a6e643a05d06a2a273d74318fee7f2c647)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/time.c79
-rw-r--r--source3/lib/util_str.c50
-rw-r--r--source3/lib/util_unistr.c64
3 files changed, 156 insertions, 37 deletions
diff --git a/source3/lib/time.c b/source3/lib/time.c
index ea96654108..3cea1a3e14 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -236,18 +236,6 @@ struct tm *LocalTime(time_t *t)
return(gmtime(&t2));
}
-/****************************************************************************
-take an NTTIME structure, containing high / low time. convert to unix time.
-lkclXXXX this may need 2 SIVALs not a memcpy. we'll see...
-****************************************************************************/
-time_t interpret_nt_time(NTTIME *t)
-{
- char data[8];
- memcpy(data, t, sizeof(data));
- return interpret_long_date(data);
-}
-
-
#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
/****************************************************************************
@@ -259,22 +247,19 @@ its the GMT you get by taking a localtime and adding the
serverzone. This is NOT the same as GMT in some cases. This routine
converts this to real GMT.
****************************************************************************/
-time_t interpret_long_date(char *p)
+time_t nt_time_to_unix(NTTIME *nt)
{
double d;
time_t ret;
- uint32 tlow,thigh;
/* The next two lines are a fix needed for the
broken SCO compiler. JRA. */
time_t l_time_min = TIME_T_MIN;
time_t l_time_max = TIME_T_MAX;
- tlow = IVAL(p,0);
- thigh = IVAL(p,4);
- if (thigh == 0) return(0);
+ if (nt->high == 0) return(0);
- d = ((double)thigh)*4.0*(double)(1<<30);
- d += (tlow&0xFFF00000);
+ d = ((double)nt->high)*4.0*(double)(1<<30);
+ d += (nt->low&0xFFF00000);
d *= 1.0e-7;
/* now adjust by 369 years to make the secs since 1970 */
@@ -293,37 +278,57 @@ time_t interpret_long_date(char *p)
}
+
+/****************************************************************************
+interprets an nt time into a unix time_t
+****************************************************************************/
+time_t interpret_long_date(char *p)
+{
+ NTTIME nt;
+ nt.low = IVAL(p,0);
+ nt.high = IVAL(p,4);
+ return nt_time_to_unix(&nt);
+}
+
/****************************************************************************
put a 8 byte filetime from a time_t
This takes real GMT as input and converts to kludge-GMT
****************************************************************************/
-void put_long_date(char *p,time_t t)
+void unix_to_nt_time(NTTIME *nt, time_t t)
{
- uint32 tlow,thigh;
- double d;
+ double d;
- if (t==0) {
- SIVAL(p,0,0); SIVAL(p,4,0);
- return;
- }
-
- /* this converts GMT to kludge-GMT */
- t -= LocTimeDiff(t) - serverzone;
+ if (t==0)
+ {
+ nt->low = 0;
+ nt->high = 0;
+ return;
+ }
- d = (double) (t);
+ /* this converts GMT to kludge-GMT */
+ t -= LocTimeDiff(t) - serverzone;
- d += TIME_FIXUP_CONSTANT;
+ d = (double)(t);
+ d += TIME_FIXUP_CONSTANT;
+ d *= 1.0e7;
- d *= 1.0e7;
+ nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
+ nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
+}
- thigh = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
- tlow = (uint32)(d - ((double)thigh)*4.0*(double)(1<<30));
- SIVAL(p,0,tlow);
- SIVAL(p,4,thigh);
+/****************************************************************************
+take an NTTIME structure, containing high / low time. convert to unix time.
+lkclXXXX this may need 2 SIVALs not a memcpy. we'll see...
+****************************************************************************/
+void put_long_date(char *p,time_t t)
+{
+ NTTIME nt;
+ unix_to_nt_time(&nt, t);
+ SIVAL(p, 0, nt.low);
+ SIVAL(p, 4, nt.high);
}
-
/****************************************************************************
check if it's a null mtime
****************************************************************************/
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 7eb1494382..15eefb0001 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -857,6 +857,56 @@ char *strncpyn(char *dest, char *src,int n, char c)
}
+/*************************************************************
+ Routine to get hex characters and turn them into a 16 byte array.
+ the array can be variable length, and any non-hex-numeric
+ characters are skipped. "0xnn" or "0Xnn" is specially catered
+ for.
+
+ valid examples: "0A5D15"; "0x15, 0x49, 0xa2"; "59\ta9\te3\n"
+
+**************************************************************/
+int strhex_to_str(char *p, int len, const char *strhex)
+{
+ int i;
+ int num_chars = 0;
+ unsigned char lonybble, hinybble;
+ char *hexchars = "0123456789ABCDEF";
+ char *p1 = NULL, *p2 = NULL;
+
+ for (i = 0; i < len && strhex[i] != 0; i++)
+ {
+ if (strnequal(hexchars, "0x", 2))
+ {
+ i++; /* skip two chars */
+ continue;
+ }
+
+ while (!(p1 = strchr(hexchars, toupper(strhex[i]))))
+ {
+ continue;
+ }
+
+ i++; /* next hex digit */
+
+ while (!(p2 = strchr(hexchars, toupper(strhex[i]))))
+ {
+ continue;
+ }
+
+ /* get the two nybbles */
+ hinybble = PTR_DIFF(p1, hexchars);
+ lonybble = PTR_DIFF(p2, hexchars);
+
+ p[num_chars] = (hinybble << 4) | lonybble;
+ num_chars++;
+
+ p1 = NULL;
+ p2 = NULL;
+ }
+ return num_chars;
+}
+
/****************************************************************************
check if a string is part of a list
****************************************************************************/
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 2365090f24..49fb729267 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -119,6 +119,70 @@ char *unistr2_to_str(UNISTR2 *str)
}
/*******************************************************************
+Return a number stored in a buffer
+********************************************************************/
+uint32 buffer2_to_uint32(BUFFER2 *str)
+{
+ if (str->buf_len == 4)
+ {
+ return IVAL(str->buffer, 0);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/*******************************************************************
+Return a ascii version of a NOTunicode string
+********************************************************************/
+char *buffer2_to_str(BUFFER2 *str)
+{
+ char *lbuf = lbufs[nexti];
+ char *p;
+ uint16 *buf = str->buffer;
+ int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
+
+ nexti = (nexti+1)%8;
+
+ for (p = lbuf; *buf && p-lbuf < max_size; p++, buf++)
+ {
+ *p = *buf;
+ }
+
+ *p = 0;
+ return lbuf;
+}
+
+/*******************************************************************
+Return a ascii version of a NOTunicode string
+********************************************************************/
+char *buffer2_to_multistr(BUFFER2 *str)
+{
+ char *lbuf = lbufs[nexti];
+ char *p;
+ uint16 *buf = str->buffer;
+ int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2);
+
+ nexti = (nexti+1)%8;
+
+ for (p = lbuf; p-lbuf < max_size; p++, buf++)
+ {
+ if (*buf == 0)
+ {
+ *p = ' ';
+ }
+ else
+ {
+ *p = *buf;
+ }
+ }
+
+ *p = 0;
+ return lbuf;
+}
+
+/*******************************************************************
create a null-terminated unicode string from a null-terminated ascii string.
return number of unicode chars copied, excluding the null character.