How to compile and install Samba server in Linux and how to write configured macro

Time:2020-9-15

Compile and install
Query whether Samba is installed on the system

Copy code

The code is as follows:

# rpm -aq | grep samba
yast2-samba-client-2.13.36-0.8
samba-client-3.0.24-2.23
yast2-samba-server-2.13.22-0.8
samba-3.0.24-2.23

Uninstall the original Samba
 

Copy code

The code is as follows:

# rpm -e samba-3.0.24-2.23

Get Samba source code
http://samba.org/samba/ftp/
Get the samba source file package (samba-3.0.24 tar.gz Do experiments, path / home /)
Unpack source package

Copy code

The code is as follows:

# tar -jxf samba-3.0.24.tar.gz

Compile and install

Copy code

The code is as follows:

# cd /home/samba-3.0.24/source/

The new version of the source directory has two: source 3 directory is samba-3. X source file, source4 directory is samba-4. X source file
 

Copy code

The code is as follows:

# ./autogen.sh
# ./configure

Samba is installed in the / usr / local / Samba directory by default
You can specify the installation directory by specifying prefix = your location:

Copy code

The code is as follows:

# ./configure –prefix=/install/samba

During this period, configure prompts that the cups header file cannot be found, so cups is installed first.

Copy code

The code is as follows:

# make
# make install

Configure DLL path
 

Copy code

The code is as follows:

# vi /etc/ld.so.conf

Join a line

Copy code

The code is as follows:

/usr/myname/install/samba/lib</p>
<p># ldconfig

Execute the ldconfig command to make the configuration take effect

Go to the installation directory

Copy code

The code is as follows:

# cd /usr/local/samba/

Prepare configuration file
 

Copy code

The code is as follows:

# mkdir -v etc/
# cp -v /home/samba-3.0.24/examples/smb.conf.default ./etc/smb.conf

Modify the configuration file and add a shared test

Copy code

The code is as follows:

# vi ./etc/smb.conf
Working group = mshome changes to your Linux working group
Security = share open sharing

stay smb.conf Finally, add

Copy code

The code is as follows:

[test]
comment = test
path = /home/
public = no
writable = yes
user = kk

Detection profile

Copy code

The code is as follows:

# cp -v ./etc/smb.conf ./lib/
# ./bin/testparm

Add account KK

Copy code

The code is as follows:

# ./bin/smbpasswd -a kk

Input password
 

Start Samba

Copy code

The code is as follows:

# /sbin/service network restart
# ./sbin/smbd -D
# ./sbin/nmbd -D

Check whether it is started

Copy code

The code is as follows:

# ps aux | grep smb
# ps aux | grep nmb

 
Password error of accessing Samba service under win7 / win8
    
In Windows system, click Start – run“ secpol.msc ”Open the management tool and expand “local policy”;
Then, click security options. Double click “network security: LAN Manager authentication level”;
Finally, click in the list: send LM and NTLMv2, if negotiated, use NTLMv2 protocol.

Basic macro writing

Samba character processing system
1. Samba uses multi byte strings — UNIX strings
UNIX strings have no fixed byte length, but follow the following principles:
A. it cannot contain null unless it is in the terminal;
B. compatible with 7-bit C strings. For constant characters and strings in C, each bit must be exactly equal to the bit in UNIX character (string);
C. case conversion means that the converted character (string) cannot occupy more bits;
D. It can accurately receive all the characters from the client.
UTF-8 and most multibyte Asian languages are well compatible with UNIX. Ucs2 is an exception (including null).
stay smb.conf UNIX charset is defined in.
When sending or receiving data with the client, pull is needed to be compatible with the character encoding of the client_ (receive) and push_ The function at the beginning of (send) formats the data in the buffer.
Lp_ The return values of the first function are all UNIX strings.
2. Definition of related macro (byteorder. H)
Cval (buf, POS) returns the byte at POS in buf as an unsigned character
PVAL (buf, POS) returns the byte at POS in buf as an unsigned integer
Scval (buf, POS, Val) sets the byte at POS in buf to val
Sval (buf, POS) returns the byte at POS in buf as an unsigned small end integer (16bit, USHORT)
Ival (buf, POS) returns the byte at POS in buf as an unsigned small end integer (32bit)
Svals (buf, POS) returns the byte at POS in buf as a signed small end integer (16bit)
Ivals (buf, POS) returns the byte at POS in buf as a signed small end integer (32bit)
Ssval (buf, POS, Val) sets the unsigned small end integer (16bit) value at POS in buf to val
Sival (buf, POS, Val) sets the unsigned small end integer (32bit) value at POS in buf to val
Ssvals (buf, POS, Val) sets the signed small end integer (16bit) value at POS in buf to val
Sivals (buf, POS, Val) sets the signed small end integer (32bit) value at POS in buf to val
Rsval (buf, POS) returns the byte at POS in buf as an unsigned large end integer (16bit)
Rival (buf, POS) returns the byte at POS in buf as an unsigned big end integer (32bit)
Rssval (buf, POS, Val) sets the value of the unsigned big end integer (16bit, USHORT) at POS in buf to val
Rsival (buf, POS, Val) sets the value of the unsigned large end integer (32bit) at POS in buf to val

