mirror of
https://github.com/samba-team/samba.git
synced 2025-01-13 13:18:06 +03:00
0f1f0ceb95
Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release'
designed to make browsing across subnets work.
byteorder.h: Updated copyright to 1997.
charcnv.c: Updated copyright to 1997.
charset.c Updated copyright to 1997.
charset.h Updated copyright to 1997.
client.c Updated copyright to 1997.
clientutil.c Updated copyright to 1997.
dir.c Updated copyright to 1997.
fault.c Updated copyright to 1997.
includes.h Updated copyright to 1997.
interface.c Updated copyright to 1997.
ipc.c Updated copyright to 1997.
kanji.c Updated copyright to 1997.
kanji.h Updated copyright to 1997.
loadparm.c Updated copyright to 1997.
locking.c Updated copyright to 1997.
mangle.c Updated copyright to 1997.
message.c Updated copyright to 1997.
nameannounce.c
Made use of WINS subnet explicit.
Added reset_announce_timer() so announcement
can be made immediately when we become a master.
Expanded code to do sync with dmb.
namebrowse.c
Removed redundent checks for AM_MASTER in
sync code. Made use of WINS subnet explicit.
namedbname.c Made use of WINS subnet explicit.
namedbresp.c Made use of WINS subnet explicit.
namedbserver.c Made use of WINS subnet explicit.
namedbsubnet.c
Explicitly add workgroup to WINS subnet
when we become a dmb. Made use of WINS subnet explicit.
namedbwork.c
Made use of WINS subnet explicit. Removed
redundent check_work_servertype() function.
nameelect.c
Explicitly add workgroup to WINS subnet
when we become a master browser. Made use of WINS subnet explicit.
namelogon.c Updated copyright to 1997.
namepacket.c Updated copyright to 1997.
namequery.c Updated copyright to 1997.
nameresp.c
Made use of WINS subnet explicit. Made nmbd fail if
configured as master browser and one exists already.
nameserv.c
Made use of WINS subnet explicit. Remove redundent
logon server and domain master code.
nameserv.h Add emumerate subnet macros.
nameservreply.c Made use of WINS subnet explicit.
nameservresp.c Updated copyright to 1997.
namework.c
Made use of WINS subnet explicit. Updated code to
add sync browser entries to add subnet parameter.
nmbd.c
Added sanity check for misconfigured nmbd.
nmblib.c Updated copyright to 1997.
nmblookup.c Updated copyright to 1997.
nmbsync.c
Removed redundent AM_ANY_MASTER check.
params.c Updated copyright to 1997.
password.c Updated copyright to 1997.
pipes.c Updated copyright to 1997.
predict.c Updated copyright to 1997.
printing.c Updated copyright to 1997.
proto.h
Changed protos for new nmbd code.
quotas.c Updated copyright to 1997.
replace.c Updated copyright to 1997.
reply.c Updated copyright to 1997.
server.c Updated copyright to 1997.
shmem.c Updated copyright to 1997.
smb.h Updated copyright to 1997.
smbencrypt.c Updated copyright to 1997.
smbpasswd.c Updated copyright to 1997.
smbrun.c Updated copyright to 1997.
status.c Updated copyright to 1997.
system.c Updated copyright to 1997.
testparm.c Updated copyright to 1997.
testprns.c Updated copyright to 1997.
time.c Updated copyright to 1997.
trans2.c Updated copyright to 1997.
trans2.h Updated copyright to 1997.
uid.c Updated copyright to 1997.
username.c Updated copyright to 1997.
util.c Updated copyright to 1997.
version.h
Changed to 1.9.17alpha1.
(This used to be commit cf23a155a1
)
145 lines
5.5 KiB
C
145 lines
5.5 KiB
C
/*
|
|
Unix SMB/Netbios implementation.
|
|
Version 1.9.
|
|
SMB Byte handling
|
|
Copyright (C) Andrew Tridgell 1992-1997
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
/*
|
|
This file implements macros for machine independent short and
|
|
int manipulation
|
|
|
|
Here is a description of this file that I emailed to the samba list once:
|
|
|
|
> I am confused about the way that byteorder.h works in Samba. I have
|
|
> looked at it, and I would have thought that you might make a distinction
|
|
> between LE and BE machines, but you only seem to distinguish between 386
|
|
> and all other architectures.
|
|
>
|
|
> Can you give me a clue?
|
|
|
|
sure.
|
|
|
|
The distinction between 386 and other architectures is only there as
|
|
an optimisation. You can take it out completely and it will make no
|
|
difference. The routines (macros) in byteorder.h are totally byteorder
|
|
independent. The 386 optimsation just takes advantage of the fact that
|
|
the x86 processors don't care about alignment, so we don't have to
|
|
align ints on int boundaries etc. If there are other processors out
|
|
there that aren't alignment sensitive then you could also define
|
|
CAREFUL_ALIGNMENT=0 on those processors as well.
|
|
|
|
Ok, now to the macros themselves. I'll take a simple example, say we
|
|
want to extract a 2 byte integer from a SMB packet and put it into a
|
|
type called uint16 that is in the local machines byte order, and you
|
|
want to do it with only the assumption that uint16 is _at_least_ 16
|
|
bits long (this last condition is very important for architectures
|
|
that don't have any int types that are 2 bytes long)
|
|
|
|
You do this:
|
|
|
|
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
|
|
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
|
|
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
|
|
|
|
then to extract a uint16 value at offset 25 in a buffer you do this:
|
|
|
|
char *buffer = foo_bar();
|
|
uint16 xx = SVAL(buffer,25);
|
|
|
|
We are using the byteoder independence of the ANSI C bitshifts to do
|
|
the work. A good optimising compiler should turn this into efficient
|
|
code, especially if it happens to have the right byteorder :-)
|
|
|
|
I know these macros can be made a bit tidier by removing some of the
|
|
casts, but you need to look at byteorder.h as a whole to see the
|
|
reasoning behind them. byteorder.h defines the following macros:
|
|
|
|
SVAL(buf,pos) - extract a 2 byte SMB value
|
|
IVAL(buf,pos) - extract a 4 byte SMB value
|
|
SVALS(buf,pos) signed version of SVAL()
|
|
IVALS(buf,pos) signed version of IVAL()
|
|
|
|
SSVAL(buf,pos,val) - put a 2 byte SMB value into a buffer
|
|
SIVAL(buf,pos,val) - put a 4 byte SMB value into a buffer
|
|
SSVALS(buf,pos,val) - signed version of SSVAL()
|
|
SIVALS(buf,pos,val) - signed version of SIVAL()
|
|
|
|
RSVAL(buf,pos) - like SVAL() but for NMB byte ordering
|
|
RIVAL(buf,pos) - like IVAL() but for NMB byte ordering
|
|
RSSVAL(buf,pos,val) - like SSVAL() but for NMB ordering
|
|
RSIVAL(buf,pos,val) - like SIVAL() but for NMB ordering
|
|
|
|
it also defines lots of intermediate macros, just ignore those :-)
|
|
|
|
*/
|
|
|
|
#undef CAREFUL_ALIGNMENT
|
|
|
|
/* we know that the 386 can handle misalignment and has the "right"
|
|
byteorder */
|
|
#ifdef __i386__
|
|
#define CAREFUL_ALIGNMENT 0
|
|
#endif
|
|
|
|
#ifndef CAREFUL_ALIGNMENT
|
|
#define CAREFUL_ALIGNMENT 1
|
|
#endif
|
|
|
|
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos])
|
|
#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos))
|
|
#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val))
|
|
|
|
|
|
#if CAREFUL_ALIGNMENT
|
|
#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8)
|
|
#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16)
|
|
#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
|
|
#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
|
|
#define SVALS(buf,pos) ((int16)SVAL(buf,pos))
|
|
#define IVALS(buf,pos) ((int32)IVAL(buf,pos))
|
|
#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val)))
|
|
#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
|
|
#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val)))
|
|
#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val)))
|
|
#else
|
|
/* this handles things for architectures like the 386 that can handle
|
|
alignment errors */
|
|
/*
|
|
WARNING: This section is dependent on the length of int16 and int32
|
|
being correct
|
|
*/
|
|
#define SVAL(buf,pos) (*(uint16 *)((char *)(buf) + (pos)))
|
|
#define IVAL(buf,pos) (*(uint32 *)((char *)(buf) + (pos)))
|
|
#define SVALS(buf,pos) (*(int16 *)((char *)(buf) + (pos)))
|
|
#define IVALS(buf,pos) (*(int32 *)((char *)(buf) + (pos)))
|
|
#define SSVAL(buf,pos,val) SVAL(buf,pos)=((uint16)(val))
|
|
#define SIVAL(buf,pos,val) IVAL(buf,pos)=((uint32)(val))
|
|
#define SSVALS(buf,pos,val) SVALS(buf,pos)=((int16)(val))
|
|
#define SIVALS(buf,pos,val) IVALS(buf,pos)=((int32)(val))
|
|
#endif
|
|
|
|
|
|
/* now the reverse routines - these are used in nmb packets (mostly) */
|
|
#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF))
|
|
#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16)))
|
|
|
|
#define RSVAL(buf,pos) SREV(SVAL(buf,pos))
|
|
#define RIVAL(buf,pos) IREV(IVAL(buf,pos))
|
|
#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val))
|
|
#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val))
|