Samba DEBUG SYSTEM
Debug writing rules

Copy code

The code is as follows:

>debugfile<:=={>debugmsg<}
>debugmsg<:==>debughdr<’/n’>debugtext<
>debughdr<:==’[’TIME’,’LEVEL’]’FILE’:’[FUNCTION]’(’LINE’)’
>debugtext<:=={>debugline<}
>debugline<:==TEXT’/n’

Among them,
Time stamp,
Level debug level,
The source file generated by file debug information,
The function generated by function debug information,
The number of lines generated by line debug information, not supported__ FUNCTION__ The macro cannot be displayed,
Text does not contain debug information of / n
EG:

Copy code

The code is as follows:

[2011/03/17 08:33:46, 3] smbd/process.c:switch_message(914)
switch message SMBclose (pid 12153) conn 0x7f60e9a2d330
[2011/03/17 08:33:46, 3] smbd/reply.c:reply_close(3298)
close directory fnum=6574

Debug() macro
DEBUG(para1, para2);
Among them,
Para1 debug level. If it is less than or equal to the global variable debuglevel, the debug information will be output to the log,
Para2 debug information, that is, text in writing rules. In text, when ‘/ N’ is encountered, a new log will be generated (debugfile in the writing rule); if ‘/ N’ is not encountered, text will be appended.
EG:

Copy code

The code is as follows:

DEBUG(0, (“The test returned “));
if(test())
{
DEBUG(0, (“True”));
}
else
{
DEBUG(0, (“False”));
}
DEBUG(0, (“./n”));

If test() = = true, the output is:

Copy code

The code is as follows:

[2010/07/30 16:00:51, 0] file.c:function (256)
The test returned True.

Debugadd() macro
DEBUGADD(para1, para2);
Among them,
Para1 debug level. If it is less than or equal to the global variable debuglevel, the debug information will be output to the log,
Para2 debug information, that is, text in writing rules. In text, when ‘/ N’ is encountered, a new text line will be generated; if ‘/ N’ is not encountered, it will be appended. It differs from debug () in that it never generates a debughdr in a writing rule.
 
EG:

Copy code

The code is as follows:

DEBUG(0, (“This is the first line./n”));
DEBUGADD(0, (“This is the second line./n This is the third line./n”));

Output:

Copy code

The code is as follows:

[2010/07/30 16:00:51,0] file.c:function(512)
This is the first line.
This is the second line.
This is the third line.

 
Debuglvl() macro
BOOL  DEBUGLVL(para1);
Among them,
Para1. Debug level. If it is less than or equal to the global variable debuglevel, the macro returns true,
This function is mainly used to solve the inconvenience caused by too long text in writing rules.
EG:

Copy code

The code is as follows:

DEBUG(3, (“send_local_master_announcement: type %x forname %s on subnet %s forwork group, type, global_myname, subrec->subnet_name, work->work_group));

It can be replaced by:

Copy code

The code is as follows:

DEBUG(3, (“send_local_master_announcement: “));
DEBUGADD(3, (“type %x forname %s”, type, global_myname));
DEBUGADD(3, (“on subnet %s”, subrec->subnet_name));
DEBUGADD(3, (“for work group %s/n”, work->work_group));

It can be replaced by:

Copy code

The code is as follows:

if(DEBUGLVL(3))
{
dbgtext(“send_local_master_announcement: “);
dbgtext(“type %x forname %s”, type, global_myname);
dbgtext(“on subnet %s”, subrec->subnet_name);
dbgtext(“for workgroup %s/n”, work->work_group);
}

Dbgtext() function
It is used to call related functions to output debug information to log file, that is, to output text in writing rules.
After the vslprintf() function is called to format the text, the format debug text() function is called to output the text.
It is generally used in the debuglvl() macro.
 
Dbghdr() function
It is used to output the header information in debug information, that is to output debughdr in writing rules.
Do not format the output.
It is generally used in debug() macro & debugadd() macro.
 
Format debug text() function
It is used to output debug information to log file, that is to output text in writing rules.
The function saves the text to be output in the buffer until it finds a ‘/ N’, increases the indentation, calls the debug1() function, outputs the text to the log, and clears the buffer.