From 089548e728045c70f83031f5813e039cf8f06713 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Nov 2005 02:13:53 +0000 Subject: r11591: bumping version 3.0.22pre1 --- source/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/VERSION b/source/VERSION index 7e027ab538a..5e2b8df3865 100644 --- a/source/VERSION +++ b/source/VERSION @@ -19,7 +19,7 @@ ######################################################## SAMBA_VERSION_MAJOR=3 SAMBA_VERSION_MINOR=0 -SAMBA_VERSION_RELEASE=21 +SAMBA_VERSION_RELEASE=22 ######################################################## # If a official release has a serious bug # -- cgit From 1fce9f71c2010153f528945fd43de4c1498e2977 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Nov 2005 18:33:37 +0000 Subject: r11613: fixing versions --- source/VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/VERSION b/source/VERSION index 5e2b8df3865..34c48598612 100644 --- a/source/VERSION +++ b/source/VERSION @@ -19,7 +19,7 @@ ######################################################## SAMBA_VERSION_MAJOR=3 SAMBA_VERSION_MINOR=0 -SAMBA_VERSION_RELEASE=22 +SAMBA_VERSION_RELEASE=21 ######################################################## # If a official release has a serious bug # @@ -41,7 +41,7 @@ SAMBA_VERSION_REVISION= # e.g. SAMBA_VERSION_PRE_RELEASE=1 # # -> "2.2.9pre1" # ######################################################## -SAMBA_VERSION_PRE_RELEASE=1 +SAMBA_VERSION_PRE_RELEASE=3 ######################################################## # For 'rc' releases the version will be # -- cgit From c0f4e78a99f4a2657f1ae65e2ce66c221b3434bf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Nov 2005 19:35:23 +0000 Subject: r11614: Replace old crc32 code with one from the FreeBSD tree. * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or * code or tables extracted from it, as desired without restriction. Jeremy. --- source/lib/crc32.c | 148 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 92 insertions(+), 56 deletions(-) diff --git a/source/lib/crc32.c b/source/lib/crc32.c index da3aeaa901d..c6a13fada12 100644 --- a/source/lib/crc32.c +++ b/source/lib/crc32.c @@ -1,67 +1,103 @@ -/* - * Copyright Francesco Ferrara, 1998 +/*- + * COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + * code or tables extracted from it, as desired without restriction. * - * Used by kind permission, 14th October 1998. http://www.aerre.it/francesco + * First, the polynomial itself and its table of feedback terms. The + * polynomial is + * X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 * + * Note that we take it "backwards" and put the highest-order term in + * the lowest-order bit. The X^32 term is "implied"; the LSB is the + * X^31 term, etc. The X^0 term (usually shown as "+1") results in + * the MSB being 1 * + * Note that the usual hardware shift register implementation, which + * is what we're using (we're merely optimizing it by doing eight-bit + * chunks at a time) shifts bits into the lowest-order term. In our + * implementation, that means shifting towards the right. Why do we + * do it this way? Because the calculated CRC must be transmitted in + * order from highest-order term to lowest-order term. UARTs transmit + * characters in order from LSB to MSB. By storing the CRC this way + * we hand it to the UART in the order low-byte to high-byte; the UART + * sends each low-bit to hight-bit; and the result is transmission bit + * by bit from highest- to lowest-order term without requiring any bit + * shuffling on our part. Reception works similarly + * + * The feedback terms table consists of 256, 32-bit entries. Notes + * + * The table can be generated at runtime if desired; code to do so + * is shown later. It might not be obvious, but the feedback + * terms simply represent the results of eight shift/xor opera + * tions for all combinations of data and CRC register values + * + * The values must be right-shifted by eight bits by the "updcrc + * logic; the shift must be unsigned (bring in zeroes). On some + * hardware you could probably optimize the shift in assembler by + * using byte-swap instructions + * polynomial $edb88320 + * + * + * CRC32 code derived from work by Gary S. Brown. */ #include "includes.h" -static const unsigned long CRCTable[256] = -{ - 0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F, - 0xE963A535,0x9E6495A3,0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988, - 0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,0x1DB71064,0x6AB020F2, - 0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7, - 0x136C9856,0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9, - 0xFA0F3D63,0x8D080DF5,0x3B6E20C8,0x4C69105E,0xD56041E4,0xA2677172, - 0x3C03E4D1,0x4B04D447,0xD20D85FD,0xA50AB56B,0x35B5A8FA,0x42B2986C, - 0xDBBBC9D6,0xACBCF940,0x32D86CE3,0x45DF5C75,0xDCD60DCF,0xABD13D59, - 0x26D930AC,0x51DE003A,0xC8D75180,0xBFD06116,0x21B4F4B5,0x56B3C423, - 0xCFBA9599,0xB8BDA50F,0x2802B89E,0x5F058808,0xC60CD9B2,0xB10BE924, - 0x2F6F7C87,0x58684C11,0xC1611DAB,0xB6662D3D,0x76DC4190,0x01DB7106, - 0x98D220BC,0xEFD5102A,0x71B18589,0x06B6B51F,0x9FBFE4A5,0xE8B8D433, - 0x7807C9A2,0x0F00F934,0x9609A88E,0xE10E9818,0x7F6A0DBB,0x086D3D2D, - 0x91646C97,0xE6635C01,0x6B6B51F4,0x1C6C6162,0x856530D8,0xF262004E, - 0x6C0695ED,0x1B01A57B,0x8208F4C1,0xF50FC457,0x65B0D9C6,0x12B7E950, - 0x8BBEB8EA,0xFCB9887C,0x62DD1DDF,0x15DA2D49,0x8CD37CF3,0xFBD44C65, - 0x4DB26158,0x3AB551CE,0xA3BC0074,0xD4BB30E2,0x4ADFA541,0x3DD895D7, - 0xA4D1C46D,0xD3D6F4FB,0x4369E96A,0x346ED9FC,0xAD678846,0xDA60B8D0, - 0x44042D73,0x33031DE5,0xAA0A4C5F,0xDD0D7CC9,0x5005713C,0x270241AA, - 0xBE0B1010,0xC90C2086,0x5768B525,0x206F85B3,0xB966D409,0xCE61E49F, - 0x5EDEF90E,0x29D9C998,0xB0D09822,0xC7D7A8B4,0x59B33D17,0x2EB40D81, - 0xB7BD5C3B,0xC0BA6CAD,0xEDB88320,0x9ABFB3B6,0x03B6E20C,0x74B1D29A, - 0xEAD54739,0x9DD277AF,0x04DB2615,0x73DC1683,0xE3630B12,0x94643B84, - 0x0D6D6A3E,0x7A6A5AA8,0xE40ECF0B,0x9309FF9D,0x0A00AE27,0x7D079EB1, - 0xF00F9344,0x8708A3D2,0x1E01F268,0x6906C2FE,0xF762575D,0x806567CB, - 0x196C3671,0x6E6B06E7,0xFED41B76,0x89D32BE0,0x10DA7A5A,0x67DD4ACC, - 0xF9B9DF6F,0x8EBEEFF9,0x17B7BE43,0x60B08ED5,0xD6D6A3E8,0xA1D1937E, - 0x38D8C2C4,0x4FDFF252,0xD1BB67F1,0xA6BC5767,0x3FB506DD,0x48B2364B, - 0xD80D2BDA,0xAF0A1B4C,0x36034AF6,0x41047A60,0xDF60EFC3,0xA867DF55, - 0x316E8EEF,0x4669BE79,0xCB61B38C,0xBC66831A,0x256FD2A0,0x5268E236, - 0xCC0C7795,0xBB0B4703,0x220216B9,0x5505262F,0xC5BA3BBE,0xB2BD0B28, - 0x2BB45A92,0x5CB36A04,0xC2D7FFA7,0xB5D0CF31,0x2CD99E8B,0x5BDEAE1D, - 0x9B64C2B0,0xEC63F226,0x756AA39C,0x026D930A,0x9C0906A9,0xEB0E363F, - 0x72076785,0x05005713,0x95BF4A82,0xE2B87A14,0x7BB12BAE,0x0CB61B38, - 0x92D28E9B,0xE5D5BE0D,0x7CDCEFB7,0x0BDBDF21,0x86D3D2D4,0xF1D4E242, - 0x68DDB3F8,0x1FDA836E,0x81BE16CD,0xF6B9265B,0x6FB077E1,0x18B74777, - 0x88085AE6,0xFF0F6A70,0x66063BCA,0x11010B5C,0x8F659EFF,0xF862AE69, - 0x616BFFD3,0x166CCF45,0xA00AE278,0xD70DD2EE,0x4E048354,0x3903B3C2, - 0xA7672661,0xD06016F7,0x4969474D,0x3E6E77DB,0xAED16A4A,0xD9D65ADC, - 0x40DF0B66,0x37D83BF0,0xA9BCAE53,0xDEBB9EC5,0x47B2CF7F,0x30B5FFE9, - 0xBDBDF21C,0xCABAC28A,0x53B39330,0x24B4A3A6,0xBAD03605,0xCDD70693, - 0x54DE5729,0x23D967BF,0xB3667A2E,0xC4614AB8,0x5D681B02,0x2A6F2B94, - 0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D +const uint32 crc32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -uint32 crc32_calc_buffer( const char *buffer, uint32 count) +uint32 crc32_calc_buffer(const char *buf, size_t size) { - uint32 crc=0xffffffff, i; - for(i=0;i>8) ^ CRCTable[(buffer[i] ^ crc) & 0xff]; - crc^=0xffffffff; - DEBUG(10,("crc32_calc_buffer: %x\n", crc)); - dump_data(100, buffer, count); - return crc; + const unsigned char *p; + uint32 crc; + + p = buf; + crc = ~0U; + + while (size--) + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + + return crc ^ ~0U; } -- cgit From ac714a45c95521193bd2e10f148c5f027584fe7e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Nov 2005 19:37:13 +0000 Subject: r11617: fix typo --- source/rpc_server/srv_netlog_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_server/srv_netlog_nt.c b/source/rpc_server/srv_netlog_nt.c index 91566d325cf..7903adff6d5 100644 --- a/source/rpc_server/srv_netlog_nt.c +++ b/source/rpc_server/srv_netlog_nt.c @@ -633,7 +633,7 @@ NTSTATUS _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON * /* checks and updates credentials. creates reply credentials */ if (!creds_server_step(p->dc, &q_u->sam_id.client.cred, &r_u->srv_creds)) { - DEBUG(0,("_net_sam_logoff: creds_server_step failed. Rejecting auth " + DEBUG(0,("_net_sam_logon: creds_server_step failed. Rejecting auth " "request from client %s machine account %s\n", p->dc->remote_machine, p->dc->mach_acct )); return NT_STATUS_ACCESS_DENIED; -- cgit From a52c386642e6f05bc85d217441e9140139c06bb5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Nov 2005 14:30:39 +0000 Subject: r11645: mklogon updates from Ricky Nance --- examples/logon/mklogon/mklogon.conf | 75 +++++++++++++++++++------------------ examples/logon/mklogon/mklogon.pl | 50 +++++++++++++++---------- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/examples/logon/mklogon/mklogon.conf b/examples/logon/mklogon/mklogon.conf index 1f1faa77e38..b04708977c4 100644 --- a/examples/logon/mklogon/mklogon.conf +++ b/examples/logon/mklogon/mklogon.conf @@ -6,72 +6,73 @@ # infront of your # on a comment it breaks ... # logging = yes # Should Logging be enabled (YES,ON,1 or NO,OFF,0)(if not specified defaults to no) # logdir = "/root/perl" # What is the base directory the logs should be stored. -# logfile = "userlogs.txt" # What should the file be named. -# logtype = file (default) # file will log to the file specified, syslog is well... the system logs ;) +# logfile = "userlist.txt" # What should the file be named. +# VERY IMPORTANT anything that has a "\" (backslash) in it ex. "C:\" MUST be changed to a double "\\" for +# it to be used in the script. ex. "C:\\" [global] logging = yes logdir = "/home/samba/netlogon" logfile = "UserLogs.txt" -logtype = system mkprofile = 1 timesync = yes sambaconf = "/etc/samba/smb.conf" +logtype = file # Change and uncomment the below value to force the servername, some clients ocassionally # have trouble picking up the right servername so it may need to be set. It CANNOT be left blank AND uncommented. -# servername = staticservername +servername = "TIGER" [common] public = P:, public home = H:, /home [groupmap] -admin = Y:, UTILS -adm = R:, NETLOGON +adm = R:, NETLOGON, Y:, ARCHIVES +teachers = S:, RECORDS, X:, SIS +plato = T:, PLATO +webpage = W:, WEB +hsoffice = N:, HSOFFICE, Q:, COMMON, X:, SIS +suoffice = N:, super, Q:, COMMON, X:, SIS +emoffice = N:, emOFFICE, Q:, COMMON, X:, SIS +tech = O:, utils +yearbook = Y:, yearbook [usermap] -user1 = G:, GHOST -beanbags = Q:, STAR -avinst = P:\\vexira\\vexprof.bat +rnance = G:, GHOST, I:, TTL, Y:, ARCHIVES, R:, NETLOGON, X:, SIS +lwatts = G:, GHOST, I:, TTL, Y:, ARCHIVES, R:, NETLOGON, X:, SIS +droot = U:, stuhomes +2007mbk = Y:, yearbook +2008mll = Y:, yearbook +2008jtj = Y:, yearbook +2007tja = Y:, yearbook +2007hms = Y:, yearbook +2006dpv = Y:, yearbook +2006jwb2 = Y:, yearbook +2007npd = Y:, yearbook +astewart = Y:, yearbook + + # Here is where things get confusing, you can assign a computer, or make a group of computers. -# The same context will go for ip address's as well. +# The same context will go for ip address's as well, however you can also specify ip ranges, +# but I have not yet figured out how to do multiple ranges. # Use the following examples for help. # To define a single computer to do commands # mymachinename = command1, command2 # To define a group of computers to do commands # mymachinegroup = machinename1, machinename2 -# [preformcommands] +# [performcommands] # mymachinegroup = command1,command2 +# iprangegroup1 = 10.1.2.1 - 10.1.3.1 -[machines] -#emints 1 is jf -emints1 = school-w88zfod9, school-o8axvv6t, school-mmtudgbo, school-dpokmajd, school-m84hx4iw, school-74548k1j, school-vou4gdap, school-qfuw5uho -#emints 2 is kh -emints2 = school-w7loulcx, school-2tbh64eu, school-uunqieuz, school-pow35do4, school-x0v0cbiz, school-zu5qyjhw, school-l4q4j32o -[ip] -ipgroup1 = 10.5.1.1 - 10.5.1.10, 10.1.1.255/24 -ipgroup2 = 10.1.1.1 -# This is the section where you can specify things according to the operating system of the client. -# The clients OS -- Windows 95/98/ME (Win95), Windows NT (WinNT), -# Windows 2000 (Win2K), Windows XP (WinXP), and Windows 2003 -# (Win2K3). Anything else will be known as ``UNKNOWN'' -# That snippet is directly from man smb.conf. -# +[machines] -[os] -Win95 = REM your computer is windows 9x based -WinNT = -Win2K = -WinXP = -Win2K3 = -UNKNOWN = +[ip] +sixthemints = 10.1.5.201 - 10.1.5.215 -[preformcommands] -emints1 = START \\\\JF-TEACHER\\Brother, START \\\\JF-TEACHER\\Canon, REGEDIT /S P:\\SETHOME-JF.REG, your in emints 1 -emints2 = START \\\\s0034292474\\Brother, START \\\\s0034292474\\Canon, REGEDIT /S P:\\SETHOME-KH.REG -ipgroup1 = echo your in the ip group -ipgroup2 = echo your in the ip group 2, start command.com +[performcommands] +common = "XCOPY P:\\TYPEN32.INI C:\\WINDOWS\\ /Y \>NUL", "XCOPY P:\\ARPROGRAMS\\DBLOCATION\\\*\.\* C:\\WINDOWS\\ /Y \>NUL", "XCOPY P:\\EMACTIVITIES\\EMGAMESPREFS.INI C:\\WINDOWS\\ /Y \>NUL", "PATH\=\%PATH\%;p:\\PXPerl\parrot\\bin;p:\\PXPerl\\bin" +sixthemints = "start \\\\10.1.5.20\\printer" diff --git a/examples/logon/mklogon/mklogon.pl b/examples/logon/mklogon/mklogon.pl index 88ee97c9799..8bea7b22d36 100644 --- a/examples/logon/mklogon/mklogon.pl +++ b/examples/logon/mklogon/mklogon.pl @@ -22,8 +22,8 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -# Version: 1.1 Beta -# Revised: 06/28/2005 +# Version: 1.0 (Stable) +# Revised: 07/28/2005 # Comments... # Working on logging to the system logs, Logs user activity, but not errors yet. @@ -144,11 +144,11 @@ if ( defined($smbprof) ) { print "$smbprof \n"; print "$dir2 \n"; if ( !-e $dir2 ) { - print "Creating " . $user . "'s profile \n"; + print "Creating " . $user . "'s profile with a uid of $uid\n"; mkdir $smbprof; mkdir $dir2; chomp($user); - chown $uid, $gid, $smbprof; +# chown $uid, $gid, $smbprof; chown $uid, $gid, $dir2; } else { print $user . "'s profile already exists \n"; @@ -174,6 +174,13 @@ for my $key ( keys %$common ) { drive_map( @{ $common->{$key} } ); } +my @perform_common = $cfg->param("performcommands.common"); +if ( defined( $perform_common[0] ) ) { + foreach (@perform_common) { + print LOGON "$_ \r\n"; + } +} + # Map shares on a per user basis. drive_map(@username); @@ -195,30 +202,33 @@ for my $key ( keys %$compname ) { if ( ref $test eq 'ARRAY' ) { foreach (@$test) { if ( $_ eq $machine ) { - my $preformit = $cfg->param("preformcommands.$key"); - if ( defined($preformit) ) { - if ( ref $preformit ) { - foreach (@$preformit) { print LOGON "$_ \r\n"; } + my $performit = $cfg->param("performcommands.$key"); + if ( defined($performit) ) { + if ( ref $performit ) { + foreach (@$performit) { print LOGON "$_ \r\n"; } } else { - print LOGON "$preformit \r\n"; + print LOGON "$performit \r\n"; } } } } } elsif ( $test eq $machine ) { - my $preformit = $cfg->param("preformcommands.$key"); - if ( defined($preformit) ) { - if ( ref $preformit ) { - foreach (@$preformit) { print LOGON "$_ \r\n"; } + my $performit = $cfg->param("performcommands.$key"); + if ( defined($performit) ) { + if ( ref $performit ) { + foreach (@$performit) { print LOGON "$_ \r\n"; } } else { - print LOGON "$preformit \r\n"; + print LOGON "$performit \r\n"; } } } } # Here is where we test the ip address against the client to see if they have "Special Mapping" +# A huge portion of the ip matching code was made by +# Carsten Schaub (rcsu in the #samba chan on freenode.net) + my $val; for my $key ( sort keys %$ipname ) { if ( ref $ipname->{$key} eq 'ARRAY' ) { @@ -234,12 +244,12 @@ sub getipval { my ( $range, $rangename ) = @_; if ( parse( $ip, ipmap($range) ) ) { if ( $val eq 'true' ) { - my $preformit = $cfg->param("preformcommands.$rangename"); - if ( defined($preformit) ) { - if ( ref $preformit ) { - foreach (@$preformit) { print LOGON "$_ \r\n"; } + my $performit = $cfg->param("performcommands.$rangename"); + if ( defined($performit) ) { + if ( ref $performit ) { + foreach (@$performit) { print LOGON "$_ \r\n"; } } else { - print LOGON "$preformit \r\n"; + print LOGON "$performit \r\n"; } } } elsif ( $val eq 'false' ) { @@ -307,7 +317,7 @@ sub drive_map { my $sharename = $data[$i]; $i++; if ( $sharename eq '/home' ) { - print LOGON uc("NET USE $driveletter $sharename \/Y \r\n"); + print LOGON uc("NET USE $driveletter \\\\$server\\$user \/Y \r\n"); } else { print LOGON uc("NET USE $driveletter \\\\$server\\$sharename \/Y \r\n"); -- cgit From 7061459ed7f5e6c4a7896be00554a0c829217030 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Nov 2005 19:50:09 +0000 Subject: r11651: After talking to Jeremy, commit my winbindd "Do the Right Thing" patch. Still needs some more testing ni domains with multiple DCs. Coming next.... --- source/libads/kerberos.c | 19 +++++++++++++- source/nsswitch/winbindd_ads.c | 34 +++++++++++++++++++++--- source/nsswitch/winbindd_cache.c | 57 +++++++++++++++++++++++----------------- 3 files changed, 82 insertions(+), 28 deletions(-) diff --git a/source/libads/kerberos.c b/source/libads/kerberos.c index 7f855add06e..d5b4b11fa24 100644 --- a/source/libads/kerberos.c +++ b/source/libads/kerberos.c @@ -130,8 +130,25 @@ int ads_kinit_password(ADS_STRUCT *ads) { char *s; int ret; + const char *account_name; + fstring acct_name; - if (asprintf(&s, "%s@%s", ads->auth.user_name, ads->auth.realm) == -1) { + if ( IS_DC ) { + /* this will end up getting a ticket for DOMAIN@RUSTED.REA.LM */ + account_name = lp_workgroup(); + } else { + /* always use the sAMAccountName for security = domain */ + /* global_myname()$@REA.LM */ + if ( lp_security() == SEC_DOMAIN ) { + fstr_sprintf( acct_name, "%s$", global_myname() ); + account_name = acct_name; + } + else + /* This looks like host/global_myname()@REA.LM */ + account_name = ads->auth.user_name; + } + + if (asprintf(&s, "%s@%s", account_name, ads->auth.realm) == -1) { return KRB5_CC_NOMEM; } diff --git a/source/nsswitch/winbindd_ads.c b/source/nsswitch/winbindd_ads.c index 6b170c33305..32bc641b6a6 100644 --- a/source/nsswitch/winbindd_ads.c +++ b/source/nsswitch/winbindd_ads.c @@ -68,11 +68,39 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) } /* the machine acct password might have change - fetch it every time */ - SAFE_FREE(ads->auth.password); - ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); + SAFE_FREE(ads->auth.password); SAFE_FREE(ads->auth.realm); - ads->auth.realm = SMB_STRDUP(lp_realm()); + + if ( IS_DC ) { + DOM_SID sid; + time_t last_set_time; + + if ( !secrets_fetch_trusted_domain_password( domain->name, &ads->auth.password, &sid, &last_set_time ) ) { + ads_destroy( &ads ); + return NULL; + } + ads->auth.realm = SMB_STRDUP( ads->server.realm ); + strupper_m( ads->auth.realm ); + } + else { + struct winbindd_domain *our_domain = domain; + + ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); + + /* always give preference to the alt_name in our + primary domain if possible */ + + if ( !domain->primary ) + our_domain = find_our_domain(); + + if ( our_domain->alt_name[0] != '\0' ) { + ads->auth.realm = SMB_STRDUP( our_domain->alt_name ); + strupper_m( ads->auth.realm ); + } + else + ads->auth.realm = SMB_STRDUP( lp_realm() ); + } status = ads_connect(ads); if (!ADS_ERR_OK(status) || !ads->config.realm) { diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 9164a135c5b..993e6d96e8e 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -100,43 +100,52 @@ void winbindd_check_cache_size(time_t t) static struct winbind_cache *get_cache(struct winbindd_domain *domain) { struct winbind_cache *ret = wcache; + struct winbindd_domain *our_domain = domain; /* we have to know what type of domain we are dealing with first */ if ( !domain->initialized ) set_dc_type_and_flags( domain ); + /* + OK. listen up becasue I'm only going to say this once. + We have the following scenarios to consider + (a) trusted AD domains on a Samba DC, + (b) trusted AD domains and we are joined to a non-kerberos domain + (c) trusted AD domains and we are joined to a kerberos (AD) domain + + For (a) we can always contact the trusted domain using krb5 + since we have the domain trust account password + + For (b) we can only use RPC since we have no way of + getting a krb5 ticket in our own domain + + For (c) we can always use krb5 since we have a kerberos trust + + --jerry + */ + if (!domain->backend) { extern struct winbindd_methods reconnect_methods; - switch (lp_security()) { #ifdef HAVE_ADS - case SEC_ADS: { - extern struct winbindd_methods ads_methods; - /* always obey the lp_security parameter for our domain */ - if (domain->primary) { - domain->backend = &ads_methods; - break; - } + extern struct winbindd_methods ads_methods; - /* only use ADS for native modes at the momment. - The problem is the correct detection of mixed - mode domains from NT4 BDC's --jerry */ - - if ( domain->native_mode ) { - DEBUG(5,("get_cache: Setting ADS methods for domain %s\n", - domain->name)); - domain->backend = &ads_methods; - break; - } + /* find our domain first so we can figure out if we + are joined to a kerberized domain */ - /* fall through */ - } -#endif - default: - DEBUG(5,("get_cache: Setting MS-RPC methods for domain %s\n", - domain->name)); + if ( !domain->primary ) + our_domain = find_our_domain(); + + if ( (our_domain->active_directory || IS_DC) && domain->active_directory ) { + DEBUG(5,("get_cache: Setting ADS methods for domain %s\n", domain->name)); + domain->backend = &ads_methods; + } else { +#endif /* HAVE_ADS */ + DEBUG(5,("get_cache: Setting MS-RPC methods for domain %s\n", domain->name)); domain->backend = &reconnect_methods; +#ifdef HAVE_ADS } +#endif /* HAVE_ADS */ } if (ret) -- cgit From 178853af9a39d1ba40b28fe9a868da23f14a1164 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Nov 2005 20:28:23 +0000 Subject: r11652: Reinstate the netsamlogon_cache in order to work around failed query_user calls. This fixes logons to a member of a Samba domain as a user from a trusted AD domain. As per comments on samba-technical, I still need to add (a) cache the PAC info as werll as NTLM net_user_info_3 (b) expire the cache when the SMB session goes away Both Jeremy and Guenther have signed off on the idea. --- source/Makefile.in | 6 +- source/auth/auth_domain.c | 2 + source/libsmb/samlogon_cache.c | 247 +++++++++++++++++++++++++++++++++++++++ source/nsswitch/winbindd.c | 2 + source/nsswitch/winbindd_cache.c | 38 ++++++ source/nsswitch/winbindd_pam.c | 8 ++ source/nsswitch/winbindd_rpc.c | 52 +++++++++ 7 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 source/libsmb/samlogon_cache.c diff --git a/source/Makefile.in b/source/Makefile.in index 09472602c8c..6a12b2e25e9 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -368,6 +368,8 @@ VFS_CATIA_OBJ = modules/vfs_catia.o PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o +SLCACHE_OBJ = libsmb/samlogon_cache.o + DCUTIL_OBJ = libsmb/namequery_dc.o libsmb/trustdom_cache.o libsmb/trusts_util.o AUTH_BUILTIN_OBJ = auth/auth_builtin.o @@ -381,7 +383,7 @@ AUTH_SCRIPT_OBJ = auth/auth_script.o AUTH_OBJ = auth/auth.o @AUTH_STATIC@ auth/auth_util.o auth/auth_compat.o \ auth/auth_ntlmssp.o \ - $(PLAINTEXT_AUTH_OBJ) $(DCUTIL_OBJ) + $(PLAINTEXT_AUTH_OBJ) $(SLCACHE_OBJ) $(DCUTIL_OBJ) MANGLE_OBJ = smbd/mangle.o smbd/mangle_hash.o smbd/mangle_map.o smbd/mangle_hash2.o @@ -706,7 +708,7 @@ WINBINDD_OBJ = \ $(WINBINDD_OBJ1) $(PASSDB_OBJ) $(GROUPDB_OBJ) \ $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) \ $(LIBSMB_OBJ) $(LIBMSRPC_OBJ) $(RPC_PARSE_OBJ) \ - $(PROFILE_OBJ) $(SMBLDAP_OBJ) \ + $(PROFILE_OBJ) $(SLCACHE_OBJ) $(SMBLDAP_OBJ) \ $(SECRETS_OBJ) $(LIBADS_OBJ) $(KRBCLIENT_OBJ) $(POPT_LIB_OBJ) \ $(DCUTIL_OBJ) $(IDMAP_OBJ) \ $(AFS_OBJ) $(AFS_SETTOKEN_OBJ) diff --git a/source/auth/auth_domain.c b/source/auth/auth_domain.c index 94b138e55b1..242105a664b 100644 --- a/source/auth/auth_domain.c +++ b/source/auth/auth_domain.c @@ -252,6 +252,8 @@ static NTSTATUS domain_client_validate(TALLOC_CTX *mem_ctx, domain, server_info, &info3); + + netsamlogon_cache_store( mem_ctx, user_info->smb_name.str, &info3 ); } /* Note - once the cli stream is shutdown the mem_ctx used diff --git a/source/libsmb/samlogon_cache.c b/source/libsmb/samlogon_cache.c new file mode 100644 index 00000000000..ceb7b7c35a4 --- /dev/null +++ b/source/libsmb/samlogon_cache.c @@ -0,0 +1,247 @@ +/* + Unix SMB/CIFS implementation. + Net_sam_logon info3 helpers + Copyright (C) Alexander Bokovoy 2002. + Copyright (C) Andrew Bartlett 2002. + Copyright (C) Gerald Carter 2003. + Copyright (C) Tim Potter 2003. + + 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. +*/ + +#include "includes.h" + +#define NETSAMLOGON_TDB "netsamlogon_cache.tdb" + +static TDB_CONTEXT *netsamlogon_tdb = NULL; + +/*********************************************************************** + open the tdb + ***********************************************************************/ + +BOOL netsamlogon_cache_init(void) +{ + if (!netsamlogon_tdb) { + netsamlogon_tdb = tdb_open_log(lock_path(NETSAMLOGON_TDB), 0, + TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + } + + return (netsamlogon_tdb != NULL); +} + + +/*********************************************************************** + Shutdown samlogon_cache database +***********************************************************************/ + +BOOL netsamlogon_cache_shutdown(void) +{ + if(netsamlogon_tdb) + return (tdb_close(netsamlogon_tdb) == 0); + + return True; +} + +/*********************************************************************** + Clear cache getpwnam and getgroups entries from the winbindd cache +***********************************************************************/ +void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user) +{ + fstring domain; + TDB_DATA key; + BOOL got_tdb = False; + + /* We may need to call this function from smbd which will not have + winbindd_cache.tdb open. Open the tdb if a NULL is passed. */ + + if (!tdb) { + tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 5000, + TDB_DEFAULT, O_RDWR, 0600); + if (!tdb) { + DEBUG(5, ("netsamlogon_clear_cached_user: failed to open cache\n")); + return; + } + got_tdb = True; + } + + unistr2_to_ascii(domain, &user->uni_logon_dom, sizeof(domain) - 1); + + /* Clear U/DOMAIN/RID cache entry */ + + asprintf(&key.dptr, "U/%s/%d", domain, user->user_rid); + key.dsize = strlen(key.dptr) - 1; /* keys are not NULL terminated */ + + DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key.dptr)); + + tdb_delete(tdb, key); + + SAFE_FREE(key.dptr); + + /* Clear UG/DOMAIN/RID cache entry */ + + asprintf(&key.dptr, "UG/%s/%d", domain, user->user_rid); + key.dsize = strlen(key.dptr) - 1; /* keys are not NULL terminated */ + + DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key.dptr)); + + tdb_delete(tdb, key); + + SAFE_FREE(key.dptr); + + if (got_tdb) + tdb_close(tdb); +} + +/*********************************************************************** + Store a NET_USER_INFO_3 structure in a tdb for later user + username should be in UTF-8 format +***********************************************************************/ + +BOOL netsamlogon_cache_store(TALLOC_CTX *mem_ctx, const char * username, NET_USER_INFO_3 *user) +{ + TDB_DATA data; + fstring keystr; + prs_struct ps; + BOOL result = False; + DOM_SID user_sid; + time_t t = time(NULL); + + + if (!netsamlogon_cache_init()) { + DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n", NETSAMLOGON_TDB)); + return False; + } + + sid_copy( &user_sid, &user->dom_sid.sid ); + sid_append_rid( &user_sid, user->user_rid ); + + /* Prepare key as DOMAIN-SID/USER-RID string */ + slprintf(keystr, sizeof(keystr), "%s", sid_string_static(&user_sid)); + + DEBUG(10,("netsamlogon_cache_store: SID [%s]\n", keystr)); + + /* only Samba fills in the username, not sure why NT doesn't */ + /* so we fill it in since winbindd_getpwnam() makes use of it */ + + if ( !user->uni_user_name.buffer ) { + init_unistr2( &user->uni_user_name, username, UNI_STR_TERMINATE ); + init_uni_hdr( &user->hdr_user_name, &user->uni_user_name ); + } + + /* Prepare data */ + + prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + + if ( !prs_uint32( "timestamp", &ps, 0, (uint32*)&t ) ) + return False; + + if ( net_io_user_info3("", user, &ps, 0, 3, 0) ) + { + data.dsize = prs_offset( &ps ); + data.dptr = prs_data_p( &ps ); + + if (tdb_store_bystring(netsamlogon_tdb, keystr, data, TDB_REPLACE) != -1) + result = True; + + prs_mem_free( &ps ); + } + + return result; +} + +/*********************************************************************** + Retrieves a NET_USER_INFO_3 structure from a tdb. Caller must + free the user_info struct (malloc()'d memory) +***********************************************************************/ + +NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user_sid) +{ + NET_USER_INFO_3 *user = NULL; + TDB_DATA data, key; + prs_struct ps; + fstring keystr; + uint32 t; + + if (!netsamlogon_cache_init()) { + DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n", NETSAMLOGON_TDB)); + return False; + } + + /* Prepare key as DOMAIN-SID/USER-RID string */ + slprintf(keystr, sizeof(keystr), "%s", sid_string_static(user_sid)); + DEBUG(10,("netsamlogon_cache_get: SID [%s]\n", keystr)); + key.dptr = keystr; + key.dsize = strlen(keystr)+1; + data = tdb_fetch( netsamlogon_tdb, key ); + + if ( data.dptr ) { + + if ( (user = SMB_MALLOC_P(NET_USER_INFO_3)) == NULL ) + return NULL; + + prs_init( &ps, 0, mem_ctx, UNMARSHALL ); + prs_give_memory( &ps, data.dptr, data.dsize, True ); + + if ( !prs_uint32( "timestamp", &ps, 0, &t ) ) { + prs_mem_free( &ps ); + return False; + } + + if ( !net_io_user_info3("", user, &ps, 0, 3, 0) ) { + SAFE_FREE( user ); + } + + prs_mem_free( &ps ); + +#if 0 /* The netsamlogon cache needs to hang around. Something about + this feels wrong, but it is the only way we can get all of the + groups. The old universal groups cache didn't expire either. + --jerry */ + { + time_t now = time(NULL); + uint32 time_diff; + + /* is the entry expired? */ + time_diff = now - t; + + if ( (time_diff < 0 ) || (time_diff > lp_winbind_cache_time()) ) { + DEBUG(10,("netsamlogon_cache_get: cache entry expired \n")); + tdb_delete( netsamlogon_tdb, key ); + SAFE_FREE( user ); + } +#endif + } + + return user; +} + +BOOL netsamlogon_cache_have(const DOM_SID *user_sid) +{ + TALLOC_CTX *mem_ctx = talloc_init("netsamlogon_cache_have"); + NET_USER_INFO_3 *user = NULL; + BOOL result; + + if (!mem_ctx) + return False; + + user = netsamlogon_cache_get(mem_ctx, user_sid); + + result = (user != NULL); + + talloc_destroy(mem_ctx); + SAFE_FREE(user); + + return result; +} diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c index 7f2f3d780e1..60a4e2f6c01 100644 --- a/source/nsswitch/winbindd.c +++ b/source/nsswitch/winbindd.c @@ -1063,6 +1063,8 @@ int main(int argc, char **argv) poptFreeContext(pc); + netsamlogon_cache_init(); /* Non-critical */ + init_domain_list(); init_idmap_child(); diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 993e6d96e8e..83ded01d4ea 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -1073,6 +1073,18 @@ static NTSTATUS query_user(struct winbindd_domain *domain, centry = wcache_fetch(cache, domain, "U/%s", sid_string_static(user_sid)); + /* If we have an access denied cache entry and a cached info3 in the + samlogon cache then do a query. This will force the rpc back end + to return the info3 data. */ + + if (NT_STATUS_V(domain->last_status) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED) && + netsamlogon_cache_have(user_sid)) { + DEBUG(10, ("query_user: cached access denied and have cached info3\n")); + domain->last_status = NT_STATUS_OK; + centry_free(centry); + goto do_query; + } + if (!centry) goto do_query; @@ -1128,6 +1140,18 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, centry = wcache_fetch(cache, domain, "UG/%s", sid_to_string(sid_string, user_sid)); + /* If we have an access denied cache entry and a cached info3 in the + samlogon cache then do a query. This will force the rpc back end + to return the info3 data. */ + + if (NT_STATUS_V(domain->last_status) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED) && + netsamlogon_cache_have(user_sid)) { + DEBUG(10, ("query_user: cached access denied and have cached info3\n")); + domain->last_status = NT_STATUS_OK; + centry_free(centry); + goto do_query; + } + if (!centry) goto do_query; @@ -1401,6 +1425,20 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, return 0; } +/* Invalidate the getpwnam and getgroups entries for a winbindd domain */ + +void wcache_invalidate_samlogon(struct winbindd_domain *domain, + NET_USER_INFO_3 *info3) +{ + struct winbind_cache *cache; + + if (!domain) + return; + + cache = get_cache(domain); + netsamlogon_clear_cached_user(cache->tdb, info3); +} + void wcache_invalidate_cache(void) { struct winbindd_domain *domain; diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index 3571142c584..d398e41468c 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -382,6 +382,9 @@ enum winbindd_result winbindd_dual_pam_auth(struct winbindd_domain *domain, } while ( (attempts < 2) && retry ); if (NT_STATUS_IS_OK(result)) { + netsamlogon_cache_store(state->mem_ctx, name_user, &info3); + wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3); + /* Check if the user is in the right group */ if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, &info3, @@ -664,6 +667,11 @@ enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain, } while ( (attempts < 2) && retry ); if (NT_STATUS_IS_OK(result)) { + netsamlogon_cache_store(state->mem_ctx, name_user, &info3); + wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3); + + /* Check if the user is in the right group */ + if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, &info3, state->request.data.auth_crap.require_membership_of_sid))) { DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n", diff --git a/source/nsswitch/winbindd_rpc.c b/source/nsswitch/winbindd_rpc.c index b3bed2e0bee..63e24877008 100644 --- a/source/nsswitch/winbindd_rpc.c +++ b/source/nsswitch/winbindd_rpc.c @@ -329,6 +329,7 @@ static NTSTATUS query_user(struct winbindd_domain *domain, SAM_USERINFO_CTR *ctr; fstring sid_string; uint32 user_rid; + NET_USER_INFO_3 *user; struct rpc_pipe_client *cli; DEBUG(3,("rpc: query_user rid=%s\n", @@ -337,6 +338,33 @@ static NTSTATUS query_user(struct winbindd_domain *domain, if (!sid_peek_check_rid(&domain->sid, user_sid, &user_rid)) return NT_STATUS_UNSUCCESSFUL; + /* try netsamlogon cache first */ + + if ( (user = netsamlogon_cache_get( mem_ctx, user_sid )) != NULL ) + { + + DEBUG(5,("query_user: Cache lookup succeeded for %s\n", + sid_string_static(user_sid))); + + sid_compose(&user_info->user_sid, &domain->sid, user_rid); + sid_compose(&user_info->group_sid, &domain->sid, + user->group_rid); + + user_info->acct_name = unistr2_tdup(mem_ctx, + &user->uni_user_name); + user_info->full_name = unistr2_tdup(mem_ctx, + &user->uni_full_name); + + user_info->homedir = NULL; + user_info->shell = NULL; + + SAFE_FREE(user); + + return NT_STATUS_OK; + } + + /* no cache; hit the wire */ + result = cm_connect_sam(domain, mem_ctx, &cli, &dom_pol); if (!NT_STATUS_IS_OK(result)) return result; @@ -384,6 +412,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, unsigned int i; fstring sid_string; uint32 user_rid; + NET_USER_INFO_3 *user; struct rpc_pipe_client *cli; DEBUG(3,("rpc: lookup_usergroups sid=%s\n", @@ -394,6 +423,29 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, *num_groups = 0; *user_grpsids = NULL; + + /* so lets see if we have a cached user_info_3 */ + + if ( (user = netsamlogon_cache_get( mem_ctx, user_sid )) != NULL ) + { + DEBUG(5,("query_user: Cache lookup succeeded for %s\n", + sid_string_static(user_sid))); + + *num_groups = user->num_groups; + + (*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_groups); + for (i=0;i<(*num_groups);i++) { + sid_copy(&((*user_grpsids)[i]), &domain->sid); + sid_append_rid(&((*user_grpsids)[i]), + user->gids[i].g_rid); + } + + SAFE_FREE(user); + + return NT_STATUS_OK; + } + + /* no cache; hit the wire */ result = cm_connect_sam(domain, mem_ctx, &cli, &dom_pol); if (!NT_STATUS_IS_OK(result)) -- cgit From 26c677002d15dcc00c424d57f8b3fd97a0ee870a Mon Sep 17 00:00:00 2001 From: Paul Green Date: Thu, 10 Nov 2005 20:32:00 +0000 Subject: r11653: Declare the correct return value for the static initialization functions. Some compilers (guess whose) have ABIs that return int values using a different method than returning struct values. --- source/aclocal.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/aclocal.m4 b/source/aclocal.m4 index af93aa23685..7c76549dd91 100644 --- a/source/aclocal.m4 +++ b/source/aclocal.m4 @@ -56,7 +56,7 @@ AC_DEFUN(SMB_MODULE, [$6] string_shared_modules="$string_shared_modules $1" elif test x"$DEST" = xSTATIC; then - [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z]) $1_init();" + [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z]) NTSTATUS $1_init();" string_static_modules="$string_static_modules $1" $4_STATIC="$$4_STATIC $2" AC_SUBST($4_STATIC) -- cgit From 63998bfdb16b0a82b47a0696a5da677f9fff684c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Nov 2005 21:10:24 +0000 Subject: r11655: Two small fixes * remove redundant call to sub_set_smb_name() in session setup code. * Fix lockup when running 'wbinfo -t' on a Samba PDC. Cause was new authenticated session setup from winbindd which resulted in a mangled username (machine_) that was not found in the local files and so was queiued up to nss_winbindd. Deadlock.... So now make sure to keep the trailing '$' for machine account names when calling sub_set_smb_name(). --- source/lib/substitute.c | 30 ++++++++++++++++++++++++++---- source/smbd/sesssetup.c | 3 --- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/source/lib/substitute.c b/source/lib/substitute.c index 884f038e6db..4d22518230f 100644 --- a/source/lib/substitute.c +++ b/source/lib/substitute.c @@ -107,15 +107,37 @@ const char* get_local_machine_name(void) void sub_set_smb_name(const char *name) { fstring tmp; + int len; + BOOL is_machine_account = False; /* don't let anonymous logins override the name */ if (! *name) return; - fstrcpy(tmp,name); - trim_char(tmp,' ',' '); - strlower_m(tmp); - alpha_strcpy(smb_user_name,tmp,SAFE_NETBIOS_CHARS,sizeof(smb_user_name)-1); + + fstrcpy( tmp, name ); + trim_char( tmp, ' ', ' ' ); + strlower_m( tmp ); + + len = strlen( tmp ); + + if ( len == 0 ) + return; + + /* long story but here goes....we have to allow usernames + ending in '$' as they are valid machine account names. + So check for a machine account and re-add the '$' + at the end after the call to alpha_strcpy(). --jerry */ + + if ( tmp[len-1] == '$' ) + is_machine_account = True; + + alpha_strcpy( smb_user_name, tmp, SAFE_NETBIOS_CHARS, sizeof(smb_user_name)-1 ); + + if ( is_machine_account ) { + len = strlen( smb_user_name ); + smb_user_name[len-1] = '$'; + } } char* sub_get_smb_name( void ) diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c index 34b161c92ff..9ac258cb5e9 100644 --- a/source/smbd/sesssetup.c +++ b/source/smbd/sesssetup.c @@ -954,9 +954,6 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf, return ERROR_NT(NT_STATUS_LOGON_FAILURE); } fstrcpy(sub_user, user); - - /* setup the string used by %U */ - sub_set_smb_name(user); } else { fstrcpy(sub_user, lp_guestaccount()); } -- cgit From a1800ed4fe7913961a3549410f076a8915f6be1d Mon Sep 17 00:00:00 2001 From: Paul Green Date: Thu, 10 Nov 2005 21:34:25 +0000 Subject: r11657: Tiny improvement to debug error message in dir_check_ftype. --- source/smbd/dir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/smbd/dir.c b/source/smbd/dir.c index c993012a254..0635db22dbd 100644 --- a/source/smbd/dir.c +++ b/source/smbd/dir.c @@ -802,7 +802,7 @@ BOOL get_dir_entry(connection_struct *conn,char *mask,uint32 dirtype, pstring fn *mode = dos_mode(conn,pathreal,&sbuf); if (!dir_check_ftype(conn,*mode,dirtype)) { - DEBUG(5,("[%s] attribs didn't match %x\n",filename,(unsigned int)dirtype)); + DEBUG(5,("[%s] attribs 0x%x didn't match 0x%x\n",filename,(unsigned int)*mode,(unsigned int)dirtype)); continue; } -- cgit From 63a386354d86c7a76bc8636ac675c103bdc7654c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Nov 2005 00:16:43 +0000 Subject: r11658: Someone broke the initialization of the static modules by adding a 'NTSTATUS' declaration before their call. The compiler sees : { NTSTATUS fn_foo(); NT_STATUS fn_bar(); } as *definitions: They need to be : { fn_foo(); fn_bar(); } Jeremy. --- source/aclocal.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/aclocal.m4 b/source/aclocal.m4 index 7c76549dd91..86c43f80dc0 100644 --- a/source/aclocal.m4 +++ b/source/aclocal.m4 @@ -56,7 +56,7 @@ AC_DEFUN(SMB_MODULE, [$6] string_shared_modules="$string_shared_modules $1" elif test x"$DEST" = xSTATIC; then - [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z]) NTSTATUS $1_init();" + [init_static_modules_]translit([$4], [A-Z], [a-z])="$[init_static_modules_]translit([$4], [A-Z], [a-z]) $1_init();" string_static_modules="$string_static_modules $1" $4_STATIC="$$4_STATIC $2" AC_SUBST($4_STATIC) -- cgit From 7060a2c9442111650852383da1abccf01c1102f0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Nov 2005 03:03:41 +0000 Subject: r11661: Store the INFO3 in the PAC data into the netsamlogon_cache. Also remove the mem_ctx from the netsamlogon_cache_store() API. Guenther, what should we be doing with the other fields in the PAC_LOGON_INFO? --- source/auth/auth_domain.c | 2 +- source/libsmb/samlogon_cache.c | 12 ++++++++++-- source/nsswitch/winbindd_pam.c | 4 ++-- source/smbd/sesssetup.c | 12 ++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/source/auth/auth_domain.c b/source/auth/auth_domain.c index 242105a664b..266851b2292 100644 --- a/source/auth/auth_domain.c +++ b/source/auth/auth_domain.c @@ -253,7 +253,7 @@ static NTSTATUS domain_client_validate(TALLOC_CTX *mem_ctx, server_info, &info3); - netsamlogon_cache_store( mem_ctx, user_info->smb_name.str, &info3 ); + netsamlogon_cache_store( user_info->smb_name.str, &info3 ); } /* Note - once the cli stream is shutdown the mem_ctx used diff --git a/source/libsmb/samlogon_cache.c b/source/libsmb/samlogon_cache.c index ceb7b7c35a4..d0469a1a481 100644 --- a/source/libsmb/samlogon_cache.c +++ b/source/libsmb/samlogon_cache.c @@ -109,7 +109,7 @@ void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user) username should be in UTF-8 format ***********************************************************************/ -BOOL netsamlogon_cache_store(TALLOC_CTX *mem_ctx, const char * username, NET_USER_INFO_3 *user) +BOOL netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user ) { TDB_DATA data; fstring keystr; @@ -117,6 +117,7 @@ BOOL netsamlogon_cache_store(TALLOC_CTX *mem_ctx, const char * username, NET_USE BOOL result = False; DOM_SID user_sid; time_t t = time(NULL); + TALLOC_CTX *mem_ctx; if (!netsamlogon_cache_init()) { @@ -142,6 +143,11 @@ BOOL netsamlogon_cache_store(TALLOC_CTX *mem_ctx, const char * username, NET_USE /* Prepare data */ + if ( !(mem_ctx = TALLOC_P( NULL, int )) ) { + DEBUG(0,("netsamlogon_cache_store: talloc() failed!\n")); + return False; + } + prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); if ( !prs_uint32( "timestamp", &ps, 0, (uint32*)&t ) ) @@ -157,6 +163,8 @@ BOOL netsamlogon_cache_store(TALLOC_CTX *mem_ctx, const char * username, NET_USE prs_mem_free( &ps ); } + + TALLOC_FREE( mem_ctx ); return result; } @@ -175,7 +183,7 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, const DOM_SID *user uint32 t; if (!netsamlogon_cache_init()) { - DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n", NETSAMLOGON_TDB)); + DEBUG(0,("netsamlogon_cache_get: cannot open %s for write!\n", NETSAMLOGON_TDB)); return False; } diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index d398e41468c..6b65d7bfe4e 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -382,7 +382,7 @@ enum winbindd_result winbindd_dual_pam_auth(struct winbindd_domain *domain, } while ( (attempts < 2) && retry ); if (NT_STATUS_IS_OK(result)) { - netsamlogon_cache_store(state->mem_ctx, name_user, &info3); + netsamlogon_cache_store(name_user, &info3); wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3); /* Check if the user is in the right group */ @@ -667,7 +667,7 @@ enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain, } while ( (attempts < 2) && retry ); if (NT_STATUS_IS_OK(result)) { - netsamlogon_cache_store(state->mem_ctx, name_user, &info3); + netsamlogon_cache_store(name_user, &info3); wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3); /* Check if the user is in the right group */ diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c index 9ac258cb5e9..2c967601678 100644 --- a/source/smbd/sesssetup.c +++ b/source/smbd/sesssetup.c @@ -180,10 +180,6 @@ static int reply_spnego_kerberos(connection_struct *conn, return ERROR_NT(NT_STATUS_LOGON_FAILURE); } - if (pac_data) { - logon_info = get_logon_info_from_pac(pac_data); - } - DEBUG(3,("Ticket name is [%s]\n", client)); p = strchr_m(client, '@'); @@ -196,6 +192,14 @@ static int reply_spnego_kerberos(connection_struct *conn, } *p = 0; + + /* save the PAC data if we have it */ + + if (pac_data) { + logon_info = get_logon_info_from_pac(pac_data); + netsamlogon_cache_store( client, &logon_info->info3 ); + } + if (!strequal(p+1, lp_realm())) { DEBUG(3,("Ticket for foreign realm %s@%s\n", client, p+1)); if (!lp_allow_trusted_domains()) { -- cgit From 40f50e3e98066480f06fb6af6cc2d75853f8403d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 11 Nov 2005 07:03:17 +0000 Subject: r11667: Fix a debug message --- source/nsswitch/winbindd_pam.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index 6b65d7bfe4e..4582eced0e5 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -530,8 +530,9 @@ void winbindd_pam_auth_crap(struct winbindd_cli_state *state) done: set_auth_errors(&state->response, result); - DEBUG(5, ("CRAP authentication for %s returned %s (PAM: %d)\n", - state->request.data.auth.user, + DEBUG(5, ("CRAP authentication for %s\\%s returned %s (PAM: %d)\n", + state->request.data.auth_crap.domain, + state->request.data.auth_crap.user, state->response.data.auth.nt_status_string, state->response.data.auth.pam_error)); request_error(state); -- cgit From d868ed0c06a3ad85eb076ffb2338acfde25b00b9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 11 Nov 2005 21:11:33 +0000 Subject: r11685: reverting Lar's change to nistallman from r11224 since it breaks 'make installman' outside the source tree; will fix up after the rc1 release --- source/script/installman.sh | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/source/script/installman.sh b/source/script/installman.sh index e9b068a9f6c..6278012635f 100755 --- a/source/script/installman.sh +++ b/source/script/installman.sh @@ -18,10 +18,6 @@ if test ! -d $SRCDIR../docs/manpages; then exit 0 fi -# Get the configured feature set -test -f config.log && \ - eval $( grep "^[[:alnum:]]*=.*" config.log) - for lang in $langs; do if [ "X$lang" = XC ]; then echo Installing default man pages in $MANDIR/ @@ -44,20 +40,13 @@ for lang in $langs; do for sect in 1 5 7 8 ; do for m in $langdir/man$sect ; do for s in $SRCDIR../docs/manpages/$lang/*$sect; do - MP_BASENAME=${s##*/} - - # Check if this man page if required by the configured feature set - case "${MP_BASENAME}" in - smbsh.1) test -z "${SMBWRAPPER}" && continue ;; - *) ;; - esac - - FNAME="$m/${MP_BASENAME}" - + FNAME=$m/`basename $s` + # Test for writability. Involves # blowing away existing files. if (rm -f $FNAME && touch $FNAME); then + rm $FNAME if [ "x$GROFF" = x ] ; then cp $s $m # Copy raw nroff else -- cgit From fb1ce8332706fb6ed51c86cb3254211b82a5710f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 12 Nov 2005 18:22:12 +0000 Subject: r11704: methods->alternate_name is not used anymore -- remove it --- source/nsswitch/winbindd.h | 3 --- source/nsswitch/winbindd_ads.c | 37 ------------------------------------ source/nsswitch/winbindd_cache.c | 13 ------------- source/nsswitch/winbindd_passdb.c | 12 ------------ source/nsswitch/winbindd_reconnect.c | 14 -------------- source/nsswitch/winbindd_rpc.c | 8 -------- 6 files changed, 87 deletions(-) diff --git a/source/nsswitch/winbindd.h b/source/nsswitch/winbindd.h index 3adf7717d6d..00a02330559 100644 --- a/source/nsswitch/winbindd.h +++ b/source/nsswitch/winbindd.h @@ -275,9 +275,6 @@ struct winbindd_methods { char ***names, char ***alt_names, DOM_SID **dom_sids); - - /* setup the list of alternate names for the domain, if any */ - NTSTATUS (*alternate_name)(struct winbindd_domain *domain); }; /* Used to glue a policy handle and cli_state together */ diff --git a/source/nsswitch/winbindd_ads.c b/source/nsswitch/winbindd_ads.c index 32bc641b6a6..ac24b35229c 100644 --- a/source/nsswitch/winbindd_ads.c +++ b/source/nsswitch/winbindd_ads.c @@ -933,42 +933,6 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain, return result; } -/* find alternate names list for the domain - for ADS this is the - netbios name */ -static NTSTATUS alternate_name(struct winbindd_domain *domain) -{ - ADS_STRUCT *ads; - ADS_STATUS rc; - TALLOC_CTX *ctx; - const char *workgroup; - - DEBUG(3,("ads: alternate_name\n")); - - ads = ads_cached_connection(domain); - - if (!ads) { - domain->last_status = NT_STATUS_SERVER_DISABLED; - return NT_STATUS_UNSUCCESSFUL; - } - - if (!(ctx = talloc_init("alternate_name"))) { - return NT_STATUS_NO_MEMORY; - } - - rc = ads_workgroup_name(ads, ctx, &workgroup); - - if (ADS_ERR_OK(rc)) { - fstrcpy(domain->name, workgroup); - fstrcpy(domain->alt_name, ads->config.realm); - strupper_m(domain->alt_name); - strupper_m(domain->name); - } - - talloc_destroy(ctx); - - return ads_ntstatus(rc); -} - /* the ADS backend methods are exposed via this structure */ struct winbindd_methods ads_methods = { True, @@ -983,7 +947,6 @@ struct winbindd_methods ads_methods = { lookup_groupmem, sequence_number, trusted_domains, - alternate_name }; #endif diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 83ded01d4ea..2d03e452ad6 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -1401,18 +1401,6 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain, names, alt_names, dom_sids); } -/* find the alternate names for the domain, if any */ -static NTSTATUS alternate_name(struct winbindd_domain *domain) -{ - get_cache(domain); - - DEBUG(10,("alternate_name: [Cached] - doing backend query for info for domain %s\n", - domain->name )); - - /* we don't cache this call */ - return domain->backend->alternate_name(domain); -} - /* Invalidate cached user and group lists coherently */ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, @@ -1467,7 +1455,6 @@ struct winbindd_methods cache_methods = { lookup_groupmem, sequence_number, trusted_domains, - alternate_name }; static BOOL init_wcache(void) diff --git a/source/nsswitch/winbindd_passdb.c b/source/nsswitch/winbindd_passdb.c index 238e80f31b1..c32aa01a38a 100644 --- a/source/nsswitch/winbindd_passdb.c +++ b/source/nsswitch/winbindd_passdb.c @@ -378,17 +378,6 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain, return nt_status; } -/* find alternate names list for the domain - * should we look for netbios aliases?? - SSS */ -static NTSTATUS alternate_name(struct winbindd_domain *domain) -{ - DEBUG(3,("pdb: alternate_name\n")); - - return NT_STATUS_OK; -} - - /* the rpc backend methods are exposed via this structure */ struct winbindd_methods passdb_methods = { False, @@ -403,5 +392,4 @@ struct winbindd_methods passdb_methods = { lookup_groupmem, sequence_number, trusted_domains, - alternate_name }; diff --git a/source/nsswitch/winbindd_reconnect.c b/source/nsswitch/winbindd_reconnect.c index 1a90717db31..77df9c1513c 100644 --- a/source/nsswitch/winbindd_reconnect.c +++ b/source/nsswitch/winbindd_reconnect.c @@ -242,19 +242,6 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain, return result; } -static NTSTATUS alternate_name(struct winbindd_domain *domain) -{ - NTSTATUS result; - - result = msrpc_methods.alternate_name(domain); - - if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)) - result = msrpc_methods.alternate_name(domain); - - return result; -} - - /* the rpc backend methods are exposed via this structure */ struct winbindd_methods reconnect_methods = { False, @@ -269,5 +256,4 @@ struct winbindd_methods reconnect_methods = { lookup_groupmem, sequence_number, trusted_domains, - alternate_name }; diff --git a/source/nsswitch/winbindd_rpc.c b/source/nsswitch/winbindd_rpc.c index 63e24877008..6179189e309 100644 --- a/source/nsswitch/winbindd_rpc.c +++ b/source/nsswitch/winbindd_rpc.c @@ -883,13 +883,6 @@ static NTSTATUS trusted_domains(struct winbindd_domain *domain, return result; } -/* find alternate names list for the domain - none for rpc */ -static NTSTATUS alternate_name(struct winbindd_domain *domain) -{ - return NT_STATUS_OK; -} - - /* the rpc backend methods are exposed via this structure */ struct winbindd_methods msrpc_methods = { False, @@ -904,5 +897,4 @@ struct winbindd_methods msrpc_methods = { lookup_groupmem, sequence_number, trusted_domains, - alternate_name }; -- cgit From a42b388aa594d69f3d6b0523a6ac13beebb98e17 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 13 Nov 2005 11:38:17 +0000 Subject: r11706: Implement dsr_getdcname client code. It's handy: It not only gives you the IP address but also the fqdn of the remote dc and site info. Volker --- source/include/rpc_netlogon.h | 34 ++++++ source/lib/util_unistr.c | 28 +++++ source/rpc_client/cli_netlogon.c | 123 ++++++++++++++++++++ source/rpc_parse/parse_net.c | 236 +++++++++++++++++++++++++++++++++++++++ source/rpcclient/cmd_netlogon.c | 30 +++++ 5 files changed, 451 insertions(+) diff --git a/source/include/rpc_netlogon.h b/source/include/rpc_netlogon.h index c73cd03f103..bc4c41cd1f3 100644 --- a/source/include/rpc_netlogon.h +++ b/source/include/rpc_netlogon.h @@ -38,6 +38,7 @@ #define NET_LOGON_CTRL2 0x0e #define NET_SAM_SYNC 0x10 #define NET_TRUST_DOM_LIST 0x13 +#define NET_DSR_GETDCNAME 0x14 #define NET_AUTH3 0x1a /* Secure Channel types. used in NetrServerAuthenticate negotiation */ @@ -934,4 +935,37 @@ typedef struct net_r_sam_deltas_info { NTSTATUS status; } NET_R_SAM_DELTAS; +/* NET_Q_DSR_GETDCNAME - Ask a DC for a trusted DC name and its address */ +typedef struct net_q_dsr_getdcname { + uint32 ptr_server_unc; + UNISTR2 uni_server_unc; + uint32 ptr_domain_name; + UNISTR2 uni_domain_name; + uint32 ptr_domain_guid; + struct uuid *domain_guid; + uint32 ptr_site_guid; + struct uuid *site_guid; + uint32_t flags; +} NET_Q_DSR_GETDCNAME; + +/* NET_R_DSR_GETDCNAME - Ask a DC for a trusted DC name and its address */ +typedef struct net_r_dsr_getdcname { + uint32 ptr_dc_unc; + UNISTR2 uni_dc_unc; + uint32 ptr_dc_address; + UNISTR2 uni_dc_address; + int32 dc_address_type; + struct uuid domain_guid; + uint32 ptr_domain_name; + UNISTR2 uni_domain_name; + uint32 ptr_forest_name; + UNISTR2 uni_forest_name; + uint32 dc_flags; + uint32 ptr_dc_site_name; + UNISTR2 uni_dc_site_name; + uint32 ptr_client_site_name; + UNISTR2 uni_client_site_name; + WERROR result; +} NET_R_DSR_GETDCNAME; + #endif /* _RPC_NETLOGON_H */ diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index d80bb2ce521..b979745d366 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -265,6 +265,34 @@ int rpcstr_pull_unistr2_fstring(char *dest, UNISTR2 *src) src->uni_str_len * 2, 0); } +/* Helper function to return a talloc'ed string. I have implemented it with a + * copy because I don't really know how pull_ucs2 and friends calculate the + * target size. If this turns out to be a major bottleneck someone with deeper + * multi-byte knowledge needs to revisit this. + * My (VL) use is dsr_getdcname, which returns 6 strings, the alternative would + * have been to manually talloc_strdup them in rpc_client/cli_netlogon.c. + */ + +size_t rpcstr_pull_unistr2_talloc(TALLOC_CTX *mem_ctx, char **dest, + UNISTR2 *src) +{ + pstring tmp; + size_t result; + + result = pull_ucs2(NULL, tmp, src->buffer, sizeof(tmp), + src->uni_str_len * 2, 0); + if (result < 0) { + return result; + } + + *dest = talloc_strdup(mem_ctx, tmp); + if (*dest == NULL) { + return -1; + } + + return result; +} + /* Converts a string from internal samba format to unicode */ diff --git a/source/rpc_client/cli_netlogon.c b/source/rpc_client/cli_netlogon.c index af0062f2b39..f12f7d09fa7 100644 --- a/source/rpc_client/cli_netlogon.c +++ b/source/rpc_client/cli_netlogon.c @@ -417,6 +417,129 @@ NTSTATUS rpccli_netlogon_getdcname(struct rpc_pipe_client *cli, return result; } +/* Dsr_GetDCName */ + +WERROR rpccli_netlogon_dsr_getdcname(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const char *server_name, + const char *domain_name, + struct uuid *domain_guid, + struct uuid *site_guid, + uint32_t flags, + char **dc_unc, char **dc_address, + int32 *dc_address_type, + struct uuid *domain_guid_out, + char **domain_name_out, + char **forest_name, + uint32 *dc_flags, + char **dc_site_name, + char **client_site_name) +{ + prs_struct qbuf, rbuf; + NET_Q_DSR_GETDCNAME q; + NET_R_DSR_GETDCNAME r; + char *tmp_str; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Initialize input parameters */ + + tmp_str = talloc_asprintf(mem_ctx, "\\\\%s", server_name); + if (tmp_str == NULL) { + return WERR_NOMEM; + } + + init_net_q_dsr_getdcname(&q, tmp_str, domain_name, domain_guid, + site_guid, flags); + + /* Marshall data and send request */ + + CLI_DO_RPC_WERR(cli, mem_ctx, PI_NETLOGON, NET_DSR_GETDCNAME, + q, r, + qbuf, rbuf, + net_io_q_dsr_getdcname, + net_io_r_dsr_getdcname, + WERR_GENERAL_FAILURE); + + if (!W_ERROR_IS_OK(r.result)) { + return r.result; + } + + if (dc_unc != NULL) { + char *tmp; + if (rpcstr_pull_unistr2_talloc(mem_ctx, &tmp, + &r.uni_dc_unc) < 0) { + return WERR_GENERAL_FAILURE; + } + if (*tmp == '\\') tmp += 1; + if (*tmp == '\\') tmp += 1; + + /* We have to talloc_strdup, otherwise a talloc_steal would + fail */ + *dc_unc = talloc_strdup(mem_ctx, tmp); + if (*dc_unc == NULL) { + return WERR_NOMEM; + } + } + + if (dc_address != NULL) { + char *tmp; + if (rpcstr_pull_unistr2_talloc(mem_ctx, &tmp, + &r.uni_dc_address) < 0) { + return WERR_GENERAL_FAILURE; + } + if (*tmp == '\\') tmp += 1; + if (*tmp == '\\') tmp += 1; + + /* We have to talloc_strdup, otherwise a talloc_steal would + fail */ + *dc_address = talloc_strdup(mem_ctx, tmp); + if (*dc_address == NULL) { + return WERR_NOMEM; + } + } + + if (dc_address_type != NULL) { + *dc_address_type = r.dc_address_type; + } + + if (domain_guid_out != NULL) { + *domain_guid_out = r.domain_guid; + } + + if ((domain_name_out != NULL) && + (rpcstr_pull_unistr2_talloc(mem_ctx, domain_name_out, + &r.uni_domain_name) < 1)) { + return WERR_GENERAL_FAILURE; + } + + if ((forest_name != NULL) && + (rpcstr_pull_unistr2_talloc(mem_ctx, forest_name, + &r.uni_forest_name) < 1)) { + return WERR_GENERAL_FAILURE; + } + + if (dc_flags != NULL) { + *dc_flags = r.dc_flags; + } + + if ((dc_site_name != NULL) && + (rpcstr_pull_unistr2_talloc(mem_ctx, dc_site_name, + &r.uni_dc_site_name) < 1)) { + return WERR_GENERAL_FAILURE; + } + + if ((client_site_name != NULL) && + (rpcstr_pull_unistr2_talloc(mem_ctx, client_site_name, + &r.uni_client_site_name) < 1)) { + return WERR_GENERAL_FAILURE; + } + + return WERR_OK; +} + + /* Sam synchronisation */ NTSTATUS rpccli_netlogon_sam_sync(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, diff --git a/source/rpc_parse/parse_net.c b/source/rpc_parse/parse_net.c index a32edd43841..3732ab3a725 100644 --- a/source/rpc_parse/parse_net.c +++ b/source/rpc_parse/parse_net.c @@ -3153,3 +3153,239 @@ BOOL net_io_r_sam_deltas(const char *desc, return True; } + +/******************************************************************* + Inits a NET_Q_DSR_GETDCNAME structure. +********************************************************************/ + +void init_net_q_dsr_getdcname(NET_Q_DSR_GETDCNAME *r_t, const char *server_unc, + const char *domain_name, + struct uuid *domain_guid, + struct uuid *site_guid, + uint32_t flags) +{ + DEBUG(5, ("init_net_q_dsr_getdcname\n")); + + r_t->ptr_server_unc = (server_unc != NULL); + init_unistr2(&r_t->uni_server_unc, server_unc, UNI_STR_TERMINATE); + + r_t->ptr_domain_name = (domain_name != NULL); + init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE); + + r_t->ptr_domain_guid = (domain_guid != NULL); + r_t->domain_guid = domain_guid; + + r_t->ptr_site_guid = (site_guid != NULL); + r_t->site_guid = site_guid; + + r_t->flags = flags; +} + +/******************************************************************* + Reads or writes an NET_Q_DSR_GETDCNAME structure. +********************************************************************/ + +BOOL net_io_q_dsr_getdcname(const char *desc, NET_Q_DSR_GETDCNAME *r_t, + prs_struct *ps, int depth) +{ + if (r_t == NULL) + return False; + + prs_debug(ps, depth, desc, "net_io_q_dsr_getdcname"); + depth++; + + if (!prs_uint32("ptr_server_unc", ps, depth, &r_t->ptr_server_unc)) + return False; + + if (!smb_io_unistr2("server_unc", &r_t->uni_server_unc, + r_t->ptr_server_unc, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name)) + return False; + + if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name, + r_t->ptr_domain_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("ptr_domain_guid", ps, depth, &r_t->ptr_domain_guid)) + return False; + + if (UNMARSHALLING(ps) && (r_t->ptr_domain_guid)) { + r_t->domain_guid = PRS_ALLOC_MEM(ps, struct uuid, 1); + if (r_t->domain_guid == NULL) + return False; + } + + if ((r_t->ptr_domain_guid) && + (!smb_io_uuid("domain_guid", r_t->domain_guid, ps, depth))) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("ptr_site_guid", ps, depth, &r_t->ptr_site_guid)) + return False; + + if (UNMARSHALLING(ps) && (r_t->ptr_site_guid)) { + r_t->site_guid = PRS_ALLOC_MEM(ps, struct uuid, 1); + if (r_t->site_guid == NULL) + return False; + } + + if ((r_t->ptr_site_guid) && + (!smb_io_uuid("site_guid", r_t->site_guid, ps, depth))) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_uint32("flags", ps, depth, &r_t->flags)) + return False; + + return True; +} + +/******************************************************************* + Inits a NET_R_DSR_GETDCNAME structure. +********************************************************************/ +void init_net_r_dsr_getdcname(NET_R_DSR_GETDCNAME *r_t, const char *dc_unc, + const char *dc_address, int32 dc_address_type, + struct uuid domain_guid, const char *domain_name, + const char *forest_name, uint32 dc_flags, + const char *dc_site_name, + const char *client_site_name) +{ + DEBUG(5, ("init_net_q_dsr_getdcname\n")); + + r_t->ptr_dc_unc = (dc_unc != NULL); + init_unistr2(&r_t->uni_dc_unc, dc_unc, UNI_STR_TERMINATE); + + r_t->ptr_dc_address = (dc_address != NULL); + init_unistr2(&r_t->uni_dc_address, dc_address, UNI_STR_TERMINATE); + + r_t->dc_address_type = dc_address_type; + r_t->domain_guid = domain_guid; + + r_t->ptr_domain_name = (domain_name != NULL); + init_unistr2(&r_t->uni_domain_name, domain_name, UNI_STR_TERMINATE); + + r_t->ptr_forest_name = (forest_name != NULL); + init_unistr2(&r_t->uni_forest_name, forest_name, UNI_STR_TERMINATE); + + r_t->dc_flags = dc_flags; + + r_t->ptr_dc_site_name = (dc_site_name != NULL); + init_unistr2(&r_t->uni_dc_site_name, dc_site_name, UNI_STR_TERMINATE); + + r_t->ptr_client_site_name = (client_site_name != NULL); + init_unistr2(&r_t->uni_client_site_name, client_site_name, + UNI_STR_TERMINATE); +} + +/******************************************************************* + Reads or writes an NET_R_DSR_GETDCNAME structure. +********************************************************************/ + +BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t, + prs_struct *ps, int depth) +{ + uint32 info_ptr = 1; + + if (r_t == NULL) + return False; + + prs_debug(ps, depth, desc, "net_io_r_dsr_getdcname"); + depth++; + + /* The reply contains *just* an info struct, this is the ptr to it */ + if (!prs_uint32("info_ptr", ps, depth, &info_ptr)) + return False; + + if (info_ptr == 0) + return False; + + if (!prs_uint32("ptr_dc_unc", ps, depth, &r_t->ptr_dc_unc)) + return False; + + if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address)) + return False; + + if (!prs_uint32("dc_address_type", ps, depth, &r_t->dc_address_type)) + return False; + + if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth)) + return False; + + if (!prs_uint32("ptr_domain_name", ps, depth, &r_t->ptr_domain_name)) + return False; + + if (!prs_uint32("ptr_forest_name", ps, depth, &r_t->ptr_forest_name)) + return False; + + if (!prs_uint32("dc_flags", ps, depth, &r_t->dc_flags)) + return False; + + if (!prs_uint32("ptr_dc_site_name", ps, depth, &r_t->ptr_dc_site_name)) + return False; + + if (!prs_uint32("ptr_client_site_name", ps, depth, + &r_t->ptr_client_site_name)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("dc_unc", &r_t->uni_dc_unc, + r_t->ptr_dc_unc, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("dc_address", &r_t->uni_dc_address, + r_t->ptr_dc_address, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("domain_name", &r_t->uni_domain_name, + r_t->ptr_domain_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("forest_name", &r_t->uni_forest_name, + r_t->ptr_forest_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("dc_site_name", &r_t->uni_dc_site_name, + r_t->ptr_dc_site_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("client_site_name", &r_t->uni_client_site_name, + r_t->ptr_client_site_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_werror("result", ps, depth, &r_t->result)) + return False; + + return True; +} diff --git a/source/rpcclient/cmd_netlogon.c b/source/rpcclient/cmd_netlogon.c index d8f5a75b54e..20f11bc3c93 100644 --- a/source/rpcclient/cmd_netlogon.c +++ b/source/rpcclient/cmd_netlogon.c @@ -70,6 +70,35 @@ static NTSTATUS cmd_netlogon_getdcname(struct rpc_pipe_client *cli, return result; } +static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, int argc, + const char **argv) +{ + WERROR result; + char *dcname, *dcaddress; + + if (argc != 2) { + fprintf(stderr, "Usage: %s domainname\n", argv[0]); + return WERR_OK; + } + + result = rpccli_netlogon_dsr_getdcname( + cli, mem_ctx, cli->cli->desthost, argv[1], NULL, NULL, + 0x40000000, &dcname, &dcaddress, NULL, NULL, NULL, NULL, + NULL, NULL, NULL); + + if (W_ERROR_IS_OK(result)) { + printf("Domain %s's DC is called %s at IP %s\n", + argv[1], dcname, dcaddress); + return WERR_OK; + } + + printf("rpccli_netlogon_dsr_getdcname returned %s\n", + nt_errstr(werror_to_ntstatus(result))); + + return result; +} + static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -317,6 +346,7 @@ struct cmd_set netlogon_commands[] = { { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" }, { "getdcname", RPC_RTYPE_NTSTATUS, cmd_netlogon_getdcname, NULL, PI_NETLOGON, NULL, "Get trusted DC name", "" }, + { "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name", "" }, { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" }, { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" }, { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" }, -- cgit From dafe5869b2443bfdc42d5be168d2edf608424c9e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 13 Nov 2005 11:53:18 +0000 Subject: r11707: alt_names[i] might be NULL for i>0 also... Volker --- source/nsswitch/winbindd_misc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/winbindd_misc.c b/source/nsswitch/winbindd_misc.c index 4afc525b301..ec8bacc4745 100644 --- a/source/nsswitch/winbindd_misc.c +++ b/source/nsswitch/winbindd_misc.c @@ -134,7 +134,8 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain * for (i=1; imem_ctx, "%s\n%s\\%s\\%s", extra_data, - names[i], alt_names[i], + names[i], + alt_names[i] ? alt_names[i] : names[i], sid_string_static(&sids[i])); /* This is a bit excessive, but the extra data sooner or later will be -- cgit From fcd183a23b5488e8e3107fe351e20da0f45c111f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 14 Nov 2005 06:29:48 +0000 Subject: r11718: Filter stored DOS attributes by SAMBA_ATTRIBUTES_MASK (0x7f). Jeremy. --- source/smbd/dosmode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/smbd/dosmode.c b/source/smbd/dosmode.c index fec148b8e63..814d008cbbe 100644 --- a/source/smbd/dosmode.c +++ b/source/smbd/dosmode.c @@ -337,6 +337,7 @@ uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf) if (result & aSYSTEM) DEBUG(8, ("s")); if (result & aDIR ) DEBUG(8, ("d")); if (result & aARCH ) DEBUG(8, ("a")); + if (result & FILE_ATTRIBUTE_SPARSE ) DEBUG(8, ("[sparse]")); DEBUG(8,("\n")); @@ -355,6 +356,9 @@ int file_set_dosmode(connection_struct *conn, const char *fname, uint32 dosmode, mode_t unixmode; int ret = -1; + /* We only allow READONLY|HIDDEN|SYSTEM|DIRECTORY|ARCHIVE here. */ + dosmode &= SAMBA_ATTRIBUTES_MASK; + DEBUG(10,("file_set_dosmode: setting dos mode 0x%x on file %s\n", dosmode, fname)); if (!st || (st && !VALID_STAT(*st))) { st = &st1; -- cgit From 29aa4fc3c351733fb4c17ec29a84e78f8d56309f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 14 Nov 2005 06:42:44 +0000 Subject: r11719: Remove silly #define of close -> close_fn as this borks any code that includes libsmbclient.h that also calls the system close() fn. Doh ! Thanks to John Terpstra for reporting this. Jeremy. --- source/include/libsmbclient.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/source/include/libsmbclient.h b/source/include/libsmbclient.h index 46896d68e48..6d3a0cda09d 100644 --- a/source/include/libsmbclient.h +++ b/source/include/libsmbclient.h @@ -339,13 +339,6 @@ typedef int (*smbc_remove_cached_srv_fn)(SMBCCTX * c, SMBCSRV *srv); typedef int (*smbc_purge_cached_fn) (SMBCCTX * c); -/* close was renamed to close_fn, because close is often a macro. - * Allow backward compatability where this is not the case */ -#ifndef close -#define close close_fn -#endif - - /**@ingroup structure * Structure that contains a client context information * This structure is know as SMBCCTX -- cgit From 53c06d9e090f9072e4047a0b901c1f0d5cd27d65 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 14 Nov 2005 14:17:24 +0000 Subject: r11725: build smbget by default --- source/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Makefile.in b/source/Makefile.in index 6a12b2e25e9..cca0715a3aa 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -128,7 +128,7 @@ PATH_FLAGS = $(PATH_FLAGS6) $(PASSWD_FLAGS) SBIN_PROGS = bin/smbd@EXEEXT@ bin/nmbd@EXEEXT@ bin/swat@EXEEXT@ @EXTRA_SBIN_PROGS@ BIN_PROGS1 = bin/smbclient@EXEEXT@ bin/net@EXEEXT@ bin/smbspool@EXEEXT@ \ - bin/testparm@EXEEXT@ bin/smbstatus@EXEEXT@ + bin/testparm@EXEEXT@ bin/smbstatus@EXEEXT@ bin/smbget@EXEEXT@ BIN_PROGS2 = bin/smbcontrol@EXEEXT@ bin/smbtree@EXEEXT@ bin/tdbbackup@EXEEXT@ \ bin/nmblookup@EXEEXT@ bin/pdbedit@EXEEXT@ bin/tdbdump@EXEEXT@ \ bin/tdbtool@EXEEXT@ -- cgit From a1e27f15195f75a00fb5c155876ecf25d51aa3fb Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Mon, 14 Nov 2005 21:18:09 +0000 Subject: r11728: Ensure to check for the config.log in ${SRCDIR}. Revert jerry's revert from 11685. :) At the moment I don't see a way to check if there is an empty ${SMBWRAPPER} or none. If there is a way to check if ${SMBWRAPPER} isn't set at all we could make the installman script even work if config.log does not exist. --- source/script/installman.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/script/installman.sh b/source/script/installman.sh index 6278012635f..3bbca1a8aa5 100755 --- a/source/script/installman.sh +++ b/source/script/installman.sh @@ -18,6 +18,10 @@ if test ! -d $SRCDIR../docs/manpages; then exit 0 fi +# Get the configured feature set +test -f "${SRCDIR}/config.log" && \ + eval $( grep "^[[:alnum:]]*=.*" "${SRCDIR}/config.log") + for lang in $langs; do if [ "X$lang" = XC ]; then echo Installing default man pages in $MANDIR/ @@ -40,13 +44,20 @@ for lang in $langs; do for sect in 1 5 7 8 ; do for m in $langdir/man$sect ; do for s in $SRCDIR../docs/manpages/$lang/*$sect; do - FNAME=$m/`basename $s` - + MP_BASENAME=${s##*/} + + # Check if this man page if required by the configured feature set + case "${MP_BASENAME}" in + smbsh.1) test -z "${SMBWRAPPER}" && continue ;; + *) ;; + esac + + FNAME="$m/${MP_BASENAME}" + # Test for writability. Involves # blowing away existing files. if (rm -f $FNAME && touch $FNAME); then - rm $FNAME if [ "x$GROFF" = x ] ; then cp $s $m # Copy raw nroff else -- cgit From db33b9699bdbd1517b5cbe2dfe2850b072fd1745 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Nov 2005 23:09:46 +0000 Subject: r11729: Remove space from DYNEXP flags declaration for HPUX. Fixes bugzilla #3260. --- source/configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/configure.in b/source/configure.in index eb1974ccf7a..f31f26f07b5 100644 --- a/source/configure.in +++ b/source/configure.in @@ -1480,10 +1480,10 @@ if test "$enable_shared" = "yes"; then fi if test "$host_cpu" = "ia64"; then SHLIBEXT="so" - DYNEXP="-Wl,-E,+b /usr/local/lib/hpux32:/usr/lib/hpux32" + DYNEXP="-Wl,-E,+b/usr/local/lib/hpux32:/usr/lib/hpux32" else SHLIBEXT="sl" - DYNEXP="-Wl,-E,+b /usr/local/lib:/usr/lib" + DYNEXP="-Wl,-E,+b/usr/local/lib:/usr/lib" fi AC_DEFINE(STAT_ST_BLOCKSIZE,8192,[The size of a block]) AC_DEFINE(POSIX_ACL_NEEDS_MASK,1,[Does a POSIX ACL need a mask element]) -- cgit From a056ea8bcb4fd5c14fa4f3bcecde88fb91af7c36 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 15 Nov 2005 18:54:33 +0000 Subject: r11732: Remember to return early if -1 returned from *BSD EA call. Pointed out by timur@com.bat.ru. Jeremy. --- source/lib/system.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/lib/system.c b/source/lib/system.c index c59fe5c34d9..fead58faae7 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -1387,6 +1387,10 @@ ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t si */ retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0); + if (retval == -1) { + return -1; + } + if(retval > size) { errno = ERANGE; return -1; @@ -1422,6 +1426,10 @@ ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t s retval = extattr_get_link(path, attrnamespace, attrname, NULL, 0); + if (retval == -1) { + return -1; + } + if(retval > size) { errno = ERANGE; return -1; @@ -1457,6 +1465,10 @@ ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size) retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0); + if (retval == -1) { + return -1; + } + if(retval > size) { errno = ERANGE; return -1; -- cgit From df978c09a73706de73f2d9fdabbc7d92da1eef1a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 Nov 2005 20:15:46 +0000 Subject: r11734: Remove unused variable --- source/param/loadparm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index d2d739fa726..5e49a562253 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -145,7 +145,6 @@ typedef struct char *szNetbiosName; char **szNetbiosAliases; char *szNetbiosScope; - char *szDomainOtherSIDs; char *szNameResolveOrder; char *szPanicAction; char *szAddUserScript; -- cgit From c032e97eab4042a1cf25599dfebad9ac55075308 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 Nov 2005 06:54:39 +0000 Subject: r11739: As per Jeremy's request, add a panic action for developers. Now configure.in needs something along the lines of if [ $LOGNAME == "jht" ] then CFLAGS="$CFLAGS -DDEVELOPER" fi But that goes a bit far I think.... :-))) Volker --- source/param/loadparm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 5e49a562253..f45d8cf9527 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -1424,6 +1424,9 @@ static void init_globals(void) slprintf(s, sizeof(s) - 1, "%d.%d", DEFAULT_MAJOR_VERSION, DEFAULT_MINOR_VERSION); string_set(&Globals.szAnnounceVersion, s); +#ifdef DEVELOPER + string_set(&Globals.szPanicAction, "/bin/sleep 999999999"); +#endif pstrcpy(user_socket_options, DEFAULT_SOCKET_OPTIONS); -- cgit From b64bb16409fddc1ae49ae3de69e23fb90edca8aa Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 17 Nov 2005 17:41:02 +0000 Subject: r11760: fix sequential reads in the eventlog; event viewer is behaving better now as well but needs more testing --- source/rpc_parse/parse_eventlog.c | 2 +- source/rpc_server/srv_eventlog_nt.c | 186 ++++++++++++++++++++---------------- 2 files changed, 106 insertions(+), 82 deletions(-) diff --git a/source/rpc_parse/parse_eventlog.c b/source/rpc_parse/parse_eventlog.c index 0f0b02748b3..5e28a4aba5d 100644 --- a/source/rpc_parse/parse_eventlog.c +++ b/source/rpc_parse/parse_eventlog.c @@ -294,7 +294,7 @@ BOOL eventlog_io_r_read_eventlog(const char *desc, while(entry != NULL && record_written < record_total) { - DEBUG(10, ("eventlog_io_r_read_eventlog: writing record [%d] out of [%d].\n", record_written, record_total)); + DEBUG(11, ("eventlog_io_r_read_eventlog: writing record [%d] out of [%d].\n", record_written, record_total)); /* Encode the actual eventlog record record */ diff --git a/source/rpc_server/srv_eventlog_nt.c b/source/rpc_server/srv_eventlog_nt.c index 6413221031c..0f0b73029ac 100644 --- a/source/rpc_server/srv_eventlog_nt.c +++ b/source/rpc_server/srv_eventlog_nt.c @@ -28,6 +28,7 @@ typedef struct { char *logname; TDB_CONTEXT *tdb; + uint32 current_record; uint32 num_records; uint32 oldest_entry; uint32 flags; @@ -130,6 +131,45 @@ static BOOL elog_validate_logname( const char *name ) return False; } +/******************************************************************** +********************************************************************/ + +static BOOL get_num_records_hook( EVENTLOG_INFO * info ) +{ + int next_record; + int oldest_record; + + if ( !info->tdb ) { + DEBUG( 10, ( "No open tdb for %s\n", info->logname ) ); + return False; + } + + /* lock the tdb since we have to get 2 records */ + + tdb_lock_bystring( info->tdb, EVT_NEXT_RECORD, 1 ); + next_record = tdb_fetch_int32( info->tdb, EVT_NEXT_RECORD); + oldest_record = tdb_fetch_int32( info->tdb, EVT_OLDEST_ENTRY); + tdb_unlock_bystring( info->tdb, EVT_NEXT_RECORD); + + DEBUG( 8, + ( "Oldest Record %d; Next Record %d\n", oldest_record, + next_record ) ); + + info->num_records = ( next_record - oldest_record ); + info->oldest_entry = oldest_record; + + return True; +} + +/******************************************************************** + ********************************************************************/ + +static BOOL get_oldest_entry_hook( EVENTLOG_INFO * info ) +{ + /* it's the same thing */ + return get_num_records_hook( info ); +} + /******************************************************************** ********************************************************************/ @@ -199,6 +239,15 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn return NT_STATUS_NO_MEMORY; } + /* set the initial current_record pointer */ + + if ( !get_oldest_entry_hook( elog ) ) { + DEBUG(3,("elog_open: Successfully opened eventlog but can't " + "get any information on internal records!\n")); + } + + elog->current_record = elog->oldest_entry; + return NT_STATUS_OK; } @@ -397,45 +446,6 @@ static BOOL sync_eventlog_params( EVENTLOG_INFO *info ) return True; } -/******************************************************************** -********************************************************************/ - -static BOOL get_num_records_hook( EVENTLOG_INFO * info ) -{ - int next_record; - int oldest_record; - - if ( !info->tdb ) { - DEBUG( 10, ( "No open tdb for %s\n", info->logname ) ); - return False; - } - - /* lock the tdb since we have to get 2 records */ - - tdb_lock_bystring( info->tdb, EVT_NEXT_RECORD, 1 ); - next_record = tdb_fetch_int32( info->tdb, EVT_NEXT_RECORD); - oldest_record = tdb_fetch_int32( info->tdb, EVT_OLDEST_ENTRY); - tdb_unlock_bystring( info->tdb, EVT_NEXT_RECORD); - - DEBUG( 8, - ( "Oldest Record %d; Next Record %d\n", oldest_record, - next_record ) ); - - info->num_records = ( next_record - oldest_record ); - info->oldest_entry = oldest_record; - - return True; -} - -/******************************************************************** - ********************************************************************/ - -static BOOL get_oldest_entry_hook( EVENTLOG_INFO * info ) -{ - /* it's the same thing */ - return get_num_records_hook( info ); -} - /******************************************************************** ********************************************************************/ @@ -661,71 +671,85 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p, { EVENTLOG_INFO *info = find_eventlog_info_by_hnd( p, &q_u->handle ); Eventlog_entry entry, *ee_new; - uint32 num_records_read = 0; prs_struct *ps; int bytes_left, record_number; - TDB_CONTEXT *tdb; - info->flags = q_u->flags; ps = &p->out_data.rdata; + uint32 elog_read_type, elog_read_dir; bytes_left = q_u->max_read_size; - tdb = info->tdb; - if ( !tdb ) { + + if ( !info->tdb ) return NT_STATUS_ACCESS_DENIED; + + /* check for valid flags. Can't use the sequential and seek flags together */ + + elog_read_type = q_u->flags & (EVENTLOG_SEQUENTIAL_READ|EVENTLOG_SEEK_READ); + elog_read_dir = q_u->flags & (EVENTLOG_FORWARDS_READ|EVENTLOG_BACKWARDS_READ); + + if ( elog_read_type == (EVENTLOG_SEQUENTIAL_READ|EVENTLOG_SEEK_READ) + || elog_read_dir == (EVENTLOG_FORWARDS_READ|EVENTLOG_BACKWARDS_READ) ) + { + DEBUG(3,("_eventlog_read_eventlog: Invalid flags [0x%x] for ReadEventLog\n", q_u->flags)); + return NT_STATUS_INVALID_PARAMETER; } - /* DEBUG(8,("Bytes left is %d\n",bytes_left)); */ + /* a sequential read should ignore the offset */ - record_number = q_u->offset; + if ( elog_read_type & EVENTLOG_SEQUENTIAL_READ ) + record_number = info->current_record; + else + record_number = q_u->offset; while ( bytes_left > 0 ) { - if ( get_eventlog_record - ( ps, tdb, record_number, &entry ) ) { - DEBUG( 8, - ( "Retrieved record %d\n", record_number ) ); + + /* assume that when the record fetch fails, that we are done */ + + if ( !get_eventlog_record ( ps, info->tdb, record_number, &entry ) ) + break; + + DEBUG( 8, ( "Retrieved record %d\n", record_number ) ); - /* Now see if there is enough room to add */ - ee_new = read_package_entry( ps, q_u, r_u,&entry ); - if ( !ee_new ) - return NT_STATUS_NO_MEMORY; - - if ( r_u->num_bytes_in_resp + ee_new->record.length > - q_u->max_read_size ) { - r_u->bytes_in_next_record = - ee_new->record.length; - - /* response would be too big to fit in client-size buffer */ + /* Now see if there is enough room to add */ + + if ( !(ee_new = read_package_entry( ps, q_u, r_u,&entry )) ) + return NT_STATUS_NO_MEMORY; + + if ( r_u->num_bytes_in_resp + ee_new->record.length > q_u->max_read_size ) { + r_u->bytes_in_next_record = ee_new->record.length; + + /* response would be too big to fit in client-size buffer */ - bytes_left = 0; - break; - } + bytes_left = 0; + break; + } - add_record_to_resp( r_u, ee_new ); - bytes_left -= ee_new->record.length; - ZERO_STRUCT( entry ); - num_records_read = - r_u->num_records - num_records_read; + add_record_to_resp( r_u, ee_new ); + bytes_left -= ee_new->record.length; + ZERO_STRUCT( entry ); + num_records_read = r_u->num_records - num_records_read; - DEBUG( 10, - ( "_eventlog_read_eventlog: read [%d] records for a total of [%d] records using [%d] bytes out of a max of [%d].\n", - num_records_read, r_u->num_records, - r_u->num_bytes_in_resp, - q_u->max_read_size ) ); - } else { - DEBUG( 8, ( "get_eventlog_record returned NULL\n" ) ); - return NT_STATUS_NO_MEMORY; /* wrong error - but return one anyway */ - } - + DEBUG( 10, ( "_eventlog_read_eventlog: read [%d] records for a total " + "of [%d] records using [%d] bytes out of a max of [%d].\n", + num_records_read, r_u->num_records, + r_u->num_bytes_in_resp, + q_u->max_read_size ) ); if ( info->flags & EVENTLOG_FORWARDS_READ ) record_number++; else record_number--; + + /* update the eventlog record pointer */ + + info->current_record = record_number; } - - return NT_STATUS_OK; + + /* crazy by WinXP uses NT_STATUS_BUFFER_TOO_SMALL to + say when there are no more records */ + + return (num_records_read ? NT_STATUS_OK : NT_STATUS_BUFFER_TOO_SMALL); } /******************************************************************** -- cgit From 0066a6f8eed03fdb19ea3dd429cc70d85d374fa7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 17 Nov 2005 20:08:59 +0000 Subject: r11761: * fix clearing of event logs by truncating the tdb. This feature got broken in some of the other updates. Now each open handle stores an pointer to an open tdb data structure (not the tdb pointer itself). Clearing can be done with a simple elog_close_tdb( elog, True ) to force a close and then calling elog_open_tdb( logname, True ) to force an tdb truncate. Permissions on existing tdbs are maintained which is important. * We don't currently handle backup. Haven't looked at the format of a backuped up eventlog to know what the deal is. --- source/include/rpc_eventlog.h | 10 ++++ source/rpc_server/srv_eventlog_lib.c | 107 +++++++++++++++++++---------------- source/rpc_server/srv_eventlog_nt.c | 64 +++++++++++---------- source/script/mkproto.awk | 2 +- 4 files changed, 105 insertions(+), 78 deletions(-) diff --git a/source/include/rpc_eventlog.h b/source/include/rpc_eventlog.h index 67e03edbc6e..5bede97d1c9 100644 --- a/source/include/rpc_eventlog.h +++ b/source/include/rpc_eventlog.h @@ -57,6 +57,16 @@ #define ELOG_SYS "System" #define ELOG_SEC "Security" +typedef struct elog_tdb { + struct elog_tdb *prev, *next; + char *name; + TDB_CONTEXT *tdb; + int ref_count; +} ELOG_TDB; + +#define ELOG_TDB_CTX(x) ((x)->tdb) + + #define EVENTLOG_DATABASE_VERSION_V1 1 /***********************************/ diff --git a/source/rpc_server/srv_eventlog_lib.c b/source/rpc_server/srv_eventlog_lib.c index b21c2a2529f..ec5edf2f347 100644 --- a/source/rpc_server/srv_eventlog_lib.c +++ b/source/rpc_server/srv_eventlog_lib.c @@ -24,14 +24,7 @@ /* maintain a list of open eventlog tdbs with reference counts */ -struct elog_open_tdb { - struct elog_open_tdb *prev, *next; - char *name; - TDB_CONTEXT *tdb; - int ref_count; -}; - -static struct elog_open_tdb *open_elog_list; +static ELOG_TDB *open_elog_list; /******************************************************************** Init an Eventlog TDB, and return it. If null, something bad @@ -317,14 +310,14 @@ BOOL can_write_to_eventlog( TDB_CONTEXT * tdb, int32 needed ) /******************************************************************* *******************************************************************/ -TDB_CONTEXT *elog_open_tdb( char *logname ) +ELOG_TDB *elog_open_tdb( char *logname, BOOL force_clear ) { - TDB_CONTEXT *tdb; + TDB_CONTEXT *tdb = NULL; uint32 vers_id; - struct elog_open_tdb *ptr; + ELOG_TDB *ptr; char *tdbfilename; pstring tdbpath; - struct elog_open_tdb *tdb_node; + ELOG_TDB *tdb_node = NULL; char *eventlogdir; /* first see if we have an open context */ @@ -332,7 +325,19 @@ TDB_CONTEXT *elog_open_tdb( char *logname ) for ( ptr=open_elog_list; ptr; ptr=ptr->next ) { if ( strequal( ptr->name, logname ) ) { ptr->ref_count++; - return ptr->tdb; + + /* trick to alow clearing of the eventlog tdb. + The force_clear flag should imply that someone + has done a force close. So make sure the tdb + is NULL. If this is a normal open, then just + return the existing reference */ + + if ( force_clear ) { + SMB_ASSERT( ptr->tdb == NULL ); + break; + } + else + return ptr; } } @@ -348,27 +353,41 @@ TDB_CONTEXT *elog_open_tdb( char *logname ) pstrcpy( tdbpath, tdbfilename ); SAFE_FREE( tdbfilename ); - DEBUG(7,("elog_open_tdb: Opening %s...\n", tdbpath )); + DEBUG(7,("elog_open_tdb: Opening %s...(force_clear == %s)\n", + tdbpath, force_clear?"True":"False" )); + + /* the tdb wasn't already open or this is a forced clear open */ - tdb = tdb_open_log( tdbpath, 0, TDB_DEFAULT, O_RDWR , 0 ); - if ( tdb ) { - vers_id = tdb_fetch_int32( tdb, EVT_VERSION ); + if ( !force_clear ) { - if ( vers_id != EVENTLOG_DATABASE_VERSION_V1 ) { - DEBUG(1,("elog_open_tdb: Invalid version [%d] on file [%s].\n", - vers_id, tdbpath)); - tdb_close( tdb ); - tdb = elog_init_tdb( tdbpath ); + tdb = tdb_open_log( tdbpath, 0, TDB_DEFAULT, O_RDWR , 0 ); + if ( tdb ) { + vers_id = tdb_fetch_int32( tdb, EVT_VERSION ); + + if ( vers_id != EVENTLOG_DATABASE_VERSION_V1 ) { + DEBUG(1,("elog_open_tdb: Invalid version [%d] on file [%s].\n", + vers_id, tdbpath)); + tdb_close( tdb ); + tdb = elog_init_tdb( tdbpath ); + } } } - else { + + if ( !tdb ) tdb = elog_init_tdb( tdbpath ); - } /* if we got a valid context, then add it to the list */ if ( tdb ) { - if ( !(tdb_node = TALLOC_ZERO_P( NULL, struct elog_open_tdb )) ) { + /* on a forced clear, just reset the tdb context if we already + have an open entry in the list */ + + if ( ptr ) { + ptr->tdb = tdb; + return ptr; + } + + if ( !(tdb_node = TALLOC_ZERO_P( NULL, ELOG_TDB)) ) { DEBUG(0,("elog_open_tdb: talloc() failure!\n")); tdb_close( tdb ); return NULL; @@ -381,42 +400,34 @@ TDB_CONTEXT *elog_open_tdb( char *logname ) DLIST_ADD( open_elog_list, tdb_node ); } - return tdb; + return tdb_node; } /******************************************************************* Wrapper to handle reference counts to the tdb *******************************************************************/ -int elog_close_tdb( TDB_CONTEXT *tdb ) +int elog_close_tdb( ELOG_TDB *etdb, BOOL force_close ) { - struct elog_open_tdb *ptr; + TDB_CONTEXT *tdb; - if ( !tdb ) + if ( !etdb ) return 0; - /* See if we can just decrement the ref_count. - Just compare pointer values (not names ) */ - - for ( ptr=open_elog_list; ptr; ptr=ptr->next ) { - if ( tdb == ptr->tdb ) { - ptr->ref_count--; - break; - } - } + etdb->ref_count--; - /* if we have a NULL pointer; it means we are trying to - close a tdb not in the list of open eventlogs */ - - SMB_ASSERT( ptr != NULL ); - if ( !ptr ) + SMB_ASSERT( etdb->ref_count >= 0 ); + + if ( etdb->ref_count == 0 ) { + tdb = etdb->tdb; + DLIST_REMOVE( open_elog_list, etdb ); + TALLOC_FREE( etdb ); return tdb_close( tdb ); + } - SMB_ASSERT( ptr->ref_count >= 0 ); - - if ( ptr->ref_count == 0 ) { - DLIST_REMOVE( open_elog_list, ptr ); - TALLOC_FREE( ptr ); + if ( force_close ) { + tdb = etdb->tdb; + etdb->tdb = NULL; return tdb_close( tdb ); } diff --git a/source/rpc_server/srv_eventlog_nt.c b/source/rpc_server/srv_eventlog_nt.c index 0f0b73029ac..05feb51f950 100644 --- a/source/rpc_server/srv_eventlog_nt.c +++ b/source/rpc_server/srv_eventlog_nt.c @@ -27,7 +27,7 @@ typedef struct { char *logname; - TDB_CONTEXT *tdb; + ELOG_TDB *etdb; uint32 current_record; uint32 num_records; uint32 oldest_entry; @@ -42,8 +42,8 @@ static void free_eventlog_info( void *ptr ) { EVENTLOG_INFO *elog = (EVENTLOG_INFO *)ptr; - if ( elog->tdb ) - elog_close_tdb( elog->tdb ); + if ( elog->etdb ) + elog_close_tdb( elog->etdb, False ); TALLOC_FREE( elog ); } @@ -139,17 +139,17 @@ static BOOL get_num_records_hook( EVENTLOG_INFO * info ) int next_record; int oldest_record; - if ( !info->tdb ) { + if ( !info->etdb ) { DEBUG( 10, ( "No open tdb for %s\n", info->logname ) ); return False; } /* lock the tdb since we have to get 2 records */ - tdb_lock_bystring( info->tdb, EVT_NEXT_RECORD, 1 ); - next_record = tdb_fetch_int32( info->tdb, EVT_NEXT_RECORD); - oldest_record = tdb_fetch_int32( info->tdb, EVT_OLDEST_ENTRY); - tdb_unlock_bystring( info->tdb, EVT_NEXT_RECORD); + tdb_lock_bystring( ELOG_TDB_CTX(info->etdb), EVT_NEXT_RECORD, 1 ); + next_record = tdb_fetch_int32( ELOG_TDB_CTX(info->etdb), EVT_NEXT_RECORD); + oldest_record = tdb_fetch_int32( ELOG_TDB_CTX(info->etdb), EVT_OLDEST_ENTRY); + tdb_unlock_bystring( ELOG_TDB_CTX(info->etdb), EVT_NEXT_RECORD); DEBUG( 8, ( "Oldest Record %d; Next Record %d\n", oldest_record, @@ -193,10 +193,10 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn in a single process */ become_root(); - elog->tdb = elog_open_tdb( elog->logname ); + elog->etdb = elog_open_tdb( elog->logname, False ); unbecome_root(); - if ( !elog->tdb ) { + if ( !elog->etdb ) { /* according to MSDN, if the logfile cannot be found, we should default to the "Application" log */ @@ -213,11 +213,11 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn } become_root(); - elog->tdb = elog_open_tdb( elog->logname ); + elog->etdb = elog_open_tdb( elog->logname, False ); unbecome_root(); } - if ( !elog->tdb ) { + if ( !elog->etdb ) { TALLOC_FREE( elog ); return NT_STATUS_ACCESS_DENIED; /* ??? */ } @@ -226,7 +226,7 @@ static NTSTATUS elog_open( pipes_struct * p, const char *logname, POLICY_HND *hn /* now do the access check. Close the tdb if we fail here */ if ( !elog_check_access( elog, p->pipe_user.nt_user_token ) ) { - elog_close_tdb( elog->tdb ); + elog_close_tdb( elog->etdb, False ); TALLOC_FREE( elog ); return NT_STATUS_ACCESS_DENIED; } @@ -268,12 +268,12 @@ static NTSTATUS elog_close( pipes_struct *p, POLICY_HND *hnd ) static int elog_size( EVENTLOG_INFO *info ) { - if ( !info || !info->tdb ) { + if ( !info || !info->etdb ) { DEBUG(0,("elog_size: Invalid info* structure!\n")); return 0; } - return elog_tdb_size( info->tdb, NULL, NULL ); + return elog_tdb_size( ELOG_TDB_CTX(info->etdb), NULL, NULL ); } /******************************************************************** @@ -397,7 +397,7 @@ static BOOL sync_eventlog_params( EVENTLOG_INFO *info ) DEBUG( 4, ( "sync_eventlog_params with %s\n", elogname ) ); - if ( !info->tdb ) { + if ( !info->etdb ) { DEBUG( 4, ( "No open tdb! (%s)\n", info->logname ) ); return False; } @@ -440,8 +440,8 @@ static BOOL sync_eventlog_params( EVENTLOG_INFO *info ) regkey_close_internal( keyinfo ); - tdb_store_int32( info->tdb, EVT_MAXSIZE, uiMaxSize ); - tdb_store_int32( info->tdb, EVT_RETENTION, uiRetention ); + tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_MAXSIZE, uiMaxSize ); + tdb_store_int32( ELOG_TDB_CTX(info->etdb), EVT_RETENTION, uiRetention ); return True; } @@ -610,7 +610,7 @@ NTSTATUS _eventlog_open_eventlog( pipes_struct * p, DEBUG(10,("_eventlog_open_eventlog: Size [%d]\n", elog_size( info ))); sync_eventlog_params( info ); - prune_eventlog( info->tdb ); + prune_eventlog( ELOG_TDB_CTX(info->etdb) ); return NT_STATUS_OK; } @@ -634,20 +634,26 @@ NTSTATUS _eventlog_clear_eventlog( pipes_struct * p, rpcstr_pull( backup_file_name, q_u->backupfile.string->buffer, sizeof( backup_file_name ), q_u->backupfile.string->uni_str_len * 2, 0 ); + + DEBUG(8,( "_eventlog_clear_eventlog: Using [%s] as the backup " + "file name for log [%s].", + backup_file_name, info->logname ) ); } - DEBUG( 8, - ( "_eventlog_clear_eventlog: Using [%s] as the backup file name for log [%s].", - backup_file_name, info->logname ) ); + /* check for WRITE access to the file */ + + if ( !(info->access_granted&SA_RIGHT_FILE_WRITE_DATA) ) + return NT_STATUS_ACCESS_DENIED; -#if 0 - /* close the current one, reinit */ + /* Force a close and reopen */ - tdb_close( info->tdb ); + elog_close_tdb( info->etdb, True ); + become_root(); + info->etdb = elog_open_tdb( info->logname, True ); + unbecome_root(); - if ( !(info->tdb = elog_init_tdb( ttdb[i].tdbfname )) ) + if ( !info->etdb ) return NT_STATUS_ACCESS_DENIED; -#endif return NT_STATUS_OK; } @@ -680,7 +686,7 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p, bytes_left = q_u->max_read_size; - if ( !info->tdb ) + if ( !info->etdb ) return NT_STATUS_ACCESS_DENIED; /* check for valid flags. Can't use the sequential and seek flags together */ @@ -706,7 +712,7 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p, /* assume that when the record fetch fails, that we are done */ - if ( !get_eventlog_record ( ps, info->tdb, record_number, &entry ) ) + if ( !get_eventlog_record ( ps, ELOG_TDB_CTX(info->etdb), record_number, &entry ) ) break; DEBUG( 8, ( "Retrieved record %d\n", record_number ) ); diff --git a/source/script/mkproto.awk b/source/script/mkproto.awk index 73a1c2b3f0a..a0f3096c842 100644 --- a/source/script/mkproto.awk +++ b/source/script/mkproto.awk @@ -136,7 +136,7 @@ END { gotstart = 1; } - if( $0 ~ /^NODE_STATUS_STRUCT|SMB_STRUCT_DIR/ ) { + if( $0 ~ /^NODE_STATUS_STRUCT|SMB_STRUCT_DIR|ELOG_TDB/ ) { gotstart = 1; } -- cgit From bd157eddaee08399eb019e4d904254fd802fcba9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 17 Nov 2005 21:03:22 +0000 Subject: r11762: fix my build breakage --- source/rpc_server/srv_eventlog_nt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/rpc_server/srv_eventlog_nt.c b/source/rpc_server/srv_eventlog_nt.c index 05feb51f950..658928b9270 100644 --- a/source/rpc_server/srv_eventlog_nt.c +++ b/source/rpc_server/srv_eventlog_nt.c @@ -680,9 +680,10 @@ NTSTATUS _eventlog_read_eventlog( pipes_struct * p, uint32 num_records_read = 0; prs_struct *ps; int bytes_left, record_number; + uint32 elog_read_type, elog_read_dir; + info->flags = q_u->flags; ps = &p->out_data.rdata; - uint32 elog_read_type, elog_read_dir; bytes_left = q_u->max_read_size; -- cgit From 961a8eedcce345e4091edad402fede96015a365e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 17 Nov 2005 21:07:24 +0000 Subject: r11763: fix more build breakage --- source/utils/eventlogadm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/utils/eventlogadm.c b/source/utils/eventlogadm.c index 31e853b61f4..1d60d6b7ea8 100644 --- a/source/utils/eventlogadm.c +++ b/source/utils/eventlogadm.c @@ -79,7 +79,7 @@ int DoWriteCommand( int argc, char **argv, BOOL debugflag, char *exename ) { FILE *f1; char *argfname; - TDB_CONTEXT *elog_tdb; + ELOG_TDB *etdb; /* fixed constants are bad bad bad */ pstring linein; @@ -100,7 +100,7 @@ int DoWriteCommand( int argc, char **argv, BOOL debugflag, char *exename ) argfname = argv[0]; - if ( !( elog_tdb = elog_open_tdb( argfname ) ) ) { + if ( !( etdb = elog_open_tdb( argfname, False ) ) ) { printf( "can't open the eventlog TDB (%s)\n", argfname ); return -1; } @@ -130,7 +130,7 @@ int DoWriteCommand( int argc, char **argv, BOOL debugflag, char *exename ) /* printf("Writing to the event log\n"); */ - rcnum = write_eventlog_tdb( elog_tdb, &ee ); + rcnum = write_eventlog_tdb( ELOG_TDB_CTX(etdb), &ee ); if ( !rcnum ) { printf( "Can't write to the event log\n" ); } else { @@ -146,7 +146,7 @@ int DoWriteCommand( int argc, char **argv, BOOL debugflag, char *exename ) } } - tdb_close( elog_tdb ); + elog_close_tdb( etdb , False ); return 0; } -- cgit From 455855e674e263536bac5137da9194f40a81c2a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Nov 2005 21:57:38 +0000 Subject: r11764: Doesn't need to be exported from here. Jeremy. --- source/lib/crc32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/crc32.c b/source/lib/crc32.c index c6a13fada12..7522ab7c811 100644 --- a/source/lib/crc32.c +++ b/source/lib/crc32.c @@ -42,7 +42,7 @@ #include "includes.h" -const uint32 crc32_tab[] = { +static const uint32 crc32_tab[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, -- cgit From e95b56206c06ec49a5e9892442aaa7573bff2c0d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Nov 2005 22:39:00 +0000 Subject: r11767: Doesn't need to be exported. Jeremy. --- source/smbd/dosmode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/smbd/dosmode.c b/source/smbd/dosmode.c index 814d008cbbe..5dfeddb80ac 100644 --- a/source/smbd/dosmode.c +++ b/source/smbd/dosmode.c @@ -126,7 +126,7 @@ mode_t unix_mode(connection_struct *conn, int dosmode, const char *fname, BOOL c Change a unix mode to a dos mode. ****************************************************************************/ -uint32 dos_mode_from_sbuf(connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf) +static uint32 dos_mode_from_sbuf(connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf) { int result = 0; enum mapreadonly_options ro_opts = (enum mapreadonly_options)lp_map_readonly(SNUM(conn)); -- cgit From b05645ca8079189defc16a01420dabdf961278e3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Nov 2005 22:40:10 +0000 Subject: r11769: Looking at a performance problem enumerating accounts, wondered if changing to support samr_connect5 might help so quickly coded it up. No it doesn't :-(. Don't merge this for 3.0.21 please. Jeremy. --- source/include/rpc_samr.h | 28 +++++++++- source/rpc_parse/parse_samr.c | 112 +++++++++++++++++++++++++++++++++++++++- source/rpc_server/srv_samr.c | 34 +++++++++++- source/rpc_server/srv_samr_nt.c | 54 +++++++++++++++++++ 4 files changed, 225 insertions(+), 3 deletions(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index 6067587654e..2c125253b3d 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -143,6 +143,7 @@ SamrTestPrivateFunctionsUser #define SAMR_CONNECT 0x39 #define SAMR_SET_USERINFO 0x3A #define SAMR_CONNECT4 0x3E +#define SAMR_CONNECT5 0x40 typedef struct logon_hours_info { @@ -1697,7 +1698,7 @@ typedef struct q_samr_connect_info /* SAMR_R_CONNECT - probably an open */ typedef struct r_samr_connect_info { - POLICY_HND connect_pol; /* policy handle */ + POLICY_HND connect_pol; /* policy handle */ NTSTATUS status; /* return status */ } SAMR_R_CONNECT; @@ -1715,6 +1716,31 @@ typedef struct q_samr_connect4_info /* SAMR_R_CONNECT4 - same format as connect */ typedef struct r_samr_connect_info SAMR_R_CONNECT4; +/* SAMR_Q_CONNECT5 */ +typedef struct q_samr_connect5_info +{ + uint32 ptr_srv_name; /* pointer to server name */ + UNISTR2 uni_srv_name; + uint32 access_mask; + uint32 level; + /* These following are acutally a level dependent + value. Fudge it for now. JRA */ + uint32 info1_unk1; + uint32 info1_unk2; +} SAMR_Q_CONNECT5; + +/* SAMR_R_CONNECT5 */ +typedef struct r_samr_connect_info5 +{ + uint32 level; + uint32 info1_unk1; + uint32 info1_unk2; + POLICY_HND connect_pol; /* policy handle */ + NTSTATUS status; /* return status */ + +} SAMR_R_CONNECT5; + + /* SAMR_Q_GET_DOM_PWINFO */ typedef struct q_samr_get_dom_pwinfo { diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index dfe80a65e27..7e39b44fe66 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -6734,7 +6734,7 @@ inits a SAMR_Q_CONNECT4 structure. void init_samr_q_connect4(SAMR_Q_CONNECT4 * q_u, char *srv_name, uint32 access_mask) { - DEBUG(5, ("init_samr_q_connect\n")); + DEBUG(5, ("init_samr_q_connect4\n")); /* make PDC server name \\server */ q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0; @@ -6803,6 +6803,116 @@ BOOL samr_io_r_connect4(const char *desc, SAMR_R_CONNECT4 * r_u, return True; } +/******************************************************************* +inits a SAMR_Q_CONNECT5 structure. +********************************************************************/ + +void init_samr_q_connect5(SAMR_Q_CONNECT5 * q_u, + char *srv_name, uint32 access_mask) +{ + DEBUG(5, ("init_samr_q_connect5\n")); + + /* make PDC server name \\server */ + q_u->ptr_srv_name = (srv_name != NULL && *srv_name) ? 1 : 0; + init_unistr2(&q_u->uni_srv_name, srv_name, UNI_STR_TERMINATE); + + /* example values: 0x0000 0002 */ + q_u->access_mask = access_mask; + + q_u->level = 1; + q_u->info1_unk1 = 3; + q_u->info1_unk2 = 0; +} + +/******************************************************************* +inits a SAMR_R_CONNECT5 structure. +********************************************************************/ + +void init_samr_r_connect5(SAMR_R_CONNECT5 * r_u, POLICY_HND *pol, NTSTATUS status) +{ + DEBUG(5, ("init_samr_q_connect5\n")); + + r_u->level = 1; + r_u->info1_unk1 = 3; + r_u->info1_unk2 = 0; + + r_u->connect_pol = *pol; + r_u->status = status; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ + +BOOL samr_io_q_connect5(const char *desc, SAMR_Q_CONNECT5 * q_u, + prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_q_connect5"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name)) + return False; + if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask)) + return False; + + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + if(!prs_uint32("level", ps, depth, &q_u->level)) + return False; + + if(!prs_uint32("info1_unk1", ps, depth, &q_u->info1_unk1)) + return False; + if(!prs_uint32("info1_unk2", ps, depth, &q_u->info1_unk2)) + return False; + + return True; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ + +BOOL samr_io_r_connect5(const char *desc, SAMR_R_CONNECT5 * r_u, + prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_connect5"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("level", ps, depth, &r_u->level)) + return False; + if(!prs_uint32("level", ps, depth, &r_u->level)) + return False; + if(!prs_uint32("info1_unk1", ps, depth, &r_u->info1_unk1)) + return False; + if(!prs_uint32("info1_unk2", ps, depth, &r_u->info1_unk2)) + return False; + + if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth)) + return False; + + if(!prs_ntstatus("status", ps, depth, &r_u->status)) + return False; + + return True; +} + /******************************************************************* inits a SAMR_Q_CONNECT_ANON structure. ********************************************************************/ diff --git a/source/rpc_server/srv_samr.c b/source/rpc_server/srv_samr.c index ffb7882e110..520bf47a315 100644 --- a/source/rpc_server/srv_samr.c +++ b/source/rpc_server/srv_samr.c @@ -679,6 +679,37 @@ static BOOL api_samr_connect4(pipes_struct *p) return True; } +/******************************************************************* + api_samr_connect5 + ********************************************************************/ + +static BOOL api_samr_connect5(pipes_struct *p) +{ + SAMR_Q_CONNECT5 q_u; + SAMR_R_CONNECT5 r_u; + prs_struct *data = &p->in_data.data; + prs_struct *rdata = &p->out_data.rdata; + + ZERO_STRUCT(q_u); + ZERO_STRUCT(r_u); + + /* grab the samr open policy */ + if(!samr_io_q_connect5("", &q_u, data, 0)) { + DEBUG(0,("api_samr_connect5: unable to unmarshall SAMR_Q_CONNECT5.\n")); + return False; + } + + r_u.status = _samr_connect5(p, &q_u, &r_u); + + /* store the response in the SMB stream */ + if(!samr_io_r_connect5("", &r_u, rdata, 0)) { + DEBUG(0,("api_samr_connect5: unable to marshall SAMR_R_CONNECT5.\n")); + return False; + } + + return True; +} + /********************************************************************** api_samr_lookup_domain **********************************************************************/ @@ -1492,7 +1523,8 @@ static struct api_struct api_samr_cmds [] = {"SAMR_GET_USRDOM_PWINFO" , SAMR_GET_USRDOM_PWINFO, api_samr_get_usrdom_pwinfo}, {"SAMR_UNKNOWN_2E" , SAMR_UNKNOWN_2E , api_samr_unknown_2e }, {"SAMR_SET_DOMAIN_INFO" , SAMR_SET_DOMAIN_INFO , api_samr_set_dom_info }, - {"SAMR_CONNECT4" , SAMR_CONNECT4 , api_samr_connect4 } + {"SAMR_CONNECT4" , SAMR_CONNECT4 , api_samr_connect4 }, + {"SAMR_CONNECT5" , SAMR_CONNECT5 , api_samr_connect5 } }; void samr_get_pipe_fns( struct api_struct **fns, int *n_fns ) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 71272a9a98b..bfc96ea0f60 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -2293,6 +2293,60 @@ NTSTATUS _samr_connect4(pipes_struct *p, SAMR_Q_CONNECT4 *q_u, SAMR_R_CONNECT4 * return r_u->status; } +/******************************************************************* + samr_connect5 + ********************************************************************/ + +NTSTATUS _samr_connect5(pipes_struct *p, SAMR_Q_CONNECT5 *q_u, SAMR_R_CONNECT5 *r_u) +{ + struct samr_info *info = NULL; + SEC_DESC *psd = NULL; + uint32 acc_granted; + uint32 des_access = q_u->access_mask; + NTSTATUS nt_status; + POLICY_HND pol; + size_t sd_size; + + + DEBUG(5,("_samr_connect5: %d\n", __LINE__)); + + ZERO_STRUCTP(r_u); + + /* Access check */ + + if (!pipe_access_check(p)) { + DEBUG(3, ("access denied to samr_connect5\n")); + r_u->status = NT_STATUS_ACCESS_DENIED; + return r_u->status; + } + + make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0); + se_map_generic(&des_access, &sam_generic_mapping); + + nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token, + NULL, 0, des_access, &acc_granted, "_samr_connect5"); + + if ( !NT_STATUS_IS_OK(nt_status) ) + return nt_status; + + /* associate the user's SID and access granted with the new handle. */ + if ((info = get_samr_info_by_sid(NULL)) == NULL) + return NT_STATUS_NO_MEMORY; + + info->acc_granted = acc_granted; + info->status = q_u->access_mask; + + /* get a (unique) handle. open a policy on it. */ + if (!create_policy_hnd(p, &pol, free_samr_info, (void *)info)) + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + + DEBUG(5,("_samr_connect: %d\n", __LINE__)); + + init_samr_r_connect5(r_u, &pol, NT_STATUS_OK); + + return r_u->status; +} + /********************************************************************** api_samr_lookup_domain **********************************************************************/ -- cgit From 6542dc4c26e000aed09b6ec10a2120ed3e10cb2d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 18 Nov 2005 03:18:54 +0000 Subject: r11770: BUG 2718: don't use qpathinfo_basic() call when remote server is Win9x or the do_cd() call will fail --- source/client/client.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/client/client.c b/source/client/client.c index f849738da0a..697b4e95698 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -288,9 +288,10 @@ static int do_cd(char *newdir) if ( strequal(targetpath,"\\" ) ) return 0; - /* use a trans2_qpathinfo to test directories for modern servers */ + /* Use a trans2_qpathinfo to test directories for modern servers. + Except Win9x doesn't support the qpathinfo_basic() call..... */ - if ( targetcli->protocol >= PROTOCOL_LANMAN2 ) { + if ( targetcli->protocol >= PROTOCOL_LANMAN2 && !targetcli->win95 ) { if ( !cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) { d_printf("cd %s: %s\n", dname, cli_errstr(targetcli)); pstrcpy(cur_dir,saved_dir); -- cgit From 3bebdc6480e26e8a5d6a4ded12fa7ef2121cd7a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 18 Nov 2005 13:02:19 +0000 Subject: r11784: Fix minor glitch found by Rainer Weikusat -- Thanks --- examples/VFS/skel_opaque.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index e6b7d032fcf..e6af475da6e 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -524,7 +524,7 @@ static int skel_aio_fsync(struct vfs_handle_struct *handle, struct files_struct static int skel_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *ts) { - return vfswrap_aioi_suspend(NULL, fsp, aiocb, n, ts); + return vfswrap_aio_suspend(NULL, fsp, aiocb, n, ts); } /* VFS operations structure */ -- cgit From b1b549451c183aad74e2e7b79dddfc02c9bcbf71 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 18 Nov 2005 14:33:12 +0000 Subject: r11790: Avoid infinite retry to gather a connection. Guenther --- source/client/smbspool.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/client/smbspool.c b/source/client/smbspool.c index da517297f71..aff241adeed 100644 --- a/source/client/smbspool.c +++ b/source/client/smbspool.c @@ -30,6 +30,7 @@ #define CC_MAX_FILE_PATH_LEN (sizeof(TICKET_CC_DIR)-1)+ CC_MAX_FILE_LEN+2 #define OVERWRITE 1 #define KRB5CCNAME "KRB5CCNAME" +#define MAX_RETRY_CONNECT 3 /* @@ -71,6 +72,7 @@ static int smb_print(struct cli_state *, char *, FILE *); int status=0; /* Status of LPD job */ struct cli_state *cli; /* SMB interface */ char null_str[1]; + int tries = 0; null_str[0] = '\0'; @@ -229,17 +231,23 @@ static int smb_print(struct cli_state *, char *, FILE *); { if (getenv("CLASS") == NULL) { - fprintf(stderr, "ERROR: Unable to connect to CIFS host, will retry in 60 seconds..."); + fprintf(stderr, "ERROR: Unable to connect to CIFS host, will retry in 60 seconds...\n"); sleep (60); /* should just waiting and retrying fix authentication ??? */ + tries++; } else { - fprintf(stderr, "ERROR: Unable to connect to CIFS host, trying next printer..."); + fprintf(stderr, "ERROR: Unable to connect to CIFS host, trying next printer...\n"); return (1); } } } - while (cli == NULL); + while ((cli == NULL) && (tries < MAX_RETRY_CONNECT)); + + if (cli == NULL) { + fprintf(stderr, "ERROR: Unable to connect to CIFS host after (tried %d times)\n", tries); + return (1); + } /* * Now that we are connected to the server, ignore SIGTERM so that we -- cgit From ba8eb1c93722e6e9454395d41b7c820e44f60288 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Nov 2005 23:15:47 +0000 Subject: r11793: Fix the SAMR cache so it works across completely insane client behaviour (ie.: open pipe/open SAMR handle/enumerate 0 - 1024 close SAMR handle, close pipe. open pipe/open SAMR handle/enumerate 1024 - 2048... close SAMR handle, close pipe. And on ad-nausium. Amazing.... probably object-oriented client side programming in action yet again. This change should *massively* improve performance when enumerating users from an LDAP database. Jeremy. --- source/include/rpc_samr.h | 14 +- source/rpc_parse/parse_samr.c | 18 +- source/rpc_server/srv_samr.c | 20 +- source/rpc_server/srv_samr_nt.c | 522 ++++++++++++++++++++++++++++++---------- 4 files changed, 423 insertions(+), 151 deletions(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index 2c125253b3d..eff3cd6d4c3 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -126,7 +126,7 @@ SamrTestPrivateFunctionsUser #define SAMR_UNKNOWN_2b 0x2b #define SAMR_GET_USRDOM_PWINFO 0x2c #define SAMR_REMOVE_SID_FOREIGN_DOMAIN 0x2d -#define SAMR_UNKNOWN_2E 0x2e /* looks like an alias for SAMR_QUERY_DOMAIN_INFO */ +#define SAMR_QUERY_DOMAIN_INFO2 0x2e /* looks like an alias for SAMR_QUERY_DOMAIN_INFO */ #define SAMR_UNKNOWN_2f 0x2f #define SAMR_QUERY_DISPINFO3 0x30 /* Alias for SAMR_QUERY_DISPINFO with info level 3 */ @@ -1839,23 +1839,23 @@ typedef struct sid_info_3 } DOM_SID3; -/* SAMR_Q_UNKNOWN_2E */ -typedef struct q_samr_unknown_2e_info +/* SAMR_Q_QUERY_DOMAIN_INFO2 */ +typedef struct q_samr_query_domain_info2 { POLICY_HND domain_pol; /* policy handle */ uint16 switch_value; -} SAMR_Q_UNKNOWN_2E; +} SAMR_Q_QUERY_DOMAIN_INFO2; -/* SAMR_R_UNKNOWN_2E */ -typedef struct r_samr_unknown_2e_info +/* SAMR_R_QUERY_DOMAIN_INFO2 */ +typedef struct r_samr_query_domain_info2 { uint32 ptr_0; uint16 switch_value; SAM_UNK_CTR *ctr; NTSTATUS status; /* return status */ -} SAMR_R_UNKNOWN_2E; +} SAMR_R_QUERY_DOMAIN_INFO2; /* SAMR_Q_SET_DOMAIN_INFO */ typedef struct q_samr_set_domain_info diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index 7e39b44fe66..817244a2b2c 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -7253,10 +7253,10 @@ BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u, reads or writes a structure. ********************************************************************/ -void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u, +void init_samr_q_query_domain_info2(SAMR_Q_QUERY_DOMAIN_INFO2 *q_u, POLICY_HND *domain_pol, uint16 switch_value) { - DEBUG(5, ("init_samr_q_unknown_2e\n")); + DEBUG(5, ("init_samr_q_query_domain_info2\n")); q_u->domain_pol = *domain_pol; q_u->switch_value = switch_value; @@ -7266,13 +7266,13 @@ void init_samr_q_unknown_2e(SAMR_Q_UNKNOWN_2E *q_u, reads or writes a structure. ********************************************************************/ -BOOL samr_io_q_unknown_2e(const char *desc, SAMR_Q_UNKNOWN_2E *q_u, +BOOL samr_io_q_query_domain_info2(const char *desc, SAMR_Q_QUERY_DOMAIN_INFO2 *q_u, prs_struct *ps, int depth) { if (q_u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_q_unknown_2e"); + prs_debug(ps, depth, desc, "samr_io_q_query_domain_info2"); depth++; if(!prs_align(ps)) @@ -7291,11 +7291,11 @@ BOOL samr_io_q_unknown_2e(const char *desc, SAMR_Q_UNKNOWN_2E *q_u, inits a SAMR_R_QUERY_DOMAIN_INFO structure. ********************************************************************/ -void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u, +void init_samr_r_samr_query_domain_info2(SAMR_R_QUERY_DOMAIN_INFO2 * r_u, uint16 switch_value, SAM_UNK_CTR * ctr, NTSTATUS status) { - DEBUG(5, ("init_samr_r_samr_unknown_2e\n")); + DEBUG(5, ("init_samr_r_samr_query_domain_info2\n")); r_u->ptr_0 = 0; r_u->switch_value = 0; @@ -7312,13 +7312,13 @@ void init_samr_r_samr_unknown_2e(SAMR_R_UNKNOWN_2E * r_u, reads or writes a structure. ********************************************************************/ -BOOL samr_io_r_samr_unknown_2e(const char *desc, SAMR_R_UNKNOWN_2E * r_u, +BOOL samr_io_r_samr_query_domain_info2(const char *desc, SAMR_R_QUERY_DOMAIN_INFO2 * r_u, prs_struct *ps, int depth) { if (r_u == NULL) return False; - prs_debug(ps, depth, desc, "samr_io_r_samr_unknown_2e"); + prs_debug(ps, depth, desc, "samr_io_r_samr_query_domain_info2"); depth++; if(!prs_align(ps)) @@ -7363,7 +7363,7 @@ BOOL samr_io_r_samr_unknown_2e(const char *desc, SAMR_R_UNKNOWN_2E * r_u, return False; break; default: - DEBUG(0, ("samr_io_r_samr_unknown_2e: unknown switch level 0x%x\n", + DEBUG(0, ("samr_io_r_samr_query_domain_info2: unknown switch level 0x%x\n", r_u->switch_value)); r_u->status = NT_STATUS_INVALID_INFO_CLASS; return False; diff --git a/source/rpc_server/srv_samr.c b/source/rpc_server/srv_samr.c index 520bf47a315..e8fd86ba467 100644 --- a/source/rpc_server/srv_samr.c +++ b/source/rpc_server/srv_samr.c @@ -1405,13 +1405,13 @@ static BOOL api_samr_remove_sid_foreign_domain(pipes_struct *p) } /******************************************************************* - api_samr_query_dom_info + api_samr_query_dom_info2 ********************************************************************/ -static BOOL api_samr_unknown_2e(pipes_struct *p) +static BOOL api_samr_query_domain_info2(pipes_struct *p) { - SAMR_Q_UNKNOWN_2E q_u; - SAMR_R_UNKNOWN_2E r_u; + SAMR_Q_QUERY_DOMAIN_INFO2 q_u; + SAMR_R_QUERY_DOMAIN_INFO2 r_u; prs_struct *data = &p->in_data.data; prs_struct *rdata = &p->out_data.rdata; @@ -1419,16 +1419,16 @@ static BOOL api_samr_unknown_2e(pipes_struct *p) ZERO_STRUCT(r_u); /* grab the samr unknown 8 command */ - if(!samr_io_q_unknown_2e("", &q_u, data, 0)) { - DEBUG(0,("api_samr_unknown_2e: unable to unmarshall SAMR_Q_UNKNOWN_2E.\n")); + if(!samr_io_q_query_domain_info2("", &q_u, data, 0)) { + DEBUG(0,("api_samr_query_domain_info2: unable to unmarshall SAMR_Q_QUERY_DOMAIN_INFO2.\n")); return False; } - r_u.status = _samr_unknown_2e(p, &q_u, &r_u); + r_u.status = _samr_query_domain_info2(p, &q_u, &r_u); /* store the response in the SMB stream */ - if(!samr_io_r_samr_unknown_2e("", &r_u, rdata, 0)) { - DEBUG(0,("api_samr_unknown_2e: unable to marshall SAMR_R_UNKNOWN_2E.\n")); + if(!samr_io_r_samr_query_domain_info2("", &r_u, rdata, 0)) { + DEBUG(0,("api_samr_query_domain_info2: unable to marshall SAMR_R_QUERY_DOMAIN_INFO2.\n")); return False; } @@ -1521,7 +1521,7 @@ static struct api_struct api_samr_cmds [] = {"SAMR_QUERY_SEC_OBJECT" , SAMR_QUERY_SEC_OBJECT , api_samr_query_sec_obj }, {"SAMR_SET_SEC_OBJECT" , SAMR_SET_SEC_OBJECT , api_samr_set_sec_obj }, {"SAMR_GET_USRDOM_PWINFO" , SAMR_GET_USRDOM_PWINFO, api_samr_get_usrdom_pwinfo}, - {"SAMR_UNKNOWN_2E" , SAMR_UNKNOWN_2E , api_samr_unknown_2e }, + {"SAMR_QUERY_DOMAIN_INFO2", SAMR_QUERY_DOMAIN_INFO2, api_samr_query_domain_info2}, {"SAMR_SET_DOMAIN_INFO" , SAMR_SET_DOMAIN_INFO , api_samr_set_dom_info }, {"SAMR_CONNECT4" , SAMR_CONNECT4 , api_samr_connect4 }, {"SAMR_CONNECT5" , SAMR_CONNECT5 , api_samr_connect5 } diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index bfc96ea0f60..563c3f864f2 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -40,11 +40,16 @@ SA_RIGHT_USER_CHANGE_PASSWORD | \ SA_RIGHT_USER_SET_LOC_COM ) +#define DISP_INFO_CACHE_TIMEOUT 30 + extern rid_name domain_group_rids[]; extern rid_name domain_alias_rids[]; extern rid_name builtin_alias_rids[]; typedef struct disp_info { + struct disp_info *next, *prev; + TALLOC_CTX *mem_ctx; + DOM_SID sid; /* identify which domain this is. */ struct pdb_search *users; /* querydispinfo 1 and 4 */ struct pdb_search *machines; /* querydispinfo 2 */ struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */ @@ -53,8 +58,15 @@ typedef struct disp_info { uint16 enum_acb_mask; struct pdb_search *enum_users; /* enumusers with a mask */ + + smb_event_id_t di_cache_timeout_event; /* cache idle timeout handler. */ } DISP_INFO; +/* We keep a static list of these by SID as modern clients close down + all resources between each request in a complete enumeration. */ + +static DISP_INFO *disp_info_list; + struct samr_info { /* for use by the \PIPE\samr policy */ DOM_SID sid; @@ -62,8 +74,7 @@ struct samr_info { uint32 acc_granted; uint16 acb_mask; BOOL only_machines; - DISP_INFO disp_info; - + DISP_INFO *disp_info; TALLOC_CTX *mem_ctx; }; @@ -215,6 +226,39 @@ static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_requir return NT_STATUS_ACCESS_DENIED; } +/******************************************************************* + Fetch or create a dispinfo struct. +********************************************************************/ + +static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid, const char *sid_str) +{ + TALLOC_CTX *mem_ctx; + DISP_INFO *dpi; + + for (dpi = disp_info_list; dpi; dpi = dpi->next) { + if (sid_equal(psid, &dpi->sid)) { + return dpi; + } + } + + /* This struct is never free'd - I'm using talloc so we + can get a list out of smbd using smbcontrol. There will + be one of these per SID we're authorative for. JRA. */ + + mem_ctx = talloc_init("DISP_INFO for domain sid %s", sid_str); + + if ((dpi = TALLOC_ZERO_P(mem_ctx, DISP_INFO)) == NULL) + return NULL; + + dpi->mem_ctx = mem_ctx; + if (psid) { + sid_copy( &dpi->sid, psid); + } + + DLIST_ADD(disp_info_list, dpi); + + return dpi; +} /******************************************************************* Create a samr_info struct. @@ -244,41 +288,143 @@ static struct samr_info *get_samr_info_by_sid(DOM_SID *psid) DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n")); } info->mem_ctx = mem_ctx; + + info->disp_info = get_samr_dispinfo_by_sid(psid, sid_str); + + if (!info->disp_info) { + talloc_destroy(mem_ctx); + return NULL; + } + return info; } /******************************************************************* - Function to free the per handle data. + Function to free the per SID data. ********************************************************************/ +static void free_samr_cache(DISP_INFO *disp_info) +{ + DEBUG(10,("free_samr_cache: deleting cache\n")); + + if (disp_info->users) { + DEBUG(10,("free_samr_cache: deleting users cache\n")); + pdb_search_destroy(disp_info->users); + disp_info->users = NULL; + } + if (disp_info->machines) { + DEBUG(10,("free_samr_cache: deleting machines cache\n")); + pdb_search_destroy(disp_info->machines); + disp_info->machines = NULL; + } + if (disp_info->groups) { + DEBUG(10,("free_samr_cache: deleting groups cache\n")); + pdb_search_destroy(disp_info->groups); + disp_info->groups = NULL; + } + if (disp_info->aliases) { + DEBUG(10,("free_samr_cache: deleting aliases cache\n")); + pdb_search_destroy(disp_info->aliases); + disp_info->aliases = NULL; + } + if (disp_info->builtins) { + DEBUG(10,("free_samr_cache: deleting builtins cache\n")); + pdb_search_destroy(disp_info->builtins); + disp_info->builtins = NULL; + } + if (disp_info->enum_users) { + DEBUG(10,("free_samr_cache: deleting enum_users cache\n")); + pdb_search_destroy(disp_info->enum_users); + disp_info->enum_users = NULL; + } + disp_info->enum_acb_mask = 0; +} + /******************************************************************* Function to free the per handle data. ********************************************************************/ -static void free_samr_db(struct samr_info *info) -{ - pdb_search_destroy(info->disp_info.users); - info->disp_info.users = NULL; - pdb_search_destroy(info->disp_info.machines); - info->disp_info.machines = NULL; - pdb_search_destroy(info->disp_info.groups); - info->disp_info.groups = NULL; - pdb_search_destroy(info->disp_info.aliases); - info->disp_info.aliases = NULL; - pdb_search_destroy(info->disp_info.builtins); - info->disp_info.builtins = NULL; - pdb_search_destroy(info->disp_info.enum_users); - info->disp_info.enum_users = NULL; -} - static void free_samr_info(void *ptr) { struct samr_info *info=(struct samr_info *) ptr; - free_samr_db(info); + /* Only free the dispinfo cache if no one bothered to set up + a timeout. */ + + if (info->disp_info && info->disp_info->di_cache_timeout_event == (smb_event_id_t)0) { + free_samr_cache(info->disp_info); + } + talloc_destroy(info->mem_ctx); } +/******************************************************************* + Idle event handler. Throw away the disp info cache. + ********************************************************************/ + +static void disp_info_cache_idle_timeout_handler(void **private_data, + time_t *ev_interval, + time_t ev_now) +{ + DISP_INFO *disp_info = (DISP_INFO *)(*private_data); + + free_samr_cache(disp_info); + + /* Remove the event. */ + smb_unregister_idle_event(disp_info->di_cache_timeout_event); + disp_info->di_cache_timeout_event = (smb_event_id_t)0; + + DEBUG(10,("disp_info_cache_idle_timeout_handler: caching timed out at %u\n", + (unsigned int)ev_now)); +} + +/******************************************************************* + Setup cache removal idle event handler. + ********************************************************************/ + +static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow) +{ + /* Remove any pending timeout and update. */ + + if (disp_info->di_cache_timeout_event) { + smb_unregister_idle_event(disp_info->di_cache_timeout_event); + disp_info->di_cache_timeout_event = (smb_event_id_t)0; + } + + DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for %u seconds\n", + (unsigned int)secs_fromnow )); + + disp_info->di_cache_timeout_event = + smb_register_idle_event(disp_info_cache_idle_timeout_handler, + disp_info, + secs_fromnow); +} + +/******************************************************************* + Remove the cache removal idle event handler. + ********************************************************************/ + +static void clear_disp_info_cache_timeout(DISP_INFO *disp_info) +{ + if (disp_info->di_cache_timeout_event) { + smb_unregister_idle_event(disp_info->di_cache_timeout_event); + disp_info->di_cache_timeout_event = (smb_event_id_t)0; + DEBUG(10,("clear_disp_info_cache_timeout: clearing idle event.\n")); + } +} + +/******************************************************************* + Force flush any cache. We do this on any samr_set_xxx call. + ********************************************************************/ + +static void force_flush_samr_cache(DISP_INFO *disp_info) +{ + if (disp_info) { + clear_disp_info_cache_timeout(disp_info); + free_samr_cache(disp_info); + } +} + /******************************************************************* Ensure password info is never given out. Paranioa... JRA. ********************************************************************/ @@ -298,24 +444,36 @@ static void samr_clear_sam_passwd(SAM_ACCOUNT *sam_pass) static uint32 count_sam_users(struct disp_info *info, uint16 acct_flags) { struct samr_displayentry *entry; - if (info->users == NULL) + if (info->users == NULL) { info->users = pdb_search_users(acct_flags); - if (info->users == NULL) - return 0; + if (info->users == NULL) { + return 0; + } + } /* Fetch the last possible entry, thus trigger an enumeration */ pdb_search_entries(info->users, 0xffffffff, 1, &entry); + + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT); + return info->users->num_entries; } static uint32 count_sam_groups(struct disp_info *info) { struct samr_displayentry *entry; - if (info->groups == NULL) + if (info->groups == NULL) { info->groups = pdb_search_groups(); - if (info->groups == NULL) - return 0; + if (info->groups == NULL) { + return 0; + } + } /* Fetch the last possible entry, thus trigger an enumeration */ pdb_search_entries(info->groups, 0xffffffff, 1, &entry); + + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT); + return info->groups->num_entries; } @@ -431,12 +589,12 @@ NTSTATUS _samr_set_sec_obj(pipes_struct *p, SAMR_Q_SET_SEC_OBJ *q_u, SAMR_R_SET_ return NT_STATUS_NOT_IMPLEMENTED; } - /******************************************************************* ********************************************************************/ static BOOL get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol, - DOM_SID *sid, uint32 *acc_granted) + DOM_SID *sid, uint32 *acc_granted, + DISP_INFO **ppdisp_info) { struct samr_info *info = NULL; @@ -449,6 +607,10 @@ static BOOL get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol, *sid = info->sid; *acc_granted = info->acc_granted; + if (ppdisp_info) { + *ppdisp_info = info->disp_info; + } + return True; } @@ -467,42 +629,35 @@ NTSTATUS _samr_query_sec_obj(pipes_struct *p, SAMR_Q_QUERY_SEC_OBJ *q_u, SAMR_R_ r_u->status = NT_STATUS_OK; /* Get the SID. */ - if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &pol_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &pol_sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; - - DEBUG(10,("_samr_query_sec_obj: querying security on SID: %s\n", sid_to_string(str_sid, &pol_sid))); /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */ /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */ - if (pol_sid.sid_rev_num == 0) - { + if (pol_sid.sid_rev_num == 0) { DEBUG(5,("_samr_query_sec_obj: querying security on SAM\n")); r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0); - } - else if (sid_equal(&pol_sid,get_global_sam_sid())) /* check if it is our domain SID */ - - { + } else if (sid_equal(&pol_sid,get_global_sam_sid())) { + /* check if it is our domain SID */ DEBUG(5,("_samr_query_sec_obj: querying security on Domain with SID: %s\n", sid_to_string(str_sid, &pol_sid))); r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0); - } - else if (sid_equal(&pol_sid,&global_sid_Builtin)) /* check if it is the Builtin Domain */ - { + } else if (sid_equal(&pol_sid,&global_sid_Builtin)) { + /* check if it is the Builtin Domain */ /* TODO: Builtin probably needs a different SD with restricted write access*/ DEBUG(5,("_samr_query_sec_obj: querying security on Builtin Domain with SID: %s\n", sid_to_string(str_sid, &pol_sid))); r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0); - } - else if (sid_check_is_in_our_domain(&pol_sid) || - sid_check_is_in_builtin(&pol_sid)) - { + } else if (sid_check_is_in_our_domain(&pol_sid) || + sid_check_is_in_builtin(&pol_sid)) { /* TODO: different SDs have to be generated for aliases groups and users. Currently all three get a default user SD */ DEBUG(10,("_samr_query_sec_obj: querying security on Object with SID: %s\n", sid_to_string(str_sid, &pol_sid))); r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &pol_sid, SAMR_USR_RIGHTS_WRITE_PW); + } else { + return NT_STATUS_OBJECT_TYPE_MISMATCH; } - else return NT_STATUS_OBJECT_TYPE_MISMATCH; if ((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL) return NT_STATUS_NO_MEMORY; @@ -594,21 +749,32 @@ NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__)); become_root(); - if ((info->disp_info.enum_users != NULL) && - (info->disp_info.enum_acb_mask != q_u->acb_mask)) { - pdb_search_destroy(info->disp_info.enum_users); - info->disp_info.enum_users = NULL; + + /* AS ROOT !!!! */ + + if ((info->disp_info->enum_users != NULL) && + (info->disp_info->enum_acb_mask != q_u->acb_mask)) { + pdb_search_destroy(info->disp_info->enum_users); + info->disp_info->enum_users = NULL; } - if (info->disp_info.enum_users == NULL) { - info->disp_info.enum_users = pdb_search_users(q_u->acb_mask); - info->disp_info.enum_acb_mask = q_u->acb_mask; + if (info->disp_info->enum_users == NULL) { + info->disp_info->enum_users = pdb_search_users(q_u->acb_mask); + info->disp_info->enum_acb_mask = q_u->acb_mask; } - if (info->disp_info.enum_users == NULL) + + if (info->disp_info->enum_users == NULL) { + /* END AS ROOT !!!! */ + unbecome_root(); return NT_STATUS_ACCESS_DENIED; - num_account = pdb_search_entries(info->disp_info.enum_users, + } + + num_account = pdb_search_entries(info->disp_info->enum_users, enum_context, max_entries, &entries); + + /* END AS ROOT !!!! */ + unbecome_root(); if (num_account == 0) { @@ -625,8 +791,13 @@ NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, if (!NT_STATUS_IS_OK(r_u->status)) return r_u->status; - if (max_entries <= num_account) + if (max_entries <= num_account) { + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); r_u->status = STATUS_MORE_ENTRIES; + } else { + clear_disp_info_cache_timeout(info->disp_info); + } DEBUG(5, ("_samr_enum_dom_users: %d\n", __LINE__)); @@ -705,18 +876,23 @@ NTSTATUS _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAM /* the domain group array is being allocated in the function below */ become_root(); - if (info->disp_info.groups == NULL) - info->disp_info.groups = pdb_search_groups(); - unbecome_root(); - if (info->disp_info.groups == NULL) - return NT_STATUS_ACCESS_DENIED; + if (info->disp_info->groups == NULL) { + info->disp_info->groups = pdb_search_groups(); - become_root(); - num_groups = pdb_search_entries(info->disp_info.groups, q_u->start_idx, + if (info->disp_info->groups == NULL) { + unbecome_root(); + return NT_STATUS_ACCESS_DENIED; + } + } + + num_groups = pdb_search_entries(info->disp_info->groups, q_u->start_idx, MAX_SAM_ENTRIES, &groups); unbecome_root(); + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); + make_group_sam_entry_list(p->mem_ctx, &r_u->sam, &r_u->uni_grp_name, num_groups, groups); @@ -752,26 +928,30 @@ NTSTATUS _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, S sid_string_static(&info->sid))); if (sid_check_is_domain(&info->sid)) - search = &info->disp_info.aliases; + search = &info->disp_info->aliases; if (sid_check_is_builtin(&info->sid)) - search = &info->disp_info.builtins; + search = &info->disp_info->builtins; if (search == NULL) return NT_STATUS_INVALID_HANDLE; become_root(); - if (*search == NULL) - *search = pdb_search_aliases(&info->sid); - unbecome_root(); - if (*search == NULL) - return NT_STATUS_ACCESS_DENIED; + if (*search == NULL) { + *search = pdb_search_aliases(&info->sid); + if (*search == NULL) { + unbecome_root(); + return NT_STATUS_ACCESS_DENIED; + } + } - become_root(); num_aliases = pdb_search_entries(*search, q_u->start_idx, MAX_SAM_ENTRIES, &aliases); unbecome_root(); + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); + make_group_sam_entry_list(p->mem_ctx, &r_u->sam, &r_u->uni_grp_name, num_aliases, aliases); @@ -872,38 +1052,68 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, become_root(); + /* THe following done as ROOT. Don't return without unbecome_root(). */ + switch (q_u->switch_level) { case 0x1: case 0x4: - if (info->disp_info.users == NULL) - info->disp_info.users = pdb_search_users(ACB_NORMAL); - if (info->disp_info.users == NULL) - return NT_STATUS_ACCESS_DENIED; - num_account = pdb_search_entries(info->disp_info.users, + if (info->disp_info->users == NULL) { + info->disp_info->users = pdb_search_users(ACB_NORMAL); + if (info->disp_info->users == NULL) { + unbecome_root(); + return NT_STATUS_ACCESS_DENIED; + } + DEBUG(10,("samr_reply_query_dispinfo: starting user enumeration at index %u\n", + (unsigned int)enum_context )); + } else { + DEBUG(10,("samr_reply_query_dispinfo: using cached user enumeration at index %u\n", + (unsigned int)enum_context )); + } + + num_account = pdb_search_entries(info->disp_info->users, enum_context, max_entries, &entries); break; case 0x2: - if (info->disp_info.machines == NULL) - info->disp_info.machines = + if (info->disp_info->machines == NULL) { + info->disp_info->machines = pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST); - if (info->disp_info.machines == NULL) - return NT_STATUS_ACCESS_DENIED; - num_account = pdb_search_entries(info->disp_info.machines, + if (info->disp_info->machines == NULL) { + unbecome_root(); + return NT_STATUS_ACCESS_DENIED; + } + DEBUG(10,("samr_reply_query_dispinfo: starting machine enumeration at index %u\n", + (unsigned int)enum_context )); + } else { + DEBUG(10,("samr_reply_query_dispinfo: using cached machine enumeration at index %u\n", + (unsigned int)enum_context )); + } + + num_account = pdb_search_entries(info->disp_info->machines, enum_context, max_entries, &entries); break; case 0x3: case 0x5: - if (info->disp_info.groups == NULL) - info->disp_info.groups = pdb_search_groups(); - if (info->disp_info.groups == NULL) - return NT_STATUS_ACCESS_DENIED; - num_account = pdb_search_entries(info->disp_info.groups, + if (info->disp_info->groups == NULL) { + info->disp_info->groups = pdb_search_groups(); + if (info->disp_info->groups == NULL) { + unbecome_root(); + return NT_STATUS_ACCESS_DENIED; + } + DEBUG(10,("samr_reply_query_dispinfo: starting group enumeration at index %u\n", + (unsigned int)enum_context )); + } else { + DEBUG(10,("samr_reply_query_dispinfo: using cached group enumeration at index %u\n", + (unsigned int)enum_context )); + } + + num_account = pdb_search_entries(info->disp_info->groups, enum_context, max_entries, &entries); break; default: + unbecome_root(); smb_panic("info class changed"); break; } @@ -947,10 +1157,14 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, /* calculate the total size */ total_data_size=num_account*struct_size; - if (num_account) + if (num_account) { + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); r_u->status = STATUS_MORE_ENTRIES; - else + } else { + clear_disp_info_cache_timeout(info->disp_info); r_u->status = NT_STATUS_OK; + } DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__)); @@ -978,7 +1192,7 @@ NTSTATUS _samr_query_aliasinfo(pipes_struct *p, SAMR_Q_QUERY_ALIASINFO *q_u, SAM DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_LOOKUP_INFO, "_samr_query_aliasinfo"))) { return r_u->status; @@ -1096,7 +1310,7 @@ NTSTATUS _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LO ZERO_ARRAY(rid); ZERO_ARRAY(type); - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted)) { + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted, NULL)) { init_samr_r_lookup_names(p->mem_ctx, r_u, 0, NULL, NULL, NT_STATUS_OBJECT_TYPE_MISMATCH); return r_u->status; } @@ -1255,7 +1469,7 @@ NTSTATUS _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOK DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (num_rids > 1000) { @@ -1317,7 +1531,7 @@ NTSTATUS _samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USE /* find the domain policy handle and get domain SID / access bits in the domain policy. */ - if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted) ) + if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) ) return NT_STATUS_INVALID_HANDLE; nt_status = access_check_samr_function( acc_granted, @@ -1712,7 +1926,7 @@ NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, S DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_USER_GET_GROUPS, "_samr_query_usergroups"))) { @@ -1858,9 +2072,9 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA /* AS ROOT !!! */ - num_users=count_sam_users(&info->disp_info, + num_users=count_sam_users(info->disp_info, ACB_NORMAL); - num_groups=count_sam_groups(&info->disp_info); + num_groups=count_sam_groups(info->disp_info); pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp); u_logout = account_policy_temp; @@ -1993,9 +2207,10 @@ NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREA uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS; BOOL can_add_account = False; SE_PRIV se_rights; + DISP_INFO *disp_info = NULL; /* Get the domain SID stored in the domain policy */ - if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(nt_status = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_USER, "_samr_create_user"))) { @@ -2141,6 +2356,9 @@ NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREA return NT_STATUS_OBJECT_NAME_NOT_FOUND; } + /* After a "set" ensure we have no cached display info. */ + force_flush_samr_cache(info->disp_info); + r_u->user_rid=pdb_get_user_rid(sam_pass); r_u->access_granted = acc_granted; @@ -2478,7 +2696,7 @@ NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_A /* find the domain policy and get the SID / access bits stored in the domain policy */ - if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted) ) + if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) ) return NT_STATUS_INVALID_HANDLE; status = access_check_samr_function(acc_granted, @@ -2873,13 +3091,14 @@ NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SE BOOL ret; BOOL has_enough_rights = False; uint32 acb_info; + DISP_INFO *disp_info = NULL; DEBUG(5, ("_samr_set_userinfo: %d\n", __LINE__)); r_u->status = NT_STATUS_OK; /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; /* observed when joining an XP client to a Samba domain */ @@ -2995,6 +3214,10 @@ NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SE /* ================ END SeMachineAccountPrivilege BLOCK ================ */ + if (NT_STATUS_IS_OK(r_u->status)) { + force_flush_samr_cache(disp_info); + } + return r_u->status; } @@ -3014,13 +3237,14 @@ NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_ BOOL ret; BOOL has_enough_rights = False; uint32 acb_info; + DISP_INFO *disp_info = NULL; DEBUG(5, ("samr_reply_set_userinfo2: %d\n", __LINE__)); r_u->status = NT_STATUS_OK; /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; /* observed when joining XP client to Samba domain */ @@ -3101,6 +3325,10 @@ NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_ /* ================ END SeMachineAccountPrivilege BLOCK ================ */ + if (NT_STATUS_IS_OK(r_u->status)) { + force_flush_samr_cache(disp_info); + } + return r_u->status; } @@ -3184,7 +3412,7 @@ NTSTATUS _samr_query_aliasmem(pipes_struct *p, SAMR_Q_QUERY_ALIASMEM *q_u, SAMR_ uint32 acc_granted; /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = @@ -3296,7 +3524,7 @@ NTSTATUS _samr_query_groupmem(pipes_struct *p, SAMR_Q_QUERY_GROUPMEM *q_u, SAMR_ NTSTATUS result; /* find the policy handle. open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->group_pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->group_pol, &group_sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_GET_MEMBERS, "_samr_query_groupmem"))) { @@ -3345,10 +3573,10 @@ NTSTATUS _samr_add_aliasmem(pipes_struct *p, SAMR_Q_ADD_ALIASMEM *q_u, SAMR_R_AD SE_PRIV se_rights; BOOL can_add_accounts; BOOL ret; - + DISP_INFO *disp_info = NULL; /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_ADD_MEMBER, "_samr_add_aliasmem"))) { @@ -3372,6 +3600,10 @@ NTSTATUS _samr_add_aliasmem(pipes_struct *p, SAMR_Q_ADD_ALIASMEM *q_u, SAMR_R_AD /******** END SeAddUsers BLOCK *********/ + if (ret) { + force_flush_samr_cache(disp_info); + } + return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED; } @@ -3386,9 +3618,10 @@ NTSTATUS _samr_del_aliasmem(pipes_struct *p, SAMR_Q_DEL_ALIASMEM *q_u, SAMR_R_DE SE_PRIV se_rights; BOOL can_add_accounts; BOOL ret; + DISP_INFO *disp_info = NULL; /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_REMOVE_MEMBER, "_samr_del_aliasmem"))) { @@ -3413,6 +3646,10 @@ NTSTATUS _samr_del_aliasmem(pipes_struct *p, SAMR_Q_DEL_ALIASMEM *q_u, SAMR_R_DE /******** END SeAddUsers BLOCK *********/ + if (ret) { + force_flush_samr_cache(disp_info); + } + return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED; } @@ -3436,9 +3673,10 @@ NTSTATUS _samr_add_groupmem(pipes_struct *p, SAMR_Q_ADD_GROUPMEM *q_u, SAMR_R_AD uint32 acc_granted; SE_PRIV se_rights; BOOL can_add_accounts; + DISP_INFO *disp_info = NULL; /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_ADD_MEMBER, "_samr_add_groupmem"))) { @@ -3524,6 +3762,9 @@ NTSTATUS _samr_add_groupmem(pipes_struct *p, SAMR_Q_ADD_GROUPMEM *q_u, SAMR_R_AD } passwd_free(&pwd); + + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3542,6 +3783,7 @@ NTSTATUS _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DE uint32 acc_granted; SE_PRIV se_rights; BOOL can_add_accounts; + DISP_INFO *disp_info = NULL; /* * delete the group member named q_u->rid @@ -3550,7 +3792,7 @@ NTSTATUS _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DE */ /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_REMOVE_MEMBER, "_samr_del_groupmem"))) { @@ -3609,6 +3851,9 @@ NTSTATUS _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DE } pdb_free_sam(&sam_pass); + + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3644,11 +3889,12 @@ NTSTATUS _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAM uint32 acc_granted; BOOL can_add_accounts; BOOL ret; + DISP_INFO *disp_info = NULL; DEBUG(5, ("_samr_delete_dom_user: %d\n", __LINE__)); /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &user_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &user_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_delete_dom_user"))) { @@ -3705,6 +3951,8 @@ NTSTATUS _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAM if (!close_policy_hnd(p, &q_u->user_pol)) return NT_STATUS_OBJECT_NAME_INVALID; + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3725,11 +3973,12 @@ NTSTATUS _samr_delete_dom_group(pipes_struct *p, SAMR_Q_DELETE_DOM_GROUP *q_u, S SE_PRIV se_rights; BOOL can_add_accounts; BOOL ret; + DISP_INFO *disp_info = NULL; DEBUG(5, ("samr_delete_dom_group: %d\n", __LINE__)); /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->group_pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->group_pol, &group_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_delete_dom_group"))) { @@ -3788,6 +4037,8 @@ NTSTATUS _samr_delete_dom_group(pipes_struct *p, SAMR_Q_DELETE_DOM_GROUP *q_u, S if (!close_policy_hnd(p, &q_u->group_pol)) return NT_STATUS_OBJECT_NAME_INVALID; + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3802,11 +4053,12 @@ NTSTATUS _samr_delete_dom_alias(pipes_struct *p, SAMR_Q_DELETE_DOM_ALIAS *q_u, S SE_PRIV se_rights; BOOL can_add_accounts; BOOL ret; + DISP_INFO *disp_info = NULL; DEBUG(5, ("_samr_delete_dom_alias: %d\n", __LINE__)); /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_delete_dom_alias"))) { @@ -3842,6 +4094,8 @@ NTSTATUS _samr_delete_dom_alias(pipes_struct *p, SAMR_Q_DELETE_DOM_ALIAS *q_u, S if (!close_policy_hnd(p, &q_u->alias_pol)) return NT_STATUS_OBJECT_NAME_INVALID; + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3862,9 +4116,10 @@ NTSTATUS _samr_create_dom_group(pipes_struct *p, SAMR_Q_CREATE_DOM_GROUP *q_u, S SE_PRIV se_rights; BOOL can_add_accounts; NTSTATUS result; + DISP_INFO *disp_info = NULL; /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &dom_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &dom_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_GROUP, "_samr_create_dom_group"))) { @@ -3933,6 +4188,8 @@ NTSTATUS _samr_create_dom_group(pipes_struct *p, SAMR_Q_CREATE_DOM_GROUP *q_u, S if (!create_policy_hnd(p, &r_u->pol, free_samr_info, (void *)info)) return NT_STATUS_OBJECT_NAME_NOT_FOUND; + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -3951,9 +4208,10 @@ NTSTATUS _samr_create_dom_alias(pipes_struct *p, SAMR_Q_CREATE_DOM_ALIAS *q_u, S NTSTATUS result; SE_PRIV se_rights; BOOL can_add_accounts; + DISP_INFO *disp_info = NULL; /* Find the policy handle. Open a policy on it. */ - if (!get_lsa_policy_samr_sid(p, &q_u->dom_pol, &dom_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->dom_pol, &dom_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_ALIAS, "_samr_create_alias"))) { @@ -4005,6 +4263,8 @@ NTSTATUS _samr_create_dom_alias(pipes_struct *p, SAMR_Q_CREATE_DOM_ALIAS *q_u, S if (!create_policy_hnd(p, &r_u->alias_pol, free_samr_info, (void *)info)) return NT_STATUS_OBJECT_NAME_NOT_FOUND; + force_flush_samr_cache(disp_info); + return NT_STATUS_OK; } @@ -4026,7 +4286,7 @@ NTSTATUS _samr_query_groupinfo(pipes_struct *p, SAMR_Q_QUERY_GROUPINFO *q_u, SAM uint32 acc_granted; BOOL ret; - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_LOOKUP_INFO, "_samr_query_groupinfo"))) { @@ -4083,8 +4343,9 @@ NTSTATUS _samr_set_groupinfo(pipes_struct *p, SAMR_Q_SET_GROUPINFO *q_u, SAMR_R_ uint32 acc_granted; BOOL ret; BOOL can_mod_accounts; + DISP_INFO *disp_info = NULL; - if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_SET_INFO, "_samr_set_groupinfo"))) { @@ -4121,6 +4382,10 @@ NTSTATUS _samr_set_groupinfo(pipes_struct *p, SAMR_Q_SET_GROUPINFO *q_u, SAMR_R_ /******** End SeAddUsers BLOCK *********/ + if (ret) { + force_flush_samr_cache(disp_info); + } + return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED; } @@ -4138,8 +4403,9 @@ NTSTATUS _samr_set_aliasinfo(pipes_struct *p, SAMR_Q_SET_ALIASINFO *q_u, SAMR_R_ uint32 acc_granted; BOOL ret; BOOL can_mod_accounts; + DISP_INFO *disp_info = NULL; - if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &group_sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &group_sid, &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_SET_INFO, "_samr_set_aliasinfo"))) { @@ -4174,6 +4440,10 @@ NTSTATUS _samr_set_aliasinfo(pipes_struct *p, SAMR_Q_SET_ALIASINFO *q_u, SAMR_R_ /******** End SeAddUsers BLOCK *********/ + if (ret) { + force_flush_samr_cache(disp_info); + } + return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED; } @@ -4217,7 +4487,7 @@ NTSTATUS _samr_open_group(pipes_struct *p, SAMR_Q_OPEN_GROUP *q_u, SAMR_R_OPEN_G BOOL ret; SE_PRIV se_rights; - if (!get_lsa_policy_samr_sid(p, &q_u->domain_pol, &sid, &acc_granted)) + if (!get_lsa_policy_samr_sid(p, &q_u->domain_pol, &sid, &acc_granted, NULL)) return NT_STATUS_INVALID_HANDLE; status = access_check_samr_function(acc_granted, @@ -4280,7 +4550,8 @@ NTSTATUS _samr_remove_sid_foreign_domain(pipes_struct *p, DOM_SID delete_sid, domain_sid; uint32 acc_granted; NTSTATUS result; - + DISP_INFO *disp_info = NULL; + sid_copy( &delete_sid, &q_u->sid.sid ); DEBUG(5,("_samr_remove_sid_foreign_domain: removing SID [%s]\n", @@ -4289,7 +4560,7 @@ NTSTATUS _samr_remove_sid_foreign_domain(pipes_struct *p, /* Find the policy handle. Open a policy on it. */ if (!get_lsa_policy_samr_sid(p, &q_u->dom_pol, &domain_sid, - &acc_granted)) + &acc_granted, &disp_info)) return NT_STATUS_INVALID_HANDLE; result = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, @@ -4324,6 +4595,7 @@ NTSTATUS _samr_remove_sid_foreign_domain(pipes_struct *p, return NT_STATUS_OK; } + force_flush_samr_cache(disp_info); result = NT_STATUS_OK; @@ -4331,10 +4603,12 @@ NTSTATUS _samr_remove_sid_foreign_domain(pipes_struct *p, } /******************************************************************* - _samr_unknown_2e + _samr_query_domain_info2 ********************************************************************/ -NTSTATUS _samr_unknown_2e(pipes_struct *p, SAMR_Q_UNKNOWN_2E *q_u, SAMR_R_UNKNOWN_2E *r_u) +NTSTATUS _samr_query_domain_info2(pipes_struct *p, + SAMR_Q_QUERY_DOMAIN_INFO2 *q_u, + SAMR_R_QUERY_DOMAIN_INFO2 *r_u) { struct samr_info *info = NULL; SAM_UNK_CTR *ctr; @@ -4363,7 +4637,7 @@ NTSTATUS _samr_unknown_2e(pipes_struct *p, SAMR_Q_UNKNOWN_2E *q_u, SAMR_R_UNKNOW r_u->status = NT_STATUS_OK; - DEBUG(5,("_samr_unknown_2e: %d\n", __LINE__)); + DEBUG(5,("_samr_query_domain_info2: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)&info)) @@ -4394,13 +4668,11 @@ NTSTATUS _samr_unknown_2e(pipes_struct *p, SAMR_Q_UNKNOWN_2E *q_u, SAMR_R_UNKNOW break; case 0x02: become_root(); - num_users = count_sam_users(&info->disp_info, + num_users = count_sam_users(info->disp_info, ACB_NORMAL); - num_groups = count_sam_groups(&info->disp_info); + num_groups = count_sam_groups(info->disp_info); unbecome_root(); - free_samr_db(info); - pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp); u_logout = account_policy_temp; @@ -4464,9 +4736,9 @@ NTSTATUS _samr_unknown_2e(pipes_struct *p, SAMR_Q_UNKNOWN_2E *q_u, SAMR_R_UNKNOW return NT_STATUS_INVALID_INFO_CLASS; } - init_samr_r_samr_unknown_2e(r_u, q_u->switch_value, ctr, NT_STATUS_OK); + init_samr_r_samr_query_domain_info2(r_u, q_u->switch_value, ctr, NT_STATUS_OK); - DEBUG(5,("_samr_unknown_2e: %d\n", __LINE__)); + DEBUG(5,("_samr_query_domain_info2: %d\n", __LINE__)); return r_u->status; } -- cgit From e3762fad8275642ac308572d728f68d52f9969d4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 19 Nov 2005 01:14:05 +0000 Subject: r11799: Added OpenSSH fix for "%.*s" format crash. From Darren Tucker Jeremy. --- source/lib/snprintf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/lib/snprintf.c b/source/lib/snprintf.c index 633517def28..a3e4b06d47f 100644 --- a/source/lib/snprintf.c +++ b/source/lib/snprintf.c @@ -89,6 +89,12 @@ * * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even * if the C library has some snprintf functions already. + * + * Darren Tucker (dtucker@zip.com.au) + * Fix bug allowing read overruns of the source string with "%.*s" + * Usually harmless unless the read runs outside the process' allocation + * (eg if your malloc does guard pages) in which case it will segfault. + * From OpenSSH. Also added test for same. **************************************************************/ #ifndef NO_CONFIG_H @@ -479,7 +485,7 @@ static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, value = ""; } - for (strln = 0; value[strln]; ++strln); /* strlen */ + for (strln = 0; strln < max && value[strln]; ++strln); /* strlen */ padlen = min - strln; if (padlen < 0) padlen = 0; @@ -892,6 +898,7 @@ int smb_snprintf(char *str,size_t count,const char *fmt,...) { char buf1[1024]; char buf2[1024]; + char *buf3; char *fp_fmt[] = { "%1.1f", "%-1.5f", @@ -1001,6 +1008,20 @@ int smb_snprintf(char *str,size_t count,const char *fmt,...) } } +#define BUFSZ 2048 + + if ((buf3 = malloc(BUFSZ)) == NULL) { + fail++; + } else { + num++; + memset(buf3, 'a', BUFSZ); + snprintf(buf1, sizeof(buf1), "%.*s", 1, buf3); + if (strcmp(buf1, "a") != 0) { + printf("length limit buf1 '%s' expected 'a'\n", buf1); + fail++; + } + } + printf ("%d tests failed out of %d.\n", fail, num); printf("seeing how many digits we support\n"); -- cgit From 8bd991a6e13850cdec6b6229092a6ace6bc96890 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 21 Nov 2005 13:00:36 +0000 Subject: r11830: patch from Rashid N. Achilov to add descriptions for some common services --- source/services/services_db.c | 72 ++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/source/services/services_db.c b/source/services/services_db.c index 5c87225f573..c75cb38c48b 100644 --- a/source/services/services_db.c +++ b/source/services/services_db.c @@ -35,43 +35,51 @@ struct service_display_info { }; struct service_display_info builtin_svcs[] = { - { "Spooler", "smbd", "Print Spooler", - "Internal service for spooling files to print devices" }, - { "NETLOGON", "smbd", "Net Logon", - "File service providing access to policy and profile data" }, - { "RemoteRegistry", "smbd", "Remote Registry Service", - "Internal service providing remote access to the Samba registry" }, - { "WINS", "nmbd", "Windows Internet Name Service (WINS)", - "Internal service providing a NetBIOS point-to-point name server" }, + { "Spooler", "smbd", "Print Spooler", "Internal service for spooling files to print devices" }, + { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data" }, + { "RemoteRegistry", "smbd", "Remote Registry Service", "Internal service providing remote access to " + "the Samba registry" }, + { "WINS", "nmbd", "Windows Internet Name Service (WINS)", "Internal service providing a " + "NetBIOS point-to-point name server" }, { NULL, NULL, NULL, NULL } }; struct service_display_info common_unix_svcs[] = { - { "cups", NULL, "Common Unix Printing System", NULL }, - { "postfix", NULL, "Internet Mail Service", NULL }, - { "sendmail", NULL, "Internet Mail Service", NULL }, - { "portmap", NULL, "TCP Port to RPC PortMapper", NULL }, - { "xinetd", NULL, "Internet Meta-Daemon", NULL }, - { "inet", NULL, "Internet Meta-Daemon", NULL }, - { "xntpd", NULL, "Network Time Service", NULL }, - { "ntpd", NULL, "Network Time Service", NULL }, - { "lpd", NULL, "BSD Print Spooler", NULL }, - { "nfsserver", NULL, "Network File Service", NULL }, - { "cron", NULL, "Scheduling Service", NULL }, - { "at", NULL, "Scheduling Service", NULL }, - { "nscd", NULL, "Name Service Cache Daemon", NULL }, - { "slapd", NULL, "LDAP Directory Service", NULL }, - { "ldap", NULL, "LDAP DIrectory Service", NULL }, - { "ypbind", NULL, "NIS Directory Service", NULL }, - { "courier-imap", NULL, "IMAP4 Mail Service", NULL }, - { "courier-pop3", NULL, "POP3 Mail Service", NULL }, - { "named", NULL, "Domain Name Service", NULL }, - { "bind", NULL, "Domain Name Service", NULL }, - { "httpd", NULL, "HTTP Server", NULL }, - { "apache", NULL, "HTTP Server", NULL }, - { "autofs", NULL, "Automounter", NULL }, - { "squid", NULL, "Web Cache Proxy ", NULL }, + { "cups", NULL, "Common Unix Printing System","Provides unified printing support for all operating systems" }, + { "postfix", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, + { "sendmail", NULL, "Internet Mail Service", "Provides support for sending and receiving electonic mail" }, + { "portmap", NULL, "TCP Port to RPC PortMapper",NULL }, + { "xinetd", NULL, "Internet Meta-Daemon", NULL }, + { "inet", NULL, "Internet Meta-Daemon", NULL }, + { "xntpd", NULL, "Network Time Service", NULL }, + { "ntpd", NULL, "Network Time Service", NULL }, + { "lpd", NULL, "BSD Print Spooler", NULL }, + { "nfsserver", NULL, "Network File Service", NULL }, + { "cron", NULL, "Scheduling Service", NULL }, + { "at", NULL, "Scheduling Service", NULL }, + { "nscd", NULL, "Name Service Cache Daemon", NULL }, + { "slapd", NULL, "LDAP Directory Service", NULL }, + { "ldap", NULL, "LDAP DIrectory Service", NULL }, + { "ypbind", NULL, "NIS Directory Service", NULL }, + { "courier-imap", NULL, "IMAP4 Mail Service", NULL }, + { "courier-pop3", NULL, "POP3 Mail Service", NULL }, + { "named", NULL, "Domain Name Service", NULL }, + { "bind", NULL, "Domain Name Service", NULL }, + { "httpd", NULL, "HTTP Server", NULL }, + { "apache", NULL, "HTTP Server", "Provides s highly scalable and flexible web server " + "capable of implementing various protocols incluing " + "but not limited to HTTP" }, + { "autofs", NULL, "Automounter", NULL }, + { "squid", NULL, "Web Cache Proxy ", NULL }, { "perfcountd", NULL, "Performance Monitoring Daemon", NULL }, + { "pgsql", NULL, "PgSQL Database Server", "Provides service for SQL database from Postgresql.org" }, + { "arpwatch", NULL, "ARP Tables watcher", "Provides service for monitoring ARP tables for changes" }, + { "dhcpd", NULL, "DHCP Server", "Provides service for dynamic host configuration and IP assignment" }, + { "nwserv", NULL, "NetWare Server Emulator", "Provides service for emulating Novell NetWare 3.12 server" }, + { "proftpd", NULL, "Professional FTP Server", "Provides high configurable service for FTP connection and " + "file transferring" }, + { "ssh2", NULL, "SSH Secure Shell", "Provides service for secure connection for remote administration" }, + { "sshd", NULL, "SSH Secure Shell", "Provides service for secure connection for remote administration" }, { NULL, NULL, NULL, NULL } }; -- cgit From 0fd4a8969f47ecae788fbcc171723c65eae521db Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 21 Nov 2005 15:52:10 +0000 Subject: r11833: fix build issues in smbget with the Sun compiler. Reported by Richard Bollinger --- source/utils/smbget.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/source/utils/smbget.c b/source/utils/smbget.c index e8069802ca9..eab5e5ac02f 100644 --- a/source/utils/smbget.c +++ b/source/utils/smbget.c @@ -28,6 +28,10 @@ int columns = 0; +static int _resume, _recursive, debuglevel; +static char *outputfile; + + time_t total_start_time = 0; off_t total_bytes = 0; @@ -507,16 +511,13 @@ int readrcfile(const char *name, const struct poptOption long_options[]) int main(int argc, const char **argv) { - int resume = 0, recursive = 0; int c = 0; - int debuglevel = 0; const char *file = NULL; char *rcfile = NULL; - char *outputfile = NULL; struct poptOption long_options[] = { {"guest", 'a', POPT_ARG_NONE, NULL, 'a', "Work as user guest" }, - {"resume", 'r', POPT_ARG_NONE, &resume, 0, "Automatically resume aborted files" }, - {"recursive", 'R', POPT_ARG_NONE, &recursive, 0, "Recursively download files" }, + {"resume", 'r', POPT_ARG_NONE, &_resume, 0, "Automatically resume aborted files" }, + {"recursive", 'R', POPT_ARG_NONE, &_recursive, 0, "Recursively download files" }, {"username", 'u', POPT_ARG_STRING, &username, 'u', "Username to use" }, {"password", 'p', POPT_ARG_STRING, &password, 'p', "Password to use" }, {"workgroup", 'w', POPT_ARG_STRING, &workgroup, 'w', "Workgroup to use (optional)" }, @@ -537,7 +538,8 @@ int main(int argc, const char **argv) /* only read rcfile if it exists */ asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME")); - if(access(rcfile, F_OK) == 0) readrcfile(rcfile, long_options); + if(access(rcfile, F_OK) == 0) + readrcfile(rcfile, long_options); free(rcfile); #ifdef SIGWINCH @@ -559,7 +561,7 @@ int main(int argc, const char **argv) } } - if((send_stdout || outputfile) && recursive) { + if((send_stdout || outputfile) && _recursive) { fprintf(stderr, "The -o or -O and -R options can not be used together.\n"); return 1; } @@ -578,9 +580,11 @@ int main(int argc, const char **argv) total_start_time = time(NULL); - while((file = poptGetArg(pc))) { - if(!recursive) return smb_download_file(file, "", recursive, resume, outputfile); - else return smb_download_dir(file, "", resume); + while ( (file = poptGetArg(pc)) ) { + if (!_recursive) + return smb_download_file(file, "", _recursive, _resume, outputfile); + else + return smb_download_dir(file, "", _resume); } clean_exit(); -- cgit From 03b65e7748daa83ecaf65966d9a9a30d18508d6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Nov 2005 05:21:26 +0000 Subject: r11839: Info level 0x101 is really a protocol NT level. Fix bug #3274 from Guenter Kukkukk Jeremy. --- source/client/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/client.c b/source/client/client.c index 697b4e95698..47a45b8a53b 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -291,7 +291,7 @@ static int do_cd(char *newdir) /* Use a trans2_qpathinfo to test directories for modern servers. Except Win9x doesn't support the qpathinfo_basic() call..... */ - if ( targetcli->protocol >= PROTOCOL_LANMAN2 && !targetcli->win95 ) { + if ( targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95 ) { if ( !cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) { d_printf("cd %s: %s\n", dname, cli_errstr(targetcli)); pstrcpy(cur_dir,saved_dir); -- cgit From 3aeac417535319bed9e7a01860b5dc06ed0c087f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Nov 2005 06:04:00 +0000 Subject: r11841: Fix #3262 from Timur Bakeyev to improve reporting on FreeBSD DOS attribute errors. Jeremy. --- source/lib/system.c | 74 +++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/source/lib/system.c b/source/lib/system.c index fead58faae7..4b91fac13f9 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -1370,6 +1370,8 @@ int sys_dup2(int oldfd, int newfd) support for IRIX and (Net|Free)BSD also. Expand as other systems have them. ****************************************************************************/ +/* Possible error codes are: ENOATTR, ERANGE, ENOTSUP. From stat(2): + EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size) { #if defined(HAVE_GETXATTR) @@ -1385,18 +1387,17 @@ ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t si * the returned value to the size of the buffer, so we have to check * that the buffer is large enough to fit the returned value. */ - retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0); - - if (retval == -1) { - return -1; - } - - if(retval > size) { - errno = ERANGE; - return -1; + if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) { + if(retval > size) { + errno = ERANGE; + return -1; + } + if((retval=extattr_get_file(path, attrnamespace, attrname, value, size)) >= 0) + return retval; } - return extattr_get_file(path, attrnamespace, attrname, value, size); + DEBUG(10,("sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno))); + return -1; #elif defined(HAVE_ATTR_GET) int retval, flags = 0; int valuelength = (int)size; @@ -1424,18 +1425,17 @@ ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t s EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER; const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1; - retval = extattr_get_link(path, attrnamespace, attrname, NULL, 0); - - if (retval == -1) { - return -1; - } - - if(retval > size) { - errno = ERANGE; - return -1; + if((retval=extattr_get_link(path, attrnamespace, attrname, NULL, 0)) >= 0) { + if(retval > size) { + errno = ERANGE; + return -1; + } + if((retval=extattr_get_link(path, attrnamespace, attrname, value, size)) >= 0) + return retval; } - - return extattr_get_link(path, attrnamespace, attrname, value, size); + + DEBUG(10,("sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno))); + return -1; #elif defined(HAVE_ATTR_GET) int retval, flags = ATTR_DONTFOLLOW; int valuelength = (int)size; @@ -1463,18 +1463,17 @@ ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size) EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER; const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1; - retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0); - - if (retval == -1) { - return -1; - } - - if(retval > size) { - errno = ERANGE; - return -1; + if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) { + if(retval > size) { + errno = ERANGE; + return -1; + } + if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0) + return retval; } - - return extattr_get_fd(filedes, attrnamespace, attrname, value, size); + + DEBUG(10,("sys_fgetxattr: extattr_get_fd() failed with: %s\n", strerror(errno))); + return -1; #elif defined(HAVE_ATTR_GETF) int retval, flags = 0; int valuelength = (int)size; @@ -1566,7 +1565,7 @@ static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size errno = ERANGE; return -1; } - /* Shift the results back, so we can prepend prefixes */ + /* Shift results back, so we can prepend prefixes */ buf = memmove(list + len, list, list_size); for(i = 0; i < list_size; i += len + 1) { @@ -1652,6 +1651,8 @@ static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t #endif +/* Possible error codes are: ERANGE, ENOTSUP. From stat(2): + EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ ssize_t sys_listxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LISTXATTR) @@ -1700,6 +1701,8 @@ ssize_t sys_flistxattr (int filedes, char *list, size_t size) #endif } +/* Possible error codes are: ENOATTR, ENOTSUP. From stat(2): + EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ int sys_removexattr (const char *path, const char *name) { #if defined(HAVE_REMOVEXATTR) @@ -1777,6 +1780,8 @@ int sys_fremovexattr (int filedes, const char *name) #define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */ #endif +/* Possible error codes are: EEXIST, ENOATTR, ENOSPC, EDQUOT, ENOTSUP. From + stat(2): EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags) { #if defined(HAVE_SETXATTR) @@ -1796,6 +1801,7 @@ int sys_setxattr (const char *path, const char *name, const void *value, size_t errno = ENOATTR; return -1; } + /* Ignore other errors */ } else { /* CREATE attribute, that already exists */ @@ -1841,6 +1847,7 @@ int sys_lsetxattr (const char *path, const char *name, const void *value, size_t errno = ENOATTR; return -1; } + /* Ignore other errors */ } else { /* CREATE attribute, that already exists */ @@ -1887,6 +1894,7 @@ int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size errno = ENOATTR; return -1; } + /* Ignore other errors */ } else { /* CREATE attribute, that already exists */ -- cgit From c9fa47bb75a5bd3b8fca2f3103366a1e77e5e695 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Nov 2005 06:07:26 +0000 Subject: r11845: Removed error code list as it isn't correct for Linux. Jeremy. --- source/lib/system.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/lib/system.c b/source/lib/system.c index 4b91fac13f9..e9c13e6d079 100644 --- a/source/lib/system.c +++ b/source/lib/system.c @@ -1370,8 +1370,6 @@ int sys_dup2(int oldfd, int newfd) support for IRIX and (Net|Free)BSD also. Expand as other systems have them. ****************************************************************************/ -/* Possible error codes are: ENOATTR, ERANGE, ENOTSUP. From stat(2): - EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size) { #if defined(HAVE_GETXATTR) @@ -1651,8 +1649,6 @@ static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t #endif -/* Possible error codes are: ERANGE, ENOTSUP. From stat(2): - EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ ssize_t sys_listxattr (const char *path, char *list, size_t size) { #if defined(HAVE_LISTXATTR) @@ -1701,8 +1697,6 @@ ssize_t sys_flistxattr (int filedes, char *list, size_t size) #endif } -/* Possible error codes are: ENOATTR, ENOTSUP. From stat(2): - EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ int sys_removexattr (const char *path, const char *name) { #if defined(HAVE_REMOVEXATTR) @@ -1780,8 +1774,6 @@ int sys_fremovexattr (int filedes, const char *name) #define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */ #endif -/* Possible error codes are: EEXIST, ENOATTR, ENOSPC, EDQUOT, ENOTSUP. From - stat(2): EBADF, ENOENT, ENOTDIR, ELOOP, EFAULT, EACCES, ENOMEM, ENAMETOOLONG. */ int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags) { #if defined(HAVE_SETXATTR) -- cgit From 36a460464a9a58eba2325311cdb627d33f8cc21f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 10:22:59 +0000 Subject: r11846: Destroy the TALLOC_CTX on error in the Kerberos session setup and give a more precise inline comment why PAC verification may fail. Guenther --- source/libads/kerberos_verify.c | 6 +++--- source/smbd/sesssetup.c | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/libads/kerberos_verify.c b/source/libads/kerberos_verify.c index f21577d0802..220bf14e32c 100644 --- a/source/libads/kerberos_verify.c +++ b/source/libads/kerberos_verify.c @@ -400,9 +400,9 @@ NTSTATUS ads_verify_ticket(TALLOC_CTX *mem_ctx, file_save("/tmp/ticket.dat", ticket->data, ticket->length); #endif - /* continue when no PAC is retrieved - (like accounts that have the UF_NO_AUTH_DATA_REQUIRED flag set, - or Kerberos tickets encryped using a DES key) - Guenther */ + /* continue when no PAC is retrieved or we couldn't decode the PAC + (like accounts that have the UF_NO_AUTH_DATA_REQUIRED flag set, or + Kerberos tickets encrypted using a DES key) - Guenther */ got_auth_data = get_auth_data_from_tkt(mem_ctx, &auth_data, tkt); if (!got_auth_data) { diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c index 2c967601678..8aa046b85a6 100644 --- a/source/smbd/sesssetup.c +++ b/source/smbd/sesssetup.c @@ -168,6 +168,7 @@ static int reply_spnego_kerberos(connection_struct *conn, return ERROR_NT(NT_STATUS_NO_MEMORY); if (!spnego_parse_krb5_wrap(*secblob, &ticket, tok_id)) { + talloc_destroy(mem_ctx); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -177,6 +178,7 @@ static int reply_spnego_kerberos(connection_struct *conn, if (!NT_STATUS_IS_OK(ret)) { DEBUG(1,("Failed to verify incoming ticket!\n")); + talloc_destroy(mem_ctx); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -188,6 +190,7 @@ static int reply_spnego_kerberos(connection_struct *conn, data_blob_free(&ap_rep); data_blob_free(&session_key); SAFE_FREE(client); + talloc_destroy(mem_ctx); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -206,6 +209,7 @@ static int reply_spnego_kerberos(connection_struct *conn, data_blob_free(&ap_rep); data_blob_free(&session_key); SAFE_FREE(client); + talloc_destroy(mem_ctx); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } } @@ -283,6 +287,7 @@ static int reply_spnego_kerberos(connection_struct *conn, SAFE_FREE(client); data_blob_free(&ap_rep); data_blob_free(&session_key); + talloc_destroy(mem_ctx); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } } @@ -302,6 +307,7 @@ static int reply_spnego_kerberos(connection_struct *conn, data_blob_free(&ap_rep); data_blob_free(&session_key); passwd_free(&pw); + talloc_destroy(mem_ctx); return ERROR_NT(ret); } @@ -314,6 +320,7 @@ static int reply_spnego_kerberos(connection_struct *conn, data_blob_free(&ap_rep); data_blob_free(&session_key); passwd_free(&pw); + talloc_destroy(mem_ctx); return ERROR_NT(ret); } -- cgit From 27b4246f0af43d79400e7e7abf720ffc07edcc8a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 12:45:53 +0000 Subject: r11847: Fix typo. Guenther --- source/passdb/pdb_ldap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 92ef5133258..8a9730c3c8a 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3415,7 +3415,7 @@ static NTSTATUS ldapsam_get_account_policy_from_ldap(struct pdb_methods *methods ldap_get_option(ldap_state->smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,&ld_error); - DEBUG(0, ("ldapsam_get_account_policy_from_ldap: Could not set account policy " + DEBUG(0, ("ldapsam_get_account_policy_from_ldap: Could not get account policy " "for %s, error: %s (%s)\n", ldap_state->domain_dn, ldap_err2string(rc), ld_error?ld_error:"unknown")); SAFE_FREE(ld_error); -- cgit From 568f505caf3d615b9066e4b118ee55513698d83e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 13:33:44 +0000 Subject: r11851: Display correct error string. Guenther --- source/nsswitch/winbindd_pam.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index 4582eced0e5..e683f397b66 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -797,7 +797,7 @@ void winbindd_pam_chauthtok(struct winbindd_cli_state *state) done: state->response.data.auth.nt_status = NT_STATUS_V(result); fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result)); - fstrcpy(state->response.data.auth.error_string, nt_errstr(result)); + fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result)); state->response.data.auth.pam_error = nt_status_to_pam(result); DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2, -- cgit From 1bbe8a2ef49b5c6ef0a75b6394ac3c614a93efcb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 13:58:51 +0000 Subject: r11852: Fill in samr_get_dom_pwinfo based on Samba4. Guenther --- source/include/rpc_samr.h | 14 +++++++++----- source/rpc_client/cli_samr.c | 10 +++++----- source/rpc_parse/parse_samr.c | 8 ++------ source/rpcclient/cmd_samr.c | 27 +++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index eff3cd6d4c3..ae8bb7a2bed 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -1750,14 +1750,18 @@ typedef struct q_samr_get_dom_pwinfo } SAMR_Q_GET_DOM_PWINFO; +#define DOMAIN_PASSWORD_COMPLEX 0x00000001 +#define DOMAIN_PASSWORD_NO_ANON_CHANGE 0x00000002 +#define DOMAIN_PASSWORD_NO_CLEAR_CHANGE 0x00000004 +#define DOMAIN_LOCKOUT_ADMINS 0x00000008 +#define DOMAIN_PASSWORD_STORE_CLEARTEXT 0x00000010 +#define DOMAIN_REFUSE_PASSWORD_CHANGE 0x00000020 + /* SAMR_R_GET_DOM_PWINFO */ typedef struct r_samr_get_dom_pwinfo { - /* - * See Samba4 IDL - */ - uint16 unk_0; - uint32 unk_1; + uint16 min_pwd_length; + uint32 password_properties; NTSTATUS status; } SAMR_R_GET_DOM_PWINFO; diff --git a/source/rpc_client/cli_samr.c b/source/rpc_client/cli_samr.c index d68c72e20c8..047d0a1f956 100644 --- a/source/rpc_client/cli_samr.c +++ b/source/rpc_client/cli_samr.c @@ -1723,7 +1723,7 @@ NTSTATUS rpccli_samr_query_sec_obj(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ /* Get domain password info */ NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, - uint16 *unk_0, uint16 *unk_1) + uint16 *min_pwd_length, uint32 *password_properties) { prs_struct qbuf, rbuf; SAMR_Q_GET_DOM_PWINFO q; @@ -1751,10 +1751,10 @@ NTSTATUS rpccli_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem result = r.status; if (NT_STATUS_IS_OK(result)) { - if (unk_0) - *unk_0 = r.unk_0; - if (unk_1) - *unk_1 = r.unk_1; + if (min_pwd_length) + *min_pwd_length = r.min_pwd_length; + if (password_properties) + *password_properties = r.password_properties; } return result; diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index 817244a2b2c..e0efb72aabb 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -7038,15 +7038,11 @@ BOOL samr_io_r_get_dom_pwinfo(const char *desc, SAMR_R_GET_DOM_PWINFO * r_u, if(!prs_align(ps)) return False; - /* - * see the Samba4 IDL for what these actually are. - */ - - if(!prs_uint16("unk_0", ps, depth, &r_u->unk_0)) + if(!prs_uint16("min_pwd_length", ps, depth, &r_u->min_pwd_length)) return False; if(!prs_align(ps)) return False; - if(!prs_uint32("unk_1", ps, depth, &r_u->unk_1)) + if(!prs_uint32("password_properties", ps, depth, &r_u->password_properties)) return False; if(!prs_ntstatus("status", ps, depth, &r_u->status)) diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 665fe342265..a761ea31634 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -1650,18 +1650,37 @@ static NTSTATUS cmd_samr_get_dom_pwinfo(struct rpc_pipe_client *cli, int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - uint16 unk_0, unk_1; + uint16 min_pwd_length; + uint32 password_properties; if (argc != 1) { printf("Usage: %s\n", argv[0]); return NT_STATUS_OK; } - result = rpccli_samr_get_dom_pwinfo(cli, mem_ctx, &unk_0, &unk_1) ; + result = rpccli_samr_get_dom_pwinfo(cli, mem_ctx, &min_pwd_length, &password_properties) ; if (NT_STATUS_IS_OK(result)) { - printf("unk_0 = 0x%08x\n", unk_0); - printf("unk_1 = 0x%08x\n", unk_1); + printf("min_pwd_length: %d\n", min_pwd_length); + printf("password_properties: 0x%08x\n", password_properties); + + if (password_properties & DOMAIN_PASSWORD_COMPLEX) + printf("\tDOMAIN_PASSWORD_COMPLEX\n"); + + if (password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE) + printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n"); + + if (password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE) + printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n"); + + if (password_properties & DOMAIN_LOCKOUT_ADMINS) + printf("\tDOMAIN_LOCKOUT_ADMINS\n"); + + if (password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT) + printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n"); + + if (password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE) + printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n"); } return result; -- cgit From 515dc74ba81594bd2811be8357de32c6fe4cc697 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:10:49 +0000 Subject: r11853: Add Dsr_GetSiteName (handy for experimenting with GPOs). Guenther --- source/include/rpc_netlogon.h | 15 +++++++++ source/rpc_client/cli_netlogon.c | 41 +++++++++++++++++++++++ source/rpc_parse/parse_net.c | 72 ++++++++++++++++++++++++++++++++++++++++ source/rpcclient/cmd_netlogon.c | 26 +++++++++++++++ 4 files changed, 154 insertions(+) diff --git a/source/include/rpc_netlogon.h b/source/include/rpc_netlogon.h index bc4c41cd1f3..fdf2f08c03c 100644 --- a/source/include/rpc_netlogon.h +++ b/source/include/rpc_netlogon.h @@ -40,6 +40,7 @@ #define NET_TRUST_DOM_LIST 0x13 #define NET_DSR_GETDCNAME 0x14 #define NET_AUTH3 0x1a +#define NET_DSR_GETSITENAME 0x1c /* Secure Channel types. used in NetrServerAuthenticate negotiation */ #define SEC_CHAN_WKSTA 2 @@ -968,4 +969,18 @@ typedef struct net_r_dsr_getdcname { WERROR result; } NET_R_DSR_GETDCNAME; +/* NET_Q_DSR_GESITENAME */ +typedef struct net_q_dsr_getsitename { + uint32 ptr_computer_name; + UNISTR2 uni_computer_name; +} NET_Q_DSR_GETSITENAME; + +/* NET_R_DSR_GETSITENAME */ +typedef struct net_r_dsr_getsitename { + uint32 ptr_site_name; + UNISTR2 uni_site_name; + WERROR result; +} NET_R_DSR_GETSITENAME; + + #endif /* _RPC_NETLOGON_H */ diff --git a/source/rpc_client/cli_netlogon.c b/source/rpc_client/cli_netlogon.c index f12f7d09fa7..e3cc97cdc6b 100644 --- a/source/rpc_client/cli_netlogon.c +++ b/source/rpc_client/cli_netlogon.c @@ -539,6 +539,47 @@ WERROR rpccli_netlogon_dsr_getdcname(struct rpc_pipe_client *cli, return WERR_OK; } +/* Dsr_GetSiteName */ + +WERROR rpccli_netlogon_dsr_getsitename(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const char *computer_name, + char **site_name) +{ + prs_struct qbuf, rbuf; + NET_Q_DSR_GETSITENAME q; + NET_R_DSR_GETSITENAME r; + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + /* Initialize input parameters */ + + init_net_q_dsr_getsitename(&q, computer_name); + + /* Marshall data and send request */ + + CLI_DO_RPC_WERR(cli, mem_ctx, PI_NETLOGON, NET_DSR_GETSITENAME, + q, r, + qbuf, rbuf, + net_io_q_dsr_getsitename, + net_io_r_dsr_getsitename, + WERR_GENERAL_FAILURE); + + if (!W_ERROR_IS_OK(r.result)) { + return r.result; + } + + if ((site_name != NULL) && + (rpcstr_pull_unistr2_talloc(mem_ctx, site_name, + &r.uni_site_name) < 1)) { + return WERR_GENERAL_FAILURE; + } + + return WERR_OK; +} + + /* Sam synchronisation */ diff --git a/source/rpc_parse/parse_net.c b/source/rpc_parse/parse_net.c index 3732ab3a725..ce2a085f478 100644 --- a/source/rpc_parse/parse_net.c +++ b/source/rpc_parse/parse_net.c @@ -3389,3 +3389,75 @@ BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t, return True; } + +/******************************************************************* + Inits a NET_Q_DSR_GETSITENAME structure. +********************************************************************/ + +void init_net_q_dsr_getsitename(NET_Q_DSR_GETSITENAME *r_t, const char *computer_name) +{ + DEBUG(5, ("init_net_q_dsr_getsitename\n")); + + r_t->ptr_computer_name = (computer_name != NULL); + init_unistr2(&r_t->uni_computer_name, computer_name, UNI_STR_TERMINATE); +} + +/******************************************************************* + Reads or writes an NET_Q_DSR_GETSITENAME structure. +********************************************************************/ + +BOOL net_io_q_dsr_getsitename(const char *desc, NET_Q_DSR_GETSITENAME *r_t, + prs_struct *ps, int depth) +{ + if (r_t == NULL) + return False; + + prs_debug(ps, depth, desc, "net_io_q_dsr_getsitename"); + depth++; + + if (!prs_uint32("ptr_computer_name", ps, depth, &r_t->ptr_computer_name)) + return False; + + if (!smb_io_unistr2("computer_name", &r_t->uni_computer_name, + r_t->ptr_computer_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + return True; +} + +/******************************************************************* + Reads or writes an NET_R_DSR_GETSITENAME structure. +********************************************************************/ + +BOOL net_io_r_dsr_getsitename(const char *desc, NET_R_DSR_GETSITENAME *r_t, + prs_struct *ps, int depth) +{ + if (r_t == NULL) + return False; + + prs_debug(ps, depth, desc, "net_io_r_dsr_getsitename"); + depth++; + + if (!prs_uint32("ptr_site_name", ps, depth, &r_t->ptr_site_name)) + return False; + + if (!prs_align(ps)) + return False; + + if (!smb_io_unistr2("site_name", &r_t->uni_site_name, + r_t->ptr_site_name, ps, depth)) + return False; + + if (!prs_align(ps)) + return False; + + if (!prs_werror("result", ps, depth, &r_t->result)) + return False; + + return True; +} + + diff --git a/source/rpcclient/cmd_netlogon.c b/source/rpcclient/cmd_netlogon.c index 20f11bc3c93..9377f8fde8c 100644 --- a/source/rpcclient/cmd_netlogon.c +++ b/source/rpcclient/cmd_netlogon.c @@ -99,6 +99,31 @@ static WERROR cmd_netlogon_dsr_getdcname(struct rpc_pipe_client *cli, return result; } +static WERROR cmd_netlogon_dsr_getsitename(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, int argc, + const char **argv) +{ + WERROR result; + char *sitename; + + if (argc != 2) { + fprintf(stderr, "Usage: %s computername\n", argv[0]); + return WERR_OK; + } + + result = rpccli_netlogon_dsr_getsitename(cli, mem_ctx, argv[1], &sitename); + + if (!W_ERROR_IS_OK(result)) { + printf("rpccli_netlogon_dsr_gesitename returned %s\n", + nt_errstr(werror_to_ntstatus(result))); + return result; + } + + printf("Computer %s is on Site: %s\n", argv[1], sitename); + + return WERR_OK; +} + static NTSTATUS cmd_netlogon_logon_ctrl(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, int argc, const char **argv) @@ -347,6 +372,7 @@ struct cmd_set netlogon_commands[] = { { "logonctrl2", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl2, NULL, PI_NETLOGON, NULL, "Logon Control 2", "" }, { "getdcname", RPC_RTYPE_NTSTATUS, cmd_netlogon_getdcname, NULL, PI_NETLOGON, NULL, "Get trusted DC name", "" }, { "dsr_getdcname", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getdcname, PI_NETLOGON, NULL, "Get trusted DC name", "" }, + { "dsr_getsitename", RPC_RTYPE_WERROR, NULL, cmd_netlogon_dsr_getsitename, PI_NETLOGON, NULL, "Get sitename", "" }, { "logonctrl", RPC_RTYPE_NTSTATUS, cmd_netlogon_logon_ctrl, NULL, PI_NETLOGON, NULL, "Logon Control", "" }, { "samsync", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_sync, NULL, PI_NETLOGON, NULL, "Sam Synchronisation", "" }, { "samdeltas", RPC_RTYPE_NTSTATUS, cmd_netlogon_sam_deltas, NULL, PI_NETLOGON, NULL, "Query Sam Deltas", "" }, -- cgit From ae677715dc736601e40d7b60b015a7b0744e0000 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:13:56 +0000 Subject: r11854: Remove unused DOM_SID. Guenther --- source/rpc_client/cli_lsarpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_client/cli_lsarpc.c b/source/rpc_client/cli_lsarpc.c index c64de2b8e88..aa1cb95fda1 100644 --- a/source/rpc_client/cli_lsarpc.c +++ b/source/rpc_client/cli_lsarpc.c @@ -1264,7 +1264,7 @@ NTSTATUS rpccli_lsa_open_trusted_domain(struct rpc_pipe_client *cli, TALLOC_CTX NTSTATUS rpccli_lsa_query_trusted_domain_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, - uint16 info_class, DOM_SID *dom_sid, + uint16 info_class, LSA_TRUSTED_DOMAIN_INFO **info) { prs_struct qbuf, rbuf; -- cgit From 60203f23bd7ae622e75327b9b2d9282f03766d01 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 14:20:02 +0000 Subject: r11855: patch from Aruna Prabakar for checking that the spooler si running on HP-UX --- source/printing/print_svid.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/source/printing/print_svid.c b/source/printing/print_svid.c index 1213b917342..c369e52cd91 100644 --- a/source/printing/print_svid.c +++ b/source/printing/print_svid.c @@ -40,10 +40,39 @@ BOOL sysv_cache_reload(void) char **lines; int i; +#if defined(HPUX) + DEBUG(5, ("reloading hpux printcap cache\n")); +#else DEBUG(5, ("reloading sysv printcap cache\n")); +#endif if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL) + { +#if defined(HPUX) + + /* + * if "lpstat -v" is NULL then we check if schedular is running if it is + * that means no printers are added on the HP-UX system, if schedular is not + * running we display reload error. + */ + + char **scheduler; + scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL); + if(!strcmp(*scheduler,"scheduler is running")){ + DEBUG(3,("No Printers found!!!\n")); + file_lines_free(scheduler); + return True; + } + else{ + DEBUG(3,("Scheduler is not running!!!\n")); + file_lines_free(scheduler); + return False; + } +#else + DEBUG(3,("No Printers found!!!\n")); return False; +#endif + } for (i = 0; lines[i]; i++) { char *name, *tmp; -- cgit From 36c2bbc3c49c5a9ecb5ada0eb25866bb58690dfb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:29:14 +0000 Subject: r11856: Replace unknown1 with group_attr. Can anyone remember why we initialize groups only with 0x03 instead of 0x07 ? Guenther --- source/include/rpc_samr.h | 4 ++-- source/rpc_parse/parse_samr.c | 8 ++++---- source/rpc_server/srv_samr_nt.c | 2 +- source/rpcclient/cmd_samr.c | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index ae8bb7a2bed..ac56e2dcc62 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -1065,7 +1065,7 @@ typedef struct samr_group_info1 { UNIHDR hdr_acct_name; - uint32 unknown_1; /* 0x0000 0003 - number of group members? */ + uint32 group_attr; /* 0x0000 0003 - group attribute */ uint32 num_members; /* 0x0000 0001 - number of group members? */ UNIHDR hdr_acct_desc; @@ -1085,7 +1085,7 @@ typedef struct samr_group_info2 typedef struct samr_group_info3 { - uint32 unknown_1; /* 0x0000 0003 - number of group members? */ + uint32 group_attr; /* 0x0000 0003 - group attribute */ } GROUP_INFO3; diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index e0efb72aabb..ed6abc398b6 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -2141,7 +2141,7 @@ void init_samr_group_info1(GROUP_INFO1 * gr1, { DEBUG(5, ("init_samr_group_info1\n")); - gr1->unknown_1 = 0x3; + gr1->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */ gr1->num_members = num_members; init_unistr2(&gr1->uni_acct_name, acct_name, UNI_FLAGS_NONE); @@ -2174,7 +2174,7 @@ BOOL samr_io_group_info1(const char *desc, GROUP_INFO1 * gr1, if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth)) return False; - if(!prs_uint32("unknown_1", ps, depth, &gr1->unknown_1)) + if(!prs_uint32("group_attr", ps, depth, &gr1->group_attr)) return False; if(!prs_uint32("num_members", ps, depth, &gr1->num_members)) return False; @@ -2238,7 +2238,7 @@ void init_samr_group_info3(GROUP_INFO3 *gr3) { DEBUG(5, ("init_samr_group_info3\n")); - gr3->unknown_1 = 0x3; + gr3->group_attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT); /* why not | SE_GROUP_ENABLED ? */ } /******************************************************************* @@ -2256,7 +2256,7 @@ BOOL samr_io_group_info3(const char *desc, GROUP_INFO3 *gr3, prs_struct *ps, int if(!prs_align(ps)) return False; - if(!prs_uint32("unknown_1", ps, depth, &gr3->unknown_1)) + if(!prs_uint32("group_attr", ps, depth, &gr3->group_attr)) return False; return True; diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 563c3f864f2..34779348a4a 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -1980,7 +1980,7 @@ NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, S continue; gids = TALLOC_REALLOC_ARRAY(p->mem_ctx, gids, DOM_GID, num_gids+1); - gids[num_gids].attr=7; + gids[num_gids].attr= (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_ENABLED); gids[num_gids].g_rid = rid; num_gids += 1; } diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index a761ea31634..7727330388f 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -404,10 +404,19 @@ static void display_group_info1(GROUP_INFO1 *info1) printf("\tGroup Name:\t%s\n", temp); unistr2_to_ascii(temp, &info1->uni_acct_desc, sizeof(temp)-1); printf("\tDescription:\t%s\n", temp); - printf("\tunk1:%d\n", info1->unknown_1); + printf("\tGroup Attribute:%d\n", info1->group_attr); printf("\tNum Members:%d\n", info1->num_members); } +/**************************************************************************** + display group info + ****************************************************************************/ +static void display_group_info3(GROUP_INFO3 *info3) +{ + printf("\tGroup Attribute:%d\n", info3->group_attr); +} + + /**************************************************************************** display group info ****************************************************************************/ @@ -429,6 +438,10 @@ static void display_group_info_ctr(GROUP_INFO_CTR *ctr) display_group_info1(&ctr->group.info1); break; } + case 3: { + display_group_info3(&ctr->group.info3); + break; + } case 4: { display_group_info4(&ctr->group.info4); break; -- cgit From 13d414c46fa00c73ac344fe25ce45e84dff59a3a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:32:29 +0000 Subject: r11857: Fix the build. Guenther --- source/rpcclient/cmd_lsarpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpcclient/cmd_lsarpc.c b/source/rpcclient/cmd_lsarpc.c index 2cc1ffcca0f..5a0ba054833 100644 --- a/source/rpcclient/cmd_lsarpc.c +++ b/source/rpcclient/cmd_lsarpc.c @@ -934,7 +934,7 @@ static NTSTATUS cmd_lsa_query_trustdominfo(struct rpc_pipe_client *cli, goto done; result = rpccli_lsa_query_trusted_domain_info(cli, mem_ctx, &trustdom_pol, - info_class, &dom_sid, &info); + info_class, &info); if (!NT_STATUS_IS_OK(result)) goto done; -- cgit From b556fd3ea74437431f521f0edd262721338b5bac Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:38:49 +0000 Subject: r11858: Fill in the clientside TRUSTED_DOMAIN_INFO_EX query. Guenther --- source/rpc_parse/parse_lsa.c | 42 ++++++++++++++++++++++++++++++++++++++++++ source/rpcclient/cmd_lsarpc.c | 16 +++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/source/rpc_parse/parse_lsa.c b/source/rpc_parse/parse_lsa.c index d924ea27d1f..3d28b657f33 100644 --- a/source/rpc_parse/parse_lsa.c +++ b/source/rpc_parse/parse_lsa.c @@ -3009,6 +3009,44 @@ static BOOL lsa_io_trustdom_query_4(const char *desc, TRUSTED_DOMAIN_INFO_PASSWO /******************************************************************* ********************************************************************/ +static BOOL lsa_io_trustdom_query_6(const char *desc, TRUSTED_DOMAIN_INFO_EX *info_ex, + prs_struct *ps, int depth) +{ + uint32 dom_sid_ptr; + + if (!smb_io_unihdr("domain_name_hdr", &info_ex->domain_name.hdr, ps, depth)) + return False; + + if (!smb_io_unihdr("netbios_name_hdr", &info_ex->netbios_name.hdr, ps, depth)) + return False; + + if (!prs_uint32("dom_sid_ptr", ps, depth, &dom_sid_ptr)) + return False; + + if (!prs_uint32("trust_direction", ps, depth, &info_ex->trust_direction)) + return False; + + if (!prs_uint32("trust_type", ps, depth, &info_ex->trust_type)) + return False; + + if (!prs_uint32("trust_attributes", ps, depth, &info_ex->trust_attributes)) + return False; + + if (!smb_io_unistr2("domain_name_unistring", &info_ex->domain_name.unistring, info_ex->domain_name.hdr.buffer, ps, depth)) + return False; + + if (!smb_io_unistr2("netbios_name_unistring", &info_ex->netbios_name.unistring, info_ex->netbios_name.hdr.buffer, ps, depth)) + return False; + + if (!smb_io_dom_sid2("sid", &info_ex->sid, ps, depth)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + static BOOL lsa_io_trustdom_query(const char *desc, prs_struct *ps, int depth, LSA_TRUSTED_DOMAIN_INFO *info) { prs_debug(ps, depth, desc, "lsa_io_trustdom_query"); @@ -3033,6 +3071,10 @@ static BOOL lsa_io_trustdom_query(const char *desc, prs_struct *ps, int depth, L if(!lsa_io_trustdom_query_4("password", &info->password, ps, depth)) return False; break; + case 6: + if(!lsa_io_trustdom_query_6("info_ex", &info->info_ex, ps, depth)) + return False; + break; default: DEBUG(0,("unsupported info-level: %d\n", info->info_class)); return False; diff --git a/source/rpcclient/cmd_lsarpc.c b/source/rpcclient/cmd_lsarpc.c index 5a0ba054833..c79508de8d0 100644 --- a/source/rpcclient/cmd_lsarpc.c +++ b/source/rpcclient/cmd_lsarpc.c @@ -771,7 +771,7 @@ static void display_trust_dom_info_1(TRUSTED_DOMAIN_INFO_NAME *n) static void display_trust_dom_info_3(TRUSTED_DOMAIN_INFO_POSIX_OFFSET *p) { - printf("Posix Offset:\t%d\n", p->posix_offset); + printf("Posix Offset:\t%08x (%d)\n", p->posix_offset, p->posix_offset); } static void display_trust_dom_info_4(TRUSTED_DOMAIN_INFO_PASSWORD *p, const char *password) @@ -800,6 +800,17 @@ static void display_trust_dom_info_4(TRUSTED_DOMAIN_INFO_PASSWORD *p, const char data_blob_free(&data_old); } +static void display_trust_dom_info_6(TRUSTED_DOMAIN_INFO_EX *i) +{ + printf("Domain Name:\t\t%s\n", unistr2_static(&i->domain_name.unistring)); + printf("NetBIOS Name:\t\t%s\n", unistr2_static(&i->netbios_name.unistring)); + printf("SID:\t\t\t%s\n", sid_string_static(&i->sid.sid)); + printf("Trust Direction:\t0x%08x\n", i->trust_direction); + printf("Trust Type:\t\t0x%08x\n", i->trust_type); + printf("Trust Attributes:\t0x%08x\n", i->trust_attributes); +} + + static void display_trust_dom_info(LSA_TRUSTED_DOMAIN_INFO *info, uint32 info_class, const char *pass) { switch (info_class) { @@ -812,6 +823,9 @@ static void display_trust_dom_info(LSA_TRUSTED_DOMAIN_INFO *info, uint32 info_cl case 4: display_trust_dom_info_4(&info->password, pass); break; + case 6: + display_trust_dom_info_6(&info->info_ex); + break; default: printf("unsupported info-class: %d\n", info_class); break; -- cgit From f78d7d6c59922bbe23f317d9ac9bafe58ca4504e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Nov 2005 14:41:40 +0000 Subject: r11859: Another place where the SE_GROUP constants read better then "7". Guenther --- source/rpc_server/srv_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_server/srv_util.c b/source/rpc_server/srv_util.c index 79d5d06d23a..3666d474787 100644 --- a/source/rpc_server/srv_util.c +++ b/source/rpc_server/srv_util.c @@ -102,7 +102,7 @@ NTSTATUS nt_token_to_group_list(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, for (i=PRIMARY_GROUP_SID_INDEX; i < nt_token->num_sids; i++) { if (sid_compare_domain(domain_sid, &nt_token->user_sids[i])==0) { sid_peek_rid(&nt_token->user_sids[i], &(gids[*numgroups].g_rid)); - gids[*numgroups].attr=7; + gids[*numgroups].attr= (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_ENABLED); (*numgroups)++; } } -- cgit From 81f1af28378f4592c548e31c2e088de08294fa0b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 15:52:22 +0000 Subject: r11860: BUG 3156: don't use find_service() when explicitly looking for a printer as the username map might get in the way --- source/registry/reg_printing.c | 11 ++++++++++- source/rpc_server/srv_spoolss_nt.c | 30 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/source/registry/reg_printing.c b/source/registry/reg_printing.c index b07c8e9644f..592069052f8 100644 --- a/source/registry/reg_printing.c +++ b/source/registry/reg_printing.c @@ -227,7 +227,16 @@ static int key_printers_fetch_keys( const char *key, REGSUBKEY_CTR *subkeys ) reg_split_path( printers_key, &printername, &printerdatakey ); - if ( find_service(printername) == -1 + /* validate the printer name */ + + for (snum=0; snum=n_services || !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) ) { return -1; diff --git a/source/rpc_server/srv_spoolss_nt.c b/source/rpc_server/srv_spoolss_nt.c index e5b3ca3947d..f0ba863b4d7 100644 --- a/source/rpc_server/srv_spoolss_nt.c +++ b/source/rpc_server/srv_spoolss_nt.c @@ -479,29 +479,30 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename) DEBUGADD(5, ("searching for [%s]\n", aprinter )); /* Search all sharenames first as this is easier than pulling - the printer_info_2 off of disk */ + the printer_info_2 off of disk. Don't use find_service() since + that calls out to map_username() */ - snum = find_service(aprinter); - - if ( lp_snum_ok(snum) && lp_print_ok(snum) ) { - found = True; - fstrcpy( sname, aprinter ); - } - /* do another loop to look for printernames */ for (snum=0; !found && snum Date: Tue, 22 Nov 2005 16:21:52 +0000 Subject: r11861: Fix inspired by Thomas Neumann to ensure that default case applies only to new files and correctly examines 8.3 and long names. Jeremy. --- source/smbd/filename.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/source/smbd/filename.c b/source/smbd/filename.c index b389b9c1ae7..2ee8ba1e4ff 100644 --- a/source/smbd/filename.c +++ b/source/smbd/filename.c @@ -150,9 +150,6 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen pstrcpy(saved_last_component, name); } - if (!conn->case_preserve || (mangle_is_8_3(name, False, SNUM(conn)) && !conn->short_case_preserve)) - strnorm(name, lp_defaultcase(SNUM(conn))); - start = name; pstrcpy(orig_path, name); @@ -301,16 +298,17 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen return(False); } - /* + /* * Just the last part of the name doesn't exist. - * We may need to strupper() or strlower() it in case - * this conversion is being used for file creation - * purposes. If the filename is of mixed case then - * don't normalise it. + * We need to strupper() or strlower() it as + * this conversion may be used for file creation + * purposes. Fix inspired by Thomas Neumann . */ - - if (!conn->case_preserve && (!strhasupper(start) || !strhaslower(start))) + if (!conn->case_preserve || + (mangle_is_8_3(start, False, SNUM(conn)) && + !conn->short_case_preserve)) { strnorm(start, lp_defaultcase(SNUM(conn))); + } /* * check on the mangled stack to see if we can recover the -- cgit From a72cdbb11f911095781538563bb20e9dc920ff8b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 17:15:28 +0000 Subject: r11863: BUG 3196: patch from Alex Deiter to compile against the Sun LDAP client libs. But not for AD support; just ldap support --- source/configure.in | 36 +++++++++++++++++++++++++++++++----- source/include/includes.h | 9 +++++++++ source/libads/ldap.c | 8 +++++++- source/passdb/pdb_nds.c | 5 +++++ 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/source/configure.in b/source/configure.in index f31f26f07b5..296673e4b53 100644 --- a/source/configure.in +++ b/source/configure.in @@ -2796,8 +2796,6 @@ if test x"$with_ldap_support" != x"no"; then # now see if we can find the ldap libs in standard paths AC_CHECK_LIB_EXT(ldap, LDAP_LIBS, ldap_init) - AC_CHECK_FUNC_EXT(ldap_domain2hostlist,$LDAP_LIBS) - ######################################################## # If we have LDAP, does it's rebind procedure take 2 or 3 arguments? # Check found in pam_ldap 145. @@ -2816,9 +2814,7 @@ if test x"$with_ldap_support" != x"no"; then AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $smb_ldap_cv_ldap_set_rebind_proc, [Number of arguments to ldap_set_rebind_proc]) - AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS) - - if test x"$ac_cv_lib_ext_ldap_ldap_init" = x"yes" -a x"$ac_cv_func_ext_ldap_domain2hostlist" = x"yes"; then + if test x"$ac_cv_lib_ext_ldap_ldap_init" = x"yes"; then AC_DEFINE(HAVE_LDAP,1,[Whether ldap is available]) CPPFLAGS="$CPPFLAGS -DLDAP_DEPRECATED" default_static_modules="$default_static_modules pdb_ldap idmap_ldap"; @@ -2870,6 +2866,36 @@ if test x"$with_ldap_support" != x"yes"; then with_ads_support=no fi +AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS) + +if test x"$ac_cv_func_ext_ldap_initialize" != x"yes"; then + if test x"$with_ads_support" = x"yes"; then + AC_MSG_ERROR(Active Directory Support requires ldap_initialize) + fi + AC_MSG_WARN(Active Directory Support requires ldap_initialize) + with_ads_support=no +fi + +AC_CHECK_FUNC_EXT(ldap_domain2hostlist,$LDAP_LIBS) + +if test x"$ac_cv_func_ext_ldap_domain2hostlist" != x"yes"; then + if test x"$with_ads_support" = x"yes"; then + AC_MSG_ERROR(Active Directory Support requires ldap_domain2hostlist) + fi + AC_MSG_WARN(Active Directory Support requires ldap_domain2hostlist) + with_ads_support=no +fi + +AC_CHECK_FUNC_EXT(ldap_add_result_entry,$LDAP_LIBS) + +if test x"$ac_cv_func_ext_ldap_add_result_entry" != x"yes"; then + if test x"$with_ads_support" = x"yes"; then + AC_MSG_ERROR(Active Directory Support requires ldap_add_result_entry) + fi + AC_MSG_WARN(Active Directory Support requires ldap_add_result_entry) + with_ads_support=no +fi + if test x"$with_ads_support" != x"no"; then # Do no harm to the values of CFLAGS and LIBS while testing for diff --git a/source/include/includes.h b/source/include/includes.h index 626124523e5..cde199eed8b 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -458,10 +458,19 @@ #if HAVE_LBER_H #include +#ifndef LBER_USE_DER +#define LBER_USE_DER 0x01 +#endif #endif #if HAVE_LDAP_H #include +#ifndef LDAP_CONST +#define LDAP_CONST const +#endif +#ifndef LDAP_OPT_SUCCESS +#define LDAP_OPT_SUCCESS 0 +#endif #else #undef HAVE_LDAP #endif diff --git a/source/libads/ldap.c b/source/libads/ldap.c index bf402b3499e..6d1ca245378 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -577,8 +577,10 @@ ADS_STATUS ads_do_search_all(ADS_STRUCT *ads, const char *bind_path, status = ads_do_paged_search(ads, bind_path, scope, expr, attrs, res, &count, &cookie); - if (!ADS_ERR_OK(status)) return status; + if (!ADS_ERR_OK(status)) + return status; +#ifdef HAVE_LDAP_ADD_RESULT_ENTRY while (cookie) { void *res2 = NULL; ADS_STATUS status2; @@ -598,6 +600,10 @@ ADS_STATUS ads_do_search_all(ADS_STRUCT *ads, const char *bind_path, /* note that we do not free res2, as the memory is now part of the main returned list */ } +#else + DEBUG(0, ("no ldap_add_result_entry() support in LDAP libs!\n")); + status = ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL); +#endif return status; } diff --git a/source/passdb/pdb_nds.c b/source/passdb/pdb_nds.c index 5de80a827fa..13855830867 100644 --- a/source/passdb/pdb_nds.c +++ b/source/passdb/pdb_nds.c @@ -846,12 +846,17 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods, /* Turn on ssl if required */ if(strequal(protocol, "ldaps")) { +#ifdef LDAP_OPT_X_TLS int tls = LDAP_OPT_X_TLS_HARD; if (ldap_set_option (ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) { DEBUG(1, ("pdb_nds_update_login_attempts: Failed to setup a TLS session\n")); } else { DEBUG(4, ("pdb_nds_update_login_attempts: Activated TLS on session\n")); } +#else + DEBUG(0,("pdb_nds_update_login_attempts: Secure connection not supported by LDAP client libraries!\n")); + return NT_STATUS_INVALID_PARAMETER; +#endif } } -- cgit From d1f35d594e9a4e340f110ee1798bcc0979ca05f1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 19:48:33 +0000 Subject: r11864: fix build breakage with solaris LDAP patch (my fault) --- source/utils/net_lookup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/utils/net_lookup.c b/source/utils/net_lookup.c index 3a6781f7621..cd62245600d 100644 --- a/source/utils/net_lookup.c +++ b/source/utils/net_lookup.c @@ -85,7 +85,7 @@ static void print_ldap_srvlist(char *srvlist) static int net_lookup_ldap(int argc, const char **argv) { -#ifdef HAVE_LDAP +#ifdef HAVE_ADS char *srvlist; const char *domain; int rc; @@ -127,7 +127,7 @@ static int net_lookup_ldap(int argc, const char **argv) } return -1; #endif - DEBUG(1,("No LDAP support\n")); + DEBUG(1,("No ADS support\n")); return -1; } -- cgit From e6f874e692b71460153dfb477cc7ec4fd2bb8d68 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 22 Nov 2005 20:26:23 +0000 Subject: r11865: The only way to stop multiple LDAP searches is to agressively cache results. We now cache them for 10 seconds, down from 30 seconds (however each re-use will refresh the idle timeout). Any set calls will flush the cache. Jeremy. --- source/rpc_server/srv_samr_nt.c | 66 ++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 34779348a4a..00c8a9956cc 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -40,7 +40,7 @@ SA_RIGHT_USER_CHANGE_PASSWORD | \ SA_RIGHT_USER_SET_LOC_COM ) -#define DISP_INFO_CACHE_TIMEOUT 30 +#define DISP_INFO_CACHE_TIMEOUT 10 extern rid_name domain_group_rids[]; extern rid_name domain_alias_rids[]; @@ -303,9 +303,9 @@ static struct samr_info *get_samr_info_by_sid(DOM_SID *psid) Function to free the per SID data. ********************************************************************/ -static void free_samr_cache(DISP_INFO *disp_info) +static void free_samr_cache(DISP_INFO *disp_info, const char *sid_str) { - DEBUG(10,("free_samr_cache: deleting cache\n")); + DEBUG(10,("free_samr_cache: deleting cache for SID %s\n", sid_str)); if (disp_info->users) { DEBUG(10,("free_samr_cache: deleting users cache\n")); @@ -352,7 +352,9 @@ static void free_samr_info(void *ptr) a timeout. */ if (info->disp_info && info->disp_info->di_cache_timeout_event == (smb_event_id_t)0) { - free_samr_cache(info->disp_info); + fstring sid_str; + sid_to_string(sid_str, &info->disp_info->sid); + free_samr_cache(info->disp_info, sid_str); } talloc_destroy(info->mem_ctx); @@ -366,16 +368,19 @@ static void disp_info_cache_idle_timeout_handler(void **private_data, time_t *ev_interval, time_t ev_now) { + fstring sid_str; DISP_INFO *disp_info = (DISP_INFO *)(*private_data); - free_samr_cache(disp_info); + sid_to_string(sid_str, &disp_info->sid); + + free_samr_cache(disp_info, sid_str); /* Remove the event. */ smb_unregister_idle_event(disp_info->di_cache_timeout_event); disp_info->di_cache_timeout_event = (smb_event_id_t)0; - DEBUG(10,("disp_info_cache_idle_timeout_handler: caching timed out at %u\n", - (unsigned int)ev_now)); + DEBUG(10,("disp_info_cache_idle_timeout_handler: caching timed out for SID %s at %u\n", + sid_str, (unsigned int)ev_now)); } /******************************************************************* @@ -384,6 +389,10 @@ static void disp_info_cache_idle_timeout_handler(void **private_data, static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow) { + fstring sid_str; + + sid_to_string(sid_str, &disp_info->sid); + /* Remove any pending timeout and update. */ if (disp_info->di_cache_timeout_event) { @@ -391,8 +400,8 @@ static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromno disp_info->di_cache_timeout_event = (smb_event_id_t)0; } - DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for %u seconds\n", - (unsigned int)secs_fromnow )); + DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for SID %s for %u seconds\n", + sid_str, (unsigned int)secs_fromnow )); disp_info->di_cache_timeout_event = smb_register_idle_event(disp_info_cache_idle_timeout_handler, @@ -400,28 +409,24 @@ static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromno secs_fromnow); } -/******************************************************************* - Remove the cache removal idle event handler. - ********************************************************************/ - -static void clear_disp_info_cache_timeout(DISP_INFO *disp_info) -{ - if (disp_info->di_cache_timeout_event) { - smb_unregister_idle_event(disp_info->di_cache_timeout_event); - disp_info->di_cache_timeout_event = (smb_event_id_t)0; - DEBUG(10,("clear_disp_info_cache_timeout: clearing idle event.\n")); - } -} - /******************************************************************* Force flush any cache. We do this on any samr_set_xxx call. + We must also remove the timeout handler. ********************************************************************/ static void force_flush_samr_cache(DISP_INFO *disp_info) { if (disp_info) { - clear_disp_info_cache_timeout(disp_info); - free_samr_cache(disp_info); + fstring sid_str; + + sid_to_string(sid_str, &disp_info->sid); + if (disp_info->di_cache_timeout_event) { + smb_unregister_idle_event(disp_info->di_cache_timeout_event); + disp_info->di_cache_timeout_event = (smb_event_id_t)0; + DEBUG(10,("force_flush_samr_cache: clearing idle event for SID %s\n", + sid_str)); + } + free_samr_cache(disp_info, sid_str); } } @@ -792,13 +797,14 @@ NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, return r_u->status; if (max_entries <= num_account) { - /* Ensure we cache this enumeration. */ - set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); r_u->status = STATUS_MORE_ENTRIES; } else { - clear_disp_info_cache_timeout(info->disp_info); + r_u->status = NT_STATUS_OK; } + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); + DEBUG(5, ("_samr_enum_dom_users: %d\n", __LINE__)); init_samr_r_enum_dom_users(r_u, q_u->start_idx + num_account, @@ -1158,14 +1164,14 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, total_data_size=num_account*struct_size; if (num_account) { - /* Ensure we cache this enumeration. */ - set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); r_u->status = STATUS_MORE_ENTRIES; } else { - clear_disp_info_cache_timeout(info->disp_info); r_u->status = NT_STATUS_OK; } + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT); + DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__)); init_samr_r_query_dispinfo(r_u, num_account, total_data_size, -- cgit From 091a04581d3dcd4ec457becb26c671b0b6e70894 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 22 Nov 2005 20:48:56 +0000 Subject: r11867: attempt at fixing the compile issue with nss_winbind.so on HP-UX caused by Solaris specific return codes --- source/nsswitch/winbind_nss_solaris.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/winbind_nss_solaris.c b/source/nsswitch/winbind_nss_solaris.c index 64b8b734f17..8076c043e04 100644 --- a/source/nsswitch/winbind_nss_solaris.c +++ b/source/nsswitch/winbind_nss_solaris.c @@ -340,6 +340,7 @@ _nss_winbind_group_constr (const char* db_name, /***************************************************************** hosts and ipnodes backend *****************************************************************/ +#if defined(SUNOS5) /* not compatible with HP-UX */ /* this parser is shared between get*byname and get*byaddr, as key type in request is stored in different locations, I had to provide the @@ -627,4 +628,5 @@ _nss_winbind_hosts_constr(dummy1, dummy2, dummy3) sizeof (host_ops) / sizeof (host_ops[0]))); } -#endif /* SUN_NSS */ +#endif /* defined(SUNOS5) */ +#endif /* defined(HAVE_NSS_COMMON_H) || defined(HPUX) */ -- cgit From 373ce92afebc33c825d9d1c4d13864dfffd843ee Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 23 Nov 2005 11:17:04 +0000 Subject: r11874: Merge LDAP connection setup in lib/smbldap.c and pdb_nds.c. Also allow to use START_TLS in the pdb_nds_update_login_attempts function when doing simple binds to eDir. Guenther --- source/lib/smbldap.c | 187 +++++++++++++++++++++++++++++++++++------------- source/passdb/pdb_nds.c | 59 ++------------- 2 files changed, 142 insertions(+), 104 deletions(-) diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index f08a67a22c8..75842ec193e 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -523,24 +523,56 @@ static void smbldap_store_state(LDAP *ld, struct smbldap_state *smbldap_state) t->smbldap_state = smbldap_state; } -/******************************************************************* - open a connection to the ldap server. -******************************************************************/ -static int smbldap_open_connection (struct smbldap_state *ldap_state) +/******************************************************************** + start TLS on an existing LDAP connection +*******************************************************************/ + +int smb_ldap_start_tls(LDAP *ldap_struct, int version) +{ + int rc; + + if (lp_ldap_ssl() != LDAP_SSL_START_TLS) { + return LDAP_SUCCESS; + } + +#ifdef LDAP_OPT_X_TLS + if (version != LDAP_VERSION3) { + DEBUG(0, ("Need LDAPv3 for Start TLS\n")); + return LDAP_OPERATIONS_ERROR; + } + if ((rc = ldap_start_tls_s (ldap_struct, NULL, NULL)) != LDAP_SUCCESS) { + DEBUG(0,("Failed to issue the StartTLS instruction: %s\n", + ldap_err2string(rc))); + return rc; + } + + DEBUG (3, ("StartTLS issued: using a TLS connection\n")); + return LDAP_SUCCESS; +#else + DEBUG(0,("StartTLS not supported by LDAP client libraries!\n")); + return LDAP_OPERATIONS_ERROR; +#endif +} + +/******************************************************************** + setup a connection to the LDAP server based on a uri +*******************************************************************/ + +int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri) { - int rc = LDAP_SUCCESS; - int version; - BOOL ldap_v3 = False; - LDAP **ldap_struct = &ldap_state->ldap_struct; + int rc; + DEBUG(10, ("smb_ldap_setup_connection: %s\n", uri)); + #ifdef HAVE_LDAP_INITIALIZE - DEBUG(10, ("smbldap_open_connection: %s\n", ldap_state->uri)); - if ((rc = ldap_initialize(ldap_struct, ldap_state->uri)) != LDAP_SUCCESS) { + rc = ldap_initialize(ldap_struct, uri); + if (rc) { DEBUG(0, ("ldap_initialize: %s\n", ldap_err2string(rc))); - return rc; } + + return rc; #else /* Parse the string manually */ @@ -549,15 +581,15 @@ static int smbldap_open_connection (struct smbldap_state *ldap_state) int port = 0; fstring protocol; fstring host; - const char *p = ldap_state->uri; SMB_ASSERT(sizeof(protocol)>10 && sizeof(host)>254); - + + /* skip leading "URL:" (if any) */ - if ( strnequal( p, "URL:", 4 ) ) { - p += 4; + if ( strnequal( uri, "URL:", 4 ) ) { + uri += 4; } - sscanf(p, "%10[^:]://%254[^:/]:%d", protocol, host, &port); + sscanf(uri, "%10[^:]://%254[^:/]:%d", protocol, host, &port); if (port == 0) { if (strequal(protocol, "ldap")) { @@ -586,10 +618,88 @@ static int smbldap_open_connection (struct smbldap_state *ldap_state) #else DEBUG(0,("smbldap_open_connection: Secure connection not supported by LDAP client libraries!\n")); return LDAP_OPERATIONS_ERROR; -#endif +#endif /* LDAP_OPT_X_TLS */ } + + } +#endif /* HAVE_LDAP_INITIALIZE */ + return LDAP_SUCCESS; +} + +/******************************************************************** + try to upgrade to Version 3 LDAP if not already, in either case return current + version + *******************************************************************/ + +int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) +{ + int version; + int rc; + + /* assume the worst */ + *new_version = LDAP_VERSION2; + + rc = ldap_get_option(ldap_struct, LDAP_OPT_PROTOCOL_VERSION, &version); + if (rc) { + return rc; + } + + if (version == LDAP_VERSION3) { + *new_version = LDAP_VERSION3; + return LDAP_SUCCESS; + } + + /* try upgrade */ + version = LDAP_VERSION3; + rc = ldap_set_option (ldap_struct, LDAP_OPT_PROTOCOL_VERSION, &version); + if (rc) { + return rc; + } + + *new_version = LDAP_VERSION3; + return LDAP_SUCCESS; +} + +/******************************************************************* + open a connection to the ldap server (just until the bind) + ******************************************************************/ + +int smb_ldap_setup_full_conn(LDAP *ldap_struct, const char *uri) +{ + int rc, version; + + rc = smb_ldap_setup_conn(&ldap_struct, uri); + if (rc) { + return rc; + } + + rc = smb_ldap_upgrade_conn(ldap_struct, &version); + if (rc) { + return rc; + } + + rc = smb_ldap_start_tls(ldap_struct, version); + if (rc) { + return rc; + } + + return LDAP_SUCCESS; +} + +/******************************************************************* + open a connection to the ldap server. +******************************************************************/ +static int smbldap_open_connection (struct smbldap_state *ldap_state) + +{ + int rc = LDAP_SUCCESS; + int version; + LDAP **ldap_struct = &ldap_state->ldap_struct; + + rc = smb_ldap_setup_conn(ldap_struct, ldap_state->uri); + if (rc) { + return rc; } -#endif /* Store the LDAP pointer in a lookup list */ @@ -597,45 +707,22 @@ static int smbldap_open_connection (struct smbldap_state *ldap_state) /* Upgrade to LDAPv3 if possible */ - if (ldap_get_option(*ldap_struct, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) - { - if (version != LDAP_VERSION3) - { - version = LDAP_VERSION3; - if (ldap_set_option (*ldap_struct, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) { - ldap_v3 = True; - } - } else { - ldap_v3 = True; - } + rc = smb_ldap_upgrade_conn(*ldap_struct, &version); + if (rc) { + return rc; } - if (lp_ldap_ssl() == LDAP_SSL_START_TLS) { -#ifdef LDAP_OPT_X_TLS - if (ldap_v3) { - if ((rc = ldap_start_tls_s (*ldap_struct, NULL, NULL)) != LDAP_SUCCESS) - { - DEBUG(0,("Failed to issue the StartTLS instruction: %s\n", - ldap_err2string(rc))); - return rc; - } - DEBUG (3, ("StartTLS issued: using a TLS connection\n")); - } else { - - DEBUG(0, ("Need LDAPv3 for Start TLS\n")); - return LDAP_OPERATIONS_ERROR; - } -#else - DEBUG(0,("smbldap_open_connection: StartTLS not supported by LDAP client libraries!\n")); - return LDAP_OPERATIONS_ERROR; -#endif - } + /* Start TLS if required */ + rc = smb_ldap_start_tls(*ldap_struct, version); + if (rc) { + return rc; + } + DEBUG(2, ("smbldap_open_connection: connection opened\n")); return rc; } - /******************************************************************* a rebind function for authenticated referrals This version takes a void* that we can shove useful stuff in :-) diff --git a/source/passdb/pdb_nds.c b/source/passdb/pdb_nds.c index 13855830867..c6d644827c7 100644 --- a/source/passdb/pdb_nds.c +++ b/source/passdb/pdb_nds.c @@ -762,11 +762,7 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods, const char **attr_list; size_t pwd_len; char clear_text_pw[512]; - const char *p = NULL; LDAP *ld = NULL; - int ldap_port = 0; - char protocol[12]; - char ldap_server[256]; const char *username = pdb_get_username(sam_acct); BOOL got_clear_text_pw = False; @@ -809,58 +805,13 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods, DEBUG(5,("pdb_nds_update_login_attempts: using random password %s\n", clear_text_pw)); } - /* Parse the location string */ - p = ldap_state->location; - - /* skip leading "URL:" (if any) */ - if ( strnequal( p, "URL:", 4 ) ) { - p += 4; - } - - sscanf(p, "%10[^:]://%254[^:/]:%d", protocol, ldap_server, &ldap_port); - - if (ldap_port == 0) { - if (strequal(protocol, "ldap")) { - ldap_port = LDAP_PORT; - } else if (strequal(protocol, "ldaps")) { - ldap_port = LDAPS_PORT; - } else { - DEBUG(0, ("unrecognised protocol (%s)!\n", protocol)); - } - } - - ld = ldap_init(ldap_server, ldap_port); - - if(ld != NULL) { - int version; - - /* LDAP version 3 required for ldap_sasl */ - if (ldap_get_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) { - if (version != LDAP_VERSION3) { - version = LDAP_VERSION3; - if (ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) { - DEBUG(4, ("pdb_nds_update_login_attempts: Set protocol version to LDAP_VERSION3\n")); - } - } - } - - /* Turn on ssl if required */ - if(strequal(protocol, "ldaps")) { -#ifdef LDAP_OPT_X_TLS - int tls = LDAP_OPT_X_TLS_HARD; - if (ldap_set_option (ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) { - DEBUG(1, ("pdb_nds_update_login_attempts: Failed to setup a TLS session\n")); - } else { - DEBUG(4, ("pdb_nds_update_login_attempts: Activated TLS on session\n")); - } -#else - DEBUG(0,("pdb_nds_update_login_attempts: Secure connection not supported by LDAP client libraries!\n")); - return NT_STATUS_INVALID_PARAMETER; -#endif + if((success != True) || (got_clear_text_pw == True)) { + + rc = smb_ldap_setup_full_conn(ld, ldap_state->location); + if (rc) { + return NT_STATUS_INVALID_CONNECTION; } - } - if((success != True) || (got_clear_text_pw == True)) { /* Attempt simple bind with real or bogus password */ rc = ldap_simple_bind_s(ld, dn, clear_text_pw); if (rc == LDAP_SUCCESS) { -- cgit From 39a8e07c3316b4c1af923aad0720dd7ec9be3d26 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 23 Nov 2005 11:21:16 +0000 Subject: r11875: Allow to use START_TLS (by manually setting "ldap ssl = start_tls") for LDAP connections to ADS (Windows 2003). Guenther --- source/libads/ldap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libads/ldap.c b/source/libads/ldap.c index 6d1ca245378..e4cfc456a21 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -292,6 +292,11 @@ got_connection: ldap_set_option(ads->ld, LDAP_OPT_PROTOCOL_VERSION, &version); + status = ADS_ERROR(smb_ldap_start_tls(ads->ld, version)); + if (!ADS_ERR_OK(status)) { + return status; + } + if (!ads->auth.user_name) { /* have to use the userPrincipalName value here and not servicePrincipalName; found by Guenther Deschner @ Sernet */ -- cgit From 57c54f5da5efd44b49a50967c6017e5e6cfb9d79 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 23 Nov 2005 11:29:55 +0000 Subject: r11876: When we are using START_TLS to secure the LDAP connection, we *have* to call START_TLS again after rebinding to another LDAP server. (ldaps:// uri's are handled at by recent versions of OpenLDAP). Guenther --- source/lib/smbldap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index 75842ec193e..a3ebe72df21 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -777,9 +777,18 @@ static int rebindproc_connect_with_state (LDAP *ldap_struct, { struct smbldap_state *ldap_state = arg; int rc; - DEBUG(5,("rebindproc_connect_with_state: Rebinding as \"%s\"\n", - ldap_state->bind_dn)); - + int version; + + DEBUG(5,("rebindproc_connect_with_state: Rebinding to %s as \"%s\"\n", + url, ldap_state->bind_dn)); + + /* call START_TLS again (ldaps:// is handled by the OpenLDAP library + * itself) before rebinding to another LDAP server to avoid to expose + * our credentials. At least *try* to secure the connection - Guenther */ + + smb_ldap_upgrade_conn(ldap_struct, &version); + smb_ldap_start_tls(ldap_struct, version); + /** @TODO Should we be doing something to check what servers we rebind to? Could we get a referral to a machine that we don't want to give our username and password to? */ -- cgit From c9d6f849de012583fefc87ba9a25d0b456557251 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 23 Nov 2005 22:08:57 +0000 Subject: r11886: Fix 3187: logon hours restrictions were off corresponding to our offset from GMT. Use gmtime() instead of localtime() in the calc, but still use localtime() in displaying it. --- source/auth/auth_sam.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/auth/auth_sam.c b/source/auth/auth_sam.c index c92cecdde59..558c181f704 100644 --- a/source/auth/auth_sam.c +++ b/source/auth/auth_sam.c @@ -88,7 +88,7 @@ static BOOL logon_hours_ok(SAM_ACCOUNT *sampass) } lasttime = (time_t)smb_last_time.tv_sec; - utctime = localtime(&lasttime); + utctime = gmtime(&lasttime); /* find the corresponding byte and bit */ bitpos = (utctime->tm_wday * 24 + utctime->tm_hour) % 168; @@ -96,7 +96,8 @@ static BOOL logon_hours_ok(SAM_ACCOUNT *sampass) if (! (hours[bitpos/8] & bitmask)) { DEBUG(1,("logon_hours_ok: Account for user %s not allowed to logon at this time (%s).\n", - pdb_get_username(sampass), asctime(utctime) )); + pdb_get_username(sampass), + asctime(localtime(&lasttime)) )); return False; } -- cgit From 5b967ff1bd7ffb2b5f1a224454c96dc052170eee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Nov 2005 10:19:24 +0000 Subject: r11898: Add a missing become_root(). Volker --- source/rpc_server/srv_samr_nt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 00c8a9956cc..b0472d287a2 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -307,6 +307,11 @@ static void free_samr_cache(DISP_INFO *disp_info, const char *sid_str) { DEBUG(10,("free_samr_cache: deleting cache for SID %s\n", sid_str)); + /* We need to become root here because the paged search might have to + * tell the LDAP server we're not interested in the rest anymore. */ + + become_root(); + if (disp_info->users) { DEBUG(10,("free_samr_cache: deleting users cache\n")); pdb_search_destroy(disp_info->users); @@ -338,6 +343,8 @@ static void free_samr_cache(DISP_INFO *disp_info, const char *sid_str) disp_info->enum_users = NULL; } disp_info->enum_acb_mask = 0; + + unbecome_root(); } /******************************************************************* -- cgit From a7823f7259c9152f2acd1cd3cdab19507b4f34c8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Nov 2005 12:31:40 +0000 Subject: r11909: Implement 'reset on zero vc'. This kills other connections when a session setup comes in with the vc (virtual connection) field set to zero. This is done by Windows, probably you can tweak that by some registry key. This boolean option controls whether an incoming session setup should kill other connections coming from the same IP. This matches the default Windows 2003 behaviour. Setting this parameter to yes becomes necessary when you have a flaky network and windows decides to reconnect while the old connection still has files with share modes open. These files become inaccessible over the new connection. The client sends a zero VC on the new connection, and Windows 2003 kills all other connections coming from the same IP. This way the locked files are accessible again. Please be aware that enabling this option will kill connections behind a masquerading router. Volker --- source/param/loadparm.c | 4 ++++ source/smbd/session.c | 3 ++- source/smbd/sesssetup.c | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index f45d8cf9527..86a5353dca7 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -301,6 +301,7 @@ typedef struct int name_cache_timeout; int client_signing; int server_signing; + BOOL bResetOnZeroVC; param_opt_struct *param_opt; } global; @@ -951,6 +952,7 @@ static struct parm_struct parm_table[] = { {"read raw", P_BOOL, P_GLOBAL, &Globals.bReadRaw, NULL, NULL, FLAG_ADVANCED}, {"write raw", P_BOOL, P_GLOBAL, &Globals.bWriteRaw, NULL, NULL, FLAG_ADVANCED}, {"disable netbios", P_BOOL, P_GLOBAL, &Globals.bDisableNetbios, NULL, NULL, FLAG_ADVANCED}, + {"reset on zero vc", P_BOOL, P_GLOBAL, &Globals.bResetOnZeroVC, NULL, NULL, FLAG_ADVANCED}, {"acl compatibility", P_STRING, P_GLOBAL, &Globals.szAclCompat, handle_acl_compatibility, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, {"defer sharing violations", P_BOOL, P_GLOBAL, &Globals.bDeferSharingViolations, NULL, NULL, FLAG_ADVANCED | FLAG_GLOBAL}, @@ -1522,6 +1524,7 @@ static void init_globals(void) Globals.bUseMmap = True; #endif Globals.bUnixExtensions = True; + Globals.bResetOnZeroVC = False; /* hostname lookups can be very expensive and are broken on a large number of sites (tridge) */ @@ -1809,6 +1812,7 @@ FN_GLOBAL_STRING(lp_delete_share_cmd, &Globals.szDeleteShareCommand) FN_GLOBAL_LIST(lp_eventlog_list, &Globals.szEventLogs) FN_GLOBAL_BOOL(lp_disable_netbios, &Globals.bDisableNetbios) +FN_GLOBAL_BOOL(lp_reset_on_zero_vc, &Globals.bResetOnZeroVC) FN_GLOBAL_BOOL(lp_ms_add_printer_wizard, &Globals.bMsAddPrinterWizard) FN_GLOBAL_BOOL(lp_dns_proxy, &Globals.bDNSproxy) FN_GLOBAL_BOOL(lp_wins_support, &Globals.bWINSsupport) diff --git a/source/smbd/session.c b/source/smbd/session.c index 9a9a0d90b24..27f760a088e 100644 --- a/source/smbd/session.c +++ b/source/smbd/session.c @@ -198,7 +198,8 @@ void session_yield(user_struct *vuser) tdb_delete(tdb, key); } -static BOOL session_traverse(int (*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), void *state) +BOOL session_traverse(int (*fn)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *), + void *state) { if (!session_init()) { DEBUG(3, ("No tdb opened\n")); diff --git a/source/smbd/sesssetup.c b/source/smbd/sesssetup.c index 8aa046b85a6..a22a575c762 100644 --- a/source/smbd/sesssetup.c +++ b/source/smbd/sesssetup.c @@ -744,6 +744,29 @@ static int reply_sesssetup_and_X_spnego(connection_struct *conn, char *inbuf, a new session setup with VC==0 is ignored. ****************************************************************************/ +static int shutdown_other_smbds(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *p) +{ + struct sessionid *sessionid = (struct sessionid *)dbuf.dptr; + const char *ip = (const char *)p; + + if (!process_exists(pid_to_procid(sessionid->pid))) { + return 0; + } + + if (sessionid->pid == sys_getpid()) { + return 0; + } + + if (strcmp(ip, sessionid->ip_addr) != 0) { + return 0; + } + + message_send_pid(pid_to_procid(sessionid->pid), MSG_SHUTDOWN, + NULL, 0, True); + return 0; +} + static void setup_new_vc_session(void) { DEBUG(2,("setup_new_vc_session: New VC == 0, if NT4.x compatible we would close all old resources.\n")); @@ -751,6 +774,9 @@ static void setup_new_vc_session(void) conn_close_all(); invalidate_all_vuids(); #endif + if (lp_reset_on_zero_vc()) { + session_traverse(shutdown_other_smbds, client_addr()); + } } /**************************************************************************** -- cgit From 37029811111f02b03a7d24733324d02db66f60fe Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 09:50:54 +0000 Subject: r11914: After talking to Jeremy, implement passdb:expand_explicit with a default of no. This changes our default behaviour. Sorry, Ingo, this *is* a bug that needs fixing. Jerry, you might want to put a marker into the WHATSNEW.txt when this is due. Volker --- source/passdb/passdb.c | 17 ++++++++++++++--- source/passdb/pdb_ldap.c | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index a7ff3a04f7e..14a5b73f16a 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -1756,6 +1756,8 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) uint32 pwHistLen = 0; BOOL ret = True; fstring tmpstring; + BOOL expand_explicit = lp_parm_bool(-1, "passdb", "expand_explicit", + False); if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); @@ -1820,7 +1822,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (homedir) { fstrcpy( tmpstring, homedir ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_homedir(sampass, tmpstring, PDB_SET); } else { @@ -1836,7 +1841,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (logon_script) { fstrcpy( tmpstring, logon_script ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } else { @@ -1847,7 +1855,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (profile_path) { fstrcpy( tmpstring, profile_path ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } else { diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 8a9730c3c8a..ef9eb81fbbf 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -604,6 +604,8 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, LOGIN_CACHE *cache_entry = NULL; uint32 pwHistLen; pstring tmpstring; + BOOL expand_explicit = lp_parm_bool(-1, "passdb", "expand_explicit", + False); /* * do a little initialization @@ -776,7 +778,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, homedir ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_homedir(sampass, tmpstring, PDB_SET); } @@ -788,7 +793,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, logon_script ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } @@ -800,7 +808,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, profile_path ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } -- cgit From 88e60de59ad720debe1edd809c8ff9b2897376a7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 17:54:24 +0000 Subject: r11915: Remove unused extern declarations --- source/rpc_server/srv_samr_nt.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index b0472d287a2..2bb8078f784 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -42,10 +42,6 @@ #define DISP_INFO_CACHE_TIMEOUT 10 -extern rid_name domain_group_rids[]; -extern rid_name domain_alias_rids[]; -extern rid_name builtin_alias_rids[]; - typedef struct disp_info { struct disp_info *next, *prev; TALLOC_CTX *mem_ctx; -- cgit From 232ebb657679f25d65ae3639a35b8df54c00610a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 18:20:58 +0000 Subject: r11916: auth_get_sam_account is only used in auth_rhosts.c -- move it there --- source/auth/auth_rhosts.c | 30 ++++++++++++++++++++++++++++++ source/auth/auth_util.c | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/auth/auth_rhosts.c b/source/auth/auth_rhosts.c index b295df9328f..b561e3d42be 100644 --- a/source/auth/auth_rhosts.c +++ b/source/auth/auth_rhosts.c @@ -23,6 +23,36 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_AUTH +/**************************************************************************** + Create a SAM_ACCOUNT - either by looking in the pdb, or by faking it up from + unix info. +****************************************************************************/ + +static NTSTATUS auth_get_sam_account(const char *user, SAM_ACCOUNT **account) +{ + BOOL pdb_ret; + NTSTATUS nt_status; + if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(account))) { + return nt_status; + } + + become_root(); + pdb_ret = pdb_getsampwnam(*account, user); + unbecome_root(); + + if (!pdb_ret) { + + struct passwd *pass = Get_Pwnam(user); + if (!pass) + return NT_STATUS_NO_SUCH_USER; + + if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*account, pass))) { + return nt_status; + } + } + return NT_STATUS_OK; +} + /**************************************************************************** Read the a hosts.equiv or .rhosts file and check if it allows this user from this machine. diff --git a/source/auth/auth_util.c b/source/auth/auth_util.c index 6a92c8782e8..61cb7f31cc7 100644 --- a/source/auth/auth_util.c +++ b/source/auth/auth_util.c @@ -50,36 +50,6 @@ static int smb_create_user(const char *domain, const char *unix_username, const return ret; } -/**************************************************************************** - Create a SAM_ACCOUNT - either by looking in the pdb, or by faking it up from - unix info. -****************************************************************************/ - -NTSTATUS auth_get_sam_account(const char *user, SAM_ACCOUNT **account) -{ - BOOL pdb_ret; - NTSTATUS nt_status; - if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(account))) { - return nt_status; - } - - become_root(); - pdb_ret = pdb_getsampwnam(*account, user); - unbecome_root(); - - if (!pdb_ret) { - - struct passwd *pass = Get_Pwnam(user); - if (!pass) - return NT_STATUS_NO_SUCH_USER; - - if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*account, pass))) { - return nt_status; - } - } - return NT_STATUS_OK; -} - /**************************************************************************** Create an auth_usersupplied_data structure ****************************************************************************/ -- cgit From 12e4f54c7e6d78f97fb9eaca7e98987c563b1b82 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 19:17:57 +0000 Subject: r11917: Move nt_token_to_group_list to srv_netlog_nt.c. srv_util.c is empty now. Volker --- source/Makefile.in | 2 +- source/rpc_server/srv_netlog_nt.c | 29 +++++++++++++++++++++++++++++ source/rpc_server/srv_util.c | 29 ----------------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index cca0715a3aa..26095f6d830 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -298,7 +298,7 @@ RPC_SPOOLSS_OBJ = rpc_server/srv_spoolss.o rpc_server/srv_spoolss_nt.o RPC_EVENTLOG_OBJ = rpc_server/srv_eventlog.o rpc_server/srv_eventlog_nt.o rpc_server/srv_eventlog_lib.o -RPC_PIPE_OBJ = rpc_server/srv_pipe_hnd.o rpc_server/srv_util.o \ +RPC_PIPE_OBJ = rpc_server/srv_pipe_hnd.o \ rpc_server/srv_pipe.o rpc_server/srv_lsa_hnd.o RPC_ECHO_OBJ = rpc_server/srv_echo.o rpc_server/srv_echo_nt.o diff --git a/source/rpc_server/srv_netlog_nt.c b/source/rpc_server/srv_netlog_nt.c index 7903adff6d5..d0d47be9f29 100644 --- a/source/rpc_server/srv_netlog_nt.c +++ b/source/rpc_server/srv_netlog_nt.c @@ -584,6 +584,35 @@ NTSTATUS _net_sam_logoff(pipes_struct *p, NET_Q_SAM_LOGOFF *q_u, NET_R_SAM_LOGOF } +/******************************************************************* + gets a domain user's groups from their already-calculated NT_USER_TOKEN + ********************************************************************/ +static NTSTATUS nt_token_to_group_list(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, + const NT_USER_TOKEN *nt_token, + int *numgroups, DOM_GID **pgids) +{ + DOM_GID *gids; + int i; + + gids = TALLOC_ARRAY(mem_ctx, DOM_GID, nt_token->num_sids); + + if (!gids) { + return NT_STATUS_NO_MEMORY; + } + + *numgroups=0; + + for (i=PRIMARY_GROUP_SID_INDEX; i < nt_token->num_sids; i++) { + if (sid_compare_domain(domain_sid, &nt_token->user_sids[i])==0) { + sid_peek_rid(&nt_token->user_sids[i], &(gids[*numgroups].g_rid)); + gids[*numgroups].attr= (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_ENABLED); + (*numgroups)++; + } + } + *pgids = gids; + return NT_STATUS_OK; +} + /************************************************************************* _net_sam_logon *************************************************************************/ diff --git a/source/rpc_server/srv_util.c b/source/rpc_server/srv_util.c index 3666d474787..924e08cc23a 100644 --- a/source/rpc_server/srv_util.c +++ b/source/rpc_server/srv_util.c @@ -81,32 +81,3 @@ static const rid_name domain_group_rids[] = }; #endif -/******************************************************************* - gets a domain user's groups from their already-calculated NT_USER_TOKEN - ********************************************************************/ -NTSTATUS nt_token_to_group_list(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, - const NT_USER_TOKEN *nt_token, - int *numgroups, DOM_GID **pgids) -{ - DOM_GID *gids; - int i; - - gids = TALLOC_ARRAY(mem_ctx, DOM_GID, nt_token->num_sids); - - if (!gids) { - return NT_STATUS_NO_MEMORY; - } - - *numgroups=0; - - for (i=PRIMARY_GROUP_SID_INDEX; i < nt_token->num_sids; i++) { - if (sid_compare_domain(domain_sid, &nt_token->user_sids[i])==0) { - sid_peek_rid(&nt_token->user_sids[i], &(gids[*numgroups].g_rid)); - gids[*numgroups].attr= (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_ENABLED); - (*numgroups)++; - } - } - *pgids = gids; - return NT_STATUS_OK; -} - -- cgit From 26a6c543a5573c1659aff6b89a9fe3131eee012d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 19:22:17 +0000 Subject: r11918: Remove two unused variables --- source/rpc_server/srv_samr_nt.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 2bb8078f784..9a09b5f544b 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -68,8 +68,6 @@ struct samr_info { DOM_SID sid; uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */ uint32 acc_granted; - uint16 acb_mask; - BOOL only_machines; DISP_INFO *disp_info; TALLOC_CTX *mem_ctx; }; -- cgit From 84ae4ee168f16840014c9f19b957376e508fc1f4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 20:28:12 +0000 Subject: r11919: The generic mappings in srv_samr_nt.c are only used there -- make them static. One long overdue simplification: Change local_lookup_sid to local_lookup_rid its responsible for "our" domain only, in fact it checked for it. Volker --- source/passdb/lookup_sid.c | 37 +++++++++++++++++++++++-------------- source/passdb/passdb.c | 39 ++++++++++++++------------------------- source/passdb/util_sam_sid.c | 7 +------ source/rpc_server/srv_samr_nt.c | 30 +++++++++++++++++++++++++----- 4 files changed, 63 insertions(+), 50 deletions(-) diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index 6b58210919a..5c0bf0aef87 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -76,25 +76,34 @@ BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAM /* Check if this is our own sid. This should perhaps be done by winbind? For the moment handle it here. */ - if (sid->num_auths == 4 && sid_equal(get_global_sam_sid(), sid)) { - DOM_SID tmp_sid; - sid_copy(&tmp_sid, sid); - return map_domain_sid_to_name(&tmp_sid, dom_name) && - local_lookup_sid(sid, name, name_type); + if (sid_check_is_domain(sid)) { + fstrcpy(dom_name, get_global_sam_name()); + fstrcpy(name, ""); + *name_type = SID_NAME_DOMAIN; + return True; } - if (sid->num_auths == 5) { - DOM_SID tmp_sid; - uint32 rid; + if (sid_check_is_builtin(sid)) { - sid_copy(&tmp_sid, sid); - sid_split_rid(&tmp_sid, &rid); + /* Got through map_domain_sid_to_name here so that the mapping + * of S-1-5-32 to the name "BUILTIN" in as few places as + * possible. We might add i18n... */ + SMB_ASSERT(map_domain_sid_to_name(sid, dom_name)); - if (sid_equal(get_global_sam_sid(), &tmp_sid)) { + /* Yes, W2k3 returns "BUILTIN" both as domain and name here */ + fstrcpy(name, dom_name); - return map_domain_sid_to_name(&tmp_sid, dom_name) && - local_lookup_sid(sid, name, name_type); - } + *name_type = SID_NAME_DOMAIN; + return True; + } + + if (sid_check_is_in_our_domain(sid)) { + uint32 rid; + SMB_ASSERT(sid_peek_rid(sid, &rid)); + + /* For our own domain passdb is responsible */ + fstrcpy(dom_name, get_global_sam_name()); + return local_lookup_rid(rid, name, name_type); } if (winbind_lookup_sid(sid, dom_name, name, name_type)) { diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index 14a5b73f16a..7d07e4cebaa 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -735,31 +735,20 @@ BOOL algorithmic_pdb_rid_is_user(uint32 rid) Convert a rid into a name. Used in the lookup SID rpc. ********************************************************************/ -BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_name_use) +BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) { - uint32 rid; SAM_ACCOUNT *sam_account = NULL; GROUP_MAP map; BOOL ret; + DOM_SID sid; - if (sid_equal(get_global_sam_sid(), sid)) { - *psid_name_use = SID_NAME_DOMAIN; - fstrcpy(name, ""); - DEBUG(5,("local_lookup_sid: SID is our own domain-sid: %s.\n", - sid_string_static(sid))); - return True; - } - - if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)){ - DEBUG(0,("local_lookup_sid: sid_peek_check_rid return False! SID: %s\n", - sid_string_static(&map.sid))); - return False; - } *psid_name_use = SID_NAME_UNKNOWN; - DEBUG(5,("local_lookup_sid: looking up RID %u.\n", (unsigned int)rid)); - + DEBUG(5,("local_lookup_rid: looking up RID %u.\n", (unsigned int)rid)); + sid_copy(&sid, get_global_sam_sid()); + sid_append_rid(&sid, rid); + /* see if the passdb can help us with the name of the user */ if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) { return False; @@ -767,7 +756,7 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na /* BEING ROOT BLLOCK */ become_root(); - if (pdb_getsampwsid(sam_account, sid)) { + if (pdb_getsampwsid(sam_account, &sid)) { unbecome_root(); /* -----> EXIT BECOME_ROOT() */ fstrcpy(name, pdb_get_username(sam_account)); *psid_name_use = SID_NAME_USER; @@ -778,15 +767,15 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na } pdb_free_sam(&sam_account); - ret = pdb_getgrsid(&map, *sid); + ret = pdb_getgrsid(&map, sid); unbecome_root(); /* END BECOME_ROOT BLOCK */ if ( ret ) { if (map.gid!=(gid_t)-1) { - DEBUG(5,("local_lookup_sid: mapped group %s to gid %u\n", map.nt_name, (unsigned int)map.gid)); + DEBUG(5,("local_lookup_rid: mapped group %s to gid %u\n", map.nt_name, (unsigned int)map.gid)); } else { - DEBUG(5,("local_lookup_sid: mapped group %s to no unix gid. Returning name.\n", map.nt_name)); + DEBUG(5,("local_lookup_rid: mapped group %s to no unix gid. Returning name.\n", map.nt_name)); } fstrcpy(name, map.nt_name); @@ -809,7 +798,7 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na uid = algorithmic_pdb_user_rid_to_uid(rid); pw = sys_getpwuid( uid ); - DEBUG(5,("local_lookup_sid: looking up uid %u %s\n", (unsigned int)uid, + DEBUG(5,("local_lookup_rid: looking up uid %u %s\n", (unsigned int)uid, pw ? "succeeded" : "failed" )); if ( !pw ) @@ -817,7 +806,7 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na else fstrcpy( name, pw->pw_name ); - DEBUG(5,("local_lookup_sid: found user %s for rid %u\n", name, + DEBUG(5,("local_lookup_rid: found user %s for rid %u\n", name, (unsigned int)rid )); *psid_name_use = SID_NAME_USER; @@ -832,7 +821,7 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na gid = pdb_group_rid_to_gid(rid); gr = getgrgid(gid); - DEBUG(5,("local_lookup_sid: looking up gid %u %s\n", (unsigned int)gid, + DEBUG(5,("local_lookup_rid: looking up gid %u %s\n", (unsigned int)gid, gr ? "succeeded" : "failed" )); if( !gr ) @@ -840,7 +829,7 @@ BOOL local_lookup_sid(const DOM_SID *sid, char *name, enum SID_NAME_USE *psid_na else fstrcpy( name, gr->gr_name); - DEBUG(5,("local_lookup_sid: found group %s for rid %u\n", name, + DEBUG(5,("local_lookup_rid: found group %s for rid %u\n", name, (unsigned int)rid )); /* assume algorithmic groups are domain global groups */ diff --git a/source/passdb/util_sam_sid.c b/source/passdb/util_sam_sid.c index 42e4b6df967..afbc2edcde3 100644 --- a/source/passdb/util_sam_sid.c +++ b/source/passdb/util_sam_sid.c @@ -91,7 +91,7 @@ static struct sid_name_map_info special_domains[] = { Turns a domain SID into a name, returned in the nt_domain argument. ***************************************************************************/ -BOOL map_domain_sid_to_name(DOM_SID *sid, fstring nt_domain) +BOOL map_domain_sid_to_name(const DOM_SID *sid, fstring nt_domain) { fstring sid_str; int i = 0; @@ -100,11 +100,6 @@ BOOL map_domain_sid_to_name(DOM_SID *sid, fstring nt_domain) DEBUG(5,("map_domain_sid_to_name: %s\n", sid_str)); - if (sid_check_is_domain(sid)) { - fstrcpy(nt_domain, get_global_sam_name()); - return True; - } - while (special_domains[i].sid != NULL) { DEBUG(5,("map_domain_sid_to_name: compare: %s\n", sid_string_static(special_domains[i].sid))); diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 9a09b5f544b..ec2bc3fe4af 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -72,11 +72,31 @@ struct samr_info { TALLOC_CTX *mem_ctx; }; -struct generic_mapping sam_generic_mapping = {GENERIC_RIGHTS_SAM_READ, GENERIC_RIGHTS_SAM_WRITE, GENERIC_RIGHTS_SAM_EXECUTE, GENERIC_RIGHTS_SAM_ALL_ACCESS}; -struct generic_mapping dom_generic_mapping = {GENERIC_RIGHTS_DOMAIN_READ, GENERIC_RIGHTS_DOMAIN_WRITE, GENERIC_RIGHTS_DOMAIN_EXECUTE, GENERIC_RIGHTS_DOMAIN_ALL_ACCESS}; -struct generic_mapping usr_generic_mapping = {GENERIC_RIGHTS_USER_READ, GENERIC_RIGHTS_USER_WRITE, GENERIC_RIGHTS_USER_EXECUTE, GENERIC_RIGHTS_USER_ALL_ACCESS}; -struct generic_mapping grp_generic_mapping = {GENERIC_RIGHTS_GROUP_READ, GENERIC_RIGHTS_GROUP_WRITE, GENERIC_RIGHTS_GROUP_EXECUTE, GENERIC_RIGHTS_GROUP_ALL_ACCESS}; -struct generic_mapping ali_generic_mapping = {GENERIC_RIGHTS_ALIAS_READ, GENERIC_RIGHTS_ALIAS_WRITE, GENERIC_RIGHTS_ALIAS_EXECUTE, GENERIC_RIGHTS_ALIAS_ALL_ACCESS}; +static struct generic_mapping sam_generic_mapping = { + GENERIC_RIGHTS_SAM_READ, + GENERIC_RIGHTS_SAM_WRITE, + GENERIC_RIGHTS_SAM_EXECUTE, + GENERIC_RIGHTS_SAM_ALL_ACCESS}; +static struct generic_mapping dom_generic_mapping = { + GENERIC_RIGHTS_DOMAIN_READ, + GENERIC_RIGHTS_DOMAIN_WRITE, + GENERIC_RIGHTS_DOMAIN_EXECUTE, + GENERIC_RIGHTS_DOMAIN_ALL_ACCESS}; +static struct generic_mapping usr_generic_mapping = { + GENERIC_RIGHTS_USER_READ, + GENERIC_RIGHTS_USER_WRITE, + GENERIC_RIGHTS_USER_EXECUTE, + GENERIC_RIGHTS_USER_ALL_ACCESS}; +static struct generic_mapping grp_generic_mapping = { + GENERIC_RIGHTS_GROUP_READ, + GENERIC_RIGHTS_GROUP_WRITE, + GENERIC_RIGHTS_GROUP_EXECUTE, + GENERIC_RIGHTS_GROUP_ALL_ACCESS}; +static struct generic_mapping ali_generic_mapping = { + GENERIC_RIGHTS_ALIAS_READ, + GENERIC_RIGHTS_ALIAS_WRITE, + GENERIC_RIGHTS_ALIAS_EXECUTE, + GENERIC_RIGHTS_ALIAS_ALL_ACCESS}; /******************************************************************* *******************************************************************/ -- cgit From 92338cd1eb88ee41d9bdd41b10ba74e44b1ea22e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 21:02:48 +0000 Subject: r11920: Rename local_lookup_rid to lookup_global_sam_rid, add lookup_builtin_rid. Volker --- source/passdb/lookup_sid.c | 28 +++++++++++++++++++++++----- source/passdb/passdb.c | 36 +++++++++++++++++++++--------------- source/passdb/util_sam_sid.c | 18 ++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index 5c0bf0aef87..b397e084c33 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -66,7 +66,8 @@ BOOL lookup_name(const char *domain, const char *name, DOM_SID *psid, enum SID_N Tries local lookup first - for local sids, then tries winbind. *****************************************************************/ -BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAME_USE *name_type) +BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, + enum SID_NAME_USE *name_type) { if (!name_type) return False; @@ -83,6 +84,15 @@ BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAM return True; } + if (sid_check_is_in_our_domain(sid)) { + uint32 rid; + SMB_ASSERT(sid_peek_rid(sid, &rid)); + + /* For our own domain passdb is responsible */ + fstrcpy(dom_name, get_global_sam_name()); + return lookup_global_sam_rid(rid, name, name_type); + } + if (sid_check_is_builtin(sid)) { /* Got through map_domain_sid_to_name here so that the mapping @@ -97,13 +107,21 @@ BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, enum SID_NAM return True; } - if (sid_check_is_in_our_domain(sid)) { + if (sid_check_is_in_builtin(sid)) { uint32 rid; + SMB_ASSERT(sid_peek_rid(sid, &rid)); - /* For our own domain passdb is responsible */ - fstrcpy(dom_name, get_global_sam_name()); - return local_lookup_rid(rid, name, name_type); + /* Got through map_domain_sid_to_name here so that the mapping + * of S-1-5-32 to the name "BUILTIN" in as few places as + * possible. We might add i18n... */ + SMB_ASSERT(map_domain_sid_to_name(&global_sid_Builtin, + dom_name)); + + /* There's only aliases in S-1-5-32 */ + *name_type = SID_NAME_ALIAS; + + return lookup_builtin_rid(rid, name); } if (winbind_lookup_sid(sid, dom_name, name, name_type)) { diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index 7d07e4cebaa..7f9cc7df9f5 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -732,10 +732,11 @@ BOOL algorithmic_pdb_rid_is_user(uint32 rid) } /******************************************************************* - Convert a rid into a name. Used in the lookup SID rpc. + Look up a rid in the SAM we're responsible for (i.e. passdb) ********************************************************************/ -BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) +BOOL lookup_global_sam_rid(uint32 rid, fstring name, + enum SID_NAME_USE *psid_name_use) { SAM_ACCOUNT *sam_account = NULL; GROUP_MAP map; @@ -744,7 +745,8 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) *psid_name_use = SID_NAME_UNKNOWN; - DEBUG(5,("local_lookup_rid: looking up RID %u.\n", (unsigned int)rid)); + DEBUG(5,("lookup_global_sam_rid: looking up RID %u.\n", + (unsigned int)rid)); sid_copy(&sid, get_global_sam_sid()); sid_append_rid(&sid, rid); @@ -757,7 +759,7 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) /* BEING ROOT BLLOCK */ become_root(); if (pdb_getsampwsid(sam_account, &sid)) { - unbecome_root(); /* -----> EXIT BECOME_ROOT() */ + unbecome_root(); /* -----> EXIT BECOME_ROOT() */ fstrcpy(name, pdb_get_username(sam_account)); *psid_name_use = SID_NAME_USER; @@ -773,9 +775,13 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) if ( ret ) { if (map.gid!=(gid_t)-1) { - DEBUG(5,("local_lookup_rid: mapped group %s to gid %u\n", map.nt_name, (unsigned int)map.gid)); + DEBUG(5,("lookup_global_sam_rid: mapped group %s to " + "gid %u\n", map.nt_name, + (unsigned int)map.gid)); } else { - DEBUG(5,("local_lookup_rid: mapped group %s to no unix gid. Returning name.\n", map.nt_name)); + DEBUG(5,("lookup_global_sam_rid: mapped group %s to " + "no unix gid. Returning name.\n", + map.nt_name)); } fstrcpy(name, map.nt_name); @@ -798,16 +804,16 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) uid = algorithmic_pdb_user_rid_to_uid(rid); pw = sys_getpwuid( uid ); - DEBUG(5,("local_lookup_rid: looking up uid %u %s\n", (unsigned int)uid, - pw ? "succeeded" : "failed" )); + DEBUG(5,("lookup_global_sam_rid: looking up uid %u %s\n", + (unsigned int)uid, pw ? "succeeded" : "failed" )); if ( !pw ) - fstr_sprintf(name, "unix_user.%u", (unsigned int)uid); + fstr_sprintf(name, "unix_user.%u", (unsigned int)uid); else fstrcpy( name, pw->pw_name ); - DEBUG(5,("local_lookup_rid: found user %s for rid %u\n", name, - (unsigned int)rid )); + DEBUG(5,("lookup_global_sam_rid: found user %s for rid %u\n", + name, (unsigned int)rid )); *psid_name_use = SID_NAME_USER; @@ -821,16 +827,16 @@ BOOL local_lookup_rid(uint32 rid, char *name, enum SID_NAME_USE *psid_name_use) gid = pdb_group_rid_to_gid(rid); gr = getgrgid(gid); - DEBUG(5,("local_lookup_rid: looking up gid %u %s\n", (unsigned int)gid, - gr ? "succeeded" : "failed" )); + DEBUG(5,("lookup_global_sam_rid: looking up gid %u %s\n", + (unsigned int)gid, gr ? "succeeded" : "failed" )); if( !gr ) fstr_sprintf(name, "unix_group.%u", (unsigned int)gid); else fstrcpy( name, gr->gr_name); - DEBUG(5,("local_lookup_rid: found group %s for rid %u\n", name, - (unsigned int)rid )); + DEBUG(5,("lookup_global_sam_rid: found group %s for rid %u\n", + name, (unsigned int)rid )); /* assume algorithmic groups are domain global groups */ diff --git a/source/passdb/util_sam_sid.c b/source/passdb/util_sam_sid.c index afbc2edcde3..822b7f6a349 100644 --- a/source/passdb/util_sam_sid.c +++ b/source/passdb/util_sam_sid.c @@ -164,6 +164,24 @@ BOOL lookup_special_sid(const DOM_SID *sid, const char **domain, return False; } +/******************************************************************* + Look up a rid in the BUILTIN domain + ********************************************************************/ +BOOL lookup_builtin_rid(uint32 rid, fstring name) +{ + const known_sid_users *aliases = builtin_groups; + int i; + + for (i=0; aliases[i].known_user_name != NULL; i++) { + if (rid == aliases[i].rid) { + fstrcpy(name, aliases[i].known_user_name); + return True; + } + } + + return False; +} + /***************************************************************** Check if the SID is our domain SID (S-1-5-21-x-y-z). *****************************************************************/ -- cgit From 52d281a266c72ac2c9a4514d310d5c71f3575ff2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 21:35:43 +0000 Subject: r11921: samr_open_domain can only open "our" domain and BUILTIN. Volker --- source/rpc_server/srv_samr_nt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index ec2bc3fe4af..ac774355a73 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -562,6 +562,11 @@ NTSTATUS _samr_open_domain(pipes_struct *p, SAMR_Q_OPEN_DOMAIN *q_u, SAMR_R_OPEN if ( !NT_STATUS_IS_OK(status) ) return status; + if (!sid_check_is_domain(&q_u->dom_sid.sid) && + !sid_check_is_builtin(&q_u->dom_sid.sid)) { + return NT_STATUS_NO_SUCH_DOMAIN; + } + /* associate the domain SID with the (unique) handle. */ if ((info = get_samr_info_by_sid(&q_u->dom_sid.sid))==NULL) return NT_STATUS_NO_MEMORY; -- cgit From 05de21f520d04c8d1ea5babead10c9e846a0249a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 22:04:28 +0000 Subject: r11922: Looks bigger than it is: There's no point in allocating arrays in samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in the pdb module. Remove the latter, this might happen more often. Volker --- source/include/passdb.h | 10 ++++------ source/passdb/pdb_interface.c | 38 ++++++++++++++------------------------ source/passdb/pdb_ldap.c | 27 ++++++++++----------------- source/rpc_server/srv_samr_nt.c | 4 ++-- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/source/include/passdb.h b/source/include/passdb.h index 293d18a42a2..15f0701e9ba 100644 --- a/source/include/passdb.h +++ b/source/include/passdb.h @@ -367,12 +367,11 @@ typedef struct pdb_context size_t *p_num_alias_rids); NTSTATUS (*pdb_lookup_rids)(struct pdb_context *context, - TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, size_t num_rids, uint32 *rids, - const char ***pp_names, - uint32 **attrs); + const char **pp_names, + uint32 *attrs); NTSTATUS (*pdb_get_account_policy)(struct pdb_context *context, int policy_index, uint32 *value); @@ -491,12 +490,11 @@ typedef struct pdb_methods size_t *p_num_alias_rids); NTSTATUS (*lookup_rids)(struct pdb_methods *methods, - TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, int num_rids, uint32 *rids, - const char ***pp_names, - uint32 **attrs); + const char **pp_names, + uint32 *attrs); NTSTATUS (*get_account_policy)(struct pdb_methods *methods, int policy_index, uint32 *value); diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c index 482f3e3c9b8..9605349781f 100644 --- a/source/passdb/pdb_interface.c +++ b/source/passdb/pdb_interface.c @@ -681,12 +681,11 @@ static NTSTATUS context_enum_alias_memberships(struct pdb_context *context, } static NTSTATUS context_lookup_rids(struct pdb_context *context, - TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, size_t num_rids, uint32 *rids, - const char ***pp_names, - uint32 **pp_attrs) + const char **pp_names, + uint32 *pp_attrs) { NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; @@ -696,7 +695,7 @@ static NTSTATUS context_lookup_rids(struct pdb_context *context, } return context->pdb_methods->lookup_rids(context->pdb_methods, - mem_ctx, domain_sid, num_rids, + domain_sid, num_rids, rids, pp_names, pp_attrs); } @@ -1398,12 +1397,11 @@ BOOL pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, p_num_alias_rids)); } -NTSTATUS pdb_lookup_rids(TALLOC_CTX *mem_ctx, - const DOM_SID *domain_sid, +NTSTATUS pdb_lookup_rids(const DOM_SID *domain_sid, int num_rids, uint32 *rids, - const char ***names, - uint32 **attrs) + const char **names, + uint32 *attrs) { struct pdb_context *pdb_context = pdb_get_static_context(False); @@ -1411,7 +1409,7 @@ NTSTATUS pdb_lookup_rids(TALLOC_CTX *mem_ctx, return NT_STATUS_NOT_IMPLEMENTED; } - return pdb_context->pdb_lookup_rids(pdb_context, mem_ctx, domain_sid, + return pdb_context->pdb_lookup_rids(pdb_context, domain_sid, num_rids, rids, names, attrs); } @@ -1643,24 +1641,17 @@ NTSTATUS pdb_default_enum_group_members(struct pdb_methods *methods, } NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods, - TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, int num_rids, uint32 *rids, - const char ***names, - uint32 **attrs) + const char **names, + uint32 *attrs) { int i; NTSTATUS result; BOOL have_mapped = False; BOOL have_unmapped = False; - (*names) = TALLOC_ZERO_ARRAY(mem_ctx, const char *, num_rids); - (*attrs) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_rids); - - if ((num_rids != 0) && (((*names) == NULL) || ((*attrs) == NULL))) - return NT_STATUS_NO_MEMORY; - if (!sid_equal(domain_sid, get_global_sam_sid())) { /* TODO: Sooner or later we need to look up BUILTIN rids as * well. -- vl */ @@ -1673,18 +1664,17 @@ NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods, DOM_SID sid; enum SID_NAME_USE type; - (*attrs)[i] = SID_NAME_UNKNOWN; + attrs[i] = SID_NAME_UNKNOWN; sid_copy(&sid, domain_sid); sid_append_rid(&sid, rids[i]); if (lookup_sid(&sid, domname, tmpname, &type)) { - (*attrs)[i] = (uint32)type; - (*names)[i] = talloc_strdup(mem_ctx, tmpname); - if ((*names)[i] == NULL) + attrs[i] = (uint32)type; + names[i] = talloc_strdup(names, tmpname); + if (names[i] == NULL) return NT_STATUS_NO_MEMORY; - DEBUG(5,("lookup_rids: %s:%d\n", (*names)[i], - (*attrs)[i])); + DEBUG(5,("lookup_rids: %s:%d\n", names[i], attrs[i])); have_mapped = True; } else { have_unmapped = True; diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index ef9eb81fbbf..1254dba2b89 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3514,12 +3514,11 @@ static NTSTATUS ldapsam_get_account_policy(struct pdb_methods *methods, int poli } static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods, - TALLOC_CTX *mem_ctx, const DOM_SID *domain_sid, int num_rids, uint32 *rids, - const char ***names, - uint32 **attrs) + const char **names, + uint32 *attrs) { struct ldapsam_privates *ldap_state = (struct ldapsam_privates *)methods->private_data; @@ -3532,7 +3531,7 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods, NTSTATUS result = NT_STATUS_UNSUCCESSFUL; if (!lp_parm_bool(-1, "ldapsam", "trusted", False)) - return pdb_default_lookup_rids(methods, mem_ctx, domain_sid, + return pdb_default_lookup_rids(methods, domain_sid, num_rids, rids, names, attrs); if (!sid_equal(domain_sid, get_global_sam_sid())) { @@ -3541,14 +3540,8 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods, goto done; } - (*names) = TALLOC_ZERO_ARRAY(mem_ctx, const char *, num_rids); - (*attrs) = TALLOC_ARRAY(mem_ctx, uint32, num_rids); - - if ((num_rids != 0) && (((*names) == NULL) || ((*attrs) == NULL))) - return NT_STATUS_NO_MEMORY; - for (i=0; istatus = pdb_lookup_rids(p->mem_ctx, &pol_sid, num_rids, q_u->rid, - &names, &attrs); + r_u->status = pdb_lookup_rids(&pol_sid, num_rids, q_u->rid, + names, attrs); unbecome_root(); done: -- cgit From 7a53dcf2a8d044574218299ec9d4643f19e4ac83 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Nov 2005 22:28:41 +0000 Subject: r11923: Add samr_lookup_rids for the builtin domain. Doing it this way feels a bit wrong, but so far we don't have proper multi-domain support in passdb yet... Volker --- source/passdb/pdb_interface.c | 37 ++++++++++++++++++++++++++----------- source/rpc_server/srv_samr_nt.c | 8 -------- source/rpcclient/cmd_samr.c | 23 +++++++++++++++-------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c index 9605349781f..875e264bf01 100644 --- a/source/passdb/pdb_interface.c +++ b/source/passdb/pdb_interface.c @@ -1652,24 +1652,38 @@ NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods, BOOL have_mapped = False; BOOL have_unmapped = False; - if (!sid_equal(domain_sid, get_global_sam_sid())) { - /* TODO: Sooner or later we need to look up BUILTIN rids as - * well. -- vl */ + if (sid_check_is_builtin(domain_sid)) { + + for (i=0; istatus = pdb_lookup_rids(&pol_sid, num_rids, q_u->rid, names, attrs); unbecome_root(); - done: - if(!make_samr_lookup_rids(p->mem_ctx, num_rids, names, &hdr_name, &uni_name)) return NT_STATUS_NO_MEMORY; diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 7727330388f..68ceead69d3 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -1457,8 +1457,8 @@ static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli, char **names; int i; - if (argc < 2) { - printf("Usage: %s rid1 [rid2 [rid3] [...]]\n", argv[0]); + if (argc < 3) { + printf("Usage: %s domain|builtin rid1 [rid2 [rid3] [...]]\n", argv[0]); return NT_STATUS_OK; } @@ -1470,20 +1470,27 @@ static NTSTATUS cmd_samr_lookup_rids(struct rpc_pipe_client *cli, if (!NT_STATUS_IS_OK(result)) goto done; - result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, - MAXIMUM_ALLOWED_ACCESS, - &domain_sid, &domain_pol); + if (StrCaseCmp(argv[1], "domain")==0) + result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, + MAXIMUM_ALLOWED_ACCESS, + &domain_sid, &domain_pol); + else if (StrCaseCmp(argv[1], "builtin")==0) + result = rpccli_samr_open_domain(cli, mem_ctx, &connect_pol, + MAXIMUM_ALLOWED_ACCESS, + &global_sid_Builtin, &domain_pol); + else + return NT_STATUS_OK; if (!NT_STATUS_IS_OK(result)) goto done; /* Look up rids */ - num_rids = argc - 1; + num_rids = argc - 2; rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids); - for (i = 0; i < argc - 1; i++) - sscanf(argv[i + 1], "%i", &rids[i]); + for (i = 0; i < argc - 2; i++) + sscanf(argv[i + 2], "%i", &rids[i]); result = rpccli_samr_lookup_rids(cli, mem_ctx, &domain_pol, num_rids, rids, &num_names, &names, &name_types); -- cgit From 122a4c8218253f71b29dfad29c81a09626882bcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 27 Nov 2005 01:17:24 +0000 Subject: r11924: Added Volkers's (C) to srv_samr_nt.c, removed separate "builtin" search enumeration, fixed count of groups and users to return zero if we're getting domain info on the builtin domain (need to fix the enumgroup and enumuser calls also). Added count_sam_aliases to return the correct alias count. Need to push the SID arg down into the group mapping interface so we only return the correct aliases. Upped passdb version numer for Volkers changes. SAM-MYSQL guys - you will need to fix your backend now. More tests needed. Jeremy. --- source/include/passdb.h | 5 ++- source/rpc_server/srv_samr_nt.c | 76 +++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/source/include/passdb.h b/source/include/passdb.h index 15f0701e9ba..0589b9a7cd4 100644 --- a/source/include/passdb.h +++ b/source/include/passdb.h @@ -265,9 +265,12 @@ struct pdb_search { * This next constant specifies the version number of the PASSDB interface * this SAMBA will load. Increment this if *ANY* changes are made to the interface. * Changed interface to fix int -> size_t problems. JRA. + * There's no point in allocating arrays in + * samr_lookup_rids twice. It was done in the srv_samr_nt.c code as well as in + * the pdb module. Remove the latter, this might happen more often. VL. */ -#define PASSDB_INTERFACE_VERSION 11 +#define PASSDB_INTERFACE_VERSION 12 typedef struct pdb_context { diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index b4d699188af..f10597055e9 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -5,11 +5,12 @@ * Copyright (C) Luke Kenneth Casson Leighton 1996-1997, * Copyright (C) Paul Ashton 1997, * Copyright (C) Marc Jacobsen 1999, - * Copyright (C) Jeremy Allison 2001-2002, + * Copyright (C) Jeremy Allison 2001-2005, * Copyright (C) Jean François Micouleau 1998-2001, * Copyright (C) Jim McDonough 2002, * Copyright (C) Gerald (Jerry) Carter 2003-2004, * Copyright (C) Simo Sorce 2003. + * Copyright (C) Volker Lendecke 2005. * * 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 @@ -46,15 +47,16 @@ typedef struct disp_info { struct disp_info *next, *prev; TALLOC_CTX *mem_ctx; DOM_SID sid; /* identify which domain this is. */ + BOOL builtin_domain; /* Quick flag to check if this is the builtin domain. */ struct pdb_search *users; /* querydispinfo 1 and 4 */ struct pdb_search *machines; /* querydispinfo 2 */ struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */ struct pdb_search *aliases; /* enumaliases */ - struct pdb_search *builtins; /* enumaliases */ uint16 enum_acb_mask; struct pdb_search *enum_users; /* enumusers with a mask */ + smb_event_id_t di_cache_timeout_event; /* cache idle timeout handler. */ } DISP_INFO; @@ -66,6 +68,7 @@ static DISP_INFO *disp_info_list; struct samr_info { /* for use by the \PIPE\samr policy */ DOM_SID sid; + BOOL builtin_domain; /* Quick flag to check if this is the builtin domain. */ uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */ uint32 acc_granted; DISP_INFO *disp_info; @@ -265,8 +268,12 @@ static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid, const char *sid_str) return NULL; dpi->mem_ctx = mem_ctx; + if (psid) { sid_copy( &dpi->sid, psid); + dpi->builtin_domain = sid_check_is_builtin(psid); + } else { + dpi->builtin_domain = False; } DLIST_ADD(disp_info_list, dpi); @@ -298,8 +305,10 @@ static struct samr_info *get_samr_info_by_sid(DOM_SID *psid) DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str)); if (psid) { sid_copy( &info->sid, psid); + info->builtin_domain = sid_check_is_builtin(psid); } else { DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n")); + info->builtin_domain = False; } info->mem_ctx = mem_ctx; @@ -346,11 +355,6 @@ static void free_samr_cache(DISP_INFO *disp_info, const char *sid_str) pdb_search_destroy(disp_info->aliases); disp_info->aliases = NULL; } - if (disp_info->builtins) { - DEBUG(10,("free_samr_cache: deleting builtins cache\n")); - pdb_search_destroy(disp_info->builtins); - disp_info->builtins = NULL; - } if (disp_info->enum_users) { DEBUG(10,("free_samr_cache: deleting enum_users cache\n")); pdb_search_destroy(disp_info->enum_users); @@ -470,6 +474,12 @@ static void samr_clear_sam_passwd(SAM_ACCOUNT *sam_pass) static uint32 count_sam_users(struct disp_info *info, uint16 acct_flags) { struct samr_displayentry *entry; + + if (info->builtin_domain) { + /* No users in builtin. */ + return 0; + } + if (info->users == NULL) { info->users = pdb_search_users(acct_flags); if (info->users == NULL) { @@ -488,6 +498,12 @@ static uint32 count_sam_users(struct disp_info *info, uint16 acct_flags) static uint32 count_sam_groups(struct disp_info *info) { struct samr_displayentry *entry; + + if (info->builtin_domain) { + /* No groups in builtin. */ + return 0; + } + if (info->groups == NULL) { info->groups = pdb_search_groups(); if (info->groups == NULL) { @@ -503,6 +519,25 @@ static uint32 count_sam_groups(struct disp_info *info) return info->groups->num_entries; } +static uint32 count_sam_aliases(struct disp_info *info) +{ + struct samr_displayentry *entry; + + if (info->aliases == NULL) { + info->aliases = pdb_search_aliases(&info->sid); + if (info->aliases == NULL) { + return 0; + } + } + /* Fetch the last possible entry, thus trigger an enumeration */ + pdb_search_entries(info->aliases, 0xffffffff, 1, &entry); + + /* Ensure we cache this enumeration. */ + set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT); + + return info->aliases->num_entries; +} + /******************************************************************* _samr_close_hnd ********************************************************************/ @@ -943,7 +978,6 @@ NTSTATUS _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, S { struct samr_info *info; struct samr_displayentry *aliases; - struct pdb_search **search = NULL; uint32 num_aliases = 0; /* find the policy handle. open a policy on it. */ @@ -959,25 +993,17 @@ NTSTATUS _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, S DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n", sid_string_static(&info->sid))); - if (sid_check_is_domain(&info->sid)) - search = &info->disp_info->aliases; - if (sid_check_is_builtin(&info->sid)) - search = &info->disp_info->builtins; - - if (search == NULL) - return NT_STATUS_INVALID_HANDLE; - become_root(); - if (*search == NULL) { - *search = pdb_search_aliases(&info->sid); - if (*search == NULL) { + if (info->disp_info->aliases == NULL) { + info->disp_info->aliases = pdb_search_aliases(&info->sid); + if (info->disp_info->aliases == NULL) { unbecome_root(); return NT_STATUS_ACCESS_DENIED; } } - num_aliases = pdb_search_entries(*search, q_u->start_idx, + num_aliases = pdb_search_entries(info->disp_info->aliases, q_u->start_idx, MAX_SAM_ENTRIES, &aliases); unbecome_root(); @@ -2096,9 +2122,9 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA /* AS ROOT !!! */ - num_users=count_sam_users(info->disp_info, - ACB_NORMAL); - num_groups=count_sam_groups(info->disp_info); + num_users = count_sam_users(info->disp_info, ACB_NORMAL); + num_groups = count_sam_groups(info->disp_info); + num_aliases = count_sam_aliases(info->disp_info); pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp); u_logout = account_policy_temp; @@ -4692,9 +4718,9 @@ NTSTATUS _samr_query_domain_info2(pipes_struct *p, break; case 0x02: become_root(); - num_users = count_sam_users(info->disp_info, - ACB_NORMAL); + num_users = count_sam_users(info->disp_info, ACB_NORMAL); num_groups = count_sam_groups(info->disp_info); + num_aliases = count_sam_aliases(info->disp_info); unbecome_root(); pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp); -- cgit From ba68e6cfd699b99e4f4c6ba17b82a9199495dbd7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 27 Nov 2005 01:26:52 +0000 Subject: r11927: No users or groups to return in BUILTIN domain. Jeremy. --- source/rpc_server/srv_samr_nt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index f10597055e9..6ad5ec77068 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -814,6 +814,13 @@ NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__)); + if (info->builtin_domain) { + /* No users in builtin. */ + init_samr_r_enum_dom_users(r_u, q_u->start_idx, 0); + DEBUG(5,("_samr_enum_dom_users: No users in BUILTIN\n")); + return r_u->status; + } + become_root(); /* AS ROOT !!!! */ @@ -940,6 +947,13 @@ NTSTATUS _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAM DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__)); + if (info->builtin_domain) { + /* No groups in builtin. */ + init_samr_r_enum_dom_groups(r_u, q_u->start_idx, 0); + DEBUG(5,("_samr_enum_dom_users: No groups in BUILTIN\n")); + return r_u->status; + } + /* the domain group array is being allocated in the function below */ become_root(); -- cgit From 759ff937b3bbf768cd7534000f376a5f3a384b39 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 27 Nov 2005 21:51:46 +0000 Subject: r11936: Fix bug in returning remote time found by Thomas Bork . get_time_zone() was overwriting static buffer returned by gmtime(). Lars - this is a mandatory fix for the next patch... Jeremy. --- source/rpc_server/srv_srvsvc_nt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index a7162c929db..0e7ded39f57 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -1924,6 +1924,9 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET TIME_OF_DAY_INFO *tod; struct tm *t; time_t unixdate = time(NULL); + /* We do this call first as if we do it *after* the gmtime call + it overwrites the pointed-to values. JRA */ + uint32 zone = get_time_zone(unixdate)/60; tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO); if (!tod) @@ -1947,7 +1950,7 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET t->tm_min, t->tm_sec, 0, - get_time_zone(unixdate)/60, + zone, 10000, t->tm_mday, t->tm_mon + 1, -- cgit From 73720eb6306bb52a66e36a06387d3c24ef6043eb Mon Sep 17 00:00:00 2001 From: Steve French Date: Mon, 28 Nov 2005 05:43:21 +0000 Subject: r11938: Fix cifs to handle non-numeric uid and gid parameters and merge trunk and SAMBA_3 versions of mount.cifs and cleanup cifs vfs help. Modified version of patch from Olaf Kirch for Novell Bug 120601 --- source/client/mount.cifs.c | 164 +++++++++++++++++++++++++++++++++------------ 1 file changed, 122 insertions(+), 42 deletions(-) diff --git a/source/client/mount.cifs.c b/source/client/mount.cifs.c index 5750deb31ca..ed88c92c626 100755 --- a/source/client/mount.cifs.c +++ b/source/client/mount.cifs.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,7 @@ #include #define MOUNT_CIFS_VERSION_MAJOR "1" -#define MOUNT_CIFS_VERSION_MINOR "8" +#define MOUNT_CIFS_VERSION_MINOR "10" #ifndef MOUNT_CIFS_VENDOR_SUFFIX #define MOUNT_CIFS_VENDOR_SUFFIX "" @@ -83,11 +84,16 @@ static void mount_cifs_usage(void) printf(" to a local directory.\n\nOptions:\n"); printf("\tuser=\n\tpass=\n\tdom=\n"); printf("\nLess commonly used options:"); - printf("\n\tcredentials=,guest,perm,noperm,setuids,nosetuids,rw,ro,\n\tsep=,iocharset=,suid,nosuid,exec,noexec,serverino,\n\tdirectio,mapchars,nomapchars"); - printf("\n\nOptions not needed for servers supporting CIFS Unix extensions\n\t(e.g. most Samba versions):"); - printf("\n\tuid=,gid=,dir_mode=,file_mode="); + printf("\n\tcredentials=,guest,perm,noperm,setuids,nosetuids,rw,ro,"); + printf("\n\tsep=,iocharset=,suid,nosuid,exec,noexec,serverino,"); + printf("\n\tdirectio,mapchars,nomapchars,nolock,servernetbiosname="); + printf("\n\nOptions not needed for servers supporting CIFS Unix extensions"); + printf("\n\t(e.g. unneeded for mounts to most Samba versions):"); + printf("\n\tuid=,gid=,dir_mode=,file_mode=,sfu"); printf("\n\nRarely used options:"); - printf("\n\tport=,rsize=,wsize=,unc=,ip=,\n\tdev,nodev,nouser_xattr,netbiosname,hard,soft,intr,nointr,noacl"); + printf("\n\tport=,rsize=,wsize=,unc=,ip=,"); + printf("\n\tdev,nodev,nouser_xattr,netbiosname=,hard,soft,intr,"); + printf("\n\tnointr,ignorecase,noposixpaths,noacl"); printf("\n\nOptions are described in more detail in the manual page"); printf("\n\tman 8 mount.cifs\n"); printf("\nTo display the version number of the mount helper:"); @@ -127,8 +133,10 @@ static int open_cred_file(char * file_name) if(fs == NULL) return errno; line_buf = malloc(4096); - if(line_buf == NULL) + if(line_buf == NULL) { + fclose(fs); return -ENOMEM; + } while(fgets(line_buf,4096,fs)) { /* parse line from credential file */ @@ -282,21 +290,23 @@ static int get_password_from_file(int file_descript, char * filename) return rc; } -static int parse_options(char * options, int * filesys_flags) +static int parse_options(char ** optionsp, int * filesys_flags) { char * data; char * percent_char = NULL; char * value = NULL; char * next_keyword = NULL; + char * out = NULL; + int out_len = 0; + int word_len; int rc = 0; - if (!options) + if (!optionsp || !*optionsp) return 1; - else - data = options; + data = *optionsp; if(verboseflag) - printf("parsing options: %s\n", options); + printf("parsing options: %s\n", data); /* BB fixme check for separator override BB */ @@ -314,7 +324,7 @@ static int parse_options(char * options, int * filesys_flags) /* temporarily null terminate end of keyword=value pair */ if(next_keyword) - *next_keyword = 0; + *next_keyword++ = 0; /* temporarily null terminate keyword to make keyword and value distinct */ if ((value = strchr(data, '=')) != NULL) { @@ -324,7 +334,7 @@ static int parse_options(char * options, int * filesys_flags) if (strncmp(data, "users",5) == 0) { if(!value || !*value) { - strncpy(data,",,,,,",5); + goto nocopy; } } else if (strncmp(data, "user_xattr",10) == 0) { /* do nothing - need to skip so not parsed as user name */ @@ -336,10 +346,7 @@ static int parse_options(char * options, int * filesys_flags) printf("\nskipping empty user mount parameter\n"); /* remove the parm since it would otherwise be confusing to the kernel code which would think it was a real username */ - data[0] = ','; - data[1] = ','; - data[2] = ','; - data[3] = ','; + goto nocopy; } else { printf("username specified with no parameter\n"); return 1; /* needs_arg; */ @@ -458,10 +465,34 @@ static int parse_options(char * options, int * filesys_flags) } else if (strncmp(data, "uid", 3) == 0) { if (value && *value) { got_uid = 1; + if (!isdigit(*value)) { + struct passwd *pw; + static char temp[32]; + + if (!(pw = getpwnam(value))) { + printf("bad user name \"%s\"\n", value); + exit(1); + } + sprintf(temp, "%u", pw->pw_uid); + value = temp; + endpwent(); + } } } else if (strncmp(data, "gid", 3) == 0) { if (value && *value) { got_gid = 1; + if (!isdigit(*value)) { + struct group *gr; + static char temp[32]; + + if (!(gr = getgrnam(value))) { + printf("bad group name \"%s\"\n", value); + exit(1); + } + sprintf(temp, "%u", gr->gr_gid); + value = temp; + endpwent(); + } } /* fmask and dmask synonyms for people used to smbfs syntax */ } else if (strcmp(data, "file_mode") == 0 || strcmp(data, "fmask")==0) { @@ -504,6 +535,9 @@ static int parse_options(char * options, int * filesys_flags) *filesys_flags &= ~MS_NOSUID; } else if (strncmp(data, "nodev", 5) == 0) { *filesys_flags |= MS_NODEV; + } else if ((strncmp(data, "nobrl", 5) == 0) || + (strncmp(data, "nolock", 6) == 0)) { + *filesys_flags &= ~MS_MANDLOCK; } else if (strncmp(data, "dev", 3) == 0) { *filesys_flags &= ~MS_NODEV; } else if (strncmp(data, "noexec", 6) == 0) { @@ -513,11 +547,7 @@ static int parse_options(char * options, int * filesys_flags) } else if (strncmp(data, "guest", 5) == 0) { got_password=1; /* remove the parm since it would otherwise be logged by kern */ - data[0] = ','; - data[1] = ','; - data[2] = ','; - data[3] = ','; - data[4] = ','; + goto nocopy; } else if (strncmp(data, "ro", 2) == 0) { *filesys_flags |= MS_RDONLY; } else if (strncmp(data, "rw", 2) == 0) { @@ -545,21 +575,29 @@ static int parse_options(char * options, int * filesys_flags) } */ /* nothing to do on those four mount options above. Just pass to kernel and ignore them here */ - /* move to next option */ - data = next_keyword+1; + /* Copy (possibly modified) option to out */ + word_len = strlen(data); + if (value) + word_len += 1 + strlen(value); - /* put overwritten equals sign back */ - if(value) { - value--; - *value = '='; + out = realloc(out, out_len + word_len + 2); + if (out == NULL) { + perror("malloc"); + exit(1); } - - /* put previous overwritten comma back */ - if(next_keyword) - *next_keyword = ','; /* BB handle sep= */ + + if (out_len) + out[out_len++] = ','; + if (value) + sprintf(out + out_len, "%s=%s", data, value); else - data = NULL; + sprintf(out + out_len, "%s", data); + out_len = strlen(out); + +nocopy: + data = next_keyword; } + *optionsp = out; return 0; } @@ -570,13 +608,15 @@ static void check_for_comma(char ** ppasswrd) char *pass; int i,j; int number_of_commas = 0; - int len = strlen(*ppasswrd); + int len; if(ppasswrd == NULL) return; else (pass = *ppasswrd); + len = strlen(pass); + for(i=0;i 1023) { printf("mount error: UNC name too long"); @@ -715,6 +754,13 @@ static char * parse_server(char ** punc_name) if(share) { free_share_name = 1; *punc_name = malloc(length+3); + if(*punc_name == NULL) { + /* put the original string back if + no memory left */ + *punc_name = unc_name; + return NULL; + } + *share = '/'; strncpy((*punc_name)+2,unc_name,length); unc_name = *punc_name; @@ -744,8 +790,7 @@ continue_unc_parsing: return NULL; } if(host_entry == NULL) { - printf("mount error: could not find target server. TCP name %s not found ", unc_name); - printf(" rc = %d\n",rc); + printf("mount error: could not find target server. TCP name %s not found\n", unc_name); return NULL; } else { /* BB should we pass an alternate version of the share name as Unicode */ @@ -905,10 +950,44 @@ int main(int argc, char ** argv) wsize = atoi(optarg); break; case '1': - uid = atoi(optarg); + if (isdigit(*optarg)) { + char *ep; + + uid = strtoul(optarg, &ep, 10); + if (*ep) { + printf("bad uid value \"%s\"\n", optarg); + exit(1); + } + } else { + struct passwd *pw; + + if (!(pw = getpwnam(optarg))) { + printf("bad user name \"%s\"\n", optarg); + exit(1); + } + uid = pw->pw_uid; + endpwent(); + } break; case '2': - gid = atoi(optarg); + if (isdigit(*optarg)) { + char *ep; + + gid = strtoul(optarg, &ep, 10); + if (*ep) { + printf("bad gid value \"%s\"\n", optarg); + exit(1); + } + } else { + struct group *gr; + + if (!(gr = getgrnam(optarg))) { + printf("bad user name \"%s\"\n", optarg); + exit(1); + } + gid = gr->gr_gid; + endpwent(); + } break; case 'u': got_user = 1; @@ -954,7 +1033,7 @@ int main(int argc, char ** argv) get_password_from_file(0, getenv("PASSWD_FILE")); } - if (orgoptions && parse_options(orgoptions, &flags)) + if (orgoptions && parse_options(&orgoptions, &flags)) return -1; ipaddr = parse_server(&share_name); if((ipaddr == NULL) && (got_ip == 0)) { @@ -1018,6 +1097,9 @@ mount_retry: optlen = 0; if(share_name) optlen += strlen(share_name) + 4; + else { + printf("No server share name specified\n"); + } if(user_name) optlen += strlen(user_name) + 6; if(ipaddr) @@ -1126,8 +1208,6 @@ mount_retry: strcat(mountent.mnt_opts,"rw"); if(flags & MS_MANDLOCK) strcat(mountent.mnt_opts,",mand"); - else - strcat(mountent.mnt_opts,",nomand"); if(flags & MS_NOEXEC) strcat(mountent.mnt_opts,",noexec"); if(flags & MS_NOSUID) -- cgit From 2e670e20f9994978c12b6b4a7726d79186f7e20a Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 28 Nov 2005 15:56:10 +0000 Subject: r11942: patch from Marcin to fix the mkdir() in perfcount daemon --- examples/perfcounter/perf_writer_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/perfcounter/perf_writer_util.c b/examples/perfcounter/perf_writer_util.c index bb6422bac23..78a99fef494 100644 --- a/examples/perfcounter/perf_writer_util.c +++ b/examples/perfcounter/perf_writer_util.c @@ -77,7 +77,7 @@ void usage(char *progname) fprintf(stderr, "Usage: %s [-d] [-f ].\n", progname); fprintf(stderr, "\t-d: run as a daemon.\n"); fprintf(stderr, "\t-f : path where the TDB files reside.\n"); - fprintf(stderr, "\t\tDEFAULT is /tmp/counters\n"); + fprintf(stderr, "\t\tDEFAULT is /var/lib/samba/perfmon\n"); exit(1); } @@ -116,13 +116,13 @@ void setup_file_paths(RuntimeSettings *rt) if(strlen(rt->dbDir) == 0) { /* No file path was passed in, use default */ - sprintf(rt->dbDir, "/tmp/counters"); + sprintf(rt->dbDir, "/var/lib/samba/perfmon"); } sprintf(rt->nameFile, "%s/names.tdb", rt->dbDir); sprintf(rt->counterFile, "%s/data.tdb", rt->dbDir); - mkdir(rt->dbDir, O_RDWR); + mkdir(rt->dbDir, 0755); rt->cnames = tdb_open(rt->nameFile, 0, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0644); rt->cdata = tdb_open(rt->counterFile, 0, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0644); -- cgit From 07371ba0d16325d84aa904608c3e1c4350425c78 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Nov 2005 17:03:50 +0000 Subject: r11943: Don't reset attrs to zero in EA get - we are adding to the attr list not resetting it. Jeremy. --- source/smbd/dosmode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/smbd/dosmode.c b/source/smbd/dosmode.c index 5dfeddb80ac..7f3bda582df 100644 --- a/source/smbd/dosmode.c +++ b/source/smbd/dosmode.c @@ -190,7 +190,8 @@ static BOOL get_ea_dos_attribute(connection_struct *conn, const char *path,SMB_S return False; } - *pattr = 0; + /* Don't reset pattr to zero as we may already have filename-based attributes we + need to preserve. */ sizeret = SMB_VFS_GETXATTR(conn, path, SAMBA_XATTR_DOS_ATTRIB, attrstr, sizeof(attrstr)); if (sizeret == -1) { -- cgit From 9b4b815c9078f2e6dc64016667f72691a656e50c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Nov 2005 20:14:07 +0000 Subject: r11945: Make us follow the newly documented pathname processing rules: "As a special case for directories with large numbers of files, if the case options are set as follows, "case sensitive = yes", "case preserve = no", "short preserve case = no" then the "default case" option will be applied and will modify all filenames sent from the client when accessing this share." This is needed as fixing the case preserve rules to only apply to new filenames broke the large directory fix. Glad we caught this before release. Thanks to jht for this one. Jeremy. --- source/smbd/filename.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/smbd/filename.c b/source/smbd/filename.c index 2ee8ba1e4ff..6c0f8b77585 100644 --- a/source/smbd/filename.c +++ b/source/smbd/filename.c @@ -150,6 +150,19 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen pstrcpy(saved_last_component, name); } + /* + * Large directory fix normalization. If we're case sensitive, and + * the case preserving parameters are set to "no", normalize the case of + * the incoming filename from the client WHETHER IT EXISTS OR NOT ! + * This is in conflict with the current (3.0.20) man page, but is + * what people expect from the "large directory howto". I'll update + * the man page. Thanks to jht@samba.org for finding this. JRA. + */ + + if (conn->case_sensitive && !conn->case_preserve && !conn->short_case_preserve) { + strnorm(name, lp_defaultcase(SNUM(conn))); + } + start = name; pstrcpy(orig_path, name); -- cgit From f0ef3d7c2a88d1f5939f7094fcbb19898f024d79 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 28 Nov 2005 20:42:18 +0000 Subject: r11947: Back out passdb:expand_explicit until we find consensus. I'll file this as a bugzilla entry. Volker --- source/passdb/passdb.c | 17 +++-------------- source/passdb/pdb_ldap.c | 17 +++-------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index 7f9cc7df9f5..c893ebcd424 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -1751,8 +1751,6 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) uint32 pwHistLen = 0; BOOL ret = True; fstring tmpstring; - BOOL expand_explicit = lp_parm_bool(-1, "passdb", "expand_explicit", - False); if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); @@ -1817,10 +1815,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (homedir) { fstrcpy( tmpstring, homedir ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_homedir(sampass, tmpstring, PDB_SET); } else { @@ -1836,10 +1831,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (logon_script) { fstrcpy( tmpstring, logon_script ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_logon_script(sampass, tmpstring, PDB_SET); } else { @@ -1850,10 +1842,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (profile_path) { fstrcpy( tmpstring, profile_path ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_profile_path(sampass, tmpstring, PDB_SET); } else { diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 1254dba2b89..66efe5a8ae6 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -604,8 +604,6 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, LOGIN_CACHE *cache_entry = NULL; uint32 pwHistLen; pstring tmpstring; - BOOL expand_explicit = lp_parm_bool(-1, "passdb", "expand_explicit", - False); /* * do a little initialization @@ -778,10 +776,7 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, homedir ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_homedir(sampass, tmpstring, PDB_SET); } @@ -793,10 +788,7 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, logon_script ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_logon_script(sampass, tmpstring, PDB_SET); } @@ -808,10 +800,7 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, profile_path ); - if (expand_explicit) { - standard_sub_basic( username, tmpstring, - sizeof(tmpstring) ); - } + standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); pdb_set_profile_path(sampass, tmpstring, PDB_SET); } -- cgit From 8efaa1f94ff612737ba7b877ce24ae652eb946c5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Nov 2005 02:10:52 +0000 Subject: r11950: If we got a connection oriented cancel pdu we would spin processing it. Fix that, and also add in comments for all possible CL and CO PDU types. Make sure we process them correctly. Jeremy. --- source/include/rpc_dce.h | 30 ++++++++++----- source/rpc_server/srv_pipe.c | 49 ++++++++++++++++++++++++ source/rpc_server/srv_pipe_hnd.c | 81 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 148 insertions(+), 12 deletions(-) diff --git a/source/include/rpc_dce.h b/source/include/rpc_dce.h index 3de4d2b691e..e718d92271c 100644 --- a/source/include/rpc_dce.h +++ b/source/include/rpc_dce.h @@ -26,15 +26,27 @@ /* DCE/RPC packet types */ enum RPC_PKT_TYPE { - RPC_REQUEST = 0x00, - RPC_RESPONSE = 0x02, - RPC_FAULT = 0x03, - RPC_BIND = 0x0B, - RPC_BINDACK = 0x0C, - RPC_BINDNACK = 0x0D, - RPC_ALTCONT = 0x0E, - RPC_ALTCONTRESP = 0x0F, - RPC_AUTH3 = 0x10 /* not the real name! this is undocumented! */ + RPC_REQUEST = 0x00, /* Ordinary request. */ + RPC_PING = 0x01, /* Connectionless is server alive ? */ + RPC_RESPONSE = 0x02, /* Ordinary reply. */ + RPC_FAULT = 0x03, /* Fault in processing of call. */ + RPC_WORKING = 0x04, /* Connectionless reply to a ping when server busy. */ + RPC_NOCALL = 0x05, /* Connectionless reply to a ping when server has lost part of clients call. */ + RPC_REJECT = 0x06, /* Refuse a request with a code. */ + RPC_ACK = 0x07, /* Connectionless client to server code. */ + RPC_CL_CANCEL= 0x08, /* Connectionless cancel. */ + RPC_FACK = 0x09, /* Connectionless fragment ack. Both client and server send. */ + RPC_CANCEL_ACK = 0x0A, /* Server ACK to client cancel request. */ + RPC_BIND = 0x0B, /* Bind to interface. */ + RPC_BINDACK = 0x0C, /* Server ack of bind. */ + RPC_BINDNACK = 0x0D, /* Server nack of bind. */ + RPC_ALTCONT = 0x0E, /* Alter auth. */ + RPC_ALTCONTRESP = 0x0F, /* Reply to alter auth. */ + RPC_AUTH3 = 0x10, /* not the real name! this is undocumented! */ + RPC_SHUTDOWN = 0x11, /* Server to client request to shutdown. */ + RPC_CO_CANCEL= 0x12, /* Connection-oriented cancel request. */ + RPC_ORPHANED = 0x13 /* Client telling server it's aborting a partially sent request or telling + server to stop sending replies. */ }; /* DCE/RPC flags */ diff --git a/source/rpc_server/srv_pipe.c b/source/rpc_server/srv_pipe.c index b615080d349..8084e7673a5 100644 --- a/source/rpc_server/srv_pipe.c +++ b/source/rpc_server/srv_pipe.c @@ -892,6 +892,55 @@ BOOL setup_fault_pdu(pipes_struct *p, NTSTATUS status) return True; } +#if 0 +/******************************************************************* + Marshall a cancel_ack pdu. + We should probably check the auth-verifier here. +*******************************************************************/ + +BOOL setup_cancel_ack_reply(pipes_struct *p, prs_struct *rpc_in_p) +{ + prs_struct outgoing_pdu; + RPC_HDR ack_reply_hdr; + + /* Free any memory in the current return data buffer. */ + prs_mem_free(&p->out_data.rdata); + + /* + * Marshall directly into the outgoing PDU space. We + * must do this as we need to set to the bind response + * header and are never sending more than one PDU here. + */ + + prs_init( &outgoing_pdu, 0, p->mem_ctx, MARSHALL); + prs_give_memory( &outgoing_pdu, (char *)p->out_data.current_pdu, sizeof(p->out_data.current_pdu), False); + + /* + * Initialize a cancel_ack header. + */ + + init_rpc_hdr(&ack_reply_hdr, RPC_CANCEL_ACK, RPC_FLG_FIRST | RPC_FLG_LAST, + p->hdr.call_id, RPC_HEADER_LEN, 0); + + /* + * Marshall the header into the outgoing PDU. + */ + + if(!smb_io_rpc_hdr("", &ack_reply_hdr, &outgoing_pdu, 0)) { + DEBUG(0,("setup_cancel_ack_reply: marshalling of RPC_HDR failed.\n")); + prs_mem_free(&outgoing_pdu); + return False; + } + + p->out_data.data_sent_length = 0; + p->out_data.current_pdu_len = prs_offset(&outgoing_pdu); + p->out_data.current_pdu_sent = 0; + + prs_mem_free(&outgoing_pdu); + return True; +} +#endif + /******************************************************************* Ensure a bind request has the correct abstract & transfer interface. Used to reject unknown binds from Win2k. diff --git a/source/rpc_server/srv_pipe_hnd.c b/source/rpc_server/srv_pipe_hnd.c index 6077faed164..5fb84115cc3 100644 --- a/source/rpc_server/srv_pipe_hnd.c +++ b/source/rpc_server/srv_pipe_hnd.c @@ -716,6 +716,32 @@ static void process_complete_pdu(pipes_struct *p) (unsigned int)p->hdr.pkt_type )); switch (p->hdr.pkt_type) { + case RPC_REQUEST: + reply = process_request_pdu(p, &rpc_in); + break; + + case RPC_PING: /* CL request - ignore... */ + DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n", + (unsigned int)p->hdr.pkt_type, p->name)); + break; + + case RPC_RESPONSE: /* No responses here. */ + DEBUG(0,("process_complete_pdu: Error. RPC_RESPONSE received from client on pipe %s.\n", + p->name )); + break; + + case RPC_FAULT: + case RPC_WORKING: /* CL request - reply to a ping when a call in process. */ + case RPC_NOCALL: /* CL - server reply to a ping call. */ + case RPC_REJECT: + case RPC_ACK: + case RPC_CL_CANCEL: + case RPC_FACK: + case RPC_CANCEL_ACK: + DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n", + (unsigned int)p->hdr.pkt_type, p->name)); + break; + case RPC_BIND: /* * We assume that a pipe bind is only in one pdu. @@ -724,6 +750,14 @@ static void process_complete_pdu(pipes_struct *p) reply = api_pipe_bind_req(p, &rpc_in); } break; + + case RPC_BINDACK: + case RPC_BINDNACK: + DEBUG(0,("process_complete_pdu: Error. RPC_BINDACK/RPC_BINDNACK packet type %u received on pipe %s.\n", + (unsigned int)p->hdr.pkt_type, p->name)); + break; + + case RPC_ALTCONT: /* * We assume that a pipe bind is only in one pdu. @@ -732,6 +766,12 @@ static void process_complete_pdu(pipes_struct *p) reply = api_pipe_alter_context(p, &rpc_in); } break; + + case RPC_ALTCONTRESP: + DEBUG(0,("process_complete_pdu: Error. RPC_ALTCONTRESP on pipe %s: Should only be server -> client.\n", + p->name)); + break; + case RPC_AUTH3: /* * The third packet in an NTLMSSP auth exchange. @@ -740,9 +780,38 @@ static void process_complete_pdu(pipes_struct *p) reply = api_pipe_bind_auth3(p, &rpc_in); } break; - case RPC_REQUEST: - reply = process_request_pdu(p, &rpc_in); + + case RPC_SHUTDOWN: + DEBUG(0,("process_complete_pdu: Error. RPC_SHUTDOWN on pipe %s: Should only be server -> client.\n", + p->name)); + break; + + case RPC_CO_CANCEL: + /* For now just free all client data and continue processing. */ + DEBUG(3,("process_complete_pdu: RPC_ORPHANED. Abandoning rpc call.\n")); + /* As we never do asynchronous RPC serving, we can never cancel a + call (as far as I know). If we ever did we'd have to send a cancel_ack + reply. For now, just free all client data and continue processing. */ + reply = True; break; +#if 0 + /* Enable this if we're doing async rpc. */ + /* We must check the call-id matches the outstanding callid. */ + if(pipe_init_outgoing_data(p)) { + /* Send a cancel_ack PDU reply. */ + /* We should probably check the auth-verifier here. */ + reply = setup_cancel_ack_reply(p, &rpc_in); + } + break; +#endif + + case RPC_ORPHANED: + /* We should probably check the auth-verifier here. + For now just free all client data and continue processing. */ + DEBUG(3,("process_complete_pdu: RPC_ORPHANED. Abandoning rpc call.\n")); + reply = True; + break; + default: DEBUG(0,("process_complete_pdu: Unknown rpc type = %u received.\n", (unsigned int)p->hdr.pkt_type )); break; @@ -815,7 +884,13 @@ incoming data size = %u\n", (unsigned int)p->in_data.pdu_received_len, (unsigned */ if(p->in_data.pdu_needed_len == 0) { - return unmarshall_rpc_header(p); + ssize_t rret = unmarshall_rpc_header(p); + if (rret == -1 || p->in_data.pdu_needed_len > 0) { + return rret; + } + /* If rret == 0 and pdu_needed_len == 0 here we have a PDU that consists + of an RPC_HEADER only. This is a RPC_SHUTDOWN, RPC_CO_CANCEL or RPC_ORPHANED + pdu type. Deal with this in process_complete_pdu(). */ } /* -- cgit From 83e263e472a6f7fd2c33aa41c0d29204c29f4ab4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 29 Nov 2005 22:46:16 +0000 Subject: r11960: add 'wbinfo --separator' to get the currently active winbind_separator. Needed for KDM/GDM login masks. Guenther --- source/nsswitch/wbinfo.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c index 45195fb86ab..aae76e44238 100644 --- a/source/nsswitch/wbinfo.c +++ b/source/nsswitch/wbinfo.c @@ -30,7 +30,7 @@ extern int winbindd_fd; -static char winbind_separator(void) +static char winbind_separator_int(BOOL strict) { struct winbindd_response response; static BOOL got_sep; @@ -46,6 +46,9 @@ static char winbind_separator(void) if (winbindd_request_response(WINBINDD_INFO, NULL, &response) != NSS_STATUS_SUCCESS) { d_printf("could not obtain winbind separator!\n"); + if (strict) { + return -1; + } /* HACK: (this module should not call lp_ funtions) */ return *lp_winbind_separator(); } @@ -55,6 +58,9 @@ static char winbind_separator(void) if (!sep) { d_printf("winbind separator was NULL!\n"); + if (strict) { + return -1; + } /* HACK: (this module should not call lp_ funtions) */ sep = *lp_winbind_separator(); } @@ -62,6 +68,11 @@ static char winbind_separator(void) return sep; } +static char winbind_separator(void) +{ + return winbind_separator_int(False); +} + static const char *get_winbind_domain(void) { struct winbindd_response response; @@ -956,7 +967,8 @@ enum { OPT_SEQUENCE, OPT_GETDCNAME, OPT_USERDOMGROUPS, - OPT_USERSIDS + OPT_USERSIDS, + OPT_SEPARATOR }; int main(int argc, char **argv) @@ -1004,6 +1016,7 @@ int main(int argc, char **argv) #ifdef WITH_FAKE_KASERVER { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" }, #endif + { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL }, POPT_COMMON_VERSION POPT_TABLEEND }; @@ -1197,6 +1210,10 @@ int main(int argc, char **argv) case OPT_GETDCNAME: wbinfo_getdcname(string_arg); break; + case OPT_SEPARATOR: + d_printf("%c\n", winbind_separator_int(True)); + break; + /* generic configuration options */ case OPT_DOMAIN_NAME: break; -- cgit From e2684f671444073d2558e5dcf0c9b0dbc26ae1d6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Nov 2005 23:01:39 +0000 Subject: r11962: Bring talloc up to date with Samba4, re-add the talloc_describe_all() function. Fix smbcontrol pool-usage as we desparately need it working in the field to track down memory leaks. Seriously, when new functionality like the Samba4 talloc is added, don't just disable working functionality like "pool-usage", fix the damn thing first ! Jeremy. --- source/Makefile.in | 2 +- source/lib/talloc.c | 263 +++++++++++++++++++++++++++++++++++++--------- source/lib/tallocmsg.c | 15 ++- source/utils/smbcontrol.c | 4 +- 4 files changed, 229 insertions(+), 55 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index 26095f6d830..888a0ebe344 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -106,7 +106,7 @@ LIBSMBSHAREMODES=bin/libsmbsharemodes.a @LIBSMBSHAREMODES_SHARED@ LIBSMBSHAREMODES_MAJOR=0 LIBSMBSHAREMODES_MINOR=1 -FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) +FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ FLAGS2 = FLAGS3 = FLAGS4 = diff --git a/source/lib/talloc.c b/source/lib/talloc.c index 2df4588f425..b95e35152fe 100644 --- a/source/lib/talloc.c +++ b/source/lib/talloc.c @@ -26,7 +26,6 @@ inspired by http://swapped.cc/halloc/ */ - #ifdef _SAMBA_BUILD_ #include "includes.h" #if ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) @@ -56,8 +55,9 @@ #define MAX_TALLOC_SIZE 0x10000000 -#define TALLOC_MAGIC 0xe814ec4f -#define TALLOC_MAGIC_FREE 0x7faebef3 +#define TALLOC_MAGIC 0xe814ec70 +#define TALLOC_FLAG_FREE 0x01 +#define TALLOC_FLAG_LOOP 0x02 #define TALLOC_MAGIC_REFERENCE ((const char *)1) /* by default we abort when given a bad pointer (such as when talloc_free() is called @@ -93,27 +93,27 @@ struct talloc_chunk { struct talloc_chunk *next, *prev; struct talloc_chunk *parent, *child; struct talloc_reference_handle *refs; - size_t size; talloc_destructor_t destructor; const char *name; - union { - unsigned magic; - double align_dummy; - } u; + size_t size; + unsigned flags; }; +/* 16 byte alignment seems to keep everyone happy */ +#define TC_HDR_SIZE ((sizeof(struct talloc_chunk)+15)&~15) +#define TC_PTR_FROM_CHUNK(tc) ((void *)(TC_HDR_SIZE + (char*)tc)) + /* panic if we get a bad magic value */ static struct talloc_chunk *talloc_chunk_from_ptr(const void *ptr) { - struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, ptr)-1; - if (tc->u.magic != TALLOC_MAGIC) { - if (tc->u.magic == TALLOC_MAGIC_FREE) { - TALLOC_ABORT("Bad talloc magic value - double free"); - } else { - TALLOC_ABORT("Bad talloc magic value - unknown value"); - } + const char *pp = ptr; + struct talloc_chunk *tc = discard_const_p(struct talloc_chunk, pp - TC_HDR_SIZE); + if ((tc->flags & ~0xF) != TALLOC_MAGIC) { + TALLOC_ABORT("Bad talloc magic value - unknown value"); + } + if (tc->flags & TALLOC_FLAG_FREE) { + TALLOC_ABORT("Bad talloc magic value - double free"); } - return tc; } @@ -158,7 +158,7 @@ static struct talloc_chunk *talloc_parent_chunk(const void *ptr) void *talloc_parent(const void *ptr) { struct talloc_chunk *tc = talloc_parent_chunk(ptr); - return tc ? (void *)(tc+1) : NULL; + return tc? TC_PTR_FROM_CHUNK(tc) : NULL; } /* @@ -176,11 +176,11 @@ void *_talloc(const void *context, size_t size) return NULL; } - tc = malloc(sizeof(*tc)+size); + tc = malloc(TC_HDR_SIZE+size); if (tc == NULL) return NULL; tc->size = size; - tc->u.magic = TALLOC_MAGIC; + tc->flags = TALLOC_MAGIC; tc->destructor = NULL; tc->child = NULL; tc->name = NULL; @@ -200,7 +200,7 @@ void *_talloc(const void *context, size_t size) tc->next = tc->prev = tc->parent = NULL; } - return (void *)(tc+1); + return TC_PTR_FROM_CHUNK(tc); } @@ -285,7 +285,7 @@ static int talloc_unreference(const void *context, const void *ptr) for (h=tc->refs;h;h=h->next) { struct talloc_chunk *p = talloc_parent_chunk(h); - if ((p==NULL && context==NULL) || p+1 == context) break; + if ((p==NULL && context==NULL) || TC_PTR_FROM_CHUNK(p) == context) break; } if (h == NULL) { return -1; @@ -336,7 +336,7 @@ int talloc_unlink(const void *context, void *ptr) new_p = talloc_parent_chunk(tc_p->refs); if (new_p) { - new_parent = new_p+1; + new_parent = TC_PTR_FROM_CHUNK(new_p); } else { new_parent = NULL; } @@ -464,6 +464,8 @@ void *talloc_init(const char *fmt, ...) va_list ap; void *ptr; + talloc_enable_null_tracking(); + ptr = _talloc(NULL, 0); if (ptr == NULL) return NULL; @@ -495,16 +497,16 @@ void talloc_free_children(void *ptr) choice is owner of any remaining reference to this pointer, the second choice is our parent, and the final choice is the null context. */ - void *child = tc->child+1; + void *child = TC_PTR_FROM_CHUNK(tc->child); const void *new_parent = null_context; if (tc->child->refs) { struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs); - if (p) new_parent = p+1; + if (p) new_parent = TC_PTR_FROM_CHUNK(p); } if (talloc_free(child) == -1) { if (new_parent == null_context) { struct talloc_chunk *p = talloc_parent_chunk(ptr); - if (p) new_parent = p+1; + if (p) new_parent = TC_PTR_FROM_CHUNK(p); } talloc_steal(new_parent, child); } @@ -534,6 +536,11 @@ int talloc_free(void *ptr) return -1; } + if (tc->flags & TALLOC_FLAG_LOOP) { + /* we have a free loop - stop looping */ + return 0; + } + if (tc->destructor) { talloc_destructor_t d = tc->destructor; if (d == (talloc_destructor_t)-1) { @@ -547,6 +554,8 @@ int talloc_free(void *ptr) tc->destructor = NULL; } + tc->flags |= TALLOC_FLAG_LOOP; + talloc_free_children(ptr); if (tc->parent) { @@ -559,7 +568,7 @@ int talloc_free(void *ptr) if (tc->next) tc->next->prev = tc->prev; } - tc->u.magic = TALLOC_MAGIC_FREE; + tc->flags |= TALLOC_FLAG_FREE; free(tc); return 0; @@ -599,24 +608,24 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n } /* by resetting magic we catch users of the old memory */ - tc->u.magic = TALLOC_MAGIC_FREE; + tc->flags |= TALLOC_FLAG_FREE; #if ALWAYS_REALLOC - new_ptr = malloc(size + sizeof(*tc)); + new_ptr = malloc(size + TC_HDR_SIZE); if (new_ptr) { - memcpy(new_ptr, tc, tc->size + sizeof(*tc)); + memcpy(new_ptr, tc, tc->size + TC_HDR_SIZE); free(tc); } #else - new_ptr = realloc(tc, size + sizeof(*tc)); + new_ptr = realloc(tc, size + TC_HDR_SIZE); #endif if (!new_ptr) { - tc->u.magic = TALLOC_MAGIC; + tc->flags &= ~TALLOC_FLAG_FREE; return NULL; } tc = new_ptr; - tc->u.magic = TALLOC_MAGIC; + tc->flags &= ~TALLOC_FLAG_FREE; if (tc->parent) { tc->parent->child = new_ptr; } @@ -632,9 +641,9 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n } tc->size = size; - talloc_set_name_const(tc+1, name); + talloc_set_name_const(TC_PTR_FROM_CHUNK(tc), name); - return (void *)(tc+1); + return TC_PTR_FROM_CHUNK(tc); } /* @@ -711,10 +720,19 @@ off_t talloc_total_size(const void *ptr) tc = talloc_chunk_from_ptr(ptr); + if (tc->flags & TALLOC_FLAG_LOOP) { + return 0; + } + + tc->flags |= TALLOC_FLAG_LOOP; + total = tc->size; for (c=tc->child;c;c=c->next) { - total += talloc_total_size(c+1); + total += talloc_total_size(TC_PTR_FROM_CHUNK(c)); } + + tc->flags &= ~TALLOC_FLAG_LOOP; + return total; } @@ -726,10 +744,19 @@ off_t talloc_total_blocks(const void *ptr) off_t total = 0; struct talloc_chunk *c, *tc = talloc_chunk_from_ptr(ptr); + if (tc->flags & TALLOC_FLAG_LOOP) { + return 0; + } + + tc->flags |= TALLOC_FLAG_LOOP; + total++; for (c=tc->child;c;c=c->next) { - total += talloc_total_blocks(c+1); + total += talloc_total_blocks(TC_PTR_FROM_CHUNK(c)); } + + tc->flags &= ~TALLOC_FLAG_LOOP; + return total; } @@ -755,23 +782,29 @@ void talloc_report_depth(const void *ptr, FILE *f, int depth) { struct talloc_chunk *c, *tc = talloc_chunk_from_ptr(ptr); + if (tc->flags & TALLOC_FLAG_LOOP) { + return; + } + + tc->flags |= TALLOC_FLAG_LOOP; + for (c=tc->child;c;c=c->next) { if (c->name == TALLOC_MAGIC_REFERENCE) { - struct talloc_reference_handle *handle = (void *)(c+1); + struct talloc_reference_handle *handle = TC_PTR_FROM_CHUNK(c); const char *name2 = talloc_get_name(handle->ptr); fprintf(f, "%*sreference to: %s\n", depth*4, "", name2); } else { - const char *name = talloc_get_name(c+1); + const char *name = talloc_get_name(TC_PTR_FROM_CHUNK(c)); fprintf(f, "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n", depth*4, "", name, - (unsigned long)talloc_total_size(c+1), - (unsigned long)talloc_total_blocks(c+1), - talloc_reference_count(c+1)); - talloc_report_depth(c+1, f, depth+1); + (unsigned long)talloc_total_size(TC_PTR_FROM_CHUNK(c)), + (unsigned long)talloc_total_blocks(TC_PTR_FROM_CHUNK(c)), + talloc_reference_count(TC_PTR_FROM_CHUNK(c))); + talloc_report_depth(TC_PTR_FROM_CHUNK(c), f, depth+1); } } - + tc->flags &= ~TALLOC_FLAG_LOOP; } /* @@ -814,9 +847,9 @@ void talloc_report(const void *ptr, FILE *f) for (c=tc->child;c;c=c->next) { fprintf(f, "\t%-30s contains %6lu bytes in %3lu blocks\n", - talloc_get_name(c+1), - (unsigned long)talloc_total_size(c+1), - (unsigned long)talloc_total_blocks(c+1)); + talloc_get_name(TC_PTR_FROM_CHUNK(c)), + (unsigned long)talloc_total_size(TC_PTR_FROM_CHUNK(c)), + (unsigned long)talloc_total_blocks(TC_PTR_FROM_CHUNK(c))); } fflush(f); } @@ -851,6 +884,74 @@ void talloc_enable_null_tracking(void) } } +#ifdef _SAMBA_BUILD_ +/* Ugly calls to Samba-specific sprintf_append... JRA. */ + +/* + report on memory usage by all children of a pointer, giving a full tree view +*/ +static void talloc_report_depth_str(const void *ptr, char **pps, ssize_t *plen, size_t *pbuflen, int depth) +{ + struct talloc_chunk *c, *tc = talloc_chunk_from_ptr(ptr); + + if (tc->flags & TALLOC_FLAG_LOOP) { + return; + } + + tc->flags |= TALLOC_FLAG_LOOP; + + for (c=tc->child;c;c=c->next) { + if (c->name == TALLOC_MAGIC_REFERENCE) { + struct talloc_reference_handle *handle = TC_PTR_FROM_CHUNK(c); + const char *name2 = talloc_get_name(handle->ptr); + + sprintf_append(NULL, pps, plen, pbuflen, + "%*sreference to: %s\n", depth*4, "", name2); + + } else { + const char *name = talloc_get_name(TC_PTR_FROM_CHUNK(c)); + + sprintf_append(NULL, pps, plen, pbuflen, + "%*s%-30s contains %6lu bytes in %3lu blocks (ref %d)\n", + depth*4, "", + name, + (unsigned long)talloc_total_size(TC_PTR_FROM_CHUNK(c)), + (unsigned long)talloc_total_blocks(TC_PTR_FROM_CHUNK(c)), + talloc_reference_count(TC_PTR_FROM_CHUNK(c))); + + talloc_report_depth_str(TC_PTR_FROM_CHUNK(c), pps, plen, pbuflen, depth+1); + } + } + tc->flags &= ~TALLOC_FLAG_LOOP; +} + +/* + report on memory usage by all children of a pointer +*/ +char *talloc_describe_all(void) +{ + ssize_t len = 0; + size_t buflen = 512; + char *s = NULL; + + if (null_context == NULL) { + return NULL; + } + + sprintf_append(NULL, &s, &len, &buflen, + "full talloc report on '%s' (total %lu bytes in %lu blocks)\n", + talloc_get_name(null_context), + (unsigned long)talloc_total_size(null_context), + (unsigned long)talloc_total_blocks(null_context)); + + if (!s) { + return NULL; + } + talloc_report_depth_str(null_context, &s, &len, &buflen, 1); + return s; +} +#endif + /* enable leak reporting on exit */ @@ -914,6 +1015,28 @@ char *talloc_strdup(const void *t, const char *p) return ret; } +/* + append to a talloced string +*/ +char *talloc_append_string(const void *t, char *orig, const char *append) +{ + char *ret; + size_t olen = strlen(orig); + size_t alenz = strlen(append) + 1; + + if (!append) + return orig; + + ret = talloc_realloc(t, orig, char, olen + alenz); + if (!ret) + return NULL; + + /* append the string with the trailing \0 */ + memcpy(&ret[olen], append, alenz); + + return ret; +} + /* strndup with a talloc */ @@ -989,6 +1112,7 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINT static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) { + struct talloc_chunk *tc; int len, s_len; va_list ap2; @@ -996,9 +1120,11 @@ static char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) return talloc_vasprintf(NULL, fmt, ap); } + tc = talloc_chunk_from_ptr(s); + VA_COPY(ap2, ap); - s_len = strlen(s); + s_len = tc->size - 1; len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(NULL, s, char, s_len + len+1); @@ -1102,3 +1228,46 @@ size_t talloc_get_size(const void *context) return tc->size; } + +/* + find a parent of this context that has the given name, if any +*/ +void *talloc_find_parent_byname(const void *context, const char *name) +{ + struct talloc_chunk *tc; + + if (context == NULL) { + return NULL; + } + + tc = talloc_chunk_from_ptr(context); + while (tc) { + if (tc->name && strcmp(tc->name, name) == 0) { + return TC_PTR_FROM_CHUNK(tc); + } + while (tc && tc->prev) tc = tc->prev; + tc = tc->parent; + } + return NULL; +} + +/* + show the parentage of a context +*/ +void talloc_show_parents(const void *context, FILE *file) +{ + struct talloc_chunk *tc; + + if (context == NULL) { + fprintf(file, "talloc no parents for NULL\n"); + return; + } + + tc = talloc_chunk_from_ptr(context); + fprintf(file, "talloc parents of '%s'\n", talloc_get_name(context)); + while (tc) { + fprintf(file, "\t'%s'\n", talloc_get_name(TC_PTR_FROM_CHUNK(tc))); + while (tc && tc->prev) tc = tc->prev; + tc = tc->parent; + } +} diff --git a/source/lib/tallocmsg.c b/source/lib/tallocmsg.c index 8f03fd66ff1..b515093cd69 100644 --- a/source/lib/tallocmsg.c +++ b/source/lib/tallocmsg.c @@ -33,18 +33,23 @@ void msg_pool_usage(int msg_type, struct process_id src_pid, void *UNUSED(buf), size_t UNUSED(len)) { - off_t reply; - fstring reply_str; + char *reply = NULL; SMB_ASSERT(msg_type == MSG_REQ_POOL_USAGE); DEBUG(2,("Got POOL_USAGE\n")); - reply = talloc_total_size(NULL); - fstr_sprintf(reply_str, "%ld", (long)reply); + reply = talloc_describe_all(); + if (!reply) { + return; + } + become_root(); message_send_pid(src_pid, MSG_POOL_USAGE, - reply_str, strlen(reply_str)+1, True); + reply, strlen(reply)+1, True); + unbecome_root(); + + SAFE_FREE(reply); } /** diff --git a/source/utils/smbcontrol.c b/source/utils/smbcontrol.c index a0304eb89a9..25b42a58c1e 100644 --- a/source/utils/smbcontrol.c +++ b/source/utils/smbcontrol.c @@ -508,13 +508,13 @@ static BOOL do_poolusage(const struct process_id pid, return False; } + message_register(MSG_POOL_USAGE, print_string_cb); + /* Send a message and register our interest in a reply */ if (!send_message(pid, MSG_REQ_POOL_USAGE, NULL, 0, False)) return False; - message_register(MSG_POOL_USAGE, print_string_cb); - wait_replies(procid_to_pid(&pid) == 0); /* No replies were received within the timeout period */ -- cgit From 6398eb3a4ec49d10f4260046ac1dc270f7bdf5be Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 29 Nov 2005 23:23:02 +0000 Subject: r11963: add rpccli_samr_chgpasswd3 from samba4. Guenther --- source/include/rpc_samr.h | 43 +++++++++++ source/rpc_client/cli_samr.c | 89 ++++++++++++++++++++++ source/rpc_parse/parse_samr.c | 168 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 299 insertions(+), 1 deletion(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index ac56e2dcc62..236c37a17e2 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -143,6 +143,7 @@ SamrTestPrivateFunctionsUser #define SAMR_CONNECT 0x39 #define SAMR_SET_USERINFO 0x3A #define SAMR_CONNECT4 0x3E +#define SAMR_CHGPASSWD3 0x3F #define SAMR_CONNECT5 0x40 typedef struct logon_hours_info @@ -1810,6 +1811,48 @@ typedef struct r_samr_chgpasswd_user_info } SAMR_R_CHGPASSWD_USER; +/* SAMR_Q_CHGPASSWD3 */ +typedef struct q_samr_chgpasswd3 +{ + uint32 ptr_0; + + UNIHDR hdr_dest_host; /* server name unicode header */ + UNISTR2 uni_dest_host; /* server name unicode string */ + + UNIHDR hdr_user_name; /* username unicode string header */ + UNISTR2 uni_user_name; /* username unicode string */ + + SAMR_ENC_PASSWD nt_newpass; + SAMR_ENC_HASH nt_oldhash; + + uint32 lm_change; /* 0x0000 0001 */ + + SAMR_ENC_PASSWD lm_newpass; + SAMR_ENC_HASH lm_oldhash; + + SAMR_ENC_PASSWD password3; + +} SAMR_Q_CHGPASSWD3; + +/* SAMR_CHANGE_REJECT */ +typedef struct samr_change_reject +{ + uint32 reject_reason; + uint32 unknown1; + uint32 unknown2; + +} SAMR_CHANGE_REJECT; + +/* SAMR_R_CHGPASSWD3 */ +typedef struct r_samr_chgpasswd3 +{ + SAM_UNK_INFO_1 info; + SAMR_CHANGE_REJECT reject; + NTSTATUS status; /* 0 == OK, C000006A (NT_STATUS_WRONG_PASSWORD) */ + +} SAMR_R_CHGPASSWD3; + + /* SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN */ typedef struct q_samr_remove_sid_foreign_domain_info diff --git a/source/rpc_client/cli_samr.c b/source/rpc_client/cli_samr.c index 047d0a1f956..fb95da97aef 100644 --- a/source/rpc_client/cli_samr.c +++ b/source/rpc_client/cli_samr.c @@ -1205,6 +1205,95 @@ NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli, return result; } +/* change password 3 */ + +NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli, + TALLOC_CTX *mem_ctx, + const char *username, + const char *newpassword, + const char *oldpassword, + SAM_UNK_INFO_1 **info, + SAMR_CHANGE_REJECT **reject) +{ + prs_struct qbuf, rbuf; + SAMR_Q_CHGPASSWD3 q; + SAMR_R_CHGPASSWD3 r; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + + uchar new_nt_password[516]; + uchar new_lm_password[516]; + uchar old_nt_hash[16]; + uchar old_lanman_hash[16]; + uchar old_nt_hash_enc[16]; + uchar old_lanman_hash_enc[16]; + + uchar new_nt_hash[16]; + uchar new_lanman_hash[16]; + + char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost); + + DEBUG(10,("rpccli_samr_chgpasswd3\n")); + + ZERO_STRUCT(q); + ZERO_STRUCT(r); + + *info = NULL; + *reject = NULL; + + /* Calculate the MD4 hash (NT compatible) of the password */ + E_md4hash(oldpassword, old_nt_hash); + E_md4hash(newpassword, new_nt_hash); + + if (lp_client_lanman_auth() + && E_deshash(newpassword, new_lanman_hash) + && E_deshash(oldpassword, old_lanman_hash)) { + /* E_deshash returns false for 'long' passwords (> 14 + DOS chars). This allows us to match Win2k, which + does not store a LM hash for these passwords (which + would reduce the effective password length to 14) */ + + encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE); + + SamOEMhash( new_lm_password, old_nt_hash, 516); + E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc); + } else { + ZERO_STRUCT(new_lm_password); + ZERO_STRUCT(old_lanman_hash_enc); + } + + encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE); + + SamOEMhash( new_nt_password, old_nt_hash, 516); + E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc); + + /* Marshall data and send request */ + + init_samr_q_chgpasswd3(&q, srv_name_slash, username, + new_nt_password, + old_nt_hash_enc, + new_lm_password, + old_lanman_hash_enc); + + CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD3, + q, r, + qbuf, rbuf, + samr_io_q_chgpasswd3, + samr_io_r_chgpasswd3, + NT_STATUS_UNSUCCESSFUL); + + /* Return output parameters */ + + if (!NT_STATUS_IS_OK(result = r.status)) { + *info = &r.info; + *reject = &r.reject; + goto done; + } + + done: + + return result; +} + /* This function returns the bizzare set of (max_entries, max_size) required for the QueryDisplayInfo RPC to actually work against a domain controller with large (10k and higher) numbers of users. These values were diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index ed6abc398b6..b5aa2cd831a 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -7137,7 +7137,7 @@ BOOL samr_io_enc_hash(const char *desc, SAMR_ENC_HASH * hsh, } /******************************************************************* -inits a SAMR_R_GET_DOM_PWINFO structure. +inits a SAMR_Q_CHGPASSWD_USER structure. ********************************************************************/ void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u, @@ -7245,6 +7245,172 @@ BOOL samr_io_r_chgpasswd_user(const char *desc, SAMR_R_CHGPASSWD_USER * r_u, return True; } +/******************************************************************* +inits a SAMR_Q_CHGPASSWD3 structure. +********************************************************************/ + +void init_samr_q_chgpasswd3(SAMR_Q_CHGPASSWD3 * q_u, + const char *dest_host, const char *user_name, + const uchar nt_newpass[516], + const uchar nt_oldhash[16], + const uchar lm_newpass[516], + const uchar lm_oldhash[16]) +{ + DEBUG(5, ("init_samr_q_chgpasswd3\n")); + + q_u->ptr_0 = 1; + init_unistr2(&q_u->uni_dest_host, dest_host, UNI_FLAGS_NONE); + init_uni_hdr(&q_u->hdr_dest_host, &q_u->uni_dest_host); + + init_unistr2(&q_u->uni_user_name, user_name, UNI_FLAGS_NONE); + init_uni_hdr(&q_u->hdr_user_name, &q_u->uni_user_name); + + init_enc_passwd(&q_u->nt_newpass, (const char *)nt_newpass); + init_enc_hash(&q_u->nt_oldhash, nt_oldhash); + + q_u->lm_change = 0x01; + + init_enc_passwd(&q_u->lm_newpass, (const char *)lm_newpass); + init_enc_hash(&q_u->lm_oldhash, lm_oldhash); + + init_enc_passwd(&q_u->password3, NULL); +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ + +BOOL samr_io_q_chgpasswd3(const char *desc, SAMR_Q_CHGPASSWD3 * q_u, + prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_q_chgpasswd3"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0)) + return False; + + if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth)) + return False; + + if(!prs_align(ps)) + return False; + if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth)) + return False; + if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth)) + return False; + + if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth)) + return False; + if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth)) + return False; + + if(!prs_uint32("lm_change", ps, depth, &q_u->lm_change)) + return False; + + if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth)) + return False; + if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth)) + return False; + + if(!samr_io_enc_passwd("password3", &q_u->password3, ps, depth)) + return False; + + return True; +} + +/******************************************************************* +inits a SAMR_R_CHGPASSWD3 structure. +********************************************************************/ + +void init_samr_r_chgpasswd3(SAMR_R_CHGPASSWD3 * r_u, NTSTATUS status) +{ + DEBUG(5, ("init_r_chgpasswd3\n")); + + r_u->status = status; +} + +/******************************************************************* + Reads or writes an SAMR_CHANGE_REJECT structure. +********************************************************************/ + +BOOL samr_io_change_reject(const char *desc, SAMR_CHANGE_REJECT *reject, prs_struct *ps, int depth) +{ + if (reject == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_change_reject"); + depth++; + + if(!prs_align(ps)) + return False; + + if(UNMARSHALLING(ps)) + ZERO_STRUCTP(reject); + + if (!prs_uint32("reject_reason", ps, depth, &reject->reject_reason)) + return False; + + if (!prs_uint32("unknown1", ps, depth, &reject->unknown1)) + return False; + + if (!prs_uint32("unknown2", ps, depth, &reject->unknown2)) + return False; + + return True; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ + +BOOL samr_io_r_chgpasswd3(const char *desc, SAMR_R_CHGPASSWD3 * r_u, + prs_struct *ps, int depth) +{ + uint32 ptr_info, ptr_reject; + + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_chgpasswd3"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("ptr_info", ps, depth, &ptr_info)) + return False; + + if (ptr_info) { + + /* SAM_UNK_INFO_1 */ + if(!sam_io_unk_info1("info", &r_u->info, ps, depth)) + return False; + } + + if(!prs_uint32("ptr_reject", ps, depth, &ptr_reject)) + return False; + + if (ptr_reject) { + + /* SAMR_CHANGE_REJECT */ + if(!samr_io_change_reject("reject", &r_u->reject, ps, depth)) + return False; + } + + if(!prs_ntstatus("status", ps, depth, &r_u->status)) + return False; + + return True; +} + /******************************************************************* reads or writes a structure. ********************************************************************/ -- cgit From 9746c6e3b4667d196e780bab80e2f87aa168ce38 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 29 Nov 2005 23:40:01 +0000 Subject: r11964: rename flag to password_properties in SAM_UNK_INFO_1 because that's what it is. (SAM_UNK_INFO_1 should get a better name as well). Guenther --- source/rpc_parse/parse_samr.c | 6 +++--- source/rpc_server/srv_samr_nt.c | 2 +- source/rpcclient/cmd_samr.c | 32 +++++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index b5aa2cd831a..0a055ff826a 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -778,11 +778,11 @@ inits a structure. ********************************************************************/ void init_unk_info1(SAM_UNK_INFO_1 *u_1, uint16 min_pass_len, uint16 pass_hist, - uint32 flag, NTTIME nt_expire, NTTIME nt_min_age) + uint32 password_properties, NTTIME nt_expire, NTTIME nt_min_age) { u_1->min_length_password = min_pass_len; u_1->password_history = pass_hist; - u_1->flag = flag; + u_1->password_properties = password_properties; /* password never expire */ u_1->expire.high = nt_expire.high; @@ -811,7 +811,7 @@ static BOOL sam_io_unk_info1(const char *desc, SAM_UNK_INFO_1 * u_1, return False; if(!prs_uint16("password_history", ps, depth, &u_1->password_history)) return False; - if(!prs_uint32("flag", ps, depth, &u_1->flag)) + if(!prs_uint32("password_properties", ps, depth, &u_1->password_properties)) return False; if(!smb_io_time("expire", &u_1->expire, ps, depth)) return False; diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 6ad5ec77068..52b78d5e8de 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -4834,7 +4834,7 @@ NTSTATUS _samr_set_dom_info(pipes_struct *p, SAMR_Q_SET_DOMAIN_INFO *q_u, SAMR_R pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)q_u->ctr->info.inf1.min_length_password); pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)q_u->ctr->info.inf1.password_history); - pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)q_u->ctr->info.inf1.flag); + pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)q_u->ctr->info.inf1.password_properties); pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire); pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age); break; diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 68ceead69d3..35598fb50c0 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -165,14 +165,32 @@ static const char* server_role_str(uint32 server_role) static void display_sam_unk_info_1(SAM_UNK_INFO_1 *info1) { - printf("Minimum password length: %d\n", info1->min_length_password); - printf("Password uniqueness (remember x passwords): %d\n", info1->password_history); - printf("flag: "); - if(info1->flag&&2==2) printf("users must open a session to change password "); - printf("\n"); + printf("Minimum password length:\t\t\t%d\n", info1->min_length_password); + printf("Password uniqueness (remember x passwords):\t%d\n", info1->password_history); + printf("Password Properties:\t\t\t\t0x%08x\n", info1->password_properties); + + if (info1->password_properties & DOMAIN_PASSWORD_COMPLEX) + printf("\tDOMAIN_PASSWORD_COMPLEX\n"); + + if (info1->password_properties & DOMAIN_PASSWORD_NO_ANON_CHANGE) { + printf("\tDOMAIN_PASSWORD_NO_ANON_CHANGE\n"); + printf("users must open a session to change password "); + } + + if (info1->password_properties & DOMAIN_PASSWORD_NO_CLEAR_CHANGE) + printf("\tDOMAIN_PASSWORD_NO_CLEAR_CHANGE\n"); + + if (info1->password_properties & DOMAIN_LOCKOUT_ADMINS) + printf("\tDOMAIN_LOCKOUT_ADMINS\n"); + + if (info1->password_properties & DOMAIN_PASSWORD_STORE_CLEARTEXT) + printf("\tDOMAIN_PASSWORD_STORE_CLEARTEXT\n"); + + if (info1->password_properties & DOMAIN_REFUSE_PASSWORD_CHANGE) + printf("\tDOMAIN_REFUSE_PASSWORD_CHANGE\n"); - printf("password expire in: %s\n", display_time(info1->expire)); - printf("Min password age (allow changing in x days): %s\n", display_time(info1->min_passwordage)); + printf("password expire in:\t\t\t\t%s\n", display_time(info1->expire)); + printf("Min password age (allow changing in x days):\t%s\n", display_time(info1->min_passwordage)); } static void display_sam_unk_info_2(SAM_UNK_INFO_2 *info2) -- cgit From 5503d37383c831c061cb3fa436ed279e519051c5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 30 Nov 2005 00:09:14 +0000 Subject: r11966: fix the build\n\nGuenther --- source/include/rpc_samr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index 236c37a17e2..5555aaef0e4 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -594,7 +594,7 @@ typedef struct sam_unknown_info_1_inf { uint16 min_length_password; uint16 password_history; - uint32 flag; + uint32 password_properties; NTTIME expire; NTTIME min_passwordage; -- cgit From 5ee871654205be47fb4e32edf9a9950e00850aca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 30 Nov 2005 17:29:33 +0000 Subject: r11975: Fix valgrind error -- bug 3291 --- source/libsmb/cliconnect.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/libsmb/cliconnect.c b/source/libsmb/cliconnect.c index b352d3572a7..ac7d1b1650c 100644 --- a/source/libsmb/cliconnect.c +++ b/source/libsmb/cliconnect.c @@ -163,6 +163,7 @@ static BOOL cli_session_setup_guest(struct cli_state *cli) char *p; uint32 capabilities = cli_session_setup_capabilities(cli); + memset(cli->outbuf, '\0', smb_size); set_message(cli->outbuf,13,0,True); SCVAL(cli->outbuf,smb_com,SMBsesssetupX); cli_setup_packet(cli); -- cgit From 315bad9be12ecc6c0d3fb2a7e0e7c3832f3a8b01 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Nov 2005 17:53:21 +0000 Subject: r11976: (Slightly modified) Volker fix for #3293. Use SMBecho instead of chkpath to keep a connection alive. Jeremy. --- source/client/client.c | 7 ++++++- source/libsmb/clientgen.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/source/client/client.c b/source/client/client.c index 47a45b8a53b..7a4f853d543 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -3088,7 +3088,12 @@ static void readline_callback(void) goto again; } - cli_chkpath(cli, "\\"); + /* Ping the server to keep the connection alive using SMBecho. */ + { + unsigned char garbage[16]; + memset(garbage, 0xf0, sizeof(garbage)); + cli_echo(cli, garbage, sizeof(garbage)); + } } /**************************************************************************** diff --git a/source/libsmb/clientgen.c b/source/libsmb/clientgen.c index bc64cc919b7..6dc7386c03b 100644 --- a/source/libsmb/clientgen.c +++ b/source/libsmb/clientgen.c @@ -481,6 +481,7 @@ BOOL cli_set_case_sensitive(struct cli_state *cli, BOOL case_sensitive) /**************************************************************************** Send a keepalive packet to the server ****************************************************************************/ + BOOL cli_send_keepalive(struct cli_state *cli) { if (cli->fd == -1) { @@ -495,3 +496,36 @@ BOOL cli_send_keepalive(struct cli_state *cli) } return True; } + +/**************************************************************************** + Send/receive a SMBecho command: ping the server +****************************************************************************/ + +BOOL cli_echo(struct cli_state *cli, unsigned char *data, size_t length) +{ + char *p; + + SMB_ASSERT(length < 1024); + + memset(cli->outbuf,'\0',smb_size); + set_message(cli->outbuf,1,length,True); + SCVAL(cli->outbuf,smb_com,SMBecho); + SSVAL(cli->outbuf,smb_tid,65535); + SSVAL(cli->outbuf,smb_vwv0,1); + cli_setup_packet(cli); + p = smb_buf(cli->outbuf); + memcpy(p, data, length); + p += length; + + cli_setup_bcc(cli, p); + + cli_send_smb(cli); + if (!cli_receive_smb(cli)) { + return False; + } + + if (cli_is_error(cli)) { + return False; + } + return True; +} -- cgit From c9e5a09d558180ab3d0858ceabc08e2ea23c503f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Nov 2005 17:56:50 +0000 Subject: r11978: Volker's fix for #3292 (smbclient spins if server terminates connection). Jeremy. --- source/client/client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/client/client.c b/source/client/client.c index 7a4f853d543..f95bbea6718 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -3084,7 +3084,11 @@ static void readline_callback(void) session keepalives and then drop them here. */ if (FD_ISSET(cli->fd,&fds)) { - receive_smb(cli->fd,cli->inbuf,0); + if (!receive_smb(cli->fd,cli->inbuf,0)) { + DEBUG(0, ("Read from server failed, maybe it closed the " + "connection\n")); + return; + } goto again; } -- cgit From 8b0be74864dae41b373567b0a15abbdee3586ccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 1 Dec 2005 00:43:34 +0000 Subject: r11985: Move to LGPL as per tridge's Samba4 change. Jeremy. --- source/include/talloc.h | 38 +++++++++++++++++++++++++++----------- source/lib/talloc.c | 32 ++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/source/include/talloc.h b/source/include/talloc.h index 738506e323d..1001a951702 100644 --- a/source/include/talloc.h +++ b/source/include/talloc.h @@ -6,19 +6,23 @@ Copyright (C) Andrew Tridgell 2004-2005 - 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. + ** NOTE! The following LGPL license applies to the talloc + ** library. This does NOT imply that all of Samba is released + ** under the LGPL - This program is distributed in the hope that it will be useful, + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* this is only needed for compatibility with the old talloc */ @@ -58,9 +62,18 @@ typedef void TALLOC_CTX; #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) +#if 0 +/* Not correct for Samba3. */ +#define data_blob(ptr, size) data_blob_named(ptr, size, "DATA_BLOB: "__location__) +#define data_blob_talloc(ctx, ptr, size) data_blob_talloc_named(ctx, ptr, size, "DATA_BLOB: "__location__) +#define data_blob_dup_talloc(ctx, blob) data_blob_talloc_named(ctx, (blob)->data, (blob)->length, "DATA_BLOB: "__location__) +#endif + #define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type) #define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type) +#define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type) + #if TALLOC_DEPRECATED #define talloc_zero_p(ctx, type) talloc_zero(ctx, type) @@ -113,6 +126,7 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name); void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name); char *talloc_strdup(const void *t, const char *p); char *talloc_strndup(const void *t, const char *p, size_t n); +char *talloc_append_string(const void *t, char *orig, const char *append); char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(2,0); char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); char *talloc_asprintf_append(char *s, @@ -123,6 +137,8 @@ void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned void *talloc_realloc_fn(const void *context, void *ptr, size_t size); void *talloc_autofree_context(void); size_t talloc_get_size(const void *ctx); +void *talloc_find_parent_byname(const void *ctx, const char *name); +void talloc_show_parents(const void *context, FILE *file); #endif diff --git a/source/lib/talloc.c b/source/lib/talloc.c index b95e35152fe..00f889d682c 100644 --- a/source/lib/talloc.c +++ b/source/lib/talloc.c @@ -1,4 +1,4 @@ -/* +/* Samba Unix SMB/CIFS implementation. Samba trivial allocation library - new interface @@ -6,20 +6,24 @@ NOTE: Please read talloc_guide.txt for full documentation Copyright (C) Andrew Tridgell 2004 - - 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, + + ** NOTE! The following LGPL license applies to the talloc + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* -- cgit From 038c39804739ec1a4d7131bdadae4d5c5c378088 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 1 Dec 2005 12:52:35 +0000 Subject: r11998: Add lookupname to rpcclient query_user as a fallback, we now accept both rid and username. Volker --- source/rpcclient/cmd_samr.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 35598fb50c0..2050f2a7796 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -351,7 +351,7 @@ static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli, return NT_STATUS_OK; } - sscanf(argv[1], "%i", &user_rid); + user_rid = strtoul(argv[1], NULL, 10); if (argc > 2) sscanf(argv[2], "%i", &info_level); @@ -380,6 +380,27 @@ static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli, access_mask, user_rid, &user_pol); + if (NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) && + (user_rid == 0)) { + + /* Probably this was a user name, try lookupnames */ + uint32 num_rids; + uint32 *rids, *types; + + result = rpccli_samr_lookup_names(cli, mem_ctx, &domain_pol, + 1000, 1, &argv[1], + &num_rids, &rids, + &types); + + if (NT_STATUS_IS_OK(result)) { + result = rpccli_samr_open_user(cli, mem_ctx, + &domain_pol, + access_mask, + rids[0], &user_pol); + } + } + + if (!NT_STATUS_IS_OK(result)) goto done; -- cgit From 6bb9f48b28e03ad1710d784b3300007803c4a6b6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 1 Dec 2005 14:46:56 +0000 Subject: r11999: Re-add "passdb expand explicit". We came to the conclusion that changing the default is something that has to wait one or two more releases, but it will happen one way or the other. Volker --- source/param/loadparm.c | 4 ++++ source/passdb/passdb.c | 16 +++++++++++++--- source/passdb/pdb_ldap.c | 16 +++++++++++++--- source/utils/testparm.c | 5 +++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 86a5353dca7..cdef0340618 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -168,6 +168,7 @@ typedef struct char *szIdmapUID; char *szIdmapGID; BOOL bEnableRidAlgorithm; + BOOL bPassdbExpandExplicit; int AlgorithmicRidBase; char *szTemplateHomedir; char *szTemplateShell; @@ -1240,6 +1241,7 @@ static struct parm_struct parm_table[] = { {N_("Winbind options"), P_SEP, P_SEPARATOR}, {"enable rid algorithm", P_BOOL, P_GLOBAL, &Globals.bEnableRidAlgorithm, NULL, NULL, FLAG_DEPRECATED}, + {"passdb expand explicit", P_BOOL, P_GLOBAL, &Globals.bPassdbExpandExplicit, NULL, NULL, FLAG_ADVANCED}, {"idmap backend", P_LIST, P_GLOBAL, &Globals.szIdmapBackend, NULL, NULL, FLAG_ADVANCED}, {"idmap uid", P_STRING, P_GLOBAL, &Globals.szIdmapUID, handle_idmap_uid, NULL, FLAG_ADVANCED}, {"winbind uid", P_STRING, P_GLOBAL, &Globals.szIdmapUID, handle_idmap_uid, NULL, FLAG_HIDE}, @@ -1603,6 +1605,7 @@ static void init_globals(void) Globals.szWinbindNssInfo = str_list_make("template", NULL); Globals.bEnableRidAlgorithm = True; + Globals.bPassdbExpandExplicit = True; Globals.name_cache_timeout = 660; /* In seconds */ @@ -1792,6 +1795,7 @@ FN_GLOBAL_BOOL(lp_winbind_nested_groups, &Globals.bWinbindNestedGroups) FN_GLOBAL_LIST(lp_idmap_backend, &Globals.szIdmapBackend) FN_GLOBAL_BOOL(lp_enable_rid_algorithm, &Globals.bEnableRidAlgorithm) +FN_GLOBAL_BOOL(lp_passdb_expand_explicit, &Globals.bPassdbExpandExplicit) #ifdef WITH_LDAP_SAMCONFIG FN_GLOBAL_STRING(lp_ldap_server, &Globals.szLdapServer) diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index c893ebcd424..e073db3499c 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -1751,6 +1751,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) uint32 pwHistLen = 0; BOOL ret = True; fstring tmpstring; + BOOL expand_explicit = lp_passdb_expand_explicit(); if(sampass == NULL || buf == NULL) { DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); @@ -1815,7 +1816,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (homedir) { fstrcpy( tmpstring, homedir ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_homedir(sampass, tmpstring, PDB_SET); } else { @@ -1831,7 +1835,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (logon_script) { fstrcpy( tmpstring, logon_script ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } else { @@ -1842,7 +1849,10 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) if (profile_path) { fstrcpy( tmpstring, profile_path ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } else { diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 66efe5a8ae6..fac95e37866 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -604,6 +604,7 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, LOGIN_CACHE *cache_entry = NULL; uint32 pwHistLen; pstring tmpstring; + BOOL expand_explicit = lp_passdb_expand_explicit(); /* * do a little initialization @@ -776,7 +777,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, homedir ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_homedir(sampass, tmpstring, PDB_SET); } @@ -788,7 +792,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, logon_script ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_logon_script(sampass, tmpstring, PDB_SET); } @@ -800,7 +807,10 @@ static BOOL init_sam_from_ldap(struct ldapsam_privates *ldap_state, PDB_DEFAULT ); } else { pstrcpy( tmpstring, profile_path ); - standard_sub_basic( username, tmpstring, sizeof(tmpstring) ); + if (expand_explicit) { + standard_sub_basic( username, tmpstring, + sizeof(tmpstring) ); + } pdb_set_profile_path(sampass, tmpstring, PDB_SET); } diff --git a/source/utils/testparm.c b/source/utils/testparm.c index b4561b58deb..0ce838e5c76 100644 --- a/source/utils/testparm.c +++ b/source/utils/testparm.c @@ -73,6 +73,11 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n"); ret = 1; } + if (lp_passdb_expand_explicit()) { + fprintf(stderr, "WARNING: passdb expand explicit = yes is " + "deprecated\n"); + } + /* * Password server sanity checks. */ -- cgit From b6fcad513d72939b3ed0e100f8bad2221586ee13 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 1 Dec 2005 23:10:27 +0000 Subject: r12002: patch from marcin to allow for the creation of a File value in the eventlog registry keys so that file properties can be displayed --- source/registry/reg_eventlog.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/registry/reg_eventlog.c b/source/registry/reg_eventlog.c index d802b18aca2..1c65c9b2178 100644 --- a/source/registry/reg_eventlog.c +++ b/source/registry/reg_eventlog.c @@ -33,6 +33,7 @@ BOOL eventlog_init_keys( void ) /* Find all of the eventlogs, add keys for each of them */ const char **elogs = lp_eventlog_list( ); pstring evtlogpath; + pstring evtfilepath; REGSUBKEY_CTR *subkeys; REGVAL_CTR *values; uint32 uiDisplayNameId; @@ -98,10 +99,12 @@ BOOL eventlog_init_keys( void ) regval_ctr_addvalue( values, "MaxSize", REG_DWORD, ( char * ) &uiMaxSize, sizeof( uint32 ) ); + regval_ctr_addvalue( values, "Retention", REG_DWORD, ( char * ) &uiRetention, sizeof( uint32 ) ); init_unistr2( &data, *elogs, UNI_STR_TERMINATE ); + regval_ctr_addvalue( values, "PrimaryModule", REG_SZ, ( char * ) data.buffer, data.uni_str_len * @@ -112,6 +115,11 @@ BOOL eventlog_init_keys( void ) ( char * ) data.buffer, data.uni_str_len * sizeof( uint16 ) ); + + pstr_sprintf( evtfilepath, "%%SystemRoot%%\\system32\\config\\%s.tdb", *elogs ); + init_unistr2( &data, evtfilepath, UNI_STR_TERMINATE ); + regval_ctr_addvalue( values, "File", REG_EXPAND_SZ, ( char * ) data.buffer, + data.uni_str_len * sizeof( uint16 ) ); regdb_store_values( evtlogpath, values ); } -- cgit From 95798e251ffb97de416847b0517b761d5536777c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 2 Dec 2005 10:26:29 +0000 Subject: r12015: When smbspool tries to connect to a printer shared on a standalone Windows XP box, smbspool has to mimic smbclient behaviour and also send a password-less NTLMSSP session setup. Guenther --- source/client/smbspool.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/client/smbspool.c b/source/client/smbspool.c index aff241adeed..7fe918413d5 100644 --- a/source/client/smbspool.c +++ b/source/client/smbspool.c @@ -461,6 +461,7 @@ smb_connect(const char *workgroup, /* I - Workgroup */ { struct cli_state *cli; /* New connection */ pstring myname; /* Client name */ + struct passwd *pwd; /* * Get the names and addresses of the client and server... @@ -488,12 +489,24 @@ smb_connect(const char *workgroup, /* I - Workgroup */ if (cli ) { return cli; } + /* give a chance for a passwordless NTLMSSP session setup */ + + pwd = getpwuid(geteuid()); + if (pwd == NULL) { + return NULL; + } + + cli = smb_complete_connection(myname, server, port, pwd->pw_name, "", + workgroup, share, 0); + + if (cli) { return cli; } + /* * last try. Use anonymous authentication */ + cli = smb_complete_connection(myname, server, port, "", "", workgroup, share, 0); - /* * Return the new connection... */ -- cgit From 89aa927b4ad26c3a93a519ca723a4baf623ea12f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 2 Dec 2005 19:30:01 +0000 Subject: r12027: changing version to 3.0.22pre1 since 3.0.21 is frozen now --- source/VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/VERSION b/source/VERSION index 34c48598612..5e2b8df3865 100644 --- a/source/VERSION +++ b/source/VERSION @@ -19,7 +19,7 @@ ######################################################## SAMBA_VERSION_MAJOR=3 SAMBA_VERSION_MINOR=0 -SAMBA_VERSION_RELEASE=21 +SAMBA_VERSION_RELEASE=22 ######################################################## # If a official release has a serious bug # @@ -41,7 +41,7 @@ SAMBA_VERSION_REVISION= # e.g. SAMBA_VERSION_PRE_RELEASE=1 # # -> "2.2.9pre1" # ######################################################## -SAMBA_VERSION_PRE_RELEASE=3 +SAMBA_VERSION_PRE_RELEASE=1 ######################################################## # For 'rc' releases the version will be # -- cgit From b6918f6167dadfc706161c76fa832aec15263658 Mon Sep 17 00:00:00 2001 From: John Terpstra Date: Fri, 2 Dec 2005 20:46:15 +0000 Subject: r12031: Added net idmap to common help list. --- source/utils/net_help.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/utils/net_help.c b/source/utils/net_help.c index 7c7c583fa38..c5188c3608e 100644 --- a/source/utils/net_help.c +++ b/source/utils/net_help.c @@ -61,7 +61,7 @@ static int help_usage(int argc, const char **argv) "Valid functions are:\n"\ " RPC RAP ADS FILE SHARE SESSION SERVER DOMAIN PRINTQ USER GROUP VALIDATE\n"\ " GROUPMEMBER ADMIN SERVICE PASSWORD TIME LOOKUP GETLOCALSID SETLOCALSID\n"\ -" CHANGESCRETPW\n"); +" CHANGESCRETPW IDMAP\n"); return -1; } @@ -224,6 +224,7 @@ static int net_usage(int argc, const char **argv) " net user\t\tto manage users\n"\ " net group\t\tto manage groups\n"\ " net groupmap\t\tto manage group mappings\n"\ + " net idmap\t\tto manage the idmap id mappings\n"\ " net join\t\tto join a domain\n"\ " net cache\t\tto operate on cache tdb file\n"\ " net getlocalsid [NAME]\tto get the SID for local name\n"\ @@ -273,7 +274,7 @@ int net_help(int argc, const char **argv) #ifdef WITH_FAKE_KASERVER {"AFS", net_help_afs}, #endif - + {"IDMAP", net_help_idmap}, {"HELP", help_usage}, {NULL, NULL}}; -- cgit From defd101878b9bb8e1bb82dbc5f54ff85dfe403f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 00:51:23 +0000 Subject: r12038: This file is no longer used, and no one noticed.... Jeremy. --- source/lib/util_smbd.c | 86 -------------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 source/lib/util_smbd.c diff --git a/source/lib/util_smbd.c b/source/lib/util_smbd.c deleted file mode 100644 index c6f6bc0a32a..00000000000 --- a/source/lib/util_smbd.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions, used in smbd only - Copyright (C) Andrew Tridgell 2002 - - 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. -*/ - -#include "includes.h" - -/* - This function requires sys_getgrouplist - which is only - available in smbd due to it's use of become_root() in a - legacy systems hack. -*/ - -/* - return a full list of groups for a user - - returns the number of groups the user is a member of. The return will include the - users primary group. - - remember to free the resulting gid_t array - - NOTE! uses become_root() to gain correct priviages on systems - that lack a native getgroups() call (uses initgroups and getgroups) -*/ -BOOL getgroups_user(const char *user, gid_t primary_gid, gid_t **ret_groups, int *ngroups) -{ - int ngrp, max_grp; - gid_t *temp_groups; - gid_t *groups; - int i; - - max_grp = groups_max(); - temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp); - if (! temp_groups) { - return False; - } - - if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { - - gid_t *groups_tmp; - - groups_tmp = SMB_REALLOC_ARRAY(temp_groups, gid_t, max_grp); - - if (!groups_tmp) { - SAFE_FREE(temp_groups); - return False; - } - temp_groups = groups_tmp; - - if (sys_getgrouplist(user, primary_gid, temp_groups, &max_grp) == -1) { - DEBUG(0, ("get_user_groups: failed to get the unix group list\n")); - SAFE_FREE(temp_groups); - return False; - } - } - - ngrp = 0; - groups = NULL; - - /* Add in primary group first */ - add_gid_to_array_unique(NULL, primary_gid, &groups, &ngrp); - - for (i=0; i Date: Sat, 3 Dec 2005 01:03:16 +0000 Subject: r12040: merging packaging fixes from release branch --- MAINTAINERS | 11 ++++++++++- packaging/Fedora/samba.spec.tmpl | 12 ++++-------- packaging/Solaris/makepkg.sh | 2 +- source/script/installman.sh | 5 ++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b84f01b519b..9f67bf945de 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21,10 +21,19 @@ Feature/Function Developer ---------------- --------- documentation John Terpstra + libmsrpc Chris Nichols + libsmbclient Derrell Lipman -pdb_mysql Jelmer Vernooij + +pdb_*sql + Peter Rindfuss: pdb_mysql + Darrell McGuire: pdb_mysql + Ulrich Meis: pdb_pgsql + Filip Jirsák: pdb_pgsql + printing Gerald (Jerry) Carter + samba-vscan Rainer Link diff --git a/packaging/Fedora/samba.spec.tmpl b/packaging/Fedora/samba.spec.tmpl index 7d494d1a651..bac333699ff 100644 --- a/packaging/Fedora/samba.spec.tmpl +++ b/packaging/Fedora/samba.spec.tmpl @@ -213,12 +213,9 @@ install -m644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/samba ## ## Clean out man pages for tools not installed here ## -rm -f $RPM_BUILD_ROOT/%{_mandir}/man1/editreg.1* rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbget.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man5/smbgetrc.5* -rm -f $RPM_BUILD_ROOT/%{_mandir}/man1/testprns.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man1/vfstest.1* %clean rm -rf $RPM_BUILD_ROOT @@ -343,12 +340,15 @@ fi %{_mandir}/man8/umount.cifs.8.* %{_mandir}/man8/smbspool.8* %{_bindir}/nmblookup +%{_bindir}/smbget %{_bindir}/smbclient %{_bindir}/smbprint %{_bindir}/smbspool %{_bindir}/smbtar %{_bindir}/net %{_bindir}/smbtree +%{_mandir}/man1/smbget.1* +%{_mandir}/man5/smbgetrc.5* %{_mandir}/man1/findsmb.1* %{_mandir}/man1/nmblookup.1* %{_mandir}/man1/rpcclient.1* @@ -377,15 +377,12 @@ fi %{_libdir}/samba/auth/script.so %{_bindir}/testparm %{_bindir}/smbpasswd -# %{_bindir}/make_printerdef %{_bindir}/wbinfo -# %{_bindir}/editreg %{_bindir}/ntlm_auth %{_bindir}/pdbedit %{_bindir}/eventlogadm %{_bindir}/profiles %{_bindir}/smbcquotas -#%{_bindir}/vfstest %{_sbindir}/winbindd %config(noreplace) %{_sysconfdir}/samba/smb.conf %config(noreplace) %{_sysconfdir}/samba/lmhosts @@ -404,7 +401,6 @@ fi %{_mandir}/man8/smbpasswd.8* %{_mandir}/man1/wbinfo.1* %{_mandir}/man8/winbindd.8* -%{_mandir}/man1/vfstest.1* %changelog * Fri Jan 16 2004 Gerald (Jerry) Carter diff --git a/packaging/Solaris/makepkg.sh b/packaging/Solaris/makepkg.sh index aaa06c4af4b..2d599fca9b7 100644 --- a/packaging/Solaris/makepkg.sh +++ b/packaging/Solaris/makepkg.sh @@ -14,7 +14,7 @@ MSGFILES="de.msg en.msg fr.msg it.msg ja.msg nl.msg pl.msg tr.msg" VFSLIBS="audit.so default_quota.so extd_audit.so full_audit.so readonly.so shadow_copy.so cap.so expand_msdfs.so fake_perms.so netatalk.so recycle.so" DATFILES="lowcase.dat upcase.dat valid.dat" CHARSETLIBS="CP437.so CP850.so" -AUTHLIBS="auth_script.so" +AUTHLIBS="script.so" add_dynamic_entries() { diff --git a/source/script/installman.sh b/source/script/installman.sh index 3bbca1a8aa5..9235217ff00 100755 --- a/source/script/installman.sh +++ b/source/script/installman.sh @@ -19,8 +19,7 @@ if test ! -d $SRCDIR../docs/manpages; then fi # Get the configured feature set -test -f "${SRCDIR}/config.log" && \ - eval $( grep "^[[:alnum:]]*=.*" "${SRCDIR}/config.log") +test -f "${SRCDIR}/config.log" && eval `grep '^[A-Za-z0-9]*=.*' ${SRCDIR}/config.log` for lang in $langs; do if [ "X$lang" = XC ]; then @@ -44,7 +43,7 @@ for lang in $langs; do for sect in 1 5 7 8 ; do for m in $langdir/man$sect ; do for s in $SRCDIR../docs/manpages/$lang/*$sect; do - MP_BASENAME=${s##*/} + MP_BASENAME=`basename $s` # Check if this man page if required by the configured feature set case "${MP_BASENAME}" in -- cgit From 65530ce393a9180766bdb7c4c8e0901f09ee2a47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:46:46 +0000 Subject: r12043: It's amazing the warnings you find when compiling on a 64-bit box with gcc4 and -O6... Fix a bunch of C99 dereferencing type-punned pointer will break strict-aliasing rules errors. Also added prs_int32 (not uint32...) as it's needed in one place. Find places where prs_uint32 was being used to marshall/unmarshall a time_t (a big no no on 64-bits). More warning fixes to come. Thanks to Volker for nudging me to compile like this. Jeremy. --- source/lib/charcnv.c | 2 +- source/lib/clobber.c | 2 +- source/lib/crc32.c | 2 +- source/lib/util_file.c | 2 +- source/libads/ads_ldap.c | 2 +- source/libads/ldap.c | 10 +++++----- source/libsmb/climessage.c | 2 +- source/libsmb/samlogon_cache.c | 8 ++++++-- source/nmbd/nmbd_namelistdb.c | 2 +- source/passdb/secrets.c | 20 +++++++++---------- source/rpc_parse/parse_net.c | 2 +- source/rpc_parse/parse_prs.c | 29 +++++++++++++++++++++++++++ source/rpc_server/srv_eventlog_nt.c | 2 +- source/rpc_server/srv_lsa_nt.c | 40 ++++++++++++++++++------------------- source/rpc_server/srv_reg_nt.c | 2 +- source/rpc_server/srv_samr_nt.c | 32 ++++++++++++++++------------- source/rpc_server/srv_spoolss_nt.c | 2 +- source/rpc_server/srv_svcctl_nt.c | 2 +- source/smbd/message.c | 2 +- 19 files changed, 100 insertions(+), 65 deletions(-) diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index 4fbad0f3d18..0c806167f41 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -781,7 +781,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen, - (void **) &buffer, True); + (void **)(void *)&buffer, True); if (size == (size_t)-1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } diff --git a/source/lib/clobber.c b/source/lib/clobber.c index fb3a0dc2815..54b24ffed39 100644 --- a/source/lib/clobber.c +++ b/source/lib/clobber.c @@ -54,7 +54,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ - VALGRIND_MAKE_WRITABLE(dest, len); +// VALGRIND_MAKE_WRITABLE(dest, len); #endif /* VALGRIND */ #endif /* DEVELOPER */ } diff --git a/source/lib/crc32.c b/source/lib/crc32.c index 7522ab7c811..a4ae90c4693 100644 --- a/source/lib/crc32.c +++ b/source/lib/crc32.c @@ -93,7 +93,7 @@ uint32 crc32_calc_buffer(const char *buf, size_t size) const unsigned char *p; uint32 crc; - p = buf; + p = (const unsigned char *)buf; crc = ~0U; while (size--) diff --git a/source/lib/util_file.c b/source/lib/util_file.c index 963d610beff..407a8b24fc9 100644 --- a/source/lib/util_file.c +++ b/source/lib/util_file.c @@ -525,7 +525,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines) char **file_lines_load(const char *fname, int *numlines) { char *p; - size_t size; + size_t size = 0; p = file_load(fname, &size); if (!p) { diff --git a/source/libads/ads_ldap.c b/source/libads/ads_ldap.c index ae86ef0b764..fea4cd0fd09 100644 --- a/source/libads/ads_ldap.c +++ b/source/libads/ads_ldap.c @@ -56,7 +56,7 @@ ADS_STATUS ads_sid_to_dn(ADS_STRUCT *ads, goto done; } - rc = ads_search_retry(ads, (void **)&msg, ldap_exp, attr); + rc = ads_search_retry(ads, (void **)(void *)&msg, ldap_exp, attr); if (!ADS_ERR_OK(rc)) { DEBUG(1,("ads_sid_to_dn ads_search: %s\n", ads_errstr(rc))); diff --git a/source/libads/ldap.c b/source/libads/ldap.c index e4cfc456a21..fa2a8b5ea57 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -1162,7 +1162,7 @@ uint32 ads_get_kvno(ADS_STRUCT *ads, const char *machine_name) if (asprintf(&filter, "(samAccountName=%s$)", machine_name) == -1) { return kvno; } - ret = ads_search(ads, (void**) &res, filter, attrs); + ret = ads_search(ads, (void**)(void *)&res, filter, attrs); SAFE_FREE(filter); if (!ADS_ERR_OK(ret) && ads_count_replies(ads, res)) { DEBUG(1,("ads_get_kvno: Computer Account For %s not found.\n", machine_name)); @@ -1216,7 +1216,7 @@ ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machin ADS_STATUS ret = ADS_ERROR(LDAP_SUCCESS); char *dn_string = NULL; - ret = ads_find_machine_acct(ads, (void **)&res, machine_name); + ret = ads_find_machine_acct(ads, (void **)(void *)&res, machine_name); if (!ADS_ERR_OK(ret) || ads_count_replies(ads, res) != 1) { DEBUG(5,("ads_clear_service_principal_names: WARNING: Host Account for %s not found... skipping operation.\n", machine_name)); DEBUG(5,("ads_clear_service_principal_names: WARNING: Service Principals for %s have NOT been cleared.\n", machine_name)); @@ -1284,7 +1284,7 @@ ADS_STATUS ads_add_service_principal_name(ADS_STRUCT *ads, const char *machine_n char *dn_string = NULL; const char *servicePrincipalName[4] = {NULL, NULL, NULL, NULL}; - ret = ads_find_machine_acct(ads, (void **)&res, machine_name); + ret = ads_find_machine_acct(ads, (void **)(void *)&res, machine_name); if (!ADS_ERR_OK(ret) || ads_count_replies(ads, res) != 1) { DEBUG(1,("ads_add_service_principal_name: WARNING: Host Account for %s not found... skipping operation.\n", machine_name)); @@ -1398,7 +1398,7 @@ static ADS_STATUS ads_add_machine_acct(ADS_STRUCT *ads, const char *machine_name name_to_fqdn(my_fqdn, machine_name); - status = ads_find_machine_acct(ads, (void **)&res, machine_name); + status = ads_find_machine_acct(ads, (void **)(void *)&res, machine_name); if (ADS_ERR_OK(status) && ads_count_replies(ads, res) == 1) { char *dn_string = ads_get_dn(ads, res); if (!dn_string) { @@ -1771,7 +1771,7 @@ ADS_STATUS ads_join_realm(ADS_STRUCT *ads, const char *machine_name, return status; } - status = ads_find_machine_acct(ads, (void **)&res, machine); + status = ads_find_machine_acct(ads, (void **)(void *)&res, machine); if (!ADS_ERR_OK(status)) { DEBUG(0, ("ads_join_realm: Host account test failed for machine %s\n", machine)); SAFE_FREE(machine); diff --git a/source/libsmb/climessage.c b/source/libsmb/climessage.c index f646096a4e5..1aa659c1ba3 100644 --- a/source/libsmb/climessage.c +++ b/source/libsmb/climessage.c @@ -85,7 +85,7 @@ int cli_message_text_build(struct cli_state *cli, char *msg, int len, int grp) p = smb_buf(cli->outbuf); *p++ = 1; - if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **) &msgdos, True)) < 0 || !msgdos) { + if ((lendos = (int)convert_string_allocate(NULL,CH_UNIX, CH_DOS, msg,len, (void **)(void *)&msgdos, True)) < 0 || !msgdos) { DEBUG(3,("Conversion failed, sending message in UNIX charset\n")); SSVAL(p, 0, len); p += 2; memcpy(p, msg, len); diff --git a/source/libsmb/samlogon_cache.c b/source/libsmb/samlogon_cache.c index d0469a1a481..ef60055cf47 100644 --- a/source/libsmb/samlogon_cache.c +++ b/source/libsmb/samlogon_cache.c @@ -150,8 +150,12 @@ BOOL netsamlogon_cache_store( const char *username, NET_USER_INFO_3 *user ) prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - if ( !prs_uint32( "timestamp", &ps, 0, (uint32*)&t ) ) - return False; + { + uint32 ts; + if ( !prs_uint32( "timestamp", &ps, 0, &ts ) ) + return False; + t = (time_t)ts; + } if ( net_io_user_info3("", user, &ps, 0, 3, 0) ) { diff --git a/source/nmbd/nmbd_namelistdb.c b/source/nmbd/nmbd_namelistdb.c index 344d3c7ca19..88d5ea52f58 100644 --- a/source/nmbd/nmbd_namelistdb.c +++ b/source/nmbd/nmbd_namelistdb.c @@ -78,7 +78,7 @@ static void update_name_in_namelist( struct subnet_record *subrec, { struct name_record *oldrec = NULL; - ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); + ubi_trInsert( subrec->namelist, namerec, &namerec->name, &oldrec ); if( oldrec ) { SAFE_FREE( oldrec->data.ip ); SAFE_FREE( oldrec ); diff --git a/source/passdb/secrets.c b/source/passdb/secrets.c index 35ccb2c725b..bf57e013fc5 100644 --- a/source/passdb/secrets.c +++ b/source/passdb/secrets.c @@ -138,7 +138,7 @@ BOOL secrets_fetch_domain_sid(const char *domain, DOM_SID *sid) { DOM_SID *dyn_sid; fstring key; - size_t size; + size_t size = 0; slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_DOMAIN_SID, domain); strupper_m(key); @@ -147,8 +147,7 @@ BOOL secrets_fetch_domain_sid(const char *domain, DOM_SID *sid) if (dyn_sid == NULL) return False; - if (size != sizeof(DOM_SID)) - { + if (size != sizeof(DOM_SID)) { SAFE_FREE(dyn_sid); return False; } @@ -171,7 +170,7 @@ BOOL secrets_fetch_domain_guid(const char *domain, struct uuid *guid) { struct uuid *dyn_guid; fstring key; - size_t size; + size_t size = 0; struct uuid new_guid; slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_DOMAIN_GUID, domain); @@ -187,8 +186,7 @@ BOOL secrets_fetch_domain_guid(const char *domain, struct uuid *guid) return False; } - if (size != sizeof(struct uuid)) - { + if (size != sizeof(struct uuid)) { DEBUG(1,("UUID size %d is wrong!\n", (int)size)); SAFE_FREE(dyn_guid); return False; @@ -276,7 +274,7 @@ BOOL secrets_fetch_trust_account_password(const char *domain, uint8 ret_pwd[16], { struct machine_acct_pass *pass; char *plaintext; - size_t size; + size_t size = 0; plaintext = secrets_fetch_machine_password(domain, pass_last_set_time, channel); @@ -326,7 +324,7 @@ BOOL secrets_fetch_trusted_domain_password(const char *domain, char** pwd, DOM_SID *sid, time_t *pass_last_set_time) { struct trusted_dom_pass pass; - size_t size; + size_t size = 0; /* unpacking structures */ char* pass_buf; @@ -599,7 +597,7 @@ BOOL secrets_store_ldap_pw(const char* dn, char* pw) BOOL fetch_ldap_pw(char **dn, char** pw) { char *key = NULL; - size_t size; + size_t size = 0; *dn = smb_xstrdup(lp_ldap_admin_dn()); @@ -682,7 +680,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in char *pattern; unsigned int start_idx; uint32 idx = 0; - size_t size, packed_size = 0; + size_t size = 0, packed_size = 0; fstring dom_name; char *packed_pass; struct trusted_dom_pass *pass = TALLOC_ZERO_P(ctx, struct trusted_dom_pass); @@ -877,7 +875,7 @@ BOOL secrets_fetch_afs_key(const char *cell, struct afs_key *result) { fstring key; struct afs_keyfile *keyfile; - size_t size; + size_t size = 0; uint32 i; slprintf(key, sizeof(key)-1, "%s/%s", SECRETS_AFS_KEYFILE, cell); diff --git a/source/rpc_parse/parse_net.c b/source/rpc_parse/parse_net.c index ce2a085f478..3bd6977dbb1 100644 --- a/source/rpc_parse/parse_net.c +++ b/source/rpc_parse/parse_net.c @@ -3317,7 +3317,7 @@ BOOL net_io_r_dsr_getdcname(const char *desc, NET_R_DSR_GETDCNAME *r_t, if (!prs_uint32("ptr_dc_address", ps, depth, &r_t->ptr_dc_address)) return False; - if (!prs_uint32("dc_address_type", ps, depth, &r_t->dc_address_type)) + if (!prs_int32("dc_address_type", ps, depth, &r_t->dc_address_type)) return False; if (!smb_io_uuid("domain_guid", &r_t->domain_guid, ps, depth)) diff --git a/source/rpc_parse/parse_prs.c b/source/rpc_parse/parse_prs.c index 77f0e6d5c88..7c84ee800b9 100644 --- a/source/rpc_parse/parse_prs.c +++ b/source/rpc_parse/parse_prs.c @@ -707,6 +707,35 @@ BOOL prs_uint32(const char *name, prs_struct *ps, int depth, uint32 *data32) return True; } +/******************************************************************* + Stream an int32. + ********************************************************************/ + +BOOL prs_int32(const char *name, prs_struct *ps, int depth, int32 *data32) +{ + char *q = prs_mem_get(ps, sizeof(int32)); + if (q == NULL) + return False; + + if (UNMARSHALLING(ps)) { + if (ps->bigendian_data) + *data32 = RIVALS(q,0); + else + *data32 = IVALS(q,0); + } else { + if (ps->bigendian_data) + RSIVALS(q,0,*data32); + else + SIVALS(q,0,*data32); + } + + DEBUG(5,("%s%04x %s: %08x\n", tab_depth(depth), ps->data_offset, name, *data32)); + + ps->data_offset += sizeof(int32); + + return True; +} + /******************************************************************* Stream a NTSTATUS ********************************************************************/ diff --git a/source/rpc_server/srv_eventlog_nt.c b/source/rpc_server/srv_eventlog_nt.c index 658928b9270..a8b9c66717e 100644 --- a/source/rpc_server/srv_eventlog_nt.c +++ b/source/rpc_server/srv_eventlog_nt.c @@ -56,7 +56,7 @@ static EVENTLOG_INFO *find_eventlog_info_by_hnd( pipes_struct * p, { EVENTLOG_INFO *info; - if ( !find_policy_by_hnd( p, handle, ( void ** ) &info ) ) { + if ( !find_policy_by_hnd( p, handle, (void **)(void *)&info ) ) { DEBUG( 2, ( "find_eventlog_info_by_hnd: eventlog not found.\n" ) ); return NULL; diff --git a/source/rpc_server/srv_lsa_nt.c b/source/rpc_server/srv_lsa_nt.c index 15d420538ef..b56ae109141 100644 --- a/source/rpc_server/srv_lsa_nt.c +++ b/source/rpc_server/srv_lsa_nt.c @@ -501,7 +501,7 @@ NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_E uint32 num_domains; NTSTATUS nt_status; - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights */ @@ -539,7 +539,7 @@ NTSTATUS _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INF r_u->status = NT_STATUS_OK; - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; switch (q_u->info_class) { @@ -657,7 +657,7 @@ NTSTATUS _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_ ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF); names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM); - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) { + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) { r_u->status = NT_STATUS_INVALID_HANDLE; goto done; } @@ -706,7 +706,7 @@ NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF); rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries); - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) { + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) { r_u->status = NT_STATUS_INVALID_HANDLE; goto done; } @@ -817,7 +817,7 @@ NTSTATUS _lsa_enum_privs(pipes_struct *p, LSA_Q_ENUM_PRIVS *q_u, LSA_R_ENUM_PRIV DEBUG(10,("_lsa_enum_privs: enum_context:%d total entries:%d\n", enum_context, num_privs)); - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights @@ -864,7 +864,7 @@ NTSTATUS _lsa_priv_get_dispname(pipes_struct *p, LSA_Q_PRIV_GET_DISPNAME *q_u, L fstring name_asc; const char *description; - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights */ @@ -912,7 +912,7 @@ NTSTATUS _lsa_enum_accounts(pipes_struct *p, LSA_Q_ENUM_ACCOUNTS *q_u, LSA_R_ENU LSA_SID_ENUM *sids=&r_u->sids; NTSTATUS ret; - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION)) @@ -988,7 +988,7 @@ NTSTATUS _lsa_create_account(pipes_struct *p, LSA_Q_CREATEACCOUNT *q_u, LSA_R_CR struct lsa_info *info; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights */ @@ -1036,7 +1036,7 @@ NTSTATUS _lsa_open_account(pipes_struct *p, LSA_Q_OPENACCOUNT *q_u, LSA_R_OPENAC struct lsa_info *info; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights */ @@ -1079,7 +1079,7 @@ NTSTATUS _lsa_enum_privsaccount(pipes_struct *p, prs_struct *ps, LSA_Q_ENUMPRIVS PRIVILEGE_SET privileges; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; if ( !get_privileges_for_sids( &mask, &info->sid, 1 ) ) @@ -1114,7 +1114,7 @@ NTSTATUS _lsa_getsystemaccount(pipes_struct *p, LSA_Q_GETSYSTEMACCOUNT *q_u, LSA /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; if (!lookup_sid(&info->sid, dom_name, name, &type)) @@ -1145,7 +1145,7 @@ NTSTATUS _lsa_setsystemaccount(pipes_struct *p, LSA_Q_SETSYSTEMACCOUNT *q_u, LSA r_u->status = NT_STATUS_OK; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check to see if the pipe_user is a Domain Admin since @@ -1175,7 +1175,7 @@ NTSTATUS _lsa_addprivs(pipes_struct *p, LSA_Q_ADDPRIVS *q_u, LSA_R_ADDPRIVS *r_u struct current_user user; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check to see if the pipe_user is root or a Domain Admin since @@ -1216,7 +1216,7 @@ NTSTATUS _lsa_removeprivs(pipes_struct *p, LSA_Q_REMOVEPRIVS *q_u, LSA_R_REMOVEP struct current_user user; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check to see if the pipe_user is root or a Domain Admin since @@ -1259,7 +1259,7 @@ NTSTATUS _lsa_query_secobj(pipes_struct *p, LSA_Q_QUERY_SEC_OBJ *q_u, LSA_R_QUER r_u->status = NT_STATUS_OK; /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; /* check if the user have enough rights */ @@ -1316,7 +1316,7 @@ NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_I ZERO_STRUCT(guid); r_u->status = NT_STATUS_OK; - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) return NT_STATUS_INVALID_HANDLE; switch (q_u->info_class) { @@ -1378,7 +1378,7 @@ NTSTATUS _lsa_add_acct_rights(pipes_struct *p, LSA_Q_ADD_ACCT_RIGHTS *q_u, LSA_R /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check to see if the pipe_user is a Domain Admin since @@ -1436,7 +1436,7 @@ NTSTATUS _lsa_remove_acct_rights(pipes_struct *p, LSA_Q_REMOVE_ACCT_RIGHTS *q_u, /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* check to see if the pipe_user is a Domain Admin since @@ -1498,7 +1498,7 @@ NTSTATUS _lsa_enum_acct_rights(pipes_struct *p, LSA_Q_ENUM_ACCT_RIGHTS *q_u, LSA /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* according to an NT4 PDC, you can add privileges to SIDs even without @@ -1539,7 +1539,7 @@ NTSTATUS _lsa_lookup_priv_value(pipes_struct *p, LSA_Q_LOOKUP_PRIV_VALUE *q_u, L /* find the connection policy handle. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; unistr2_to_ascii(name, &q_u->privname.unistring, sizeof(name)); diff --git a/source/rpc_server/srv_reg_nt.c b/source/rpc_server/srv_reg_nt.c index 35a060c38e3..33711d0fac9 100644 --- a/source/rpc_server/srv_reg_nt.c +++ b/source/rpc_server/srv_reg_nt.c @@ -54,7 +54,7 @@ static REGISTRY_KEY *find_regkey_index_by_hnd(pipes_struct *p, POLICY_HND *hnd) { REGISTRY_KEY *regkey = NULL; - if(!find_policy_by_hnd(p,hnd,(void **)®key)) { + if(!find_policy_by_hnd(p,hnd,(void **)(void *)®key)) { DEBUG(2,("find_regkey_index_by_hnd: Registry Key not found: ")); return NULL; } diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 52b78d5e8de..635d8707623 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -573,7 +573,7 @@ NTSTATUS _samr_open_domain(pipes_struct *p, SAMR_Q_OPEN_DOMAIN *q_u, SAMR_R_OPEN /* find the connection policy handle. */ - if ( !find_policy_by_hnd(p, &q_u->pol, (void**)&info) ) + if ( !find_policy_by_hnd(p, &q_u->pol, (void**)(void *)&info) ) return NT_STATUS_INVALID_HANDLE; status = access_check_samr_function( info->acc_granted, @@ -627,7 +627,7 @@ NTSTATUS _samr_get_usrdom_pwinfo(pipes_struct *p, SAMR_Q_GET_USRDOM_PWINFO *q_u, r_u->status = NT_STATUS_OK; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->user_pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->user_pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; if (!sid_check_is_in_our_domain(&info->sid)) @@ -665,7 +665,7 @@ static BOOL get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol, struct samr_info *info = NULL; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, pol, (void **)&info)) + if (!find_policy_by_hnd(p, pol, (void **)(void *)&info)) return False; if (!info) @@ -803,7 +803,7 @@ NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, r_u->status = NT_STATUS_OK; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted, @@ -936,7 +936,7 @@ NTSTATUS _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAM r_u->status = NT_STATUS_OK; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; r_u->status = access_check_samr_function(info->acc_granted, @@ -995,7 +995,7 @@ NTSTATUS _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, S uint32 num_aliases = 0; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; r_u->status = access_check_samr_function(info->acc_granted, @@ -1061,7 +1061,7 @@ NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, r_u->status = NT_STATUS_UNSUCCESSFUL; /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* @@ -1857,7 +1857,7 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ r_u->status=NT_STATUS_OK; /* search for the handle */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; domain_sid = info->sid; @@ -2094,7 +2094,7 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA DEBUG(5,("_samr_query_dom_info: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)&info)) { + if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)(void *)&info)) { return NT_STATUS_INVALID_HANDLE; } @@ -2165,7 +2165,11 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA /* AS ROOT !!! */ - pdb_get_account_policy(AP_TIME_TO_LOGOUT, (unsigned int *)&u_logout); + { + uint32 ul; + pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul); + u_logout = (time_t)ul; + } /* !AS ROOT */ @@ -2641,7 +2645,7 @@ NTSTATUS _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_ r_u->status = NT_STATUS_OK; - if (!find_policy_by_hnd(p, &q_u->connect_pol, (void**)&info)) + if (!find_policy_by_hnd(p, &q_u->connect_pol, (void**)(void *)&info)) return NT_STATUS_INVALID_HANDLE; /* win9x user manager likes to use SA_RIGHT_SAM_ENUM_DOMAINS here. @@ -2717,7 +2721,7 @@ NTSTATUS _samr_enum_domains(pipes_struct *p, SAMR_Q_ENUM_DOMAINS *q_u, SAMR_R_EN r_u->status = NT_STATUS_OK; - if (!find_policy_by_hnd(p, &q_u->pol, (void**)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void**)(void *)&info)) return NT_STATUS_INVALID_HANDLE; if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted, SA_RIGHT_SAM_ENUM_DOMAINS, "_samr_enum_domains"))) { @@ -3418,7 +3422,7 @@ NTSTATUS _samr_query_useraliases(pipes_struct *p, SAMR_Q_QUERY_USERALIASES *q_u, DEBUG(5,("_samr_query_useraliases: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; ntstatus1 = access_check_samr_function(info->acc_granted, SA_RIGHT_DOMAIN_LOOKUP_ALIAS_BY_MEM, "_samr_query_useraliases"); @@ -4704,7 +4708,7 @@ NTSTATUS _samr_query_domain_info2(pipes_struct *p, DEBUG(5,("_samr_query_domain_info2: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)&info)) + if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; switch (q_u->switch_value) { diff --git a/source/rpc_server/srv_spoolss_nt.c b/source/rpc_server/srv_spoolss_nt.c index f0ba863b4d7..334158bbbd2 100644 --- a/source/rpc_server/srv_spoolss_nt.c +++ b/source/rpc_server/srv_spoolss_nt.c @@ -267,7 +267,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd { Printer_entry *find_printer = NULL; - if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) { + if(!find_policy_by_hnd(p,hnd,(void **)(void *)&find_printer)) { DEBUG(2,("find_printer_index_by_hnd: Printer handle not found: ")); return NULL; } diff --git a/source/rpc_server/srv_svcctl_nt.c b/source/rpc_server/srv_svcctl_nt.c index 19648f5e78b..bbf313f7fa1 100644 --- a/source/rpc_server/srv_svcctl_nt.c +++ b/source/rpc_server/srv_svcctl_nt.c @@ -186,7 +186,7 @@ static SERVICE_INFO *find_service_info_by_hnd(pipes_struct *p, POLICY_HND *hnd) { SERVICE_INFO *service_info = NULL; - if( !find_policy_by_hnd( p, hnd, (void **)&service_info) ) { + if( !find_policy_by_hnd( p, hnd, (void **)(void *)&service_info) ) { DEBUG(2,("find_service_info_by_hnd: handle not found")); return NULL; } diff --git a/source/smbd/message.c b/source/smbd/message.c index e975da3e153..fd28df0d801 100644 --- a/source/smbd/message.c +++ b/source/smbd/message.c @@ -65,7 +65,7 @@ static void msg_deliver(void) * Incoming message is in DOS codepage format. Convert to UNIX. */ - if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **) &msg, True)) < 0 || !msg) { + if ((len = (int)convert_string_allocate(NULL,CH_DOS, CH_UNIX, msgbuf, msgpos, (void **)(void *)&msg, True)) < 0 || !msg) { DEBUG(3,("Conversion failed, delivering message in DOS codepage format\n")); for (i = 0; i < msgpos;) { if (msgbuf[i] == '\r' && i < (msgpos-1) && msgbuf[i+1] == '\n') { -- cgit From 93424c3c73a2bcb07e14b1497b89fa6f83b616d6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:58:54 +0000 Subject: r12045: More warning fixes... Just a few more to go. Jeremy. --- source/client/clitar.c | 2 ++ source/nsswitch/winbindd_ads.c | 2 +- source/utils/net_lookup.c | 2 +- source/utils/smbcquotas.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/client/clitar.c b/source/client/clitar.c index ad3387ffdda..5afe154cbbe 100644 --- a/source/client/clitar.c +++ b/source/client/clitar.c @@ -1097,6 +1097,8 @@ static void do_tarput(void) char *longfilename = NULL, linkflag; int skip = False; + ZERO_STRUCT(finfo); + GetTimeOfDay(&tp_start); DEBUG(5, ("RJS do_tarput called ...\n")); diff --git a/source/nsswitch/winbindd_ads.c b/source/nsswitch/winbindd_ads.c index ac24b35229c..29129e823a2 100644 --- a/source/nsswitch/winbindd_ads.c +++ b/source/nsswitch/winbindd_ads.c @@ -621,7 +621,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, goto done; } - rc = ads_search_retry_dn(ads, (void**)&msg, user_dn, attrs); + rc = ads_search_retry_dn(ads, (void**)(void *)&msg, user_dn, attrs); if (!ADS_ERR_OK(rc)) { status = ads_ntstatus(rc); DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: %s\n", diff --git a/source/utils/net_lookup.c b/source/utils/net_lookup.c index cd62245600d..8ee63515d45 100644 --- a/source/utils/net_lookup.c +++ b/source/utils/net_lookup.c @@ -211,7 +211,7 @@ static int net_lookup_kdc(int argc, const char **argv) realm.length = strlen(realm.data); } - rc = krb5_locate_kdc(ctx, &realm, (struct sockaddr **) &addrs, &num_kdcs, 0); + rc = krb5_locate_kdc(ctx, &realm, (struct sockaddr **)(void *)&addrs, &num_kdcs, 0); if (rc) { DEBUG(1, ("krb5_locate_kdc failed (%s)\n", error_message(rc))); return -1; diff --git a/source/utils/smbcquotas.c b/source/utils/smbcquotas.c index c516fbb2187..be7c2c64e6a 100644 --- a/source/utils/smbcquotas.c +++ b/source/utils/smbcquotas.c @@ -396,7 +396,7 @@ static struct cli_state *connect_one(const char *share) pstring username_str = {0}; pstring path = {0}; pstring set_str = {0}; - enum SMB_QUOTA_TYPE qtype; + enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE; int cmd = 0; static BOOL test_args = False; struct cli_state *cli; -- cgit From 702a186c5ec0e7dcc1f451a13e5fae0da805a226 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 3 Dec 2005 10:15:03 +0000 Subject: r12046: Fix typo --- source/include/ntdomain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/ntdomain.h b/source/include/ntdomain.h index fd36006c0b7..a30b7243727 100644 --- a/source/include/ntdomain.h +++ b/source/include/ntdomain.h @@ -284,7 +284,7 @@ typedef struct pipes_struct { output_data out_data; - /* This context is used for PUD data and is freed between each pdu. + /* This context is used for PDU data and is freed between each pdu. Don't use for pipe state storage. */ TALLOC_CTX *mem_ctx; -- cgit From 345796c1d0d831dc0c4d6456b445348ea4ba8336 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 3 Dec 2005 18:34:13 +0000 Subject: r12051: Merge across the lookup_name and lookup_sid work. Lets see how the build farm reacts :-) Volker --- source/Makefile.in | 2 +- source/auth/auth_util.c | 7 +- source/groupdb/mapping.c | 15 +- source/include/passdb.h | 14 ++ source/include/smb.h | 4 + source/lib/util_sid.c | 45 +---- source/modules/vfs_afsacl.c | 35 +--- source/nsswitch/wb_client.c | 41 +++-- source/passdb/lookup_sid.c | 399 +++++++++++++++++++++++++++++++--------- source/passdb/machine_sid.c | 24 +++ source/passdb/passdb.c | 135 ++++++++------ source/passdb/pdb_interface.c | 116 ++++++++++-- source/passdb/secrets.c | 2 +- source/passdb/util_builtin.c | 110 +++++++++++ source/passdb/util_sam_sid.c | 238 ------------------------ source/passdb/util_wellknown.c | 149 +++++++++++++++ source/rpc_server/srv_lsa_nt.c | 123 +++++++------ source/rpc_server/srv_samr_nt.c | 144 +++++++++------ source/smbd/lanman.c | 10 +- 19 files changed, 999 insertions(+), 614 deletions(-) create mode 100644 source/passdb/util_builtin.c delete mode 100644 source/passdb/util_sam_sid.c create mode 100644 source/passdb/util_wellknown.c diff --git a/source/Makefile.in b/source/Makefile.in index 888a0ebe344..c0753a76c00 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -326,7 +326,7 @@ LOCKING_OBJ = locking/locking.o locking/brlock.o locking/posix.o PASSDB_GET_SET_OBJ = passdb/pdb_get_set.o PASSDB_OBJ = $(PASSDB_GET_SET_OBJ) passdb/passdb.o passdb/pdb_interface.o \ - passdb/util_sam_sid.o passdb/pdb_compat.o \ + passdb/util_wellknown.o passdb/util_builtin.o passdb/pdb_compat.o \ passdb/lookup_sid.o \ passdb/login_cache.o @PDB_STATIC@ passdb/pdb_sql.o \ lib/system_smbd.o lib/account_pol.o lib/privileges.o diff --git a/source/auth/auth_util.c b/source/auth/auth_util.c index 61cb7f31cc7..ce1ce31d08a 100644 --- a/source/auth/auth_util.c +++ b/source/auth/auth_util.c @@ -1550,7 +1550,7 @@ NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken) Check for a SID in an NT_USER_TOKEN ****************************************************************************/ -BOOL nt_token_check_sid ( DOM_SID *sid, NT_USER_TOKEN *token ) +static BOOL nt_token_check_sid ( DOM_SID *sid, NT_USER_TOKEN *token ) { int i; @@ -1598,8 +1598,6 @@ BOOL nt_token_check_domain_rid( NT_USER_TOKEN *token, uint32 rid ) BOOL is_trusted_domain(const char* dom_name) { DOM_SID trustdom_sid; - char *pass = NULL; - time_t lct; BOOL ret; /* no trusted domains for a standalone server */ @@ -1613,9 +1611,8 @@ BOOL is_trusted_domain(const char* dom_name) become_root(); DEBUG (5,("is_trusted_domain: Checking for domain trust with [%s]\n", dom_name )); - ret = secrets_fetch_trusted_domain_password(dom_name, &pass, &trustdom_sid, &lct); + ret = secrets_fetch_trusted_domain_password(dom_name, NULL, NULL, NULL); unbecome_root(); - SAFE_FREE(pass); if (ret) return True; } diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 1e8586786cd..14040e4f52b 100644 --- a/source/groupdb/mapping.c +++ b/source/groupdb/mapping.c @@ -1166,11 +1166,22 @@ NTSTATUS pdb_default_create_alias(struct pdb_methods *methods, enum SID_NAME_USE type; uint32 new_rid; gid_t gid; - + BOOL exists; GROUP_MAP map; - if (lookup_name(get_global_sam_name(), name, &sid, &type)) + TALLOC_CTX *mem_ctx = talloc_new(NULL); + + if (mem_ctx == NULL) { + return NT_STATUS_NO_MEMORY; + } + + exists = lookup_name(mem_ctx, name, LOOKUP_NAME_ISOLATED, + NULL, NULL, &sid, &type); + talloc_free(mem_ctx); + + if (exists) { return NT_STATUS_ALIAS_EXISTS; + } if (!winbind_allocate_rid_and_gid(&new_rid, &gid)) return NT_STATUS_ACCESS_DENIED; diff --git a/source/include/passdb.h b/source/include/passdb.h index 0589b9a7cd4..20ea7021d07 100644 --- a/source/include/passdb.h +++ b/source/include/passdb.h @@ -376,6 +376,13 @@ typedef struct pdb_context const char **pp_names, uint32 *attrs); + NTSTATUS (*pdb_lookup_names)(struct pdb_context *context, + const DOM_SID *domain_sid, + size_t num_names, + const char **names, + uint32 *rids, + uint32 *attrs); + NTSTATUS (*pdb_get_account_policy)(struct pdb_context *context, int policy_index, uint32 *value); @@ -499,6 +506,13 @@ typedef struct pdb_methods const char **pp_names, uint32 *attrs); + NTSTATUS (*lookup_names)(struct pdb_methods *methods, + const DOM_SID *domain_sid, + int num_names, + const char **pp_names, + uint32 *rids, + uint32 *attrs); + NTSTATUS (*get_account_policy)(struct pdb_methods *methods, int policy_index, uint32 *value); diff --git a/source/include/smb.h b/source/include/smb.h index 6511f10365f..50b8c0369f4 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -264,6 +264,10 @@ enum SID_NAME_USE SID_NAME_COMPUTER /* sid for a computer */ }; +#define LOOKUP_NAME_ISOLATED 1 /* Look up unqualified names */ +#define LOOKUP_NAME_REMOTE 2 /* Ask others */ +#define LOOKUP_NAME_ALL (LOOKUP_NAME_ISOLATED|LOOKUP_NAME_REMOTE) + /** * @brief Security Identifier * diff --git a/source/lib/util_sid.c b/source/lib/util_sid.c index 4c274b5e01d..92bc2fb8931 100644 --- a/source/lib/util_sid.c +++ b/source/lib/util_sid.c @@ -75,11 +75,14 @@ const DOM_SID global_sid_Builtin_Backup_Operators = /* Builtin backup operators const DOM_SID global_sid_Builtin_Replicator = /* Builtin replicator */ { 1, 2, {0,0,0,0,0,5}, {32,552,0,0,0,0,0,0,0,0,0,0,0,0,0}}; +/* Unused, left here for documentary purposes */ +#if 0 #define SECURITY_NULL_SID_AUTHORITY 0 #define SECURITY_WORLD_SID_AUTHORITY 1 #define SECURITY_LOCAL_SID_AUTHORITY 2 #define SECURITY_CREATOR_SID_AUTHORITY 3 #define SECURITY_NT_AUTHORITY 5 +#endif /* * An NT compatible anonymous token. @@ -188,24 +191,6 @@ void split_domain_name(const char *fullname, char *domain, char *name) fullname, domain, name)); } -/**************************************************************************** - Test if a SID is wellknown and resolvable. -****************************************************************************/ - -BOOL resolvable_wellknown_sid(DOM_SID *sid) -{ - uint32 ia = (sid->id_auth[5]) + - (sid->id_auth[4] << 8 ) + - (sid->id_auth[3] << 16) + - (sid->id_auth[2] << 24); - - if (sid->sid_rev_num != SEC_DESC_REVISION || sid->num_auths < 1) - return False; - - return (ia == SECURITY_WORLD_SID_AUTHORITY || - ia == SECURITY_CREATOR_SID_AUTHORITY); -} - /***************************************************************** Convert a SID to an ascii string. *****************************************************************/ @@ -532,30 +517,6 @@ BOOL sid_equal(const DOM_SID *sid1, const DOM_SID *sid2) return sid_compare(sid1, sid2) == 0; } -/***************************************************************** - Check if the SID is the builtin SID (S-1-5-32). -*****************************************************************/ - -BOOL sid_check_is_builtin(const DOM_SID *sid) -{ - return sid_equal(sid, &global_sid_Builtin); -} - -/***************************************************************** - Check if the SID is one of the builtin SIDs (S-1-5-32-a). -*****************************************************************/ - -BOOL sid_check_is_in_builtin(const DOM_SID *sid) -{ - DOM_SID dom_sid; - uint32 rid; - - sid_copy(&dom_sid, sid); - sid_split_rid(&dom_sid, &rid); - - return sid_equal(&dom_sid, &global_sid_Builtin); -} - /***************************************************************** Calculates size of a sid. *****************************************************************/ diff --git a/source/modules/vfs_afsacl.c b/source/modules/vfs_afsacl.c index 41f40d1e3c4..3794299b9a0 100644 --- a/source/modules/vfs_afsacl.c +++ b/source/modules/vfs_afsacl.c @@ -105,27 +105,6 @@ static struct afs_ace *clone_afs_ace(TALLOC_CTX *mem_ctx, struct afs_ace *ace) return result; } - -/* Ok, this is sort-of a hack. We assume here that we have winbind users in - * AFS. And yet another copy of parse_domain_user.... */ - -static BOOL parse_domain_user(const char *domuser, fstring domain, - fstring user) -{ - char *p = strchr(domuser,*lp_winbind_separator()); - - if (p==NULL) { - return False; - } - - fstrcpy(user, p+1); - fstrcpy(domain, domuser); - domain[PTR_DIFF(p, domuser)] = 0; - strupper_m(domain); - - return True; -} - static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx, BOOL positive, const char *name, uint32 rights) @@ -168,14 +147,16 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx, } else { - fstring user, domain; + fstring domain, uname; + char *p; - if (!parse_domain_user(name, domain, user)) { - fstrcpy(user, name); - fstrcpy(domain, lp_workgroup()); + p = strchr_m(name, lp_winbind_separator()); + if (p != NULL) { + *p = '\\'; } - - if (!lookup_name(domain, user, &sid, &type)) { + + if (!lookup_name(name, LOOKUP_NAME_FULL, + domain, uname, &sid, &type)) { DEBUG(10, ("Could not find AFS user %s\n", name)); sid_copy(&sid, &global_sid_NULL); diff --git a/source/nsswitch/wb_client.c b/source/nsswitch/wb_client.c index db56cf04441..6fe55e12098 100644 --- a/source/nsswitch/wb_client.c +++ b/source/nsswitch/wb_client.c @@ -64,39 +64,52 @@ BOOL winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid, /* Call winbindd to convert sid to name */ -BOOL winbind_lookup_sid(const DOM_SID *sid, - fstring dom_name, fstring name, +BOOL winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, + char **domain, char **name, enum SID_NAME_USE *name_type) { struct winbindd_request request; struct winbindd_response response; NSS_STATUS result; - fstring sid_str; /* Initialise request */ ZERO_STRUCT(request); ZERO_STRUCT(response); - sid_to_string(sid_str, sid); - fstrcpy(request.data.sid, sid_str); + fstrcpy(request.data.sid, sid_string_static(sid)); /* Make request */ - result = winbindd_request_response(WINBINDD_LOOKUPSID, &request, &response); + result = winbindd_request_response(WINBINDD_LOOKUPSID, &request, + &response); - /* Copy out result */ + if (result != NSS_STATUS_SUCCESS) { + return False; + } - if (result == NSS_STATUS_SUCCESS) { - fstrcpy(dom_name, response.data.name.dom_name); - fstrcpy(name, response.data.name.name); - *name_type = (enum SID_NAME_USE)response.data.name.type; + /* Copy out result */ - DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", - sid_str, dom_name, name)); + if (domain != NULL) { + *domain = talloc_strdup(mem_ctx, response.data.name.dom_name); + if (*domain == NULL) { + DEBUG(0, ("talloc failed\n")); + return False; + } + } + if (name != NULL) { + *name = talloc_strdup(mem_ctx, response.data.name.name); + if (*name == NULL) { + DEBUG(0, ("talloc failed\n")); + return False; + } } - return (result == NSS_STATUS_SUCCESS); + *name_type = (enum SID_NAME_USE)response.data.name.type; + + DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", + sid_string_static(sid), *domain, *name)); + return True; } /* Call winbindd to convert SID to uid */ diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index b397e084c33..bad5d278aed 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -22,43 +22,247 @@ #include "includes.h" /***************************************************************** - *THE CANONICAL* convert name to SID function. - Tries local lookup first - for local domains - then uses winbind. + Dissect a user-provided name into domain, name, sid and type. + + If an explicit domain name was given in the form domain\user, it + has to try that. If no explicit domain name was given, we have + to do guesswork. *****************************************************************/ -BOOL lookup_name(const char *domain, const char *name, DOM_SID *psid, enum SID_NAME_USE *name_type) +BOOL lookup_name(TALLOC_CTX *mem_ctx, + const char *full_name, int flags, + char **ret_domain, char **ret_name, + DOM_SID *ret_sid, enum SID_NAME_USE *ret_type) { - fstring sid; - BOOL local_lookup = False; - - *name_type = SID_NAME_UNKNOWN; + char *p, *tmp; + char *domain = NULL; + char *name = NULL; + uint32 rid; + DOM_SID sid; + enum SID_NAME_USE type; + + p = strchr_m(full_name, '\\'); + + if (p != NULL) { + domain = talloc_strndup(mem_ctx, full_name, + PTR_DIFF(p, full_name)); + name = talloc_strdup(mem_ctx, p+1); + } else { + domain = talloc_strdup(mem_ctx, ""); + name = talloc_strdup(mem_ctx, full_name); + } + + if ((domain == NULL) || (name == NULL)) { + DEBUG(0, ("talloc failed\n")); + return False; + } - /* If we are looking up a domain user, make sure it is - for the local machine only */ - if (strequal(domain, get_global_sam_name())) { - if (local_lookup_name(name, psid, name_type)) { - DEBUG(10, - ("lookup_name: (local) [%s]\\[%s] -> SID %s (type %s: %u)\n", - domain, name, sid_to_string(sid,psid), - sid_type_lookup(*name_type), (unsigned int)*name_type)); - return True; + + /* It's our own domain, lookup the name in passdb */ + if (lookup_global_sam_name(name, &rid, &type)) { + sid_copy(&sid, get_global_sam_sid()); + sid_append_rid(&sid, rid); + goto ok; } - } else { - /* Remote */ - if (winbind_lookup_name(domain, name, psid, name_type)) { - - DEBUG(10,("lookup_name (winbindd): [%s]\\[%s] -> SID %s (type %u)\n", - domain, name, sid_to_string(sid, psid), - (unsigned int)*name_type)); - return True; + return False; + } + + if (strequal(domain, builtin_domain_name())) { + + /* Explicit request for a name in BUILTIN */ + if (lookup_builtin_name(name, &rid)) { + sid_copy(&sid, &global_sid_Builtin); + sid_append_rid(&sid, rid); + type = SID_NAME_ALIAS; + goto ok; } + return False; } - - DEBUG(10, ("lookup_name: %s lookup for [%s]\\[%s] failed\n", - local_lookup ? "local" : "winbind", domain, name)); + + if (domain[0] != '\0') { + /* An explicit domain name was given, here our last resort is + * winbind. */ + if (winbind_lookup_name(domain, name, &sid, &type)) { + goto ok; + } + return False; + } + + if (!(flags & LOOKUP_NAME_ISOLATED)) { + return False; + } + + /* Now the guesswork begins, we haven't been given an explicit + * domain. Try the sequence as documented on + * http://msdn.microsoft.com/library/en-us/secmgmt/security/lsalookupnames.asp + * November 27, 2005 */ + + /* 1. well-known names */ + + { + tmp = domain; + if (lookup_wellknown_name(mem_ctx, name, &sid, &domain)) { + talloc_free(tmp); + type = SID_NAME_WKN_GRP; + goto ok; + } + } + + /* 2. Builtin domain as such */ + + if (strequal(name, builtin_domain_name())) { + /* Swap domain and name */ + tmp = name; name = domain; domain = tmp; + sid_copy(&sid, &global_sid_Builtin); + type = SID_NAME_DOMAIN; + goto ok; + } + + /* 3. Account domain */ + + if (strequal(name, get_global_sam_name())) { + if (!secrets_fetch_domain_sid(name, &sid)) { + DEBUG(3, ("Could not fetch my SID\n")); + return False; + } + /* Swap domain and name */ + tmp = name; name = domain; domain = tmp; + type = SID_NAME_DOMAIN; + goto ok; + } + + /* 4. Primary domain */ + + if (!IS_DC && strequal(name, lp_workgroup())) { + if (!secrets_fetch_domain_sid(name, &sid)) { + DEBUG(3, ("Could not fetch the domain SID\n")); + return False; + } + /* Swap domain and name */ + tmp = name; name = domain; domain = tmp; + type = SID_NAME_DOMAIN; + goto ok; + } + + /* 5. Trusted domains as such, to me it looks as if members don't do + this, tested an XP workstation in a NT domain -- vl */ + + if (IS_DC && (secrets_fetch_trusted_domain_password(name, NULL, + &sid, NULL))) { + /* Swap domain and name */ + tmp = name; name = domain; domain = tmp; + type = SID_NAME_DOMAIN; + goto ok; + } + + /* 6. Builtin aliases */ + + if (lookup_builtin_name(name, &rid)) { + domain = talloc_strdup(mem_ctx, builtin_domain_name()); + sid_copy(&sid, &global_sid_Builtin); + sid_append_rid(&sid, rid); + type = SID_NAME_ALIAS; + goto ok; + } + + /* 7. Local systems' SAM (DCs don't have a local SAM) */ + /* 8. Primary SAM (On members, this is the domain) */ + + /* Both cases are done by looking at our passdb */ + + if (lookup_global_sam_name(name, &rid, &type)) { + domain = talloc_strdup(mem_ctx, get_global_sam_name()); + sid_copy(&sid, get_global_sam_sid()); + sid_append_rid(&sid, rid); + goto ok; + } + + /* Now our local possibilities are exhausted. */ + + if (!(flags & LOOKUP_NAME_REMOTE)) { + return False; + } + + /* If we are not a DC, we have to ask in our primary domain. Let + * winbind do that. */ + + if (!IS_DC && + (winbind_lookup_name(lp_workgroup(), name, &sid, &type))) { + domain = talloc_strdup(mem_ctx, lp_workgroup()); + goto ok; + } + + /* 9. Trusted domains */ + + /* If we're a DC we have to ask all trusted DC's. Winbind does not do + * that (yet), but give it a chance. */ + + if (IS_DC && winbind_lookup_name("", name, &sid, &type)) { + DOM_SID dom_sid; + uint32 tmp_rid; + enum SID_NAME_USE domain_type; + + if (type == SID_NAME_DOMAIN) { + /* Swap name and type */ + tmp = name; name = domain; domain = tmp; + goto ok; + } + + talloc_free(domain); + + /* Here we have to cope with a little deficiency in the + * winbind API: We have to ask it again for the name of the + * domain it figured out itself. Maybe fix that later... */ + + sid_copy(&dom_sid, &sid); + sid_split_rid(&dom_sid, &tmp_rid); + + if (!winbind_lookup_sid(mem_ctx, &dom_sid, &domain, NULL, + &domain_type) || + (domain_type != SID_NAME_DOMAIN)) { + DEBUG(2, ("winbind could not find the domain's name it " + "just looked up for us\n")); + return False; + } + + talloc_free(domain); + goto ok; + } + + /* 10. Don't translate */ return False; + + ok: + if ((domain == NULL) || (name == NULL)) { + DEBUG(0, ("talloc failed\n")); + return False; + } + + strupper_m(domain); + + if (ret_name != NULL) { + *ret_name = name; + } else { + talloc_free(name); + } + + if (ret_domain != NULL) { + *ret_domain = domain; + } else { + talloc_free(domain); + } + + if (ret_sid != NULL) { + sid_copy(ret_sid, &sid); + } + + if (ret_type != NULL) { + *ret_type = type; + } + + return True; } /***************************************************************** @@ -66,22 +270,21 @@ BOOL lookup_name(const char *domain, const char *name, DOM_SID *psid, enum SID_N Tries local lookup first - for local sids, then tries winbind. *****************************************************************/ -BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, - enum SID_NAME_USE *name_type) +BOOL lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, + char **ret_domain, char **ret_name, + enum SID_NAME_USE *ret_type) { - if (!name_type) - return False; - - *name_type = SID_NAME_UNKNOWN; - + char *domain = NULL; + char *name = NULL; + enum SID_NAME_USE type; /* Check if this is our own sid. This should perhaps be done by winbind? For the moment handle it here. */ if (sid_check_is_domain(sid)) { - fstrcpy(dom_name, get_global_sam_name()); - fstrcpy(name, ""); - *name_type = SID_NAME_DOMAIN; - return True; + domain = talloc_strdup(mem_ctx, get_global_sam_name()); + name = talloc_strdup(mem_ctx, ""); + type = SID_NAME_DOMAIN; + goto ok; } if (sid_check_is_in_our_domain(sid)) { @@ -89,22 +292,22 @@ BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, SMB_ASSERT(sid_peek_rid(sid, &rid)); /* For our own domain passdb is responsible */ - fstrcpy(dom_name, get_global_sam_name()); - return lookup_global_sam_rid(rid, name, name_type); + if (!lookup_global_sam_rid(mem_ctx, rid, &name, &type)) { + return False; + } + + domain = talloc_strdup(mem_ctx, get_global_sam_name()); + goto ok; } if (sid_check_is_builtin(sid)) { - /* Got through map_domain_sid_to_name here so that the mapping - * of S-1-5-32 to the name "BUILTIN" in as few places as - * possible. We might add i18n... */ - SMB_ASSERT(map_domain_sid_to_name(sid, dom_name)); + domain = talloc_strdup(mem_ctx, builtin_domain_name()); /* Yes, W2k3 returns "BUILTIN" both as domain and name here */ - fstrcpy(name, dom_name); - - *name_type = SID_NAME_DOMAIN; - return True; + name = talloc_strdup(mem_ctx, builtin_domain_name()); + type = SID_NAME_DOMAIN; + goto ok; } if (sid_check_is_in_builtin(sid)) { @@ -112,39 +315,56 @@ BOOL lookup_sid(const DOM_SID *sid, fstring dom_name, fstring name, SMB_ASSERT(sid_peek_rid(sid, &rid)); - /* Got through map_domain_sid_to_name here so that the mapping - * of S-1-5-32 to the name "BUILTIN" in as few places as - * possible. We might add i18n... */ - SMB_ASSERT(map_domain_sid_to_name(&global_sid_Builtin, - dom_name)); + if (!lookup_builtin_rid(mem_ctx, rid, &name)) { + return False; + } /* There's only aliases in S-1-5-32 */ - *name_type = SID_NAME_ALIAS; + type = SID_NAME_ALIAS; + domain = talloc_strdup(mem_ctx, builtin_domain_name()); - return lookup_builtin_rid(rid, name); + goto ok; } - if (winbind_lookup_sid(sid, dom_name, name, name_type)) { - return True; + if (winbind_lookup_sid(mem_ctx, sid, &domain, &name, &type)) { + goto ok; } DEBUG(10,("lookup_sid: winbind lookup for SID %s failed - trying " "special SIDs.\n", sid_string_static(sid))); - { - const char *dom, *obj_name; - - if (lookup_special_sid(sid, &dom, &obj_name, name_type)) { - DEBUG(10, ("found %s\\%s\n", dom, obj_name)); - fstrcpy(dom_name, dom); - fstrcpy(name, obj_name); - return True; - } + if (lookup_wellknown_sid(mem_ctx, sid, &domain, &name)) { + type = SID_NAME_WKN_GRP; + goto ok; } - DEBUG(10, ("lookup_sid failed\n")); - + DEBUG(10, ("Failed to lookup sid %s\n", sid_string_static(sid))); return False; + + ok: + + if ((domain == NULL) || (name == NULL)) { + DEBUG(0, ("talloc failed\n")); + return False; + } + + if (ret_domain != NULL) { + *ret_domain = domain; + } else { + talloc_free(domain); + } + + if (ret_name != NULL) { + *ret_name = name; + } else { + talloc_free(name); + } + + if (ret_type != NULL) { + *ret_type = type; + } + + return True; } /***************************************************************** @@ -187,10 +407,9 @@ static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid) for (pc = uid_sid_cache_head; pc; pc = pc->next) { if (pc->uid == uid) { - fstring sid; *psid = pc->sid; DEBUG(3,("fetch sid from uid cache %u -> %s\n", - (unsigned int)uid, sid_to_string(sid, psid))); + (unsigned int)uid, sid_string_static(psid))); DLIST_PROMOTE(uid_sid_cache_head, pc); return True; } @@ -208,10 +427,9 @@ static BOOL fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid ) for (pc = uid_sid_cache_head; pc; pc = pc->next) { if (sid_compare(&pc->sid, psid) == 0) { - fstring sid; *puid = pc->uid; DEBUG(3,("fetch uid from cache %u -> %s\n", - (unsigned int)*puid, sid_to_string(sid, psid))); + (unsigned int)*puid, sid_string_static(psid))); DLIST_PROMOTE(uid_sid_cache_head, pc); return True; } @@ -261,10 +479,9 @@ static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid) for (pc = gid_sid_cache_head; pc; pc = pc->next) { if (pc->gid == gid) { - fstring sid; *psid = pc->sid; DEBUG(3,("fetch sid from gid cache %u -> %s\n", - (unsigned int)gid, sid_to_string(sid, psid))); + (unsigned int)gid, sid_string_static(psid))); DLIST_PROMOTE(gid_sid_cache_head, pc); return True; } @@ -282,10 +499,9 @@ static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid) for (pc = gid_sid_cache_head; pc; pc = pc->next) { if (sid_compare(&pc->sid, psid) == 0) { - fstring sid; *pgid = pc->gid; DEBUG(3,("fetch gid from cache %u -> %s\n", - (unsigned int)*pgid, sid_to_string(sid, psid))); + (unsigned int)*pgid, sid_string_static(psid))); DLIST_PROMOTE(gid_sid_cache_head, pc); return True; } @@ -331,7 +547,6 @@ static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid) NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid) { - fstring sid; uid_t low, high; ZERO_STRUCTP(psid); @@ -348,7 +563,7 @@ NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid) if (winbind_uid_to_sid(psid, uid)) { DEBUG(10,("uid_to_sid: winbindd %u -> %s\n", - (unsigned int)uid, sid_to_string(sid, psid))); + (unsigned int)uid, sid_string_static(psid))); if (psid) store_uid_sid_cache(psid, uid); @@ -361,7 +576,8 @@ NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid) return NT_STATUS_UNSUCCESSFUL; } - DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid, sid_to_string(sid, psid))); + DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid, + sid_string_static(psid))); store_uid_sid_cache(psid, uid); return NT_STATUS_OK; @@ -373,7 +589,6 @@ NTSTATUS uid_to_sid(DOM_SID *psid, uid_t uid) NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid) { - fstring sid; gid_t low, high; ZERO_STRUCTP(psid); @@ -390,7 +605,7 @@ NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid) if (winbind_gid_to_sid(psid, gid)) { DEBUG(10,("gid_to_sid: winbindd %u -> %s\n", - (unsigned int)gid, sid_to_string(sid, psid))); + (unsigned int)gid, sid_string_static(psid))); if (psid) store_gid_sid_cache(psid, gid); @@ -403,7 +618,8 @@ NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid) return NT_STATUS_UNSUCCESSFUL; } - DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid, sid_to_string(sid, psid))); + DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid, + sid_string_static(psid))); store_gid_sid_cache(psid, gid); return NT_STATUS_OK; @@ -415,7 +631,6 @@ NTSTATUS gid_to_sid(DOM_SID *psid, gid_t gid) NTSTATUS sid_to_uid(const DOM_SID *psid, uid_t *puid) { - fstring dom_name, name, sid_str; enum SID_NAME_USE name_type; if (fetch_uid_from_cache(puid, psid)) @@ -437,7 +652,7 @@ NTSTATUS sid_to_uid(const DOM_SID *psid, uid_t *puid) /* If it is not our local domain, only hope is winbindd */ - if ( !winbind_lookup_sid(psid, dom_name, name, &name_type) ) { + if ( !winbind_lookup_sid(NULL, psid, NULL, NULL, &name_type) ) { DEBUG(10,("sid_to_uid: winbind lookup for non-local sid %s failed\n", sid_string_static(psid) )); @@ -456,12 +671,12 @@ NTSTATUS sid_to_uid(const DOM_SID *psid, uid_t *puid) if ( !winbind_sid_to_uid(puid, psid) ) { DEBUG(10,("sid_to_uid: winbind failed to allocate a new uid for sid %s\n", - sid_to_string(sid_str, psid) )); + sid_string_static(psid))); return NT_STATUS_UNSUCCESSFUL; } success: - DEBUG(10,("sid_to_uid: %s -> %u\n", sid_to_string(sid_str, psid), + DEBUG(10,("sid_to_uid: %s -> %u\n", sid_string_static(psid), (unsigned int)*puid )); store_uid_sid_cache(psid, *puid); @@ -475,7 +690,6 @@ success: NTSTATUS sid_to_gid(const DOM_SID *psid, gid_t *pgid) { - fstring dom_name, name, sid_str; enum SID_NAME_USE name_type; if (fetch_gid_from_cache(pgid, psid)) @@ -489,8 +703,9 @@ NTSTATUS sid_to_gid(const DOM_SID *psid, gid_t *pgid) if ( local_sid_to_gid(pgid, psid, &name_type) ) goto success; - if (!winbind_lookup_sid(psid, dom_name, name, &name_type)) { - DEBUG(10,("sid_to_gid: no one knows the SID %s (tried local, then winbind)\n", sid_to_string(sid_str, psid))); + if (!winbind_lookup_sid(NULL, psid, NULL, NULL, &name_type)) { + DEBUG(10,("sid_to_gid: no one knows the SID %s (tried local, then " + "winbind)\n", sid_string_static(psid))); return NT_STATUS_UNSUCCESSFUL; } @@ -514,13 +729,13 @@ NTSTATUS sid_to_gid(const DOM_SID *psid, gid_t *pgid) if ( !winbind_sid_to_gid(pgid, psid) ) { DEBUG(10,("sid_to_gid: winbind failed to allocate a new gid for sid %s\n", - sid_to_string(sid_str, psid) )); + sid_string_static(psid))); return NT_STATUS_UNSUCCESSFUL; } success: - DEBUG(10,("sid_to_gid: %s -> %u\n", sid_to_string(sid_str, psid), - (unsigned int)*pgid )); + DEBUG(10,("sid_to_gid: %s -> %u\n", sid_string_static(psid), + (unsigned int)*pgid )); store_gid_sid_cache(psid, *pgid); diff --git a/source/passdb/machine_sid.c b/source/passdb/machine_sid.c index 87ec27d34ea..074a516bcb6 100644 --- a/source/passdb/machine_sid.c +++ b/source/passdb/machine_sid.c @@ -198,3 +198,27 @@ void reset_global_sam_sid(void) { SAFE_FREE(global_sam_sid); } + +/***************************************************************** + Check if the SID is our domain SID (S-1-5-21-x-y-z). +*****************************************************************/ + +BOOL sid_check_is_domain(const DOM_SID *sid) +{ + return sid_equal(sid, get_global_sam_sid()); +} + +/***************************************************************** + Check if the SID is our domain SID (S-1-5-21-x-y-z). +*****************************************************************/ + +BOOL sid_check_is_in_our_domain(const DOM_SID *sid) +{ + DOM_SID dom_sid; + uint32 rid; + + sid_copy(&dom_sid, sid); + sid_split_rid(&dom_sid, &rid); + + return sid_equal(&dom_sid, get_global_sam_sid()); +} diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index e073db3499c..3ca26a57c74 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -735,7 +735,7 @@ BOOL algorithmic_pdb_rid_is_user(uint32 rid) Look up a rid in the SAM we're responsible for (i.e. passdb) ********************************************************************/ -BOOL lookup_global_sam_rid(uint32 rid, fstring name, +BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid, char **name, enum SID_NAME_USE *psid_name_use) { SAM_ACCOUNT *sam_account = NULL; @@ -760,7 +760,7 @@ BOOL lookup_global_sam_rid(uint32 rid, fstring name, become_root(); if (pdb_getsampwsid(sam_account, &sid)) { unbecome_root(); /* -----> EXIT BECOME_ROOT() */ - fstrcpy(name, pdb_get_username(sam_account)); + *name = talloc_strdup(mem_ctx, pdb_get_username(sam_account)); *psid_name_use = SID_NAME_USER; pdb_free_sam(&sam_account); @@ -784,14 +784,14 @@ BOOL lookup_global_sam_rid(uint32 rid, fstring name, map.nt_name)); } - fstrcpy(name, map.nt_name); + *name = talloc_strdup(mem_ctx, map.nt_name); *psid_name_use = map.sid_name_use; return True; } if (rid == DOMAIN_USER_RID_ADMIN) { *psid_name_use = SID_NAME_USER; - fstrcpy(name, "Administrator"); + *name = talloc_strdup(mem_ctx, "Administrator"); return True; } @@ -807,13 +807,15 @@ BOOL lookup_global_sam_rid(uint32 rid, fstring name, DEBUG(5,("lookup_global_sam_rid: looking up uid %u %s\n", (unsigned int)uid, pw ? "succeeded" : "failed" )); - if ( !pw ) - fstr_sprintf(name, "unix_user.%u", (unsigned int)uid); - else - fstrcpy( name, pw->pw_name ); + if ( !pw ) { + *name = talloc_asprintf(mem_ctx, "unix_user.%u", + (unsigned int)uid); + } else { + *name = talloc_strdup(mem_ctx, pw->pw_name ); + } DEBUG(5,("lookup_global_sam_rid: found user %s for rid %u\n", - name, (unsigned int)rid )); + *name, (unsigned int)rid )); *psid_name_use = SID_NAME_USER; @@ -830,13 +832,15 @@ BOOL lookup_global_sam_rid(uint32 rid, fstring name, DEBUG(5,("lookup_global_sam_rid: looking up gid %u %s\n", (unsigned int)gid, gr ? "succeeded" : "failed" )); - if( !gr ) - fstr_sprintf(name, "unix_group.%u", (unsigned int)gid); - else - fstrcpy( name, gr->gr_name); + if( !gr ) { + *name = talloc_asprintf(mem_ctx, "unix_group.%u", + (unsigned int)gid); + } else { + *name = talloc_strdup(mem_ctx, gr->gr_name); + } DEBUG(5,("lookup_global_sam_rid: found group %s for rid %u\n", - name, (unsigned int)rid )); + *name, (unsigned int)rid )); /* assume algorithmic groups are domain global groups */ @@ -850,17 +854,13 @@ BOOL lookup_global_sam_rid(uint32 rid, fstring name, Convert a name into a SID. Used in the lookup name rpc. ********************************************************************/ -BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psid_name_use) +BOOL lookup_global_sam_name(const char *c_user, uint32_t *rid, enum SID_NAME_USE *type) { - DOM_SID local_sid; - DOM_SID sid; fstring user; SAM_ACCOUNT *sam_account = NULL; struct group *grp; GROUP_MAP map; - *psid_name_use = SID_NAME_UNKNOWN; - /* * user may be quoted a const string, and map_username and * friends can modify it. Make a modifiable copy. JRA. @@ -868,17 +868,6 @@ BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psi fstrcpy(user, c_user); - sid_copy(&local_sid, get_global_sam_sid()); - - if (map_name_to_wellknown_sid(&sid, psid_name_use, user)){ - fstring sid_str; - sid_copy( psid, &sid); - sid_to_string(sid_str, &sid); - DEBUG(10,("lookup_name: name %s = SID %s, type = %u\n", user, sid_str, - (unsigned int)*psid_name_use )); - return True; - } - (void)map_username(user); if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_account))) { @@ -889,10 +878,28 @@ BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psi become_root(); if (pdb_getsampwnam(sam_account, user)) { + const DOM_SID *user_sid; + unbecome_root(); - sid_copy(psid, pdb_get_user_sid(sam_account)); - *psid_name_use = SID_NAME_USER; - + + user_sid = pdb_get_user_sid(sam_account); + + if (!sid_check_is_in_our_domain(user_sid)) { + DEBUG(0, ("User %s with invalid SID %s in passdb\n", + user, sid_string_static(user_sid))); + return False; + } + + sid_peek_rid(user_sid, rid); + + if (pdb_get_acct_ctrl(sam_account) & + (ACB_DOMTRUST|ACB_WSTRUST|ACB_SVRTRUST)) { + /* We have to filter them out in lsa_lookupnames, + * indicate that this is not a real user. */ + *type = SID_NAME_COMPUTER; + } else { + *type = SID_NAME_USER; + } pdb_free_sam(&sam_account); return True; } @@ -905,41 +912,51 @@ BOOL local_lookup_name(const char *c_user, DOM_SID *psid, enum SID_NAME_USE *psi /* check if it's a mapped group */ if (pdb_getgrnam(&map, user)) { - /* yes it's a mapped group */ - sid_copy(&local_sid, &map.sid); - *psid_name_use = map.sid_name_use; - } else { - /* it's not a mapped group */ - grp = getgrnam(user); - if(!grp) { - unbecome_root(); /* ---> exit form block */ + + unbecome_root(); + + /* BUILTIN groups are looked up elsewhere */ + if (!sid_check_is_in_our_domain(&map.sid)) { + DEBUG(10, ("Found group %s (%s) not in our domain -- " + "ignoring.", user, + sid_string_static(&map.sid))); return False; } - /* - *check if it's mapped, if it is reply it doesn't exist - * - * that's to prevent this case: - * - * unix group ug is mapped to nt group ng - * someone does a lookup on ug - * we must not reply as it doesn't "exist" anymore - * for NT. For NT only ng exists. - * JFM, 30/11/2001 - */ + /* yes it's a mapped group */ + sid_peek_rid(&map.sid, rid); + *type = map.sid_name_use; + return True; + } + + /* it's not a mapped group */ + grp = getgrnam(user); + if(!grp) { + unbecome_root(); /* ---> exit form block */ + return False; + } - if (pdb_getgrgid(&map, grp->gr_gid)){ - unbecome_root(); /* ---> exit form block */ - return False; - } + /* + *check if it's mapped, if it is reply it doesn't exist + * + * that's to prevent this case: + * + * unix group ug is mapped to nt group ng + * someone does a lookup on ug + * we must not reply as it doesn't "exist" anymore + * for NT. For NT only ng exists. + * JFM, 30/11/2001 + */ - sid_append_rid( &local_sid, pdb_gid_to_group_rid(grp->gr_gid)); - *psid_name_use = SID_NAME_ALIAS; + if (pdb_getgrgid(&map, grp->gr_gid)) { + unbecome_root(); /* ---> exit form block */ + return False; } unbecome_root(); /* END ROOT BLOCK */ - sid_copy( psid, &local_sid); + *rid = pdb_gid_to_group_rid(grp->gr_gid); + *type = SID_NAME_ALIAS; return True; } diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c index 875e264bf01..6ac5a3e9654 100644 --- a/source/passdb/pdb_interface.c +++ b/source/passdb/pdb_interface.c @@ -699,6 +699,25 @@ static NTSTATUS context_lookup_rids(struct pdb_context *context, rids, pp_names, pp_attrs); } +static NTSTATUS context_lookup_names(struct pdb_context *context, + const DOM_SID *domain_sid, + size_t num_names, + const char **pp_names, + uint32 *rids, + uint32 *pp_attrs) +{ + NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; + + if ((!context) || (!context->pdb_methods)) { + DEBUG(0, ("invalid pdb_context specified!\n")); + return ret; + } + + return context->pdb_methods->lookup_names(context->pdb_methods, + domain_sid, num_names, + pp_names, rids, pp_attrs); +} + static NTSTATUS context_get_account_policy(struct pdb_context *context, int policy_index, uint32 *value) { @@ -906,6 +925,7 @@ static NTSTATUS make_pdb_context(struct pdb_context **context) (*context)->pdb_enum_aliasmem = context_enum_aliasmem; (*context)->pdb_enum_alias_memberships = context_enum_alias_memberships; (*context)->pdb_lookup_rids = context_lookup_rids; + (*context)->pdb_lookup_names = context_lookup_names; (*context)->pdb_get_account_policy = context_get_account_policy; (*context)->pdb_set_account_policy = context_set_account_policy; @@ -1413,6 +1433,22 @@ NTSTATUS pdb_lookup_rids(const DOM_SID *domain_sid, num_rids, rids, names, attrs); } +NTSTATUS pdb_lookup_names(const DOM_SID *domain_sid, + int num_names, + const char **names, + uint32 *rids, + uint32 *attrs) +{ + struct pdb_context *pdb_context = pdb_get_static_context(False); + + if (!pdb_context) { + return NT_STATUS_NOT_IMPLEMENTED; + } + + return pdb_context->pdb_lookup_names(pdb_context, domain_sid, + num_names, names, rids, attrs); +} + BOOL pdb_get_account_policy(int policy_index, uint32 *value) { struct pdb_context *pdb_context = pdb_get_static_context(False); @@ -1655,14 +1691,11 @@ NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods, if (sid_check_is_builtin(domain_sid)) { for (i=0; iname != NULL) { + if (rid == aliases->rid) { + *name = talloc_strdup(mem_ctx, aliases->name); + return True; + } + aliases++; + } + + return False; +} + +/******************************************************************* + Look up a name in the BUILTIN domain + ********************************************************************/ +BOOL lookup_builtin_name(const char *name, uint32 *rid) +{ + const struct rid_name_map *aliases = builtin_aliases; + + while (aliases->name != NULL) { + if (strequal(name, aliases->name)) { + *rid = aliases->rid; + return True; + } + aliases++; + } + + return False; +} + +/***************************************************************** + Return the name of the BUILTIN domain +*****************************************************************/ + +const char *builtin_domain_name(void) +{ + return "BUILTIN"; +} + +/***************************************************************** + Check if the SID is the builtin SID (S-1-5-32). +*****************************************************************/ + +BOOL sid_check_is_builtin(const DOM_SID *sid) +{ + return sid_equal(sid, &global_sid_Builtin); +} + +/***************************************************************** + Check if the SID is one of the builtin SIDs (S-1-5-32-a). +*****************************************************************/ + +BOOL sid_check_is_in_builtin(const DOM_SID *sid) +{ + DOM_SID dom_sid; + uint32 rid; + + sid_copy(&dom_sid, sid); + sid_split_rid(&dom_sid, &rid); + + return sid_equal(&dom_sid, &global_sid_Builtin); +} + diff --git a/source/passdb/util_sam_sid.c b/source/passdb/util_sam_sid.c deleted file mode 100644 index 822b7f6a349..00000000000 --- a/source/passdb/util_sam_sid.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Luke Kenneth Caseson Leighton 1998-1999 - Copyright (C) Jeremy Allison 1999 - - 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. -*/ - -#include "includes.h" - -#define MAX_SID_NAMES 7 - -typedef struct _known_sid_users { - uint32 rid; - enum SID_NAME_USE sid_name_use; - const char *known_user_name; -} known_sid_users; - -struct sid_name_map_info -{ - const DOM_SID *sid; - const char *name; - const known_sid_users *known_users; -}; - -static const known_sid_users everyone_users[] = { - { 0, SID_NAME_WKN_GRP, "Everyone" }, - {0, (enum SID_NAME_USE)0, NULL}}; - -static const known_sid_users creator_owner_users[] = { - { 0, SID_NAME_WKN_GRP, "Creator Owner" }, - { 1, SID_NAME_WKN_GRP, "Creator Group" }, - {0, (enum SID_NAME_USE)0, NULL}}; - -static const known_sid_users nt_authority_users[] = { - { 1, SID_NAME_WKN_GRP, "Dialup" }, - { 2, SID_NAME_WKN_GRP, "Network"}, - { 3, SID_NAME_WKN_GRP, "Batch"}, - { 4, SID_NAME_WKN_GRP, "Interactive"}, - { 6, SID_NAME_WKN_GRP, "Service"}, - { 7, SID_NAME_WKN_GRP, "AnonymousLogon"}, - { 8, SID_NAME_WKN_GRP, "Proxy"}, - { 9, SID_NAME_WKN_GRP, "ServerLogon"}, - { 10, SID_NAME_WKN_GRP, "Self"}, - { 11, SID_NAME_WKN_GRP, "Authenticated Users"}, - { 12, SID_NAME_WKN_GRP, "Restricted"}, - { 13, SID_NAME_WKN_GRP, "Terminal Server User"}, - { 14, SID_NAME_WKN_GRP, "Remote Interactive Logon"}, - { 15, SID_NAME_WKN_GRP, "This Organization"}, - { 18, SID_NAME_WKN_GRP, "SYSTEM"}, - { 19, SID_NAME_WKN_GRP, "Local Service"}, - { 20, SID_NAME_WKN_GRP, "Network Service"}, - { 0, (enum SID_NAME_USE)0, NULL}}; - -static const known_sid_users builtin_groups[] = { - { BUILTIN_ALIAS_RID_ADMINS, SID_NAME_ALIAS, "Administrators" }, - { BUILTIN_ALIAS_RID_USERS, SID_NAME_ALIAS, "Users" }, - { BUILTIN_ALIAS_RID_GUESTS, SID_NAME_ALIAS, "Guests" }, - { BUILTIN_ALIAS_RID_POWER_USERS, SID_NAME_ALIAS, "Power Users" }, - { BUILTIN_ALIAS_RID_ACCOUNT_OPS, SID_NAME_ALIAS, "Account Operators" }, - { BUILTIN_ALIAS_RID_SYSTEM_OPS, SID_NAME_ALIAS, "Server Operators" }, - { BUILTIN_ALIAS_RID_PRINT_OPS, SID_NAME_ALIAS, "Print Operators" }, - { BUILTIN_ALIAS_RID_BACKUP_OPS, SID_NAME_ALIAS, "Backup Operators" }, - { BUILTIN_ALIAS_RID_REPLICATOR, SID_NAME_ALIAS, "Replicator" }, - { BUILTIN_ALIAS_RID_RAS_SERVERS, SID_NAME_ALIAS, "RAS Servers" }, - { BUILTIN_ALIAS_RID_PRE_2K_ACCESS, SID_NAME_ALIAS, "Pre-Windows 2000 Compatible Access" }, - { 0, (enum SID_NAME_USE)0, NULL}}; - -static struct sid_name_map_info special_domains[] = { - { &global_sid_Builtin, "BUILTIN", builtin_groups }, - { &global_sid_World_Domain, "", everyone_users }, - { &global_sid_Creator_Owner_Domain, "", creator_owner_users }, - { &global_sid_NT_Authority, "NT Authority", nt_authority_users }, - { NULL, NULL, NULL }}; - -/************************************************************************** - Turns a domain SID into a name, returned in the nt_domain argument. -***************************************************************************/ - -BOOL map_domain_sid_to_name(const DOM_SID *sid, fstring nt_domain) -{ - fstring sid_str; - int i = 0; - - sid_to_string(sid_str, sid); - - DEBUG(5,("map_domain_sid_to_name: %s\n", sid_str)); - - while (special_domains[i].sid != NULL) { - DEBUG(5,("map_domain_sid_to_name: compare: %s\n", - sid_string_static(special_domains[i].sid))); - if (sid_equal(special_domains[i].sid, sid)) { - fstrcpy(nt_domain, special_domains[i].name); - DEBUG(5,("map_domain_sid_to_name: found '%s'\n", - nt_domain)); - return True; - } - i++; - } - - DEBUG(5,("map_domain_sid_to_name: mapping for %s not found\n", - sid_string_static(sid))); - - return False; -} - -/************************************************************************** - Looks up a known username from one of the known domains. -***************************************************************************/ - -BOOL lookup_special_sid(const DOM_SID *sid, const char **domain, - const char **name, enum SID_NAME_USE *type) -{ - int i; - DOM_SID dom_sid; - uint32 rid; - const known_sid_users *users = NULL; - - sid_copy(&dom_sid, sid); - if (!sid_split_rid(&dom_sid, &rid)) { - DEBUG(2, ("Could not split rid from SID\n")); - return False; - } - - for (i=0; special_domains[i].sid != NULL; i++) { - if (sid_equal(&dom_sid, special_domains[i].sid)) { - *domain = special_domains[i].name; - users = special_domains[i].known_users; - break; - } - } - - if (users == NULL) { - DEBUG(10, ("SID %s is no special sid\n", - sid_string_static(sid))); - return False; - } - - for (i=0; users[i].known_user_name != NULL; i++) { - if (rid == users[i].rid) { - *name = users[i].known_user_name; - *type = users[i].sid_name_use; - return True; - } - } - - DEBUG(10, ("RID of special SID %s not found\n", - sid_string_static(sid))); - - return False; -} - -/******************************************************************* - Look up a rid in the BUILTIN domain - ********************************************************************/ -BOOL lookup_builtin_rid(uint32 rid, fstring name) -{ - const known_sid_users *aliases = builtin_groups; - int i; - - for (i=0; aliases[i].known_user_name != NULL; i++) { - if (rid == aliases[i].rid) { - fstrcpy(name, aliases[i].known_user_name); - return True; - } - } - - return False; -} - -/***************************************************************** - Check if the SID is our domain SID (S-1-5-21-x-y-z). -*****************************************************************/ - -BOOL sid_check_is_domain(const DOM_SID *sid) -{ - return sid_equal(sid, get_global_sam_sid()); -} - -/***************************************************************** - Check if the SID is our domain SID (S-1-5-21-x-y-z). -*****************************************************************/ - -BOOL sid_check_is_in_our_domain(const DOM_SID *sid) -{ - DOM_SID dom_sid; - uint32 rid; - - sid_copy(&dom_sid, sid); - sid_split_rid(&dom_sid, &rid); - - return sid_equal(&dom_sid, get_global_sam_sid()); -} - -/************************************************************************** - Try and map a name to one of the well known SIDs. -***************************************************************************/ - -BOOL map_name_to_wellknown_sid(DOM_SID *sid, enum SID_NAME_USE *use, const char *name) -{ - int i, j; - - DEBUG(10,("map_name_to_wellknown_sid: looking up %s\n", name)); - - for (i=0; special_domains[i].sid != NULL; i++) { - const known_sid_users *users = special_domains[i].known_users; - - if (users == NULL) - continue; - - for (j=0; users[j].known_user_name != NULL; j++) { - if ( strequal(users[j].known_user_name, name) ) { - sid_copy(sid, special_domains[i].sid); - sid_append_rid(sid, users[j].rid); - *use = users[j].sid_name_use; - return True; - } - } - } - - return False; -} - - diff --git a/source/passdb/util_wellknown.c b/source/passdb/util_wellknown.c new file mode 100644 index 00000000000..b1eb8b42372 --- /dev/null +++ b/source/passdb/util_wellknown.c @@ -0,0 +1,149 @@ +/* + Unix SMB/CIFS implementation. + Lookup routines for well-known SIDs + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Luke Kenneth Caseson Leighton 1998-1999 + Copyright (C) Jeremy Allison 1999 + Copyright (C) Volker Lendecke 2005 + + 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. +*/ + +#include "includes.h" + +struct rid_name_map { + uint32 rid; + const char *name; +}; + +struct sid_name_map_info +{ + const DOM_SID *sid; + const char *name; + const struct rid_name_map *known_users; +}; + +static const struct rid_name_map everyone_users[] = { + { 0, "Everyone" }, + { 0, NULL}}; + +static const struct rid_name_map creator_owner_users[] = { + { 0, "Creator Owner" }, + { 1, "Creator Group" }, + { 0, NULL}}; + +static const struct rid_name_map nt_authority_users[] = { + { 1, "Dialup" }, + { 2, "Network"}, + { 3, "Batch"}, + { 4, "Interactive"}, + { 6, "Service"}, + { 7, "AnonymousLogon"}, + { 8, "Proxy"}, + { 9, "ServerLogon"}, + { 10, "Self"}, + { 11, "Authenticated Users"}, + { 12, "Restricted"}, + { 13, "Terminal Server User"}, + { 14, "Remote Interactive Logon"}, + { 15, "This Organization"}, + { 18, "SYSTEM"}, + { 19, "Local Service"}, + { 20, "Network Service"}, + { 0, NULL}}; + +static struct sid_name_map_info special_domains[] = { + { &global_sid_World_Domain, "", everyone_users }, + { &global_sid_Creator_Owner_Domain, "", creator_owner_users }, + { &global_sid_NT_Authority, "NT Authority", nt_authority_users }, + { NULL, NULL, NULL }}; + +/************************************************************************** + Looks up a known username from one of the known domains. +***************************************************************************/ + +BOOL lookup_wellknown_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, + char **domain, char **name) +{ + int i; + DOM_SID dom_sid; + uint32 rid; + const struct rid_name_map *users = NULL; + + sid_copy(&dom_sid, sid); + if (!sid_split_rid(&dom_sid, &rid)) { + DEBUG(2, ("Could not split rid from SID\n")); + return False; + } + + for (i=0; special_domains[i].sid != NULL; i++) { + if (sid_equal(&dom_sid, special_domains[i].sid)) { + *domain = talloc_strdup(mem_ctx, + special_domains[i].name); + users = special_domains[i].known_users; + break; + } + } + + if (users == NULL) { + DEBUG(10, ("SID %s is no special sid\n", + sid_string_static(sid))); + return False; + } + + for (i=0; users[i].name != NULL; i++) { + if (rid == users[i].rid) { + *name = talloc_strdup(mem_ctx, users[i].name); + return True; + } + } + + DEBUG(10, ("RID of special SID %s not found\n", + sid_string_static(sid))); + + return False; +} + +/************************************************************************** + Try and map a name to one of the well known SIDs. +***************************************************************************/ + +BOOL lookup_wellknown_name(TALLOC_CTX *mem_ctx, const char *name, + DOM_SID *sid, char **domain) +{ + int i, j; + + DEBUG(10,("map_name_to_wellknown_sid: looking up %s\n", name)); + + for (i=0; special_domains[i].sid != NULL; i++) { + const struct rid_name_map *users = + special_domains[i].known_users; + + if (users == NULL) + continue; + + for (j=0; users[j].name != NULL; j++) { + if ( strequal(users[j].name, name) ) { + sid_copy(sid, special_domains[i].sid); + sid_append_rid(sid, users[j].rid); + *domain = talloc_strdup( + mem_ctx, special_domains[i].name); + return True; + } + } + } + + return False; +} diff --git a/source/rpc_server/srv_lsa_nt.c b/source/rpc_server/srv_lsa_nt.c index b56ae109141..78e9cd62112 100644 --- a/source/rpc_server/srv_lsa_nt.c +++ b/source/rpc_server/srv_lsa_nt.c @@ -135,67 +135,75 @@ static int init_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid) init_lsa_rid2s ***************************************************************************/ -static void init_lsa_rid2s(DOM_R_REF *ref, DOM_RID2 *rid2, - int num_entries, UNISTR2 *name, - uint32 *mapped_count, BOOL endian) +static int init_lsa_rid2s(TALLOC_CTX *mem_ctx, + DOM_R_REF *ref, DOM_RID2 *rid2, + int num_entries, UNISTR2 *name, + int flags) { - int i; - int total = 0; - *mapped_count = 0; + int mapped_count, i; SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS); + mapped_count = 0; + become_root(); /* lookup_name can require root privs */ for (i = 0; i < num_entries; i++) { BOOL status = False; DOM_SID sid; - uint32 rid = 0xffffffff; - int dom_idx = -1; - pstring full_name; - fstring dom_name, user; - enum SID_NAME_USE name_type = SID_NAME_UNKNOWN; + uint32 rid; + int dom_idx; + char *full_name, *domain; + enum SID_NAME_USE type = SID_NAME_UNKNOWN; /* Split name into domain and user component */ - unistr2_to_ascii(full_name, &name[i], sizeof(full_name)); - split_domain_name(full_name, dom_name, user); - - /* Lookup name */ + if (rpcstr_pull_unistr2_talloc(mem_ctx, &full_name, + &name[i]) < 0) { + DEBUG(0, ("pull_ucs2_talloc failed\n")); + return 0; + } DEBUG(5, ("init_lsa_rid2s: looking up name %s\n", full_name)); - status = lookup_name(dom_name, user, &sid, &name_type); - - if((name_type == SID_NAME_UNKNOWN) && (lp_server_role() == ROLE_DOMAIN_MEMBER) && (strncmp(dom_name, full_name, strlen(dom_name)) != 0)) { - DEBUG(5, ("init_lsa_rid2s: domain name not provided and local account not found, using member domain\n")); - fstrcpy(dom_name, lp_workgroup()); - status = lookup_name(dom_name, user, &sid, &name_type); - } + /* We can ignore the result of lookup_name, it will not touch + "type" if it's not successful */ - if (name_type == SID_NAME_WKN_GRP) { - /* BUILTIN aliases are still aliases :-) */ - name_type = SID_NAME_ALIAS; - } + lookup_name(mem_ctx, full_name, flags, &domain, NULL, + &sid, &type); DEBUG(5, ("init_lsa_rid2s: %s\n", status ? "found" : "not found")); - if (status && name_type != SID_NAME_UNKNOWN) { + switch (type) { + case SID_NAME_USER: + case SID_NAME_DOM_GRP: + case SID_NAME_DOMAIN: + case SID_NAME_ALIAS: + case SID_NAME_WKN_GRP: + /* Leave these unchanged */ + break; + default: + /* Don't hand out anything but the list above */ + type = SID_NAME_UNKNOWN; + break; + } + + rid = 0; + dom_idx = -1; + + if (type != SID_NAME_UNKNOWN) { sid_split_rid(&sid, &rid); - dom_idx = init_dom_ref(ref, dom_name, &sid); - (*mapped_count)++; - } else { - dom_idx = -1; - rid = 0; - name_type = SID_NAME_UNKNOWN; + dom_idx = init_dom_ref(ref, domain, &sid); + mapped_count++; } - init_dom_rid2(&rid2[total], rid, name_type, dom_idx); - total++; + init_dom_rid2(&rid2[i], rid, type, dom_idx); } unbecome_root(); + + return mapped_count; } /*************************************************************************** @@ -250,42 +258,44 @@ static void init_lsa_trans_names(TALLOC_CTX *ctx, DOM_R_REF *ref, LSA_TRANS_NAME DOM_SID find_sid = sid[i].sid; uint32 rid = 0xffffffff; int dom_idx = -1; - fstring name, dom_name; - enum SID_NAME_USE sid_name_use = (enum SID_NAME_USE)0; + char *name, *domain; + enum SID_NAME_USE type = SID_NAME_UNKNOWN; - sid_to_string(name, &find_sid); - DEBUG(5, ("init_lsa_trans_names: looking up sid %s\n", name)); + DEBUG(5, ("init_lsa_trans_names: looking up sid %s\n", + sid_string_static(&find_sid))); /* Lookup sid from winbindd */ - status = lookup_sid(&find_sid, dom_name, name, &sid_name_use); + status = lookup_sid(ctx, &find_sid, &domain, &name, &type); DEBUG(5, ("init_lsa_trans_names: %s\n", status ? "found" : "not found")); if (!status) { - sid_name_use = SID_NAME_UNKNOWN; - memset(dom_name, '\0', sizeof(dom_name)); - sid_to_string(name, &find_sid); + type = SID_NAME_UNKNOWN; + domain = talloc_strdup(ctx, ""); + name = talloc_strdup(ctx, + sid_string_static(&find_sid)); dom_idx = -1; - DEBUG(10,("init_lsa_trans_names: added unknown user '%s' to " - "referenced list.\n", name )); + DEBUG(10,("init_lsa_trans_names: added unknown user " + "'%s' to referenced list.\n", name )); } else { (*mapped_count)++; /* Store domain sid in ref array */ if (find_sid.num_auths == 5) { sid_split_rid(&find_sid, &rid); } - dom_idx = init_dom_ref(ref, dom_name, &find_sid); + dom_idx = init_dom_ref(ref, domain, &find_sid); - DEBUG(10,("init_lsa_trans_names: added %s '%s\\%s' (%d) to referenced list.\n", - sid_type_lookup(sid_name_use), dom_name, name, sid_name_use )); + DEBUG(10,("init_lsa_trans_names: added %s '%s\\%s' " + "(%d) to referenced list.\n", + sid_type_lookup(type), domain, name, type)); } init_lsa_trans_name(&trn->name[total], &trn->uni_name[total], - sid_name_use, name, dom_idx); + type, name, dom_idx); total++; } @@ -697,12 +707,18 @@ NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP DOM_R_REF *ref; DOM_RID2 *rids; uint32 mapped_count = 0; + int flags = 0; if (num_entries > MAX_LOOKUP_SIDS) { num_entries = MAX_LOOKUP_SIDS; DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries)); } + /* Probably the lookup_level is some sort of bitmask. */ + if (q_u->lookup_level == 1) { + flags = LOOKUP_NAME_ALL; + } + ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF); rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries); @@ -720,10 +736,11 @@ NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP if (!ref || !rids) return NT_STATUS_NO_MEMORY; + /* set up the LSA Lookup RIDs response */ + mapped_count = init_lsa_rid2s(p->mem_ctx, ref, rids, num_entries, + names, flags); done: - /* set up the LSA Lookup RIDs response */ - init_lsa_rid2s(ref, rids, num_entries, names, &mapped_count, p->endian); if (NT_STATUS_IS_OK(r_u->status)) { if (mapped_count == 0) r_u->status = NT_STATUS_NONE_MAPPED; @@ -1109,15 +1126,13 @@ NTSTATUS _lsa_enum_privsaccount(pipes_struct *p, prs_struct *ps, LSA_Q_ENUMPRIVS NTSTATUS _lsa_getsystemaccount(pipes_struct *p, LSA_Q_GETSYSTEMACCOUNT *q_u, LSA_R_GETSYSTEMACCOUNT *r_u) { struct lsa_info *info=NULL; - fstring name, dom_name; - enum SID_NAME_USE type; /* find the connection policy handle. */ if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info)) return NT_STATUS_INVALID_HANDLE; - if (!lookup_sid(&info->sid, dom_name, name, &type)) + if (!lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, NULL)) return NT_STATUS_ACCESS_DENIED; /* diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 635d8707623..13f3a3284b9 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -1366,9 +1366,7 @@ NTSTATUS _samr_query_aliasinfo(pipes_struct *p, SAMR_Q_QUERY_ALIASINFO *q_u, SAM NTSTATUS _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LOOKUP_NAMES *r_u) { uint32 rid[MAX_SAM_ENTRIES]; - uint32 local_rid; enum SID_NAME_USE type[MAX_SAM_ENTRIES]; - enum SID_NAME_USE local_type; int i; int num_rids = q_u->num_names2; DOM_SID pol_sid; @@ -1400,42 +1398,30 @@ NTSTATUS _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LO for (i = 0; i < num_rids; i++) { fstring name; - DOM_SID sid; int ret; r_u->status = NT_STATUS_NONE_MAPPED; + type[i] = SID_NAME_UNKNOWN; rid [i] = 0xffffffff; - type[i] = SID_NAME_UNKNOWN; ret = rpcstr_pull(name, q_u->uni_name[i].buffer, sizeof(name), q_u->uni_name[i].uni_str_len*2, 0); - /* - * we are only looking for a name - * the SID we get back can be outside - * the scope of the pol_sid - * - * in clear: it prevents to reply to domain\group: yes - * when only builtin\group exists. - * - * a cleaner code is to add the sid of the domain we're looking in - * to the local_lookup_name function. - */ - - if ((ret > 0) && local_lookup_name(name, &sid, &local_type)) { - sid_split_rid(&sid, &local_rid); - - if (sid_equal(&sid, &pol_sid)) { - rid[i]=local_rid; - - /* Windows does not return WKN_GRP here, even - * on lookups in builtin */ - type[i] = (local_type == SID_NAME_WKN_GRP) ? - SID_NAME_ALIAS : local_type; - - r_u->status = NT_STATUS_OK; + if (ret <= 0) { + continue; + } + + if (sid_check_is_builtin(&pol_sid)) { + if (lookup_builtin_name(name, &rid[i])) { + type[i] = SID_NAME_ALIAS; } - } + } else { + lookup_global_sam_name(name, &rid[i], &type[i]); + } + + if (type[i] != SID_NAME_UNKNOWN) { + r_u->status = NT_STATUS_OK; + } } init_samr_r_lookup_names(p->mem_ctx, r_u, num_rids, rid, (uint32 *)type, r_u->status); @@ -2247,6 +2233,41 @@ NTSTATUS _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SA return r_u->status; } +/* W2k3 seems to use the same check for all 3 objects that can be created via + * SAMR, if you try to create for example "Dialup" as an alias it says + * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user + * database. */ + +static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name) +{ + enum SID_NAME_USE type; + BOOL result; + + become_root(); + /* Lookup in our local databases (only LOOKUP_NAME_ISOLATED set) + * whether the name already exists */ + result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_ISOLATED, + NULL, NULL, NULL, &type); + unbecome_root(); + + if (!result) { + return NT_STATUS_OK; + } + + DEBUG(5, ("trying to create %s, exists as %s\n", + new_name, sid_type_lookup(type))); + + if (type == SID_NAME_DOM_GRP) { + return NT_STATUS_GROUP_EXISTS; + } + if (type == SID_NAME_ALIAS) { + return NT_STATUS_ALIAS_EXISTS; + } + + /* Yes, the default is NT_STATUS_USER_EXISTS */ + return NT_STATUS_USER_EXISTS; +} + /******************************************************************* _samr_create_user Create an account, can be either a normal user or a machine. @@ -2294,19 +2315,11 @@ NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREA rpcstr_pull(account, user_account.buffer, sizeof(account), user_account.uni_str_len*2, 0); strlower_m(account); - pdb_init_sam(&sam_pass); - - become_root(); - ret = pdb_getsampwnam(sam_pass, account); - unbecome_root(); - if (ret == True) { - /* this account exists: say so */ - pdb_free_sam(&sam_pass); - return NT_STATUS_USER_EXISTS; + nt_status = can_create(p->mem_ctx, account); + if (!NT_STATUS_IS_OK(nt_status)) { + return nt_status; } - pdb_free_sam(&sam_pass); - /********************************************************************* * HEADS UP! If we have to create a new user account, we have to get * a new RID from somewhere. This used to be done by the passdb @@ -2776,7 +2789,7 @@ NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_A /* append the alias' RID to it */ if (!sid_append_rid(&sid, alias_rid)) - return NT_STATUS_NO_SUCH_USER; + return NT_STATUS_NO_SUCH_ALIAS; /*check if access can be granted as requested by client. */ @@ -2793,12 +2806,21 @@ NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_A if ( !NT_STATUS_IS_OK(status) ) return status; - /* - * we should check if the rid really exist !!! - * JFM. - */ + { + /* Check we actually have the requested alias */ + enum SID_NAME_USE type; + BOOL result; - /* associate the user's SID with the new handle. */ + become_root(); + result = lookup_sid(NULL, &sid, NULL, NULL, &type); + unbecome_root(); + + if (!result || (type != SID_NAME_ALIAS)) { + return NT_STATUS_NO_SUCH_ALIAS; + } + } + + /* associate the alias SID with the new handle. */ if ((info = get_samr_info_by_sid(&sid)) == NULL) return NT_STATUS_NO_MEMORY; @@ -2814,12 +2836,11 @@ NTSTATUS _samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_A /******************************************************************* set_user_info_7 ********************************************************************/ -static NTSTATUS set_user_info_7(const SAM_USER_INFO_7 *id7, SAM_ACCOUNT *pwd) +static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx, + const SAM_USER_INFO_7 *id7, SAM_ACCOUNT *pwd) { fstring new_name; - SAM_ACCOUNT *check_acct = NULL; NTSTATUS rc; - BOOL check_rc; if (id7 == NULL) { DEBUG(5, ("set_user_info_7: NULL id7\n")); @@ -2842,13 +2863,9 @@ static NTSTATUS set_user_info_7(const SAM_USER_INFO_7 *id7, SAM_ACCOUNT *pwd) simply that the rename fails with a slightly different status code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */ - pdb_init_sam(&check_acct); - check_rc = pdb_getsampwnam(check_acct, new_name); - pdb_free_sam(&check_acct); - - if (check_rc == True) { - /* this account exists: say so */ - return NT_STATUS_USER_EXISTS; + rc = can_create(mem_ctx, new_name); + if (!NT_STATUS_IS_OK(rc)) { + return rc; } rc = pdb_rename_sam_account(pwd, new_name); @@ -3365,7 +3382,8 @@ NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_ switch (switch_value) { case 7: - r_u->status = set_user_info_7(ctr->info.id7, pwd); + r_u->status = set_user_info_7(p->mem_ctx, + ctr->info.id7, pwd); break; case 16: if (!set_user_info_16(ctr->info.id16, pwd)) @@ -4199,9 +4217,10 @@ NTSTATUS _samr_create_dom_group(pipes_struct *p, SAMR_Q_CREATE_DOM_GROUP *q_u, S unistr2_to_ascii(name, &q_u->uni_acct_desc, sizeof(name)-1); - /* check if group already exist */ - if ((grp=getgrnam(name)) != NULL) - return NT_STATUS_GROUP_EXISTS; + r_u->status = can_create(p->mem_ctx, name); + if (!NT_STATUS_IS_OK(r_u->status)) { + return r_u->status; + } se_priv_copy( &se_rights, &se_add_users ); can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights ); @@ -4289,6 +4308,11 @@ NTSTATUS _samr_create_dom_alias(pipes_struct *p, SAMR_Q_CREATE_DOM_ALIAS *q_u, S if (!sid_equal(&dom_sid, get_global_sam_sid())) return NT_STATUS_ACCESS_DENIED; + r_u->status = can_create(p->mem_ctx, name); + if (!NT_STATUS_IS_OK(r_u->status)) { + return r_u->status; + } + unistr2_to_ascii(name, &q_u->uni_acct_desc, sizeof(name)-1); se_priv_copy( &se_rights, &se_add_users ); diff --git a/source/smbd/lanman.c b/source/smbd/lanman.c index 1e2a2488515..90e36e2a839 100644 --- a/source/smbd/lanman.c +++ b/source/smbd/lanman.c @@ -1837,9 +1837,6 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para gid_t *gids; size_t num_groups; size_t i; - fstring grp_domain; - fstring grp_name; - enum SID_NAME_USE grp_type; struct passwd *passwd; NTSTATUS result; @@ -1896,9 +1893,12 @@ static BOOL api_NetUserGetGroups(connection_struct *conn,uint16 vuid, char *para goto out; for (i=0; imem_ctx, &sids[i], NULL, &grp_name, + NULL) ) { + pstrcpy(p, grp_name); p += 21; count++; } -- cgit From 4adba7d217f7b10897f7f8342a0b747d634e35c2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 3 Dec 2005 20:18:20 +0000 Subject: r12052: Remove unused typedefs --- source/include/smb.h | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/source/include/smb.h b/source/include/smb.h index 50b8c0369f4..b2d28b7d70e 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -330,49 +330,6 @@ typedef struct _nt_user_token { SE_PRIV privileges; } NT_USER_TOKEN; -/*** query a local group, get a list of these: shows who is in that group ***/ - -/* local group member info */ -typedef struct local_grp_member_info -{ - DOM_SID sid ; /* matches with name */ - uint8 sid_use; /* usr=1 grp=2 dom=3 alias=4 wkng=5 del=6 inv=7 unk=8 */ - fstring name ; /* matches with sid: must be of the form "DOMAIN\account" */ - -} LOCAL_GRP_MEMBER; - -/* enumerate these to get list of local groups */ - -/* local group info */ -typedef struct local_grp_info -{ - fstring name; - fstring comment; - -} LOCAL_GRP; - -/*** enumerate these to get list of domain groups ***/ - -/* domain group member info */ -typedef struct domain_grp_info -{ - fstring name; - fstring comment; - uint32 rid; /* group rid */ - uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */ - -} DOMAIN_GRP; - -/*** query a domain group, get a list of these: shows who is in that group ***/ - -/* domain group info */ -typedef struct domain_grp_member_info -{ - fstring name; - uint8 attr; /* attributes forced to be set to 0x7: SE_GROUP_xxx */ - -} DOMAIN_GRP_MEMBER; - /* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */ typedef struct time_info { -- cgit From 227bd8c0f79a28a6042c5af2f3903c5106a847ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 20:18:43 +0000 Subject: r12054: We only have one more warning at -O6. That will take some more restructuring to fix.... Coming soon. Jeremy. --- source/utils/smbget.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/source/utils/smbget.c b/source/utils/smbget.c index eab5e5ac02f..9d44017bd35 100644 --- a/source/utils/smbget.c +++ b/source/utils/smbget.c @@ -22,8 +22,10 @@ #if _FILE_OFFSET_BITS==64 #define OFF_T_FORMAT "%lld" +#define OFF_T_FORMAT_CAST long long #else #define OFF_T_FORMAT "%ld" +#define OFF_T_FORMAT_CAST long #endif int columns = 0; @@ -76,7 +78,7 @@ void human_readable(off_t s, char *buffer, int l) if(s > 1024 * 1024 * 1024) snprintf(buffer, l, "%.2fGb", 1.0 * s / (1024 * 1024 * 1024)); else if(s > 1024 * 1024) snprintf(buffer, l, "%.2fMb", 1.0 * s / (1024 * 1024)); else if(s > 1024) snprintf(buffer, l, "%.2fkb", 1.0 * s / 1024); - else snprintf(buffer, l, OFF_T_FORMAT"b", s); + else snprintf(buffer, l, OFF_T_FORMAT"b", (OFF_T_FORMAT_CAST)s); } void get_auth_data(const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen) @@ -327,8 +329,10 @@ int smb_download_file(const char *base, const char *name, int recursive, int res offset_download = localstat.st_size - RESUME_DOWNLOAD_OFFSET; offset_check = localstat.st_size - RESUME_CHECK_OFFSET; if(verbose)printf("Trying to start resume of %s at "OFF_T_FORMAT"\n" - "At the moment "OFF_T_FORMAT" of "OFF_T_FORMAT" bytes have been retrieved\n", newpath, offset_check, - localstat.st_size, remotestat.st_size); + "At the moment "OFF_T_FORMAT" of "OFF_T_FORMAT" bytes have been retrieved\n", + newpath, (OFF_T_FORMAT_CAST)offset_check, + (OFF_T_FORMAT_CAST)localstat.st_size, + (OFF_T_FORMAT_CAST)remotestat.st_size); } if(offset_check) { @@ -336,20 +340,24 @@ int smb_download_file(const char *base, const char *name, int recursive, int res /* First, check all bytes from offset_check to offset_download */ off1 = lseek(localhandle, offset_check, SEEK_SET); if(off1 < 0) { - fprintf(stderr, "Can't seek to "OFF_T_FORMAT" in local file %s\n", offset_check, newpath); + fprintf(stderr, "Can't seek to "OFF_T_FORMAT" in local file %s\n", + (OFF_T_FORMAT_CAST)offset_check, newpath); smbc_close(remotehandle); close(localhandle); return 0; } off2 = smbc_lseek(remotehandle, offset_check, SEEK_SET); if(off2 < 0) { - fprintf(stderr, "Can't seek to "OFF_T_FORMAT" in remote file %s\n", offset_check, newpath); + fprintf(stderr, "Can't seek to "OFF_T_FORMAT" in remote file %s\n", + (OFF_T_FORMAT_CAST)offset_check, newpath); smbc_close(remotehandle); close(localhandle); return 0; } if(off1 != off2) { - fprintf(stderr, "Offset in local and remote files is different (local: "OFF_T_FORMAT", remote: "OFF_T_FORMAT")\n", off1, off2); + fprintf(stderr, "Offset in local and remote files is different (local: "OFF_T_FORMAT", remote: "OFF_T_FORMAT")\n", + (OFF_T_FORMAT_CAST)off1, + (OFF_T_FORMAT_CAST)off2); return 0; } @@ -366,7 +374,7 @@ int smb_download_file(const char *base, const char *name, int recursive, int res } if(memcmp(checkbuf[0], checkbuf[1], RESUME_CHECK_SIZE) == 0) { - if(verbose)printf("Current local and remote file appear to be the same. Starting download from offset "OFF_T_FORMAT"\n", offset_download); + if(verbose)printf("Current local and remote file appear to be the same. Starting download from offset "OFF_T_FORMAT"\n", (OFF_T_FORMAT_CAST)offset_download); } else { fprintf(stderr, "Local and remote file appear to be different, not doing resume for %s\n", path); smbc_close(remotehandle); close(localhandle); @@ -386,7 +394,7 @@ int smb_download_file(const char *base, const char *name, int recursive, int res for(curpos = offset_download; curpos < remotestat.st_size; curpos+=blocksize) { ssize_t bytesread = smbc_read(remotehandle, readbuf, blocksize); if(bytesread < 0) { - fprintf(stderr, "Can't read %d bytes at offset "OFF_T_FORMAT", file %s\n", blocksize, curpos, path); + fprintf(stderr, "Can't read %u bytes at offset "OFF_T_FORMAT", file %s\n", (unsigned int)blocksize, (OFF_T_FORMAT_CAST)curpos, path); smbc_close(remotehandle); if (localhandle != STDOUT_FILENO) close(localhandle); free(readbuf); @@ -396,7 +404,7 @@ int smb_download_file(const char *base, const char *name, int recursive, int res total_bytes += bytesread; if(write(localhandle, readbuf, bytesread) < 0) { - fprintf(stderr, "Can't write %d bytes to local file %s at offset "OFF_T_FORMAT"\n", bytesread, path, curpos); + fprintf(stderr, "Can't write %u bytes to local file %s at offset "OFF_T_FORMAT"\n", (unsigned int)bytesread, path, (OFF_T_FORMAT_CAST)curpos); free(readbuf); smbc_close(remotehandle); if (localhandle != STDOUT_FILENO) close(localhandle); -- cgit From c62a97e55323256bb50729420bc93a66d2feeea7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 3 Dec 2005 20:28:18 +0000 Subject: r12055: More cruft --- source/include/passdb.h | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/source/include/passdb.h b/source/include/passdb.h index 20ea7021d07..f1896710dc9 100644 --- a/source/include/passdb.h +++ b/source/include/passdb.h @@ -200,29 +200,6 @@ typedef struct sam_passwd { } SAM_ACCOUNT; -typedef struct sam_group { - TALLOC_CTX *mem_ctx; - - void (*free_fn)(struct sam_group **); - - struct pdb_methods *methods; - - struct group_data { - /* initialization flags */ - struct bitmap *change_flags; - struct bitmap *set_flags; - - const char *name; /* Windows group name string */ - - DOM_SID sid; /* Group SID */ - enum SID_NAME_USE sid_name_use; /* Group type */ - - uint32 mem_num; /* Number of member SIDs */ - DOM_SID *members; /* SID array */ - } private_g; - -} SAM_GROUP; - struct acct_info { fstring acct_name; /* account name */ fstring acct_desc; /* account name */ -- cgit From f0de2617f1c426204db8ec45f176bd2502a9e2b3 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Mon, 5 Dec 2005 16:51:19 +0000 Subject: r12076: Ensure setmntent() returns with != NULL in the disk_quotas() Linux version. The IRIX 6.2 version is still without this check as I'm not sure if setmntent() is implemented in the same way. --- source/smbd/quotas.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/smbd/quotas.c b/source/smbd/quotas.c index 8cb94bca3d8..de31376d6c6 100644 --- a/source/smbd/quotas.c +++ b/source/smbd/quotas.c @@ -216,7 +216,9 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB devno = S.st_dev ; - fp = setmntent(MOUNTED,"r"); + if ((fp = setmntent(MOUNTED,"r")) == NULL) + return(False) ; + found = False ; while ((mnt = getmntent(fp))) { -- cgit From 0f52c58f5f9e5945fa56afd1f3bc9c5bcc18f99a Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Mon, 5 Dec 2005 21:02:23 +0000 Subject: r12077: Add configure switch to disable libmsrpc build. Add new Makefile target installlibmsrpc. This works the same way as we're already doing it for libsmbclient. Default is to build it. Add a soname to libmsrpc as we do it for libsmbclient. We already had the MAJOR and MINOR variable in the Makefile. --- source/Makefile.in | 22 ++++++++------ source/configure.in | 82 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index c0753a76c00..a80b16df715 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -36,8 +36,8 @@ KRB5LIBS=@KRB5_LIBS@ LDAP_LIBS=@LDAP_LIBS@ INSTALLCMD=@INSTALL@ -INSTALLCLIENTCMD_SH=@INSTALLCLIENTCMD_SH@ -INSTALLCLIENTCMD_A=@INSTALLCLIENTCMD_A@ +INSTALLLIBCMD_SH=@INSTALLLIBCMD_SH@ +INSTALLLIBCMD_A=@INSTALLLIBCMD_A@ VPATH=@srcdir@ srcdir=@abs_srcdir@ @@ -1074,7 +1074,7 @@ bin/libsmbsharemodes.a: $(LIBSMBSHAREMODES_PICOBJS) bin/libmsrpc.@SHLIBEXT@: $(CAC_PICOBJS) @echo Linking libmsrpc shared library $@ @$(SHLD) $(LDSHFLAGS) -o $@ $(CAC_PICOBJS) $(LDFLAGS) $(LIBS) \ - @SONAMEFLAG@`basename $@` + @SONAMEFLAG@`basename $@`.$(LIBMSRPC_MAJOR) bin/libmsrpc.a: $(CAC_PICOBJS) @echo Linking libmsrpc non-shared library $@ @@ -1389,7 +1389,7 @@ bin/t_push_ucs2@EXEEXT@: bin/libbigballofmud.@SHLIBEXT@ torture/t_push_ucs2.o bin/t_snprintf@EXEEXT@: lib/snprintf.c $(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(DYNEXP) -DTEST_SNPRINTF lib/snprintf.c -lm -install: installbin installman installscripts installdat installswat installmodules @INSTALLCLIENT@ +install: installbin installman installscripts installdat installswat installmodules @INSTALL_LIBSMBCLIENT@ @INSTALL_LIBMSRPC@ install-everything: install installmodules @@ -1439,14 +1439,18 @@ installmsg: installdirs installswat: installdirs installmsg @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir) -installclientlib: installdirs libsmbclient libmsrpc +installclientlib: installdirs libsmbclient @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(LIBDIR) - -$(INSTALLCLIENTCMD_SH) bin/libsmbclient.@SHLIBEXT@ $(DESTDIR)$(LIBDIR) - -$(INSTALLCLIENTCMD_A) bin/libsmbclient.a $(DESTDIR)$(LIBDIR) - -$(INSTALLCLIENTCMD_SH) bin/libmsrpc.@SHLIBEXT@ $(DESTDIR)$(LIBDIR) - -$(INSTALLCLIENTCMD_A) bin/libmsrpc.a $(DESTDIR)$(LIBDIR) + -$(INSTALLLIBCMD_SH) bin/libsmbclient.@SHLIBEXT@ $(DESTDIR)$(LIBDIR) + -$(INSTALLLIBCMD_A) bin/libsmbclient.a $(DESTDIR)$(LIBDIR) @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)${prefix}/include -$(INSTALLCMD) $(srcdir)/include/libsmbclient.h $(DESTDIR)${prefix}/include + +installlibmsrpc: installdirs libmsrpc + @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(LIBDIR) + -$(INSTALLLIBCMD_SH) bin/libmsrpc.@SHLIBEXT@ $(DESTDIR)$(LIBDIR) + -$(INSTALLLIBCMD_A) bin/libmsrpc.a $(DESTDIR)$(LIBDIR) + @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)${prefix}/include -$(INSTALLCMD) $(srcdir)/include/libmsrpc.h $(DESTDIR)${prefix}/include # Python extensions diff --git a/source/configure.in b/source/configure.in index 296673e4b53..ec1bdacad84 100644 --- a/source/configure.in +++ b/source/configure.in @@ -214,11 +214,15 @@ AC_SUBST(libc_cv_fpie) AC_SUBST(PIE_CFLAGS) AC_SUBST(PIE_LDFLAGS) AC_SUBST(SHLIBEXT) -AC_SUBST(INSTALLCLIENT) -AC_SUBST(INSTALLCLIENTCMD_SH) -AC_SUBST(INSTALLCLIENTCMD_A) +AC_SUBST(INSTALLLIBCMD_SH) +AC_SUBST(INSTALLLIBCMD_A) +AC_SUBST(INSTALL_LIBMSRPC) +AC_SUBST(LIBMSRPC_SHARED) +AC_SUBST(LIBMSRPC) +AC_SUBST(INSTALL_LIBSMBCLIENT) AC_SUBST(LIBSMBCLIENT_SHARED) AC_SUBST(LIBSMBCLIENT) +AC_SUBST(INSTALL_LIBSMBSHAREMODES) AC_SUBST(LIBSMBSHAREMODES_SHARED) AC_SUBST(LIBSMBSHAREMODES) AC_SUBST(PRINT_LIBS) @@ -3988,20 +3992,62 @@ else AC_MSG_RESULT(no$utmp_no_reason) fi -################################################# -# should we build libsmbclient? - -INSTALLCLIENTCMD_SH=: -INSTALLCLIENTCMD_A=: +INSTALLLIBCMD_SH=: +INSTALLLIBCMD_A=: if test $BLDSHARED = true; then - INSTALLCLIENTCMD_SH="\$(INSTALLCMD)" + INSTALLLIBCMD_SH="\$(INSTALLCMD)" fi if test $enable_static = yes; then - INSTALLCLIENTCMD_A="\$(INSTALLCMD)" + INSTALLLIBCMD_A="\$(INSTALLCMD)" fi -INSTALLCLIENT= +################################################# +# should we build libmsrpc? +INSTALL_LIBMSRPC= +LIBMSRPC_SHARED= +LIBMSRPC= +AC_MSG_CHECKING(whether to build the libmsrpc shared library) +AC_ARG_WITH(libmsrpc, +[ --with-libmsrpc Build the libmsrpc shared library (default=yes if shared libs supported)], +[ case "$withval" in + no) + AC_MSG_RESULT(no) + ;; + *) + if test $BLDSHARED = true; then + LIBMSRPC_SHARED=bin/libmsrpc.$SHLIBEXT + LIBMSRPC=libmsrpc + AC_MSG_RESULT(yes) + else + enable_static=yes + AC_MSG_RESULT(no shared library support -- will supply static library) + fi + if test $enable_static = yes; then + LIBMSRPC=libmsrpc + fi + INSTALL_LIBMSRPC=installlibmsrpc + ;; + esac ], +[ +# if unspecified, default is to built it if possible. + if test $BLDSHARED = true; then + LIBMSRPC_SHARED=bin/libmsrpc.$SHLIBEXT + LIBMSRPC=libmsrpc + AC_MSG_RESULT(yes) + else + enable_static=yes + AC_MSG_RESULT(no shared library support -- will supply static library) + fi + if test $enable_static = yes; then + LIBMSRPC=libmsrpc + fi] + INSTALL_LIBMSRPC=installlibmsrpc +) + +################################################# +# should we build libsmbclient? +INSTALL_LIBSMBCLIENT= LIBSMBCLIENT_SHARED= LIBSMBCLIENT= AC_MSG_CHECKING(whether to build the libsmbclient shared library) @@ -4023,11 +4069,11 @@ AC_ARG_WITH(libsmbclient, if test $enable_static = yes; then LIBSMBCLIENT=libsmbclient fi - INSTALLCLIENT=installclientlib + INSTALL_LIBSMBCLIENT=installclientlib ;; esac ], [ -# if unspecified, default is to built it iff possible. +# if unspecified, default is to built it if possible. if test $BLDSHARED = true; then LIBSMBCLIENT_SHARED=bin/libsmbclient.$SHLIBEXT LIBSMBCLIENT=libsmbclient @@ -4039,10 +4085,10 @@ AC_ARG_WITH(libsmbclient, if test $enable_static = yes; then LIBSMBCLIENT=libsmbclient fi] - INSTALLCLIENT=installclientlib + INSTALL_LIBSMBCLIENT=installclientlib ) -INSTALLCLIENT= +INSTALL_LIBSMBSHAREMODES= LIBSMBSHAREMODES_SHARED= LIBSMBSHAREMODES= AC_MSG_CHECKING(whether to build the libsmbsharemodes shared library) @@ -4064,11 +4110,11 @@ AC_ARG_WITH(libsmbsharemodes, if test $enable_static = yes; then LIBSMBSHAREMODES=libsmbsharemodes fi - INSTALLCLIENT=installclientlib + INSTALL_LIBSMBSHAREMODES=installlibsmbsharemodes ;; esac ], [ -# if unspecified, default is to built it iff possible. +# if unspecified, default is to built it if possible. if test $BLDSHARED = true; then LIBSMBSHAREMODES_SHARED=bin/libsmbsharemodes.$SHLIBEXT LIBSMBSHAREMODES=libsmbsharemodes @@ -4080,7 +4126,7 @@ AC_ARG_WITH(libsmbsharemodes, if test $enable_static = yes; then LIBSMBSHAREMODES=libsmbsharemodes fi] - INSTALLCLIENT=installclientlib + INSTALL_LIBSMBSHAREMODES=installlibsmbsharemodes ) ################################################# -- cgit From 4a40ba8e2c7ab5b4420d26e6e755bffcb3b5d569 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 5 Dec 2005 23:30:40 +0000 Subject: r12080: r10673@cabra: derrell | 2005-12-05 13:22:34 -0500 Correct some memory and file descriptor leaks. This should fix bugs 3257, 3267 and 3273. --- examples/libsmbclient/testbrowse.c | 238 +++++++++++++++++++++++++------------ source/libsmb/libsmbclient.c | 32 +++++ 2 files changed, 195 insertions(+), 75 deletions(-) diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 27d6a697388..6fa70eab414 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -9,24 +9,34 @@ #include #include "get_auth_data_fn.h" -void error_message(char * pMessage) -{ - printf("ERROR: %s\n", pMessage); -} +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword); + +static void browse(char * path, + int scan, + int indent); + int main(int argc, char * argv[]) { int debug = 0; + int scan = 0; + int iterations = -1; + int again; int opt; char * p; char * q; char buf[1024]; - int dir; - struct stat stat; - struct smbc_dirent * dirent; - poptContext pc; + poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP @@ -34,6 +44,14 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "scan", 's', POPT_ARG_NONE, &scan, + 0, "Scan for servers and shares", "integer" + }, + { + "iterations", 'i', POPT_ARG_INT, &iterations, + 0, "Iterations", "integer" + }, { NULL } @@ -51,94 +69,164 @@ main(int argc, char * argv[]) } } - if (smbc_init(get_auth_data_fn, debug) != 0) + if (scan) { - printf("Could not initialize smbc_ library\n"); - return 1; + if (smbc_init(no_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) + { + snprintf(buf, sizeof(buf), "smb://"); + browse(buf, scan, 0); + } } - - for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin); - p != NULL && *p != '\n' && *p != '\0'; - fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin)) + else { - if ((p = strchr(buf, '\n')) != NULL) + if (smbc_init(get_auth_data_fn, debug) != 0) { - *p = '\0'; + printf("Could not initialize smbc_ library\n"); + return 1; } - - printf("Opening (%s)...\n", buf); - - if ((dir = smbc_opendir(buf)) < 0) + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) { - printf("Could not open directory [%s] (%d:%s)\n", - buf, errno, strerror(errno)); - continue; + fputs("url: ", stdout); + p = fgets(buf, sizeof(buf), stdin); + if (! p) + { + break; + } + + if ((p = strchr(buf, '\n')) != NULL) + { + *p = '\0'; + } + + browse(buf, scan, 0); } + } - while ((dirent = smbc_readdir(dir)) != NULL) - { - printf("%-30s", dirent->name); - printf("%-30s", dirent->comment); + exit(0); +} - switch(dirent->smbc_type) - { - case SMBC_WORKGROUP: - printf("WORKGROUP"); - break; + +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) +{ + return; +} + +static void browse(char * path, int scan, int indent) +{ + char * p; + char buf[1024]; + int dir; + struct stat stat; + struct smbc_dirent * dirent; + + if (! scan) + { + printf("Opening (%s)...\n", path); + } + + if ((dir = smbc_opendir(path)) < 0) + { + printf("Could not open directory [%s] (%d:%s)\n", + path, errno, strerror(errno)); + return; + } + + while ((dirent = smbc_readdir(dir)) != NULL) + { + printf("%*.*s%-30s", indent, indent, "", dirent->name); + + switch(dirent->smbc_type) + { + case SMBC_WORKGROUP: + printf("WORKGROUP"); + break; - case SMBC_SERVER: - printf("SERVER"); - break; + case SMBC_SERVER: + printf("SERVER"); + break; - case SMBC_FILE_SHARE: - printf("FILE_SHARE"); - break; + case SMBC_FILE_SHARE: + printf("FILE_SHARE"); + break; - case SMBC_PRINTER_SHARE: - printf("PRINTER_SHARE"); - break; + case SMBC_PRINTER_SHARE: + printf("PRINTER_SHARE"); + break; - case SMBC_COMMS_SHARE: - printf("COMMS_SHARE"); - break; + case SMBC_COMMS_SHARE: + printf("COMMS_SHARE"); + break; - case SMBC_IPC_SHARE: - printf("IPC_SHARE"); - break; + case SMBC_IPC_SHARE: + printf("IPC_SHARE"); + break; - case SMBC_DIR: - printf("DIR"); - break; + case SMBC_DIR: + printf("DIR"); + break; - case SMBC_FILE: - printf("FILE"); - - q = buf + strlen(buf); - strcat(q, "/"); - strcat(q+1, dirent->name); - if (smbc_stat(buf, &stat) < 0) - { - printf(" unknown size (reason %d: %s)", - errno, strerror(errno)); - } - else - { - printf(" size %lu", (unsigned long) stat.st_size); - } - *p = '\0'; + case SMBC_FILE: + printf("FILE"); - break; - - case SMBC_LINK: - printf("LINK"); - break; + p = path + strlen(path); + strcat(p, "/"); + strcat(p+1, dirent->name); + if (smbc_stat(path, &stat) < 0) + { + printf(" unknown size (reason %d: %s)", + errno, strerror(errno)); } + else + { + printf(" size %lu", (unsigned long) stat.st_size); + } + *p = '\0'; - printf("\n"); + break; + + case SMBC_LINK: + printf("LINK"); + break; } - smbc_closedir(dir); + printf("\n"); + + if (scan && + (dirent->smbc_type == SMBC_WORKGROUP || + dirent->smbc_type == SMBC_SERVER)) + { + /* + * don't append server name to workgroup; what we want is: + * + * smb://workgroup_name + * or + * smb://server_name + * + */ + snprintf(buf, sizeof(buf), "smb://%s", dirent->name); + browse(buf, scan, indent + 2); + } } - exit(0); + smbc_closedir(dir); } + diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index f180072a70c..f482c9584f8 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -584,9 +584,25 @@ SMBCSRV *smbc_server(SMBCCTX *context, return NULL; } +#if 0 /* choice 1 */ + /* Look for a cached connection, using the provided authinfo */ srv = find_server(context, server, share, workgroup, username, password); + /* If we didn't find one... */ + if (! srv) + { + /* ... then see if there's one using anonymous login */ + fstring anonymous = ""; + srv = find_server(context, server, share, + workgroup, anonymous, password); + } +#else + /* Look for a cached connection */ + srv = find_server(context, server, share, + workgroup, username, password); +#endif + /* * If we found a connection and we're only allowed one share per * server... @@ -780,7 +796,11 @@ SMBCSRV *smbc_server(SMBCCTX *context, /* now add it to the cache (internal or external) */ /* Let the cache function set errno if it wants to */ errno = 0; +#if 0 /* choice 2 */ if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, username_used)) { +#else + if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, username)) { +#endif int saved_errno = errno; DEBUG(3, (" Failed to add server to cache\n")); errno = saved_errno; @@ -2169,6 +2189,7 @@ list_unique_wg_fn(const char *name, uint32 type, const char *comment, void *stat /* Found the end of the list. Remove it. */ dir->dir_end = dir_list; free(dir_list->next); + free(dirent); dir_list->next = NULL; break; } @@ -2337,7 +2358,11 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) * a single master browser. */ + ip_list = NULL; if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { + + SAFE_FREE(ip_list); + if (!find_master_ip(workgroup, &server_addr.ip)) { errno = ENOENT; @@ -2383,9 +2408,16 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) if (!cli_NetServerEnum(&srv->cli, workgroup, SV_TYPE_DOMAIN_ENUM, list_unique_wg_fn, (void *)dir)) { + if (dir) { + SAFE_FREE(dir->fname); + SAFE_FREE(dir); + } + continue; } } + + SAFE_FREE(ip_list); } else { /* * Server not an empty string ... Check the rest and see what -- cgit From a6820fb7d1bff20f63783f47f2285f4bc0886e6c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 5 Dec 2005 23:30:45 +0000 Subject: r12081: r10674@cabra: derrell | 2005-12-05 13:31:28 -0500 get rid of temporary #if 0 blocks --- source/libsmb/libsmbclient.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index f482c9584f8..9fda48a540b 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -584,24 +584,9 @@ SMBCSRV *smbc_server(SMBCCTX *context, return NULL; } -#if 0 /* choice 1 */ - /* Look for a cached connection, using the provided authinfo */ - srv = find_server(context, server, share, - workgroup, username, password); - - /* If we didn't find one... */ - if (! srv) - { - /* ... then see if there's one using anonymous login */ - fstring anonymous = ""; - srv = find_server(context, server, share, - workgroup, anonymous, password); - } -#else /* Look for a cached connection */ srv = find_server(context, server, share, workgroup, username, password); -#endif /* * If we found a connection and we're only allowed one share per @@ -796,11 +781,7 @@ SMBCSRV *smbc_server(SMBCCTX *context, /* now add it to the cache (internal or external) */ /* Let the cache function set errno if it wants to */ errno = 0; -#if 0 /* choice 2 */ - if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, username_used)) { -#else if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, username)) { -#endif int saved_errno = errno; DEBUG(3, (" Failed to add server to cache\n")); errno = saved_errno; -- cgit From 1536a18ee0943b8a5967106049d0eecc68375a27 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Dec 2005 16:25:27 +0000 Subject: r12096: Change uint32_t to uint32. Jerry, please pick this change up for 3.0.21 final. Jeremy. --- source/include/rpc_netlogon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/rpc_netlogon.h b/source/include/rpc_netlogon.h index fdf2f08c03c..c1d85403448 100644 --- a/source/include/rpc_netlogon.h +++ b/source/include/rpc_netlogon.h @@ -946,7 +946,7 @@ typedef struct net_q_dsr_getdcname { struct uuid *domain_guid; uint32 ptr_site_guid; struct uuid *site_guid; - uint32_t flags; + uint32 flags; } NET_Q_DSR_GETDCNAME; /* NET_R_DSR_GETDCNAME - Ask a DC for a trusted DC name and its address */ -- cgit From b8299973e37e3e20a8b4b4b078fcdf3bb18f2b55 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 6 Dec 2005 17:09:44 +0000 Subject: r12098: r10797@cabra: derrell | 2005-12-06 12:09:00 -0500 fixed another memory leak and reverted an (incorrect) fix from yesterday --- examples/libsmbclient/Makefile | 5 + examples/libsmbclient/testbrowse2.c | 214 ++++++++++++++++++++++++++++++++++++ source/libsmb/libsmbclient.c | 14 ++- 3 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 examples/libsmbclient/testbrowse2.c diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index 7e893fd4889..c324a578d14 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -15,6 +15,7 @@ TESTS= testsmbc \ tree \ testacl \ testbrowse \ + testbrowse2 \ teststat \ testchmod \ testutime \ @@ -38,6 +39,10 @@ testbrowse: testbrowse.o @echo Linking testbrowse @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< +testbrowse2: testbrowse2.o + @echo Linking testbrowse2 + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -lsmbclient -lpopt $< + teststat: teststat.o @echo Linking teststat @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< diff --git a/examples/libsmbclient/testbrowse2.c b/examples/libsmbclient/testbrowse2.c new file mode 100644 index 00000000000..a3d2cf3b8e2 --- /dev/null +++ b/examples/libsmbclient/testbrowse2.c @@ -0,0 +1,214 @@ +/* + * Alternate testbrowse utility provided by Mikhail Kshevetskiy. + * This version tests use of multiple contexts. + */ + +#include +#include +#include +#include +#include + +int debuglevel = 0; +char *workgroup = "NT"; +char *username = "guest"; +char *password = ""; + +typedef struct smbitem smbitem; +typedef int(*qsort_cmp)(const void *, const void *); + +struct smbitem{ + smbitem *next; + int type; + char name[1]; +}; + +int smbitem_cmp(smbitem *elem1, smbitem *elem2){ + return strcmp(elem1->name, elem2->name); +} + +int smbitem_list_count(smbitem *list){ + int count = 0; + + while(list != NULL){ + list = list->next; + count++; + } + return count; +} + +void smbitem_list_delete(smbitem *list){ + smbitem *elem; + + while(list != NULL){ + elem = list; + list = list->next; + free(elem); + } +} + +smbitem* smbitem_list_sort(smbitem *list){ + smbitem *item, **array; + int count, i; + + if ((count = smbitem_list_count(list)) == 0) return NULL; + if ((array = malloc(count * sizeof(smbitem*))) == NULL){ + smbitem_list_delete(list); + return NULL; + } + + for(i = 0; i < count; i++){ + array[i] = list; + list = list->next; + } + qsort(array, count, sizeof(smbitem*), (qsort_cmp)smbitem_cmp); + + for(i = 0; i < count - 1; i++) array[i]->next = array[i + 1]; + array[count - 1]->next = NULL; + + list = array[0]; + free(array); + return list; +} + +void smbc_auth_fn( + const char *server, + const char *share, + char *wrkgrp, int wrkgrplen, + char *user, int userlen, + char *passwd, int passwdlen){ + + (void) server; + (void) share; + (void) wrkgrp; + (void) wrkgrplen; + + strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; + strncpy(user, username, userlen - 1); user[userlen - 1] = 0; + strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; +} + +SMBCCTX* create_smbctx(){ + SMBCCTX *ctx; + + if ((ctx = smbc_new_context()) == NULL) return NULL; + + ctx->debug = debuglevel; + ctx->callbacks.auth_fn = smbc_auth_fn; + + if (smbc_init_context(ctx) == NULL){ + smbc_free_context(ctx, 1); + return NULL; + } + + return ctx; +} + +void delete_smbctx(SMBCCTX* ctx){ + ctx->callbacks.purge_cached_fn(ctx); + smbc_free_context(ctx, 1); +} + +smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){ + SMBCFILE *fd; + struct smbc_dirent *dirent; + smbitem *list = NULL, *item; + + if ((fd = ctx->opendir(ctx, smb_path)) == NULL) return NULL; + while((dirent = ctx->readdir(ctx, fd)) != NULL){ + if (strcmp(dirent->name, "") == 0) continue; + if (strcmp(dirent->name, ".") == 0) continue; + if (strcmp(dirent->name, "..") == 0) continue; + + if ((item = malloc(sizeof(smbitem) + strlen(dirent->name))) == NULL) + continue; + + item->next = list; + item->type = dirent->smbc_type; + strcpy(item->name, dirent->name); + list = item; + } + ctx->close_fn(ctx, fd); + return /* smbitem_list_sort */ (list); + +} + +void print_smb_path(char *group, char *path){ + if ((strlen(group) == 0) && (strlen(path) == 0)) printf("/\n"); + else if (strlen(path) == 0) printf("/%s\n", group); + else{ + if (strlen(group) == 0) group = "(unknown_group)"; + printf("/%s/%s\n", group, path); + } +} + +void recurse(SMBCCTX *ctx, char *smb_group, char *smb_path, int maxlen){ + int len; + smbitem *list, *item; + SMBCCTX *ctx1; + + len = strlen(smb_path); + + list = get_smbitem_list(ctx, smb_path); + while(list != NULL){ + switch(list->type){ + case SMBC_WORKGROUP: + case SMBC_SERVER: + if (list->type == SMBC_WORKGROUP){ + print_smb_path(list->name, ""); + smb_group = list->name; + } + else print_smb_path(smb_group, list->name); + + if (maxlen < 7 + strlen(list->name)) break; + strcpy(smb_path + 6, list->name); + if ((ctx1 = create_smbctx()) != NULL){ + recurse(ctx1, smb_group, smb_path, maxlen); + delete_smbctx(ctx1); + }else{ + recurse(ctx, smb_group, smb_path, maxlen); + ctx->callbacks.purge_cached_fn(ctx); + } + break; + case SMBC_FILE_SHARE: + case SMBC_DIR: + case SMBC_FILE: + if (maxlen < len + strlen(list->name) + 2) break; + + smb_path[len] = '/'; + strcpy(smb_path + len + 1, list->name); + print_smb_path(smb_group, smb_path + 6); + if (list->type != SMBC_FILE){ + recurse(ctx, smb_group, smb_path, maxlen); + if (list->type == SMBC_FILE_SHARE) + ctx->callbacks.purge_cached_fn(ctx); + } + break; + } + item = list; + list = list->next; + free(item); + } + smb_path[len] = '\0'; +} + +int main(int argc, char *argv[]){ + int i; + SMBCCTX *ctx; + char smb_path[32768] = "smb://"; + + if ((ctx = create_smbctx()) == NULL){ + perror("Cant create samba context."); + return 1; + } + + if (argc == 1) recurse(ctx, "", smb_path, sizeof(smb_path)); + else for(i = 1; i < argc; i++){ + strncpy(smb_path + 6, argv[i], sizeof(smb_path) - 7); + smb_path[sizeof(smb_path) - 1] = '\0'; + recurse(ctx, "", smb_path, sizeof(smb_path)); + } + + delete_smbctx(ctx); + return 0; +} diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 9fda48a540b..e6906eb79ab 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -483,6 +483,8 @@ int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv) DEBUG(3, ("smbc_remove_usused_server: %p removed.\n", srv)); context->callbacks.remove_cached_srv_fn(context, srv); + + SAFE_FREE(srv); return 0; } @@ -822,9 +824,9 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, SMBCSRV *ipc_srv=NULL; /* - * See if we've already created this special connection. Reference our - * "special" share name '*IPC$', which is an impossible real share name - * due to the leading asterisk. + * See if we've already created this special connection. Reference + * our "special" share name '*IPC$', which is an impossible real share + * name due to the leading asterisk. */ ipc_srv = find_server(context, server, "*IPC$", workgroup, username, password); @@ -2386,9 +2388,11 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) /* Now, list the stuff ... */ - if (!cli_NetServerEnum(&srv->cli, workgroup, SV_TYPE_DOMAIN_ENUM, list_unique_wg_fn, + if (!cli_NetServerEnum(&srv->cli, + workgroup, + SV_TYPE_DOMAIN_ENUM, + list_unique_wg_fn, (void *)dir)) { - if (dir) { SAFE_FREE(dir->fname); SAFE_FREE(dir); -- cgit From f8f4afc7e3a31484a005299368cb12f32043e375 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 6 Dec 2005 20:22:51 +0000 Subject: r12106: Fix return value Guenther --- source/rpc_client/cli_spoolss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_client/cli_spoolss.c b/source/rpc_client/cli_spoolss.c index 62dca0afe78..749885dbb4f 100644 --- a/source/rpc_client/cli_spoolss.c +++ b/source/rpc_client/cli_spoolss.c @@ -517,7 +517,7 @@ WERROR rpccli_spoolss_enum_printers(struct rpc_pipe_client *cli, TALLOC_CTX *mem break; case 3: if (!decode_printer_info_3(mem_ctx, out.buffer, out.returned, &ctr->printers_3)) { - WERR_GENERAL_FAILURE; + return WERR_GENERAL_FAILURE; } break; default: -- cgit From 75df23faf0f2aa7c18c4085026352b9edb944ff9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Dec 2005 23:06:38 +0000 Subject: r12107: Move to a tdb-based wins database. At the moment we still use it as though it were an in-memory db and dump out to a flat file every 2 mins, but that can now change. Jeremy. --- source/Makefile.in | 9 +- source/include/includes.h | 6 - source/include/nameserv.h | 6 +- source/include/smb.h | 7 +- source/libsmb/nmblib.c | 2 +- source/nmbd/asyncdns.c | 26 +- source/nmbd/nmbd.c | 5 +- source/nmbd/nmbd_browserdb.c | 22 +- source/nmbd/nmbd_browsesync.c | 6 +- source/nmbd/nmbd_incomingrequests.c | 6 +- source/nmbd/nmbd_mynames.c | 8 +- source/nmbd/nmbd_namelistdb.c | 327 +++++++++------ source/nmbd/nmbd_subnetdb.c | 33 +- source/nmbd/nmbd_winsproxy.c | 22 +- source/nmbd/nmbd_winsserver.c | 801 ++++++++++++++++++++++++++++-------- 15 files changed, 891 insertions(+), 395 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index a80b16df715..bb3f72847b1 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -219,9 +219,6 @@ READLINE_OBJ = lib/readline.o # Be sure to include them into your application POPT_LIB_OBJ = lib/popt_common.o -UBIQX_OBJ = ubiqx/ubi_BinTree.o ubiqx/ubi_Cache.o ubiqx/ubi_SplayTree.o \ - ubiqx/ubi_dLinkList.o ubiqx/ubi_sLinkList.o - PARAM_OBJ = dynconfig.o param/loadparm.o param/params.o KRBCLIENT_OBJ = libads/kerberos.o libads/ads_status.o @@ -441,13 +438,13 @@ NMBD_OBJ1 = nmbd/asyncdns.o nmbd/nmbd.o nmbd/nmbd_become_dmb.o \ nmbd/nmbd_subnetdb.o nmbd/nmbd_winsproxy.o nmbd/nmbd_winsserver.o \ nmbd/nmbd_workgroupdb.o nmbd/nmbd_synclists.o -NMBD_OBJ = $(NMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) $(UBIQX_OBJ) \ +NMBD_OBJ = $(NMBD_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) $(KRBCLIENT_OBJ) \ $(PROFILE_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ) $(POPT_LIB_OBJ) WREPL_OBJ1 = wrepld/server.o wrepld/process.o wrepld/parser.o wrepld/socket.o \ wrepld/partners.o -WREPL_OBJ = $(WREPL_OBJ1) $(PARAM_OBJ) $(UBIQX_OBJ) \ +WREPL_OBJ = $(WREPL_OBJ1) $(PARAM_OBJ) \ $(PROFILE_OBJ) $(LIB_NONSMBD_OBJ) $(POPT_LIB_OBJ) $(SECRETS_OBJ) \ $(LIBSAMBA_OBJ) @@ -543,7 +540,7 @@ LIBSMBSHAREMODES_OBJ = libsmb/smb_share_modes.o tdb/tdb.o tdb/spinlock.o LIBBIGBALLOFMUD_MAJOR = 0 -LIBBIGBALLOFMUD_OBJ = $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(UBIQX_OBJ) $(SECRETS_OBJ) \ +LIBBIGBALLOFMUD_OBJ = $(PARAM_OBJ) $(LIB_NONSMBD_OBJ) $(SECRETS_OBJ) \ $(LIBSMB_OBJ) $(LIBMSRPC_OBJ) $(RPC_PARSE_OBJ) $(PASSDB_OBJ) \ $(GROUPDB_OBJ) $(KRBCLIENT_OBJ) $(SMBLDAP_OBJ) diff --git a/source/include/includes.h b/source/include/includes.h index cde199eed8b..80fc3feed98 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -863,8 +863,6 @@ extern int errno; /* Lists, trees, caching, database... */ #include "xfile.h" #include "intl.h" -#include "ubi_sLinkList.h" -#include "ubi_dLinkList.h" #include "dlinklist.h" #include "tdb/tdb.h" #include "tdb/spinlock.h" @@ -887,10 +885,6 @@ extern int errno; #include "util_getent.h" -#ifndef UBI_BINTREE_H -#include "ubi_Cache.h" -#endif /* UBI_BINTREE_H */ - #include "debugparse.h" #include "version.h" diff --git a/source/include/nameserv.h b/source/include/nameserv.h index ec3d56c06b7..9f6bf76a093 100644 --- a/source/include/nameserv.h +++ b/source/include/nameserv.h @@ -217,7 +217,7 @@ struct nmb_data { /* This structure represents an entry in a local netbios name list. */ struct name_record { - ubi_trNode node[1]; + struct name_record *prev, *next; struct subnet_record *subnet; struct nmb_name name; /* The netbios name. */ struct nmb_data data; /* The netbios data. */ @@ -225,7 +225,7 @@ struct name_record { /* Browser cache for synchronising browse lists. */ struct browse_cache_record { - ubi_dlNode node[1]; + struct browse_cache_record *prev, *next; unstring lmb_name; unstring work_group; struct in_addr ip; @@ -425,7 +425,7 @@ struct subnet_record { enum subnet_type type; /* To catagorize the subnet. */ struct work_record *workgrouplist; /* List of workgroups. */ - ubi_trRoot namelist[1]; /* List of netbios names. */ + struct name_record *namelist; /* List of netbios names. */ struct response_record *responselist; /* List of responses expected. */ BOOL namelist_changed; diff --git a/source/include/smb.h b/source/include/smb.h index b2d28b7d70e..a3dce53a4ca 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -1530,17 +1530,14 @@ struct node_status_extra { /* There really is more here ... */ }; -struct pwd_info -{ +struct pwd_info { BOOL null_pwd; BOOL cleartext; fstring password; - }; -typedef struct user_struct -{ +typedef struct user_struct { struct user_struct *next, *prev; uint16 vuid; /* Tag for this entry. */ uid_t uid; /* uid of a validated user */ diff --git a/source/libsmb/nmblib.c b/source/libsmb/nmblib.c index 164f85be7bf..4d84d7bc499 100644 --- a/source/libsmb/nmblib.c +++ b/source/libsmb/nmblib.c @@ -331,7 +331,7 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name) Useful for debugging messages. ******************************************************************/ -char *nmb_namestr(struct nmb_name *n) +char *nmb_namestr(const struct nmb_name *n) { static int i=0; static fstring ret[4]; diff --git a/source/nmbd/asyncdns.c b/source/nmbd/asyncdns.c index 4db54ea198c..c0626d11619 100644 --- a/source/nmbd/asyncdns.c +++ b/source/nmbd/asyncdns.c @@ -34,16 +34,18 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_a if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); - (void)add_name_to_subnet( wins_server_subnet, qname, name_type, + add_name_to_subnet( wins_server_subnet, qname, name_type, NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr ); - return( NULL ); + return NULL; } /* add it to our WINS cache of names. give it 2 hours in the cache */ DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - return( add_name_to_subnet( wins_server_subnet, qname, name_type, - NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) ); + add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr); + + return find_name_on_subnet(wins_server_subnet, question, FIND_ANY_NAME); } #ifndef SYNC_DNS @@ -283,8 +285,7 @@ void run_dns_queue(void) queue a DNS query ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, - struct name_record **n) +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) { if (in_dns || fd_in == -1) return False; @@ -316,9 +317,9 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, we use this when we can't do async DNS lookups ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, - struct name_record **n) +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) { + struct name_record *namerec = NULL; struct in_addr dns_ip; unstring qname; @@ -334,11 +335,12 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, /* Re-block TERM signal. */ BlockSignals(True, SIGTERM); - *n = add_dns_result(question, dns_ip); - if(*n == NULL) + namerec = add_dns_result(question, dns_ip); + if(namerec == NULL) { send_wins_name_query_response(NAM_ERR, p, NULL); - else - send_wins_name_query_response(0, p, *n); + } else { + send_wins_name_query_response(0, p, namerec); + } return False; } diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c index 01fdb8e74cf..78411d34176 100644 --- a/source/nmbd/nmbd.c +++ b/source/nmbd/nmbd.c @@ -58,7 +58,7 @@ static void terminate(void) DEBUG(0,("Got SIGTERM: going down...\n")); /* Write out wins.dat file if samba is a WINS server */ - wins_write_database(False); + wins_write_database(0,False); /* Remove all SELF registered names from WINS */ release_wins_names(); @@ -773,7 +773,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) pidfile_create("nmbd"); message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election); +#if 0 + /* Until winsrepl is done. */ message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); +#endif message_register(MSG_SHUTDOWN, nmbd_terminate); message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); message_register(MSG_SEND_PACKET, msg_nmbd_send_packet); diff --git a/source/nmbd/nmbd_browserdb.c b/source/nmbd/nmbd_browserdb.c index e8797a99d51..e27e483702a 100644 --- a/source/nmbd/nmbd_browserdb.c +++ b/source/nmbd/nmbd_browserdb.c @@ -35,7 +35,7 @@ * lmb_browserlist - This is our local master browser list. */ -ubi_dlNewList( lmb_browserlist ); +struct browse_cache_record *lmb_browserlist; /* -------------------------------------------------------------------------- ** * Functions... @@ -52,7 +52,8 @@ ubi_dlNewList( lmb_browserlist ); */ static void remove_lmb_browser_entry( struct browse_cache_record *browc ) { - safe_free( ubi_dlRemThis( lmb_browserlist, browc ) ); + DLIST_REMOVE(lmb_browserlist, browc); + SAFE_FREE(browc); } /* ************************************************************************** ** @@ -85,6 +86,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, struct in_addr ip ) { struct browse_cache_record *browc; + struct browse_cache_record *tmp_browc; time_t now = time( NULL ); browc = SMB_MALLOC_P(struct browse_cache_record); @@ -113,7 +115,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, browc->ip = ip; - (void)ubi_dlAddTail( lmb_browserlist, browc ); + DLIST_ADD_END(lmb_browserlist, browc, tmp_browc); if( DEBUGLVL( 3 ) ) { Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); @@ -138,12 +140,13 @@ struct browse_cache_record *find_browser_in_lmb_cache( const char *browser_name { struct browse_cache_record *browc; - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) - if( strequal( browser_name, browc->lmb_name ) ) + for( browc = lmb_browserlist; browc; browc = browc->next ) { + if( strequal( browser_name, browc->lmb_name ) ) { break; + } + } - return( browc ); + return browc; } /* ************************************************************************** ** @@ -160,9 +163,8 @@ void expire_lmb_browsers( time_t t ) struct browse_cache_record *browc; struct browse_cache_record *nextbrowc; - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; browc = nextbrowc ) { - nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); + for( browc = lmb_browserlist; browc; browc = nextbrowc) { + nextbrowc = browc->next; if( browc->death_time < t ) { if( DEBUGLVL( 3 ) ) { diff --git a/source/nmbd/nmbd_browsesync.c b/source/nmbd/nmbd_browsesync.c index 03234bb98fa..9535a3115a6 100644 --- a/source/nmbd/nmbd_browsesync.c +++ b/source/nmbd/nmbd_browsesync.c @@ -24,7 +24,7 @@ #include "includes.h" /* This is our local master browser list database. */ -extern ubi_dlList lmb_browserlist[]; +extern struct browse_cache_record *lmb_browserlist; /**************************************************************************** As a domain master browser, do a sync with a local master browser. @@ -87,9 +87,7 @@ void dmb_expire_and_sync_browser_lists(time_t t) expire_lmb_browsers(t); - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) { + for( browc = lmb_browserlist; browc; browc = browc->next ) { if (browc->sync_time < t) sync_with_lmb(browc); } diff --git a/source/nmbd/nmbd_incomingrequests.c b/source/nmbd/nmbd_incomingrequests.c index 7fac8c25739..eaef7097b4a 100644 --- a/source/nmbd/nmbd_incomingrequests.c +++ b/source/nmbd/nmbd_incomingrequests.c @@ -339,7 +339,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), names_added = 0; - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec = subrec->namelist; while (buf < bufend) { if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { @@ -389,7 +389,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), buf = buf0 + 18*names_added; - namerec = (struct name_record *)ubi_trNext( namerec ); + namerec = namerec->next; if (!namerec) { /* End of the subnet specific name list. Now @@ -398,7 +398,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), if (uni_subrec != subrec) { subrec = uni_subrec; - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec = subrec->namelist; } } if (!namerec) diff --git a/source/nmbd/nmbd_mynames.c b/source/nmbd/nmbd_mynames.c index 07247d5495e..f34d98172c6 100644 --- a/source/nmbd/nmbd_mynames.c +++ b/source/nmbd/nmbd_mynames.c @@ -182,8 +182,8 @@ void release_wins_names(void) struct subnet_record *subrec = unicast_subnet; struct name_record *namerec, *nextnamerec; - for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = nextnamerec) { - nextnamerec = (struct name_record *)ubi_trNext( namerec ); + for (namerec = subrec->namelist; namerec; namerec = nextnamerec) { + nextnamerec = namerec->next; if( (namerec->data.source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec) ) release_name( subrec, namerec, standard_success_release, @@ -202,9 +202,7 @@ void refresh_my_names(time_t t) if (wins_srv_count() < 1) return; - for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist); - namerec; - namerec = (struct name_record *)ubi_trNext(namerec)) { + for (namerec = unicast_subnet->namelist; namerec; namerec = namerec->next) { /* Each SELF name has an individual time to be refreshed. */ if ((namerec->data.source == SELF_NAME) && (namerec->data.refresh_time < t) && diff --git a/source/nmbd/nmbd_namelistdb.c b/source/nmbd/nmbd_namelistdb.c index 88d5ea52f58..894b8776134 100644 --- a/source/nmbd/nmbd_namelistdb.c +++ b/source/nmbd/nmbd_namelistdb.c @@ -32,24 +32,26 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ void set_samba_nb_type(void) { - if( lp_wins_support() || wins_srv_count() ) + if( lp_wins_support() || wins_srv_count() ) { samba_nb_type = NB_HFLAG; /* samba is a 'hybrid' node type. */ - else + } else { samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ + } } /*************************************************************************** Convert a NetBIOS name to upper case. ***************************************************************************/ -static void upcase_name( struct nmb_name *target, struct nmb_name *source ) +static void upcase_name( struct nmb_name *target, const struct nmb_name *source ) { int i; unstring targ; fstring scope; - if( NULL != source ) + if( NULL != source ) { memcpy( target, source, sizeof( struct nmb_name ) ); + } pull_ascii_nstring(targ, sizeof(targ), target->name); strupper_m( targ ); @@ -63,25 +65,11 @@ static void upcase_name( struct nmb_name *target, struct nmb_name *source ) * unused space doesn't have garbage in it. */ - for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) + for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) { target->name[i] = '\0'; - for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) + } + for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) { target->scope[i] = '\0'; -} - -/************************************************************************** - Add a new or overwrite an existing namelist entry. -***************************************************************************/ - -static void update_name_in_namelist( struct subnet_record *subrec, - struct name_record *namerec ) -{ - struct name_record *oldrec = NULL; - - ubi_trInsert( subrec->namelist, namerec, &namerec->name, &oldrec ); - if( oldrec ) { - SAFE_FREE( oldrec->data.ip ); - SAFE_FREE( oldrec ); } } @@ -89,64 +77,81 @@ static void update_name_in_namelist( struct subnet_record *subrec, Remove a name from the namelist. ***************************************************************************/ -void remove_name_from_namelist( struct subnet_record *subrec, - struct name_record *namerec ) +void remove_name_from_namelist(struct subnet_record *subrec, + struct name_record *namerec ) { - ubi_trRemove( subrec->namelist, namerec ); + if (subrec == wins_server_subnet) { + remove_name_from_wins_namelist(namerec); + } else { + subrec->namelist_changed = True; + } + DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); - subrec->namelist_changed = True; } /************************************************************************** Find a name in a subnet. **************************************************************************/ -struct name_record *find_name_on_subnet( struct subnet_record *subrec, - struct nmb_name *nmbname, - BOOL self_only ) +struct name_record *find_name_on_subnet(struct subnet_record *subrec, + const struct nmb_name *nmbname, + BOOL self_only) { - struct nmb_name uc_name[1]; + struct nmb_name uc_name; struct name_record *name_ret; - upcase_name( uc_name, nmbname ); - name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name ); + upcase_name( &uc_name, nmbname ); + + if (subrec == wins_server_subnet) { + return find_name_on_wins_subnet(&uc_name, self_only); + } + + for( name_ret = subrec->namelist; name_ret; name_ret = name_ret->next) { + if (memcmp(&uc_name, &name_ret->name, sizeof(struct nmb_name)) == 0) { + break; + } + } + if( name_ret ) { /* Self names only - these include permanent names. */ if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) { DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); + return False; } DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) ); - return( name_ret ); + + return name_ret; } DEBUG( 9, ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); + + return NULL; } /************************************************************************** Find a name over all known broadcast subnets. ************************************************************************/ -struct name_record *find_name_for_remote_broadcast_subnet( - struct nmb_name *nmbname, - BOOL self_only ) +struct name_record *find_name_for_remote_broadcast_subnet(struct nmb_name *nmbname, + BOOL self_only) { struct subnet_record *subrec; - struct name_record *namerec = NULL; + struct name_record *namerec; for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) { - if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) - break; + namerec = find_name_on_subnet(subrec, nmbname, self_only); + if (namerec) { + return namerec; + } } - return( namerec ); + return NULL; } /************************************************************************** @@ -157,34 +162,40 @@ void update_name_ttl( struct name_record *namerec, int ttl ) { time_t time_now = time(NULL); - if( namerec->data.death_time != PERMANENT_TTL ) + if( namerec->data.death_time != PERMANENT_TTL) { namerec->data.death_time = time_now + ttl; + } namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /************************************************************************** Add an entry to a subnet name list. ***********************************************************************/ -struct name_record *add_name_to_subnet( struct subnet_record *subrec, - const char *name, - int type, - uint16 nb_flags, - int ttl, - enum name_source source, - int num_ips, - struct in_addr *iplist) +BOOL add_name_to_subnet( struct subnet_record *subrec, + const char *name, + int type, + uint16 nb_flags, + int ttl, + enum name_source source, + int num_ips, + struct in_addr *iplist) { + BOOL ret = False; struct name_record *namerec; time_t time_now = time(NULL); namerec = SMB_MALLOC_P(struct name_record); if( NULL == namerec ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); - return( NULL ); + return False; } memset( (char *)namerec, '\0', sizeof(*namerec) ); @@ -193,7 +204,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); - return NULL; + return False; } namerec->subnet = subrec; @@ -206,8 +217,9 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->data.wins_flags = WINS_ACTIVE; /* If it's our primary name, flag it as so. */ - if( strequal( my_netbios_names(0), name ) ) + if (strequal( my_netbios_names(0), name )) { namerec->data.nb_flags |= NB_PERM; + } /* Copy the IPs. */ namerec->data.num_ips = num_ips; @@ -217,16 +229,14 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->data.source = source; /* Setup the death_time and refresh_time. */ - if( ttl == PERMANENT_TTL ) + if (ttl == PERMANENT_TTL) { namerec->data.death_time = PERMANENT_TTL; - else + } else { namerec->data.death_time = time_now + ttl; + } namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); - /* Now add the record to the name list. */ - update_name_in_namelist( subrec, namerec ); - DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ ttl=%d nb_flags=%2x to subnet %s\n", nmb_namestr( &namerec->name ), @@ -235,9 +245,20 @@ ttl=%d nb_flags=%2x to subnet %s\n", (unsigned int)nb_flags, subrec->subnet_name ) ); - subrec->namelist_changed = True; + /* Now add the record to the name list. */ + + if (subrec == wins_server_subnet) { + ret = add_name_to_wins_subnet(namerec); + /* Free namerec - it's stored in the tdb. */ + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + } else { + DLIST_ADD(subrec->namelist, namerec); + subrec->namelist_changed = True; + ret = True; + } - return(namerec); + return ret; } /******************************************************************* @@ -253,8 +274,8 @@ void standard_success_register(struct subnet_record *subrec, { struct name_record *namerec; - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); - if( NULL == namerec ) { + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME); + if (namerec == NULL) { unstring name; pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet( subrec, name, nmbname->name_type, @@ -277,14 +298,15 @@ void standard_fail_register( struct subnet_record *subrec, { struct name_record *namerec; - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME); DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) ); /* Remove the name from the subnet. */ - if( namerec ) + if( namerec ) { remove_name_from_namelist(subrec, namerec); + } } /******************************************************************* @@ -293,13 +315,18 @@ on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) ); static void remove_nth_ip_in_record( struct name_record *namerec, int ind) { - if( ind != namerec->data.num_ips ) + if( ind != namerec->data.num_ips ) { memmove( (char *)(&namerec->data.ip[ind]), (char *)(&namerec->data.ip[ind+1]), ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) ); + } namerec->data.num_ips--; - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /******************************************************************* @@ -310,9 +337,11 @@ BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) { int i; - for(i = 0; i < namerec->data.num_ips; i++) - if(ip_equal( namerec->data.ip[i], ip)) + for(i = 0; i < namerec->data.num_ips; i++) { + if(ip_equal( namerec->data.ip[i], ip)) { return True; + } + } return False; } @@ -326,8 +355,9 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) struct in_addr *new_list; /* Don't add one we already have. */ - if( find_ip_in_name_record( namerec, new_ip ) ) + if( find_ip_in_name_record( namerec, new_ip )) { return; + } new_list = SMB_MALLOC_ARRAY( struct in_addr, namerec->data.num_ips + 1); if( NULL == new_list ) { @@ -342,7 +372,11 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) namerec->data.ip = new_list; namerec->data.num_ips += 1; - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /******************************************************************* @@ -388,26 +422,29 @@ on subnet %s. Name was not found on subnet.\n", nmb_namestr(nmbname), inet_ntoa( remove_ip_from_name_record( namerec, released_ip ); - if( namerec->data.num_ips == orig_num ) + if( namerec->data.num_ips == orig_num ) { DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ on subnet %s. This ip is not known for this name.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) ); + } } - if( namerec->data.num_ips == 0 ) + if( namerec->data.num_ips == 0 ) { remove_name_from_namelist( subrec, namerec ); + } } /******************************************************************* - Expires old names in a subnet namelist. + Expires old names in a subnet namelist. + NB. Does not touch the wins_subnet - no wins specific processing here. ******************************************************************/ -void expire_names_on_subnet(struct subnet_record *subrec, time_t t) +static void expire_names_on_subnet(struct subnet_record *subrec, time_t t) { struct name_record *namerec; struct name_record *next_namerec; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = next_namerec ) { - next_namerec = (struct name_record *)ubi_trNext( namerec ); + for( namerec = subrec->namelist; namerec; namerec = next_namerec ) { + next_namerec = namerec->next; if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { if( namerec->data.source == SELF_NAME ) { DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ @@ -420,13 +457,14 @@ name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name) ) ); DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name))); - remove_name_from_namelist( subrec, namerec ); + remove_name_from_namelist(subrec, namerec ); } } } /******************************************************************* - Expires old names in all subnet namelists. + Expires old names in all subnet namelists. + NB. Does not touch the wins_subnet. ******************************************************************/ void expire_names(time_t t) @@ -479,75 +517,85 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, PERMANENT_NAME, num_ips, iplist); - if(iplist != &subrec->myip) + if(iplist != &subrec->myip) { SAFE_FREE(iplist); + } } /**************************************************************************** - Dump the contents of the namelists on all the subnets (including unicast) - into a file. Initiated by SIGHUP - used to debug the state of the namelists. + Dump a name_record struct. **************************************************************************/ -static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) +void dump_name_record( struct name_record *namerec, XFILE *fp) { - struct name_record *namerec; const char *src_type; struct tm *tm; int i; - x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) { - - x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); - switch(namerec->data.source) { - case LMHOSTS_NAME: - src_type = "LMHOSTS_NAME"; - break; - case WINS_PROXY_NAME: - src_type = "WINS_PROXY_NAME"; - break; - case REGISTER_NAME: - src_type = "REGISTER_NAME"; - break; - case SELF_NAME: - src_type = "SELF_NAME"; - break; - case DNS_NAME: - src_type = "DNS_NAME"; - break; - case DNSFAIL_NAME: - src_type = "DNSFAIL_NAME"; - break; - case PERMANENT_NAME: - src_type = "PERMANENT_NAME"; - break; - default: - src_type = "unknown!"; - break; - } + x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); + switch(namerec->data.source) { + case LMHOSTS_NAME: + src_type = "LMHOSTS_NAME"; + break; + case WINS_PROXY_NAME: + src_type = "WINS_PROXY_NAME"; + break; + case REGISTER_NAME: + src_type = "REGISTER_NAME"; + break; + case SELF_NAME: + src_type = "SELF_NAME"; + break; + case DNS_NAME: + src_type = "DNS_NAME"; + break; + case DNSFAIL_NAME: + src_type = "DNSFAIL_NAME"; + break; + case PERMANENT_NAME: + src_type = "PERMANENT_NAME"; + break; + default: + src_type = "unknown!"; + break; + } - x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); + x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); - if(namerec->data.death_time != PERMANENT_TTL) { - tm = localtime(&namerec->data.death_time); - x_fprintf(fp, "death_time = %s\t", asctime(tm)); - } else { - x_fprintf(fp, "death_time = PERMANENT\t"); - } + if(namerec->data.death_time != PERMANENT_TTL) { + tm = localtime(&namerec->data.death_time); + x_fprintf(fp, "death_time = %s\t", asctime(tm)); + } else { + x_fprintf(fp, "death_time = PERMANENT\t"); + } - if(namerec->data.refresh_time != PERMANENT_TTL) { - tm = localtime(&namerec->data.refresh_time); - x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); - } else { - x_fprintf(fp, "refresh_time = PERMANENT\n"); - } + if(namerec->data.refresh_time != PERMANENT_TTL) { + tm = localtime(&namerec->data.refresh_time); + x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); + } else { + x_fprintf(fp, "refresh_time = PERMANENT\n"); + } - x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); - for(i = 0; i < namerec->data.num_ips; i++) - x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); + for(i = 0; i < namerec->data.num_ips; i++) { + x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + } + + x_fprintf(fp, "\n\n"); + +} + +/**************************************************************************** + Dump the contents of the namelists on all the subnets (including unicast) + into a file. Initiated by SIGHUP - used to debug the state of the namelists. +**************************************************************************/ - x_fprintf(fp, "\n\n"); +static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) +{ + struct name_record *namerec; + x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); + for( namerec = subrec->namelist; namerec; namerec = namerec->next) { + dump_name_record(namerec, fp); } } @@ -569,16 +617,21 @@ void dump_all_namelists(void) return; } - for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { dump_subnet_namelist( subrec, fp ); + } - if( !we_are_a_wins_client() ) + if (!we_are_a_wins_client()) { dump_subnet_namelist( unicast_subnet, fp ); + } - if( remote_broadcast_subnet->namelist != NULL ) + if (remote_broadcast_subnet->namelist != NULL) { dump_subnet_namelist( remote_broadcast_subnet, fp ); + } + + if (wins_server_subnet != NULL) { + dump_wins_subnet_namelist(fp ); + } - if( wins_server_subnet != NULL ) - dump_subnet_namelist( wins_server_subnet, fp ); x_fclose( fp ); } diff --git a/source/nmbd/nmbd_subnetdb.c b/source/nmbd/nmbd_subnetdb.c index b53a6d7328f..b2e1178bebc 100644 --- a/source/nmbd/nmbd_subnetdb.c +++ b/source/nmbd/nmbd_subnetdb.c @@ -51,34 +51,6 @@ static void add_subnet(struct subnet_record *subrec) DLIST_ADD(subnetlist, subrec); } -/* ************************************************************************** ** - * Comparison routine for ordering the splay-tree based namelists assoicated - * with each subnet record. - * - * Input: Item - Pointer to the comparison key. - * Node - Pointer to a node the splay tree. - * - * Output: The return value will be <0 , ==0, or >0 depending upon the - * ordinal relationship of the two keys. - * - * ************************************************************************** ** - */ -static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) -{ - struct name_record *NR = (struct name_record *)Node; - - if( DEBUGLVL( 10 ) ) { - struct nmb_name *Iname = (struct nmb_name *)Item; - - Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); - Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", - memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); - } - - return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); -} - /**************************************************************************** stop listening on a subnet we don't free the record as we don't have proper reference counting for it @@ -156,10 +128,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type return(NULL); } - memset( (char *)subrec, '\0', sizeof(*subrec) ); - (void)ubi_trInitTree( subrec->namelist, - namelist_entry_compare, - ubi_trOVERWRITE ); + ZERO_STRUCTP(subrec); if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) { DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); diff --git a/source/nmbd/nmbd_winsproxy.c b/source/nmbd/nmbd_winsproxy.c index 75319724616..d6dc6261c84 100644 --- a/source/nmbd/nmbd_winsproxy.c +++ b/source/nmbd/nmbd_winsproxy.c @@ -33,7 +33,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, unstring name; struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; - struct name_record *namerec; + struct name_record *namerec = NULL; uint16 nb_flags; int num_ips; int i; @@ -64,22 +64,34 @@ returned for name %s.\n", nmb_namestr(nmbname) )); return; } - for(i = 0; i < num_ips; i++) + for(i = 0; i < num_ips; i++) { putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]); + } } /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ - if(rrec == PERMANENT_TTL) + if(rrec == PERMANENT_TTL) { ttl = lp_max_ttl(); + } pull_ascii_nstring(name, sizeof(name), nmbname->name); - namerec = add_name_to_subnet( orig_broadcast_subnet, name, + add_name_to_subnet( orig_broadcast_subnet, name, nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist ); - if(iplist != &ip) + namerec = find_name_on_subnet(orig_broadcast_subnet, nmbname, FIND_ANY_NAME); + if (!namerec) { + DEBUG(0,("wins_proxy_name_query_request_success: failed to add " + "name %s to subnet %s !\n", + name, + orig_broadcast_subnet->subnet_name )); + return; + } + + if(iplist != &ip) { SAFE_FREE(iplist); + } /* * Check that none of the IP addresses we are returning is on the diff --git a/source/nmbd/nmbd_winsserver.c b/source/nmbd/nmbd_winsserver.c index 8a1f82c8b17..5c234bf8dcc 100644 --- a/source/nmbd/nmbd_winsserver.c +++ b/source/nmbd/nmbd_winsserver.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-2003 + Copyright (C) Jeremy Allison 1994-2005 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 @@ -18,12 +18,312 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + Converted to store WINS data in a tdb. Dec 2005. JRA. */ #include "includes.h" #define WINS_LIST "wins.dat" #define WINS_VERSION 1 +#define WINSDB_VERSION 1 + +/**************************************************************************** + We don't store the NetBIOS scope in the wins.tdb. We key off the (utf8) netbios + name (65 bytes with the last byte being the name type). +*****************************************************************************/ + +TDB_CONTEXT *wins_tdb; + +/**************************************************************************** + Convert a wins.tdb record to a struct name_record. Add in our global_scope(). +*****************************************************************************/ + +static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA data) +{ + struct name_record *namerec = NULL; + uint16 nb_flags; + unsigned char nr_src; + uint32 death_time, refresh_time; + uint32 id_low, id_high; + uint32 saddr; + uint32 wins_flags; + uint32 num_ips; + size_t len; + int i; + + if (data.dptr == NULL || data.dsize == 0) { + return NULL; + } + + /* Min size is "wbddddddd" + 1 ip address (4). */ + if (data.dsize < 2 + 1 + (7*4) + 4) { + return NULL; + } + + len = tdb_unpack(data.dptr, data.dsize, + "wbddddddd", + &nb_flags, + &nr_src, + &death_time, + &refresh_time, + &id_low, + &id_high, + &saddr, + &wins_flags, + &num_ips ); + + namerec = SMB_MALLOC_P(struct name_record); + if (!namerec) { + return NULL; + } + + namerec->data.ip = SMB_MALLOC_ARRAY(struct in_addr, num_ips); + if (!namerec->data.ip) { + SAFE_FREE(namerec); + return NULL; + } + + namerec->subnet = wins_server_subnet; + push_ascii_nstring(namerec->name.name, key.dptr); + namerec->name.name_type = key.dptr[sizeof(unstring)]; + /* Add the scope. */ + push_ascii(namerec->name.scope, global_scope(), 64, STR_TERMINATE); + + /* We're using a byte-by-byte compare, so we must be sure that + * unused space doesn't have garbage in it. + */ + + for( i = strlen( namerec->name.name ); i < sizeof( namerec->name.name ); i++ ) { + namerec->name.name[i] = '\0'; + } + for( i = strlen( namerec->name.scope ); i < sizeof( namerec->name.scope ); i++ ) { + namerec->name.scope[i] = '\0'; + } + + namerec->data.nb_flags = nb_flags; + namerec->data.source = (enum name_source)nr_src; + namerec->data.death_time = (time_t)death_time; + namerec->data.refresh_time = (time_t)refresh_time; + namerec->data.id = id_low; +#if defined(HAVE_LONGLONG) + namerec->data.id |= ((SMB_BIG_UINT)id_high << 32); +#endif + namerec->data.wins_ip.s_addr = saddr; + namerec->data.wins_flags = wins_flags, + namerec->data.num_ips = num_ips; + + for (i = 0; i < num_ips; i++) { + namerec->data.ip[i].s_addr = IVAL(data.dptr, len + (i*4)); + } + + return namerec; +} + +/**************************************************************************** + Convert a struct name_record to a wins.tdb record. Ignore the scope. +*****************************************************************************/ + +static TDB_DATA name_record_to_wins_record(const struct name_record *namerec) +{ + TDB_DATA data; + size_t len = 0; + int i; + uint32 id_low = (namerec->data.id & 0xFFFFFFFF); +#if defined(HAVE_LONGLONG) + uint32 id_high = (namerec->data.id >> 32) & 0xFFFFFFFF; +#else + uint32 id_high = 0; +#endif + + ZERO_STRUCT(data); + + len = (2 + 1 + (7*4)); /* "wbddddddd" */ + len += (namerec->data.num_ips * 4); + + data.dptr = SMB_MALLOC(len); + if (!data.dptr) { + return data; + } + data.dsize = len; + + len = tdb_pack(data.dptr, data.dsize, "wbddddddd", + namerec->data.nb_flags, + (unsigned char)namerec->data.source, + (uint32)namerec->data.death_time, + (uint32)namerec->data.refresh_time, + id_low, + id_high, + (uint32)namerec->data.wins_ip.s_addr, + (uint32)namerec->data.wins_flags, + (uint32)namerec->data.num_ips ); + + for (i = 0; i < namerec->data.num_ips; i++) { + SIVAL(data.dptr, len + (i*4), namerec->data.ip[i].s_addr); + } + + return data; +} + +/**************************************************************************** + Create key. Key is UNIX codepage namestring (usually utf8 64 byte len) with 1 byte type. +*****************************************************************************/ + +static TDB_DATA name_to_key(const struct nmb_name *nmbname) +{ + static char keydata[sizeof(unstring) + 1]; + TDB_DATA key; + + memset(keydata, '\0', sizeof(keydata)); + + pull_ascii_nstring(keydata, sizeof(unstring), nmbname->name); + strupper_m(keydata); + keydata[sizeof(unstring)] = nmbname->name_type; + key.dptr = keydata; + key.dsize = sizeof(keydata); + + return key; +} + +/**************************************************************************** + Lookup a given name in the wins.tdb and create a temporary malloc'ed data struct + on the linked list. We will free this later in XXXX(). +*****************************************************************************/ + +struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOOL self_only) +{ + TDB_DATA data, key; + struct name_record *nr = NULL; + struct name_record *namerec = NULL; + + if (!wins_tdb) { + return NULL; + } + + key = name_to_key(nmbname); + data = tdb_fetch(wins_tdb, key); + + if (data.dsize == 0) { + return NULL; + } + + namerec = wins_record_to_name_record(key, data); + if (!namerec) { + return NULL; + } + + /* Search for this name record on the list. Replace it if found. */ + + for( nr = wins_server_subnet->namelist; nr; nr = nr->next) { + if (memcmp(nmbname->name, nr->name.name, 16) == 0) { + /* Delete it. */ + DLIST_REMOVE(wins_server_subnet->namelist, nr); + SAFE_FREE(nr->data.ip); + SAFE_FREE(nr); + break; + } + } + + DLIST_ADD(wins_server_subnet->namelist, namerec); + return namerec; +} + +/**************************************************************************** + Overwrite or add a given name in the wins.tdb. +*****************************************************************************/ + +static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag) +{ + TDB_DATA key, data; + int ret; + + if (!wins_tdb) { + return False; + } + + key = name_to_key(&namerec->name); + data = name_record_to_wins_record(namerec); + + if (data.dptr == NULL) { + return False; + } + + ret = tdb_store(wins_tdb, key, data, tdb_flag); + + SAFE_FREE(data.dptr); + return (ret == 0) ? True : False; +} + +/**************************************************************************** + Overwrite a given name in the wins.tdb. +*****************************************************************************/ + +BOOL wins_store_changed_namerec(const struct name_record *namerec) +{ + return store_or_replace_wins_namerec(namerec, TDB_REPLACE); +} + +/**************************************************************************** + Primary interface into creating and overwriting records in the wins.tdb. +*****************************************************************************/ + +BOOL add_name_to_wins_subnet(const struct name_record *namerec) +{ + return store_or_replace_wins_namerec(namerec, TDB_INSERT); +} + +/**************************************************************************** + Delete a given name in the tdb and remove the temporary malloc'ed data struct + on the linked list. +*****************************************************************************/ + +BOOL remove_name_from_wins_namelist(struct name_record *namerec) +{ + TDB_DATA key; + int ret; + + if (!wins_tdb) { + return False; + } + + key = name_to_key(&namerec->name); + ret = tdb_delete(wins_tdb, key); + + DLIST_REMOVE(wins_server_subnet->namelist, namerec); + SAFE_FREE(namerec->data.ip); + ZERO_STRUCTP(namerec); + SAFE_FREE(namerec); + return (ret == 0) ? True : False; +} + +/**************************************************************************** + Dump out the complete namelist. +*****************************************************************************/ + +static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + XFILE *fp = (XFILE *)state; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + dump_name_record(namerec, fp); + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + return 0; +} + +void dump_wins_subnet_namelist(XFILE *fp) +{ + tdb_traverse(wins_tdb, traverse_fn, (void *)fp); +} /**************************************************************************** Change the wins owner address in the record. @@ -31,8 +331,6 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_ip) { - if (namerec==NULL) - return; namerec->data.wins_ip=wins_ip; } @@ -42,34 +340,35 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_i static void update_wins_flag(struct name_record *namerec, int flags) { - if (namerec==NULL) - return; - namerec->data.wins_flags=0x0; /* if it's a group, it can be a normal or a special one */ if (namerec->data.nb_flags & NB_GROUP) { - if (namerec->name.name_type==0x1C) + if (namerec->name.name_type==0x1C) { namerec->data.wins_flags|=WINS_SGROUP; - else - if (namerec->data.num_ips>1) + } else { + if (namerec->data.num_ips>1) { namerec->data.wins_flags|=WINS_SGROUP; - else + } else { namerec->data.wins_flags|=WINS_NGROUP; + } + } } else { /* can be unique or multi-homed */ - if (namerec->data.num_ips>1) + if (namerec->data.num_ips>1) { namerec->data.wins_flags|=WINS_MHOMED; - else + } else { namerec->data.wins_flags|=WINS_UNIQUE; + } } /* the node type are the same bits */ namerec->data.wins_flags|=namerec->data.nb_flags&NB_NODETYPEMASK; /* the static bit is elsewhere */ - if (namerec->data.death_time == PERMANENT_TTL) + if (namerec->data.death_time == PERMANENT_TTL) { namerec->data.wins_flags|=WINS_STATIC; + } /* and add the given bits */ namerec->data.wins_flags|=flags; @@ -95,12 +394,14 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) *current_id = general_id; - if (update) + if (update) { general_id++; + } } /**************************************************************************** Possibly call the WINS hook external program when a WINS change is made. + Also stores the changed record back in the wins_tdb. *****************************************************************************/ static void wins_hook(const char *operation, struct name_record *namerec, int ttl) @@ -110,7 +411,11 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt char *p, *namestr; int i; - if (!cmd || !*cmd) return; + wins_store_changed_namerec(namerec); + + if (!cmd || !*cmd) { + return; + } for (p=namerec->name.name; *p; p++) { if (!(isalnum((int)*p) || strchr_m("._-",*p))) { @@ -122,8 +427,9 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt /* Use the name without the nametype (and scope) appended */ namestr = nmb_namestr(&namerec->name); - if ((p = strchr(namestr, '<'))) + if ((p = strchr(namestr, '<'))) { *p = 0; + } p = command; p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", @@ -141,7 +447,6 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt smbrun(command, NULL); } - /**************************************************************************** Determine if this packet should be allocated to the WINS server. *****************************************************************************/ @@ -157,8 +462,9 @@ BOOL packet_is_for_wins_server(struct packet_struct *packet) } /* Check for node status requests. */ - if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) + if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) { return False; + } switch(nmb->header.opcode) { /* @@ -210,11 +516,13 @@ static int get_ttl_from_packet(struct nmb_packet *nmb) { int ttl = nmb->additional->ttl; - if(ttl < lp_min_wins_ttl() ) + if (ttl < lp_min_wins_ttl()) { ttl = lp_min_wins_ttl(); + } - if(ttl > lp_max_wins_ttl() ) + if (ttl > lp_max_wins_ttl()) { ttl = lp_max_wins_ttl(); + } return ttl; } @@ -229,8 +537,19 @@ BOOL initialise_wins(void) XFILE *fp; pstring line; - if(!lp_we_are_a_wins_server()) + if(!lp_we_are_a_wins_server()) { return True; + } + + /* Open the wins.tdb. */ + wins_tdb = tdb_open_log(lock_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0600); + if (!wins_tdb) { + DEBUG(0,("initialise_wins: failed to open wins.tdb. Error was %s\n", + strerror(errno) )); + return False; + } + + tdb_store_int32(wins_tdb, "WINSDB_VERSION", WINSDB_VERSION); add_samba_names_to_subnet(wins_server_subnet); @@ -344,8 +663,9 @@ BOOL initialise_wins(void) continue; } - if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') { nb_flags_str[strlen(nb_flags_str)-1] = '\0'; + } /* Netbios name. # divides the name from the type (hex): netbios#xx */ pstrcpy(name,name_str); @@ -361,8 +681,9 @@ BOOL initialise_wins(void) /* add all entries that have 60 seconds or more to live */ if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { - if(ttl != PERMANENT_TTL) + if(ttl != PERMANENT_TTL) { ttl -= time_now; + } DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); @@ -370,7 +691,8 @@ BOOL initialise_wins(void) (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, ttl, REGISTER_NAME, num_ips, ip_list ); } else { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", + DEBUG(4, ("initialise_wins: not adding name (ttl problem) " + "%s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } @@ -396,16 +718,21 @@ static void send_wins_wack_response(int ttl, struct packet_struct *p) identical bytes from the requesting packet header. */ rdata[0] = (nmb->header.opcode & 0xF) << 3; - if (nmb->header.nm_flags.authoritative && nmb->header.response) + if (nmb->header.nm_flags.authoritative && nmb->header.response) { rdata[0] |= 0x4; - if (nmb->header.nm_flags.trunc) + } + if (nmb->header.nm_flags.trunc) { rdata[0] |= 0x2; - if (nmb->header.nm_flags.recursion_desired) + } + if (nmb->header.nm_flags.recursion_desired) { rdata[0] |= 0x1; - if (nmb->header.nm_flags.recursion_available && nmb->header.response) + } + if (nmb->header.nm_flags.recursion_available && nmb->header.response) { rdata[1] |= 0x80; - if (nmb->header.nm_flags.bcast) + } + if (nmb->header.nm_flags.bcast) { rdata[1] |= 0x10; + } reply_netbios_packet(p, /* Packet to reply to. */ 0, /* Result code. */ @@ -545,7 +872,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, * names update the ttl and return success. */ if( (!group || (group && (question->name_type == 0x1c))) - && find_ip_in_name_record(namerec, from_ip) ) { + && find_ip_in_name_record(namerec, from_ip) ) { /* * Update the ttl. */ @@ -584,6 +911,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, * 255.255.255.255 so we can't search for the IP address. */ update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } else if(!group && (question->name_type == 0x1d)) { @@ -669,16 +997,19 @@ static void wins_register_query_fail(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - if( (namerec != NULL) && (namerec->data.source == REGISTER_NAME) && ip_equal(rrec->packet->ip, *namerec->data.ip) ) { + if ((namerec != NULL) && (namerec->data.source == REGISTER_NAME) && + ip_equal(rrec->packet->ip, *namerec->data.ip)) { remove_name_from_namelist( subrec, namerec); namerec = NULL; } - if(namerec == NULL) + if(namerec == NULL) { wins_process_name_registration_request(subrec, orig_reg_packet); - else - DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ -querying for name %s in order to replace it and this reply.\n", nmb_namestr(question_name) )); + } else { + DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between " + "querying for name %s in order to replace it and this reply.\n", + nmb_namestr(question_name) )); + } orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -828,8 +1159,9 @@ to register name %s. Name already exists in WINS with source type %d.\n", * Group names with type 0x1c are registered with individual IP addresses. */ - if(registering_group_name && (question->name_type != 0x1c)) + if(registering_group_name && (question->name_type != 0x1c)) { from_ip = *interpret_addr2("255.255.255.255"); + } /* * Ignore all attempts to register a unique 0x1d name, although return success. @@ -876,6 +1208,7 @@ to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); update_wins_owner(namerec, our_fake_ip); } update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } else { @@ -905,8 +1238,11 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); * reject without doing the query - we know we will reject it. */ - if ( namerec != NULL ) + if ( namerec != NULL ) { pull_ascii_nstring(name, sizeof(name), namerec->name.name); + } else { + name[0] = '\0'; + } if( is_myname(name) ) { if(!ismyip(from_ip)) { @@ -919,8 +1255,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's - update the ttl. */ update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response(0, ttl, p); return; } } @@ -940,8 +1276,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio && ip_equal( namerec->data.ip[0], from_ip ) && ip_equal(namerec->data.wins_ip, our_fake_ip) ) { update_name_ttl( namerec, ttl ); - send_wins_name_registration_response( 0, ttl, p ); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response( 0, ttl, p ); return; } @@ -1061,15 +1397,16 @@ a subsequent IP address.\n", nmb_namestr(question_name) )); return; } - if(!find_ip_in_name_record(namerec, from_ip)) + if(!find_ip_in_name_record(namerec, from_ip)) { add_ip_to_name_record(namerec, from_ip); + } get_global_id_and_update(&namerec->data.id, True); update_wins_owner(namerec, our_fake_ip); update_wins_flag(namerec, WINS_ACTIVE); update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, orig_reg_packet); wins_hook("add", namerec, ttl); + send_wins_name_registration_response(0, ttl, orig_reg_packet); orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -1237,18 +1574,17 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's. Ensure the IP is in the record and * update the ttl. Update the version ID to force replication. */ + update_name_ttl(namerec, ttl); + if(!find_ip_in_name_record(namerec, from_ip)) { get_global_id_and_update(&namerec->data.id, True); update_wins_owner(namerec, our_fake_ip); update_wins_flag(namerec, WINS_ACTIVE); add_ip_to_name_record(namerec, from_ip); - wins_hook("add", namerec, ttl); - } else { - wins_hook("refresh", namerec, ttl); } - update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } @@ -1272,8 +1608,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio update_wins_flag(namerec, WINS_ACTIVE); } - send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response(0, ttl, p); return; } @@ -1347,6 +1683,37 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio send_wins_name_registration_response(0, ttl, p); } +/*********************************************************************** + Fetch all *<1b> names from the WINS db and store on the namelist. +***********************************************************************/ + +static int fetch_1b_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + /* Filter out all non-1b names. */ + if (kbuf.dptr[sizeof(unstring)] != 0x1b) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + DLIST_ADD(wins_server_subnet->namelist, namerec); + return 0; +} + +void fetch_all_active_wins_1b_names(void) +{ + tdb_traverse(wins_tdb, fetch_1b_traverse_fn, NULL); +} + /*********************************************************************** Deal with the special name query for *<1b>. ***********************************************************************/ @@ -1365,10 +1732,13 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b ) + + fetch_all_active_wins_1b_names(); + + for( namerec = subrec->namelist; namerec; namerec = namerec->next ) { + if( WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { num_ips += namerec->data.num_ips; + } } if(num_ips == 0) { @@ -1391,9 +1761,8 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { + for( namerec = subrec->namelist; namerec; namerec = namerec->next ) { + if( WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { int i; for(i = 0; i < namerec->data.num_ips; i++) { set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags); @@ -1465,8 +1834,9 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, prdata, /* data to send. */ reply_data_len); /* data length. */ - if(prdata != rdata) + if(prdata != rdata) { SAFE_FREE(prdata); + } } /*********************************************************************** @@ -1548,7 +1918,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", nmb_namestr(question) )); - queue_dns_query(p, question, &namerec); + queue_dns_query(p, question); return; } @@ -1680,6 +2050,7 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question) remove_ip_from_name_record(namerec, from_ip); DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n", inet_ntoa(from_ip),nmb_namestr(question))); + wins_hook("delete", namerec, 0); send_wins_name_release_response(0, p); return; } @@ -1689,118 +2060,235 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question) * Flag the name as released and update the ttl */ - send_wins_name_release_response(0, p); - namerec->data.wins_flags |= WINS_RELEASED; update_name_ttl(namerec, EXTINCTION_INTERVAL); wins_hook("delete", namerec, 0); + send_wins_name_release_response(0, p); } /******************************************************************* WINS time dependent processing. ******************************************************************/ +static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + time_t t = *(time_t *)state; + BOOL store_record = False; + struct name_record *namerec = NULL; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { + if( namerec->data.source == SELF_NAME ) { + DEBUG( 3, ( "wins_processing_traverse_fn: Subnet %s not expiring SELF name %s\n", + wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); + namerec->data.death_time += 300; + store_record = True; + goto done; + } else if (namerec->data.source == DNS_NAME || namerec->data.source == DNSFAIL_NAME) { + DEBUG(3,("wins_processing_traverse_fn: deleting timed out DNS name %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + } + + /* handle records, samba is the wins owner */ + if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_RELEASED; + namerec->data.death_time = t + EXTINCTION_INTERVAL; + DEBUG(3,("wins_processing_traverse_fn: expiring %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_RELEASED: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + get_global_id_and_update(&namerec->data.id, True); + DEBUG(3,("wins_processing_traverse_fn: tombstoning %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_TOMBSTONED: + DEBUG(3,("wins_processing_traverse_fn: deleting %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + } + } else { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + /* that's not as MS says it should be */ + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + DEBUG(3,("wins_processing_traverse_fn: tombstoning %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_TOMBSTONED: + DEBUG(3,("wins_processing_traverse_fn: deleting %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + case WINS_RELEASED: + DEBUG(0,("wins_processing_traverse_fn: %s is in released state and\ +we are not the wins owner !\n", nmb_namestr(&namerec->name))); + goto done; + } + } + } + + done: + + if (store_record) { + wins_store_changed_namerec(namerec); + } + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + + return 0; +} + +/******************************************************************* + Time dependent wins processing. +******************************************************************/ + void initiate_wins_processing(time_t t) { static time_t lasttime = 0; - struct name_record *namerec; - struct name_record *next_namerec; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct name_record *nr = NULL; + struct name_record *nrnext = NULL; - if (!lasttime) + if (!lasttime) { lasttime = t; - if (t - lasttime < 20) + } + if (t - lasttime < 20) { return; + } + + if(!lp_we_are_a_wins_server()) { + lasttime = t; + return; + } + + tdb_traverse(wins_tdb, wins_processing_traverse_fn, &t); + + + /* Delete all temporary name records on the wins subnet linked list. */ + for( nr = wins_server_subnet->namelist; nr; nr = nrnext) { + nrnext = nr->next; + DLIST_REMOVE(wins_server_subnet->namelist, nr); + SAFE_FREE(nr->data.ip); + SAFE_FREE(nr); + } + + wins_write_database(t, True); lasttime = t; +} - if(!lp_we_are_a_wins_server()) - return; +/******************************************************************* + Write out one record. +******************************************************************/ - for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); - namerec; - namerec = next_namerec ) { - next_namerec = (struct name_record *)ubi_trNext( namerec ); - - if( (namerec->data.death_time != PERMANENT_TTL) - && (namerec->data.death_time < t) ) { - - if( namerec->data.source == SELF_NAME ) { - DEBUG( 3, ( "initiate_wins_processing: Subnet %s not expiring SELF name %s\n", - wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); - namerec->data.death_time += 300; - namerec->subnet->namelist_changed = True; - continue; - } else if (namerec->data.source == DNS_NAME || namerec->data.source == DNSFAIL_NAME) { - DEBUG(3,("initiate_wins_processing: deleting timed out DNS name %s\n", - nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - continue; - } +void wins_write_name_record(struct name_record *namerec, XFILE *fp) +{ + int i; + struct tm *tm; - /* handle records, samba is the wins owner */ - if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { - case WINS_ACTIVE: - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_RELEASED; - namerec->data.death_time = t + EXTINCTION_INTERVAL; - DEBUG(3,("initiate_wins_processing: expiring %s\n", nmb_namestr(&namerec->name))); - break; - case WINS_RELEASED: - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_TOMBSTONED; - namerec->data.death_time = t + EXTINCTION_TIMEOUT; - get_global_id_and_update(&namerec->data.id, True); - DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); - break; - case WINS_TOMBSTONED: - DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - break; - } - } else { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { - case WINS_ACTIVE: - /* that's not as MS says it should be */ - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_TOMBSTONED; - namerec->data.death_time = t + EXTINCTION_TIMEOUT; - DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); - case WINS_TOMBSTONED: - DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - break; - case WINS_RELEASED: - DEBUG(0,("initiate_wins_processing: %s is in released state and\ -we are not the wins owner !\n", nmb_namestr(&namerec->name))); - break; - } - } + DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); + + if( namerec->data.death_time != PERMANENT_TTL ) { + char *ts, *nl; + tm = localtime(&namerec->data.death_time); + ts = asctime(tm); + nl = strrchr( ts, '\n' ); + if( NULL != nl ) { + *nl = '\0'; } + DEBUGADD(4,("TTL = %s ", ts )); + } else { + DEBUGADD(4,("TTL = PERMANENT ")); + } + + for (i = 0; i < namerec->data.num_ips; i++) { + DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); } + DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - if(wins_server_subnet->namelist_changed) - wins_write_database(True); + if( namerec->data.source == REGISTER_NAME ) { + unstring name; + pull_ascii_nstring(name, sizeof(name), namerec->name.name); + x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ + (int)namerec->data.death_time); - wins_server_subnet->namelist_changed = False; + for (i = 0; i < namerec->data.num_ips; i++) + x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); + } } /******************************************************************* Write out the current WINS database. ******************************************************************/ -void wins_write_database(BOOL background) +static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + XFILE *fp = (XFILE *)state; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + wins_write_name_record(namerec, fp); + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + return 0; +} + + +void wins_write_database(time_t t, BOOL background) { - struct name_record *namerec; + static time_t last_write_time = 0; pstring fname, fnamenew; XFILE *fp; - if(!lp_we_are_a_wins_server()) + if (background) { + if (!last_write_time) { + last_write_time = t; + } + if (t - last_write_time < 120) { + return; + } + + } + + if(!lp_we_are_a_wins_server()) { return; + } /* We will do the writing in a child process to ensure that the parent doesn't block while this is done */ if (background) { @@ -1808,6 +2296,11 @@ void wins_write_database(BOOL background) if (sys_fork()) { return; } + if (tdb_reopen(wins_tdb)) { + DEBUG(0,("wins_write_database: tdb_reopen failed. Error was %s\n", + strerror(errno))); + return; + } } slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); @@ -1826,41 +2319,8 @@ void wins_write_database(BOOL background) x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); - for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - int i; - struct tm *tm; - - DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); - - if( namerec->data.death_time != PERMANENT_TTL ) { - char *ts, *nl; - - tm = localtime(&namerec->data.death_time); - ts = asctime(tm); - nl = strrchr( ts, '\n' ); - if( NULL != nl ) - *nl = '\0'; - DEBUGADD(4,("TTL = %s ", ts )); - } else { - DEBUGADD(4,("TTL = PERMANENT ")); - } + tdb_traverse(wins_tdb, wins_writedb_traverse_fn, fp); - for (i = 0; i < namerec->data.num_ips; i++) - DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); - DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - - if( namerec->data.source == REGISTER_NAME ) { - unstring name; - pull_ascii_nstring(name, sizeof(name), namerec->name.name); - x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ - (int)namerec->data.death_time); - - for (i = 0; i < namerec->data.num_ips; i++) - x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); - x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); - } - } - x_fclose(fp); chmod(fnamenew,0644); unlink(fname); @@ -1870,6 +2330,8 @@ void wins_write_database(BOOL background) } } +#if 0 + Until winsrepl is done. /**************************************************************************** Process a internal Samba message receiving a wins record. ***************************************************************************/ @@ -1885,8 +2347,9 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); int i; - if (buf==NULL) + if (buf==NULL) { return; + } /* Record should use UNIX codepage. Ensure this is so in the wrepld code. JRA. */ record=(WINS_RECORD *)buf; @@ -1900,8 +2363,15 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, DEBUG(3,("nmbd_wins_new_entry: adding new replicated record: %s<%02x> for wins server: %s\n", record->name, record->type, inet_ntoa(record->wins_ip))); - new_namerec=add_name_to_subnet( wins_server_subnet, record->name, record->type, record->nb_flags, - EXTINCTION_INTERVAL, REGISTER_NAME, record->num_ips, record->ip); + new_namerec=add_name_to_subnet( wins_server_subnet, + record->name, + record->type, + record->nb_flags, + EXTINCTION_INTERVAL, + REGISTER_NAME, + record->num_ips, + record->ip); + if (new_namerec!=NULL) { update_wins_owner(new_namerec, record->wins_ip); update_wins_flag(new_namerec, record->wins_flags); @@ -2019,3 +2489,4 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, } } +#endif -- cgit From f346c5a092233443e69f1e4ffa75da7b6dda11d1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Dec 2005 23:09:01 +0000 Subject: r12110: We're using a tdb-based wins backend now. Thanks to the ubiqx code, which has served us well for many a year.. "Well done, thou good and faithful servant". Jeremy. --- source/ubiqx/COPYING.LIB | 481 ----------------- source/ubiqx/README.UBI | 18 - source/ubiqx/debugparse.c | 308 ----------- source/ubiqx/debugparse.h | 127 ----- source/ubiqx/sys_include.h | 52 -- source/ubiqx/ubi_BinTree.c | 1172 ------------------------------------------ source/ubiqx/ubi_BinTree.h | 887 -------------------------------- source/ubiqx/ubi_Cache.c | 505 ------------------ source/ubiqx/ubi_Cache.h | 412 --------------- source/ubiqx/ubi_SplayTree.c | 512 ------------------ source/ubiqx/ubi_SplayTree.h | 377 -------------- source/ubiqx/ubi_dLinkList.c | 171 ------ source/ubiqx/ubi_dLinkList.h | 242 --------- source/ubiqx/ubi_sLinkList.c | 187 ------- source/ubiqx/ubi_sLinkList.h | 254 --------- 15 files changed, 5705 deletions(-) delete mode 100644 source/ubiqx/COPYING.LIB delete mode 100644 source/ubiqx/README.UBI delete mode 100644 source/ubiqx/debugparse.c delete mode 100644 source/ubiqx/debugparse.h delete mode 100644 source/ubiqx/sys_include.h delete mode 100644 source/ubiqx/ubi_BinTree.c delete mode 100644 source/ubiqx/ubi_BinTree.h delete mode 100644 source/ubiqx/ubi_Cache.c delete mode 100644 source/ubiqx/ubi_Cache.h delete mode 100644 source/ubiqx/ubi_SplayTree.c delete mode 100644 source/ubiqx/ubi_SplayTree.h delete mode 100644 source/ubiqx/ubi_dLinkList.c delete mode 100644 source/ubiqx/ubi_dLinkList.h delete mode 100644 source/ubiqx/ubi_sLinkList.c delete mode 100644 source/ubiqx/ubi_sLinkList.h diff --git a/source/ubiqx/COPYING.LIB b/source/ubiqx/COPYING.LIB deleted file mode 100644 index 8c8377da464..00000000000 --- a/source/ubiqx/COPYING.LIB +++ /dev/null @@ -1,481 +0,0 @@ - GNU LIBRARY GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1991 Free Software Foundation, Inc. - 675 Mass Ave, Cambridge, MA 02139, USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the library GPL. It is - numbered 2 because it goes with version 2 of the ordinary GPL.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Library General Public License, applies to some -specially designated Free Software Foundation software, and to any -other libraries whose authors decide to use it. You can use it for -your libraries, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if -you distribute copies of the library, or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link a program with the library, you must provide -complete object files to the recipients so that they can relink them -with the library, after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - Our method of protecting your rights has two steps: (1) copyright -the library, and (2) offer you this license which gives you legal -permission to copy, distribute and/or modify the library. - - Also, for each distributor's protection, we want to make certain -that everyone understands that there is no warranty for this free -library. If the library is modified by someone else and passed on, we -want its recipients to know that what they have is not the original -version, so that any problems introduced by others will not reflect on -the original authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that companies distributing free -software will individually obtain patent licenses, thus in effect -transforming the program into proprietary software. To prevent this, -we have made it clear that any patent must be licensed for everyone's -free use or not licensed at all. - - Most GNU software, including some libraries, is covered by the ordinary -GNU General Public License, which was designed for utility programs. This -license, the GNU Library General Public License, applies to certain -designated libraries. This license is quite different from the ordinary -one; be sure to read it in full, and don't assume that anything in it is -the same as in the ordinary license. - - The reason we have a separate public license for some libraries is that -they blur the distinction we usually make between modifying or adding to a -program and simply using it. Linking a program with a library, without -changing the library, is in some sense simply using the library, and is -analogous to running a utility program or application program. However, in -a textual and legal sense, the linked executable is a combined work, a -derivative of the original library, and the ordinary General Public License -treats it as such. - - Because of this blurred distinction, using the ordinary General -Public License for libraries did not effectively promote software -sharing, because most developers did not use the libraries. We -concluded that weaker conditions might promote sharing better. - - However, unrestricted linking of non-free programs would deprive the -users of those programs of all benefit from the free status of the -libraries themselves. This Library General Public License is intended to -permit developers of non-free programs to use free libraries, while -preserving your freedom as a user of such programs to change the free -libraries that are incorporated in them. (We have not seen how to achieve -this as regards changes in header files, but we have achieved it as regards -changes in the actual functions of the Library.) The hope is that this -will lead to faster development of free libraries. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, while the latter only -works together with the library. - - Note that it is possible for a library to be covered by the ordinary -General Public License rather than by this special one. - - GNU LIBRARY GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library which -contains a notice placed by the copyright holder or other authorized -party saying it may be distributed under the terms of this Library -General Public License (also called "this License"). Each licensee is -addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also compile or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - c) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - d) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the source code distributed need not include anything that is normally -distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Library General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - Appendix: How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! diff --git a/source/ubiqx/README.UBI b/source/ubiqx/README.UBI deleted file mode 100644 index a2c14ca62c9..00000000000 --- a/source/ubiqx/README.UBI +++ /dev/null @@ -1,18 +0,0 @@ -Fri Apr 17 10:21:56 CDT 1998 - -The C code files in the samba/source/ubiqx directory are licensed under -the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL). A copy of the -LGPL should also be included in this directory under the name COPYING.LIB. -If this file is not present, you can obtain a copy of the LGPL by writing -to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, -USA. - -The versions of the ubiqx modules distributed with Samba may have been -modified for inclusion with Samba. The main distribution, which contains -additional available modules, can be found at: - - http://www.interads.co.uk/~crh/ubiqx/ - -Chris Hertel -Samba Team -ubiqx@ubiqx.mn.org diff --git a/source/ubiqx/debugparse.c b/source/ubiqx/debugparse.c deleted file mode 100644 index c5fe3e2ee85..00000000000 --- a/source/ubiqx/debugparse.c +++ /dev/null @@ -1,308 +0,0 @@ -/* ========================================================================== ** - * debugparse.c - * - * Copyright (C) 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * - * -------------------------------------------------------------------------- ** - * This module is a very simple parser for Samba debug log files. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * The important function in this module is dbg_char2token(). The rest is - * basically fluff. (Potentially useful fluff, but still fluff.) - * ========================================================================== ** - */ - -#include "debugparse.h" - -/* -------------------------------------------------------------------------- ** - * Constants... - * - * DBG_BSIZE - This internal constant is used only by dbg_test(). It is the - * size of the read buffer. I've tested the function using a - * DBG_BSIZE value of 2. - */ - -#define DBG_BSIZE 128 - -/* -------------------------------------------------------------------------- ** - * Functions... - */ - -const char *dbg_token2string( dbg_Token tok ) - /* ------------------------------------------------------------------------ ** - * Given a token, return a string describing the token. - * - * Input: tok - One of the set of dbg_Tokens defined in debugparse.h. - * - * Output: A string identifying the token. This is useful for debugging, - * etc. - * - * Note: If the token is not known, this function will return the - * string "". - * - * ------------------------------------------------------------------------ ** - */ - { - switch( tok ) - { - case dbg_null: - return( "null" ); - case dbg_ignore: - return( "ignore" ); - case dbg_header: - return( "header" ); - case dbg_timestamp: - return( "time stamp" ); - case dbg_level: - return( "level" ); - case dbg_sourcefile: - return( "source file" ); - case dbg_function: - return( "function" ); - case dbg_lineno: - return( "line number" ); - case dbg_message: - return( "message" ); - case dbg_eof: - return( "[EOF]" ); - } - return( "" ); - } /* dbg_token2string */ - -dbg_Token dbg_char2token( dbg_Token *state, int c ) - /* ------------------------------------------------------------------------ ** - * Parse input one character at a time. - * - * Input: state - A pointer to a token variable. This is used to - * maintain the parser state between calls. For - * each input stream, you should set up a separate - * state variable and initialize it to dbg_null. - * Pass a pointer to it into this function with each - * character in the input stream. See dbg_test() - * for an example. - * c - The "current" character in the input stream. - * - * Output: A token. - * The token value will change when delimiters are found, - * which indicate a transition between syntactical objects. - * Possible return values are: - * - * dbg_null - The input character was an end-of-line. - * This resets the parser to its initial state - * in preparation for parsing the next line. - * dbg_eof - Same as dbg_null, except that the character - * was an end-of-file. - * dbg_ignore - Returned for whitespace and delimiters. - * These lexical tokens are only of interest - * to the parser. - * dbg_header - Indicates the start of a header line. The - * input character was '[' and was the first on - * the line. - * dbg_timestamp - Indicates that the input character was part - * of a header timestamp. - * dbg_level - Indicates that the input character was part - * of the debug-level value in the header. - * dbg_sourcefile - Indicates that the input character was part - * of the sourcefile name in the header. - * dbg_function - Indicates that the input character was part - * of the function name in the header. - * dbg_lineno - Indicates that the input character was part - * of the DEBUG call line number in the header. - * dbg_message - Indicates that the input character was part - * of the DEBUG message text. - * - * ------------------------------------------------------------------------ ** - */ - { - /* The terminating characters that we see will greatly depend upon - * how they are read. For example, if gets() is used instead of - * fgets(), then we will not see newline characters. A lot also - * depends on the calling function, which may handle terminators - * itself. - * - * '\n', '\0', and EOF are all considered line terminators. The - * dbg_eof token is sent back if an EOF is encountered. - * - * Warning: only allow the '\0' character to be sent if you are - * using gets() to read whole lines (thus replacing '\n' - * with '\0'). Sending '\0' at the wrong time will mess - * up the parsing. - */ - switch( c ) - { - case EOF: - *state = dbg_null; /* Set state to null (initial state) so */ - return( dbg_eof ); /* that we can restart with new input. */ - case '\n': - case '\0': - *state = dbg_null; /* A newline or eoln resets to the null state. */ - return( dbg_null ); - } - - /* When within the body of the message, only a line terminator - * can cause a change of state. We've already checked for line - * terminators, so if the current state is dbg_msgtxt, simply - * return that as our current token. - */ - if( dbg_message == *state ) - return( dbg_message ); - - /* If we are at the start of a new line, and the input character - * is an opening bracket, then the line is a header line, otherwise - * it's a message body line. - */ - if( dbg_null == *state ) - { - if( '[' == c ) - { - *state = dbg_timestamp; - return( dbg_header ); - } - *state = dbg_message; - return( dbg_message ); - } - - /* We've taken care of terminators, text blocks and new lines. - * The remaining possibilities are all within the header line - * itself. - */ - - /* Within the header line, whitespace can be ignored *except* - * within the timestamp. - */ - if( isspace( c ) ) - { - /* Fudge. The timestamp may contain space characters. */ - if( (' ' == c) && (dbg_timestamp == *state) ) - return( dbg_timestamp ); - /* Otherwise, ignore whitespace. */ - return( dbg_ignore ); - } - - /* Okay, at this point we know we're somewhere in the header. - * Valid header *states* are: dbg_timestamp, dbg_level, - * dbg_sourcefile, dbg_function, and dbg_lineno. - */ - switch( c ) - { - case ',': - if( dbg_timestamp == *state ) - { - *state = dbg_level; - return( dbg_ignore ); - } - break; - case ']': - if( dbg_level == *state ) - { - *state = dbg_sourcefile; - return( dbg_ignore ); - } - break; - case ':': - if( dbg_sourcefile == *state ) - { - *state = dbg_function; - return( dbg_ignore ); - } - break; - case '(': - if( dbg_function == *state ) - { - *state = dbg_lineno; - return( dbg_ignore ); - } - break; - case ')': - if( dbg_lineno == *state ) - { - *state = dbg_null; - return( dbg_ignore ); - } - break; - } - - /* If the previous block did not result in a state change, then - * return the current state as the current token. - */ - return( *state ); - } /* dbg_char2token */ - -void dbg_test( void ) - /* ------------------------------------------------------------------------ ** - * Simple test function. - * - * Input: none. - * Output: none. - * Notes: This function was used to test dbg_char2token(). It reads a - * Samba log file from stdin and prints parsing info to stdout. - * It also serves as a simple example. - * - * ------------------------------------------------------------------------ ** - */ - { - char bufr[DBG_BSIZE]; - int i; - int linecount = 1; - dbg_Token old = dbg_null, - newtok= dbg_null, - state = dbg_null; - - while( fgets( bufr, DBG_BSIZE, stdin ) ) - { - for( i = 0; bufr[i]; i++ ) - { - old = newtok; - newtok = dbg_char2token( &state, bufr[i] ); - switch( newtok ) - { - case dbg_header: - if( linecount > 1 ) - (void)putchar( '\n' ); - break; - case dbg_null: - linecount++; - break; - case dbg_ignore: - break; - default: - if( old != newtok ) - (void)printf( "\n[%05d]%12s: ", linecount, dbg_token2string(newtok) ); - (void)putchar( bufr[i] ); - } - } - } - (void)putchar( '\n' ); - } /* dbg_test */ - - -/* -------------------------------------------------------------------------- ** - * This simple main line can be uncommented and used to test the parser. - */ - -/* - * int main( void ) - * { - * dbg_test(); - * return( 0 ); - * } - */ - -/* ========================================================================== */ diff --git a/source/ubiqx/debugparse.h b/source/ubiqx/debugparse.h deleted file mode 100644 index 458eee74558..00000000000 --- a/source/ubiqx/debugparse.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef DEBUGPARSE_H -#define DEBUGPARSE_H -/* ========================================================================== ** - * debugparse.c - * - * Copyright (C) 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * - * -------------------------------------------------------------------------- ** - * This module is a very simple parser for Samba debug log files. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * The important function in this module is dbg_char2token(). The rest is - * basically fluff. (Potentially useful fluff, but still fluff.) - * ========================================================================== ** - */ - -#include "sys_include.h" - -/* This module compiles quite nicely outside of the Samba environment. - * You'll need the following headers: -#include -#include -#include - */ - -/* -------------------------------------------------------------------------- ** - * These are the tokens returned by dbg_char2token(). - */ - -typedef enum - { - dbg_null = 0, - dbg_ignore, - dbg_header, - dbg_timestamp, - dbg_level, - dbg_sourcefile, - dbg_function, - dbg_lineno, - dbg_message, - dbg_eof - } dbg_Token; - -/* -------------------------------------------------------------------------- ** - * Function prototypes... - */ - - const char *dbg_token2string( dbg_Token tok ); - /* ------------------------------------------------------------------------ ** - * Given a token, return a string describing the token. - * - * Input: tok - One of the set of dbg_Tokens defined in debugparse.h. - * - * Output: A string identifying the token. This is useful for debugging, - * etc. - * - * Note: If the token is not known, this function will return the - * string "". - * - * ------------------------------------------------------------------------ ** - */ - - dbg_Token dbg_char2token( dbg_Token *state, int c ); - /* ------------------------------------------------------------------------ ** - * Parse input one character at a time. - * - * Input: state - A pointer to a token variable. This is used to - * maintain the parser state between calls. For - * each input stream, you should set up a separate - * state variable and initialize it to dbg_null. - * Pass a pointer to it into this function with each - * character in the input stream. See dbg_test() - * for an example. - * c - The "current" character in the input stream. - * - * Output: A token. - * The token value will change when delimiters are found, - * which indicate a transition between syntactical objects. - * Possible return values are: - * - * dbg_null - The input character was an end-of-line. - * This resets the parser to its initial state - * in preparation for parsing the next line. - * dbg_eof - Same as dbg_null, except that the character - * was an end-of-file. - * dbg_ignore - Returned for whitespace and delimiters. - * These lexical tokens are only of interest - * to the parser. - * dbg_header - Indicates the start of a header line. The - * input character was '[' and was the first on - * the line. - * dbg_timestamp - Indicates that the input character was part - * of a header timestamp. - * dbg_level - Indicates that the input character was part - * of the debug-level value in the header. - * dbg_sourcefile - Indicates that the input character was part - * of the sourcefile name in the header. - * dbg_function - Indicates that the input character was part - * of the function name in the header. - * dbg_lineno - Indicates that the input character was part - * of the DEBUG call line number in the header. - * dbg_message - Indicates that the input character was part - * of the DEBUG message text. - * - * ------------------------------------------------------------------------ ** - */ - - -/* -------------------------------------------------------------------------- */ -#endif /* DEBUGPARSE_H */ diff --git a/source/ubiqx/sys_include.h b/source/ubiqx/sys_include.h deleted file mode 100644 index 8ff270afe85..00000000000 --- a/source/ubiqx/sys_include.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SYS_INCLUDE_H -#define SYS_INCLUDE_H -/* ========================================================================== ** - * sys_include.h - * - * Copyright (C) 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * This header provides system declarations and data types used internally - * by the ubiqx modules. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Samba version of sys_include.h - * - * ========================================================================== ** - */ - -#ifndef _INCLUDES_H - -/* Block the inclusion of some Samba headers so that ubiqx types won't be - * used before the headers that define them. These headers are not needed - * in the ubiqx modules anyway. - */ -#define _PROTO_H_ -#define _NAMESERV_H_ -#define _HASH_H_ - -/* The main Samba system-adaptive header file. - */ -#include "includes.h" - -#endif /* _INCLUDES_H */ - -/* ================================ The End ================================= */ -#endif /* SYS_INCLUDE_H */ diff --git a/source/ubiqx/ubi_BinTree.c b/source/ubiqx/ubi_BinTree.c deleted file mode 100644 index e452ac10dc2..00000000000 --- a/source/ubiqx/ubi_BinTree.c +++ /dev/null @@ -1,1172 +0,0 @@ -/* ========================================================================== ** - * ubi_BinTree.c - * - * Copyright (C) 1991-1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements a simple binary tree. - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_BinTree.c,v - * Revision 4.12 2004/06/06 04:51:56 crh - * Fixed a small typo in ubi_BinTree.c (leftover testing cruft). - * Did a small amount of formatting touchup to ubi_BinTree.h. - * - * Revision 4.11 2004/06/06 03:14:09 crh - * Rewrote the ubi_btLeafNode() function. It now takes several paths in an - * effort to find a deeper leaf node. There is a small amount of extra - * overhead, but it is limited. - * - * Revision 4.10 2000/06/06 20:38:40 crh - * In the ReplaceNode() function, the old node header was being copied - * to the new node header using a byte-by-byte copy. This was causing - * the 'insure' software testing program to report a memory leak. The - * fix was to do a simple assignement: *newnode = *oldnode; - * This quieted the (errant) memory leak reports and is probably a bit - * faster than the bytewise copy. - * - * Revision 4.9 2000/01/08 23:24:30 crh - * Clarified a variety of if( pointer ) lines, replacing them with - * if( NULL != pointer ). This is more correct, and I have heard - * of at least one (obscure?) system out there that uses a non-zero - * value for NULL. - * Also, speed improvement in Neighbor(). It was comparing pointers - * when it could have compared two gender values. The pointer - * comparison was somewhat indirect (does pointer equal the pointer - * of the parent of the node pointed to by pointer). Urq. - * - * Revision 4.8 1999/09/22 03:40:30 crh - * Modified ubi_btTraverse() and ubi_btKillTree(). They now return an - * unsigned long indicating the number of nodes processed. The change - * is subtle. An empty tree formerly returned False, and now returns - * zero. - * - * Revision 4.7 1998/10/21 06:14:42 crh - * Fixed bugs in FirstOf() and LastOf() reported by Massimo Campostrini. - * See function comments. - * - * Revision 4.6 1998/07/25 17:02:10 crh - * Added the ubi_trNewTree() macro. - * - * Revision 4.5 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 4.4 1998/06/03 17:42:46 crh - * Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is - * included by all of the binary tree files. - * - * Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in - * ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping - * of tree types by simply changing a header. Unfortunately, the - * macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will - * conflict if used together. You must either choose a single tree - * type, or use the underlying function calls directly. Compare - * the two header files for more information. - * - * Revision 4.3 1998/06/02 01:28:43 crh - * Changed ubi_null.h to sys_include.h to make it more generic. - * - * Revision 4.2 1998/05/20 04:32:36 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * Also, the balance and gender fields of the node were declared as - * signed char. As I understand it, at least one SunOS or Solaris - * compiler doesn't like "signed char". The declarations were - * wrong anyway, so I changed them to simple "char". - * - * Revision 4.1 1998/03/31 06:11:57 crh - * Thomas Aglassinger sent E'mail pointing out errors in the - * dereferencing of function pointers, and a missing typecast. - * Thanks, Thomas! - * - * Revision 4.0 1998/03/10 03:19:22 crh - * Added the AVL field 'balance' to the ubi_btNode structure. This means - * that all BinTree modules now use the same basic node structure, which - * greatly simplifies the AVL module. - * Decided that this was a big enough change to justify a new major revision - * number. 3.0 was an error, so we're at 4.0. - * - * Revision 2.6 1998/01/24 06:27:46 crh - * Added ubi_trCount() macro. - * - * Revision 2.5 1997/12/23 03:56:29 crh - * In this version, all constants & macros defined in the header file have - * the ubi_tr prefix. Also cleaned up anything that gcc complained about - * when run with '-pedantic -fsyntax-only -Wall'. - * - * Revision 2.4 1997/07/26 04:11:10 crh - * + Just to be annoying I changed ubi_TRUE and ubi_FALSE to ubi_trTRUE - * and ubi_trFALSE. - * + There is now a type ubi_trBool to go with ubi_trTRUE and ubi_trFALSE. - * + There used to be something called "ubi_TypeDefs.h". I got rid of it. - * + Added function ubi_btLeafNode(). - * - * Revision 2.3 1997/06/03 05:16:17 crh - * Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid conflicts. - * Also changed the interface to function InitTree(). See the comments - * for this function for more information. - * - * Revision 2.2 1995/10/03 22:00:07 CRH - * Ubisized! - * - * Revision 2.1 95/03/09 23:37:10 CRH - * Added the ModuleID static string and function. These modules are now - * self-identifying. - * - * Revision 2.0 95/02/27 22:00:17 CRH - * Revision 2.0 of this program includes the following changes: - * - * 1) A fix to a major typo in the RepaceNode() function. - * 2) The addition of the static function Border(). - * 3) The addition of the public functions FirstOf() and LastOf(), which - * use Border(). These functions are used with trees that allow - * duplicate keys. - * 4) A complete rewrite of the Locate() function. Locate() now accepts - * a "comparison" operator. - * 5) Overall enhancements to both code and comments. - * - * I decided to give this a new major rev number because the interface has - * changed. In particular, there are two new functions, and changes to the - * Locate() function. - * - * Revision 1.0 93/10/15 22:44:59 CRH - * With this revision, I have added a set of #define's that provide a single, - * standard API to all existing tree modules. Until now, each of the three - * existing modules had a different function and typedef prefix, as follows: - * - * Module Prefix - * ubi_BinTree ubi_bt - * ubi_AVLtree ubi_avl - * ubi_SplayTree ubi_spt - * - * To further complicate matters, only those portions of the base module - * (ubi_BinTree) that were superceeded in the new module had the new names. - * For example, if you were using ubi_SplayTree, the locate function was - * called "ubi_sptLocate", but the next and previous functions remained - * "ubi_btNext" and "ubi_btPrev". - * - * This was not too terrible if you were familiar with the modules and knew - * exactly which tree model you wanted to use. If you wanted to be able to - * change modules (for speed comparisons, etc), things could get messy very - * quickly. - * - * So, I have added a set of defined names that get redefined in any of the - * descendant modules. To use this standardized interface in your code, - * simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with - * "ubi_tr". The "ubi_tr" names will resolve to the correct function or - * datatype names for the module that you are using. Just remember to - * include the header for that module in your program file. Because these - * names are handled by the preprocessor, there is no added run-time - * overhead. - * - * Note that the original names do still exist, and can be used if you wish - * to write code directly to a specific module. This should probably only be - * done if you are planning to implement a new descendant type, such as - * red/black trees. CRH - * - * V0.0 - June, 1991 - Written by Christopher R. Hertel (CRH). - * - * ========================================================================== ** - */ - -#include "ubi_BinTree.h" /* Header for this module. */ - - -/* ========================================================================== ** - * Static data. - */ - -static char ModuleID[] = "ubi_BinTree\n\ -\tRevision: 4.12\n\ -\tDate: 2004/06/06 04:51:56\n\ -\tAuthor: crh\n"; - -/* ========================================================================== ** - * Internal (private) functions. - */ - -static ubi_btNodePtr qFind( ubi_btCompFunc cmp, - ubi_btItemPtr FindMe, - register ubi_btNodePtr p ) - /* ------------------------------------------------------------------------ ** - * This function performs a non-recursive search of a tree for a node - * matching a specific key. It is called "qFind()" because it is - * faster that TreeFind (below). - * - * Input: - * cmp - a pointer to the tree's comparison function. - * FindMe - a pointer to the key value for which to search. - * p - a pointer to the starting point of the search.

- * is considered to be the root of a subtree, and only - * the subtree will be searched. - * - * Output: - * A pointer to a node with a key that matches the key indicated by - * FindMe, or NULL if no such node was found. - * - * Note: In a tree that allows duplicates, the pointer returned *might - * not* point to the (sequentially) first occurance of the - * desired key. - * ------------------------------------------------------------------------ ** - */ - { - int tmp; - - while( (NULL != p) - && ((tmp = ubi_trAbNormal( (*cmp)(FindMe, p) )) != ubi_trEQUAL) ) - p = p->Link[tmp]; - - return( p ); - } /* qFind */ - -static ubi_btNodePtr TreeFind( ubi_btItemPtr findme, - ubi_btNodePtr p, - ubi_btNodePtr *parentp, - char *gender, - ubi_btCompFunc CmpFunc ) - /* ------------------------------------------------------------------------ ** - * TreeFind() searches a tree for a given value (findme). It will return a - * pointer to the target node, if found, or NULL if the target node was not - * found. - * - * TreeFind() also returns, via parameters, a pointer to the parent of the - * target node, and a LEFT or RIGHT value indicating which child of the - * parent is the target node. *If the target is not found*, then these - * values indicate the place at which the target *should be found*. This - * is useful when inserting a new node into a tree or searching for nodes - * "near" the target node. - * - * The parameters are: - * - * findme - is a pointer to the key information to be searched for. - * p - points to the root of the tree to be searched. - * parentp - will return a pointer to a pointer to the !parent! of the - * target node, which can be especially usefull if the target - * was not found. - * gender - returns LEFT or RIGHT to indicate which child of *parentp - * was last searched. - * CmpFunc - points to the comparison function. - * - * This function is called by ubi_btLocate() and ubi_btInsert(). - * ------------------------------------------------------------------------ ** - */ - { - register ubi_btNodePtr tmp_p = p; - ubi_btNodePtr tmp_pp = NULL; - char tmp_gender = ubi_trEQUAL; - int tmp_cmp; - - while( (NULL != tmp_p) - && (ubi_trEQUAL != (tmp_cmp = ubi_trAbNormal((*CmpFunc)(findme, tmp_p)))) ) - { - tmp_pp = tmp_p; /* Keep track of previous node. */ - tmp_gender = (char)tmp_cmp; /* Keep track of sex of child. */ - tmp_p = tmp_p->Link[tmp_cmp]; /* Go to child. */ - } - *parentp = tmp_pp; /* Return results. */ - *gender = tmp_gender; - return( tmp_p ); - } /* TreeFind */ - -static void ReplaceNode( ubi_btNodePtr *parent, - ubi_btNodePtr oldnode, - ubi_btNodePtr newnode ) - /* ------------------------------------------------------------------------ ** - * Remove node oldnode from the tree, replacing it with node newnode. - * - * Input: - * parent - A pointer to he parent pointer of the node to be - * replaced. may point to the Link[] field of - * a parent node, or it may indicate the root pointer at - * the top of the tree. - * oldnode - A pointer to the node that is to be replaced. - * newnode - A pointer to the node that is to be installed in the - * place of <*oldnode>. - * - * Notes: Don't forget to free oldnode. - * Also, this function used to have a really nasty typo - * bug. "oldnode" and "newnode" were swapped in the line - * that now reads: - * ((unsigned char *)newnode)[i] = ((unsigned char *)oldnode)[i]; - * Bleah! - * ------------------------------------------------------------------------ ** - */ - { - *newnode = *oldnode; /* Copy node internals to new node. */ - - (*parent) = newnode; /* Old node's parent points to new child. */ - /* Now tell the children about their new step-parent. */ - if( oldnode->Link[ubi_trLEFT] ) - (oldnode->Link[ubi_trLEFT])->Link[ubi_trPARENT] = newnode; - if( oldnode->Link[ubi_trRIGHT] ) - (oldnode->Link[ubi_trRIGHT])->Link[ubi_trPARENT] = newnode; - } /* ReplaceNode */ - -static void SwapNodes( ubi_btRootPtr RootPtr, - ubi_btNodePtr Node1, - ubi_btNodePtr Node2 ) - /* ------------------------------------------------------------------------ ** - * This function swaps two nodes in the tree. Node1 will take the place of - * Node2, and Node2 will fill in the space left vacant by Node 1. - * - * Input: - * RootPtr - pointer to the tree header structure for this tree. - * Node1 - \ - * > These are the two nodes which are to be swapped. - * Node2 - / - * - * Notes: - * This function does a three step swap, using a dummy node as a place - * holder. This function is used by ubi_btRemove(). - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr *Parent; - ubi_btNode dummy; - ubi_btNodePtr dummy_p = &dummy; - - /* Replace Node 1 with the dummy, thus removing Node1 from the tree. */ - if( NULL != Node1->Link[ubi_trPARENT] ) - Parent = &((Node1->Link[ubi_trPARENT])->Link[(int)(Node1->gender)]); - else - Parent = &(RootPtr->root); - ReplaceNode( Parent, Node1, dummy_p ); - - /* Swap Node 1 with Node 2, placing Node 1 back into the tree. */ - if( NULL != Node2->Link[ubi_trPARENT] ) - Parent = &((Node2->Link[ubi_trPARENT])->Link[(int)(Node2->gender)]); - else - Parent = &(RootPtr->root); - ReplaceNode( Parent, Node2, Node1 ); - - /* Swap Node 2 and the dummy, thus placing Node 2 back into the tree. */ - if( NULL != dummy_p->Link[ubi_trPARENT] ) - Parent = &((dummy_p->Link[ubi_trPARENT])->Link[(int)(dummy_p->gender)]); - else - Parent = &(RootPtr->root); - ReplaceNode( Parent, dummy_p, Node2 ); - } /* SwapNodes */ - -/* -------------------------------------------------------------------------- ** - * These routines allow you to walk through the tree, forwards or backwards. - */ - -static ubi_btNodePtr SubSlide( register ubi_btNodePtr P, - register int whichway ) - /* ------------------------------------------------------------------------ ** - * Slide down the side of a subtree. - * - * Given a starting node, this function returns a pointer to the LEFT-, or - * RIGHT-most descendent, *or* (if whichway is PARENT) to the tree root. - * - * Input: P - a pointer to a starting place. - * whichway - the direction (LEFT, RIGHT, or PARENT) in which to - * travel. - * Output: A pointer to a node that is either the root, or has no - * whichway-th child but is within the subtree of P. Note that - * the return value may be the same as P. The return value *will - * be* NULL if P is NULL. - * ------------------------------------------------------------------------ ** - */ - { - - if( NULL != P ) - while( NULL != P->Link[ whichway ] ) - P = P->Link[ whichway ]; - return( P ); - } /* SubSlide */ - -static ubi_btNodePtr Neighbor( register ubi_btNodePtr P, - register int whichway ) - /* ------------------------------------------------------------------------ ** - * Given starting point p, return the (key order) next or preceeding node - * in the tree. - * - * Input: P - Pointer to our starting place node. - * whichway - the direction in which to travel to find the - * neighbor, i.e., the RIGHT neighbor or the LEFT - * neighbor. - * - * Output: A pointer to the neighboring node, or NULL if P was NULL. - * - * Notes: If whichway is PARENT, the results are unpredictable. - * ------------------------------------------------------------------------ ** - */ - { - if( P ) - { - if( NULL != P->Link[ whichway ] ) - return( SubSlide( P->Link[ whichway ], (char)ubi_trRevWay(whichway) ) ); - else - while( NULL != P->Link[ ubi_trPARENT ] ) - { - if( whichway == P->gender ) - P = P->Link[ ubi_trPARENT ]; - else - return( P->Link[ ubi_trPARENT ] ); - } - } - return( NULL ); - } /* Neighbor */ - -static ubi_btNodePtr Border( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe, - ubi_btNodePtr p, - int whichway ) - /* ------------------------------------------------------------------------ ** - * Given starting point p, which has a key value equal to *FindMe, locate - * the first (index order) node with the same key value. - * - * This function is useful in trees that have can have duplicate keys. - * For example, consider the following tree: - * Tree Traversal - * 2 If

points to the root and is RIGHT, 3 - * / \ then the return value will be a pointer to the / \ - * 2 2 RIGHT child of the root node. The tree on 2 5 - * / / \ the right shows the order of traversal. / / \ - * 1 2 3 1 4 6 - * - * Input: RootPtr - Pointer to the tree root structure. - * FindMe - Key value for comparisons. - * p - Pointer to the starting-point node. - * whichway - the direction in which to travel to find the - * neighbor, i.e., the RIGHT neighbor or the LEFT - * neighbor. - * - * Output: A pointer to the first (index, or "traversal", order) node with - * a Key value that matches *FindMe. - * - * Notes: If whichway is PARENT, or if the tree does not allow duplicate - * keys, this function will return

. - * ------------------------------------------------------------------------ ** - */ - { - register ubi_btNodePtr q; - - /* Exit if there's nothing that can be done. */ - if( !ubi_trDups_OK( RootPtr ) || (ubi_trPARENT == whichway) ) - return( p ); - - /* First, if needed, move up the tree. We need to get to the root of the - * subtree that contains all of the matching nodes. - */ - q = p->Link[ubi_trPARENT]; - while( (NULL != q) - && (ubi_trEQUAL == ubi_trAbNormal( (*(RootPtr->cmp))(FindMe, q) )) ) - { - p = q; - q = p->Link[ubi_trPARENT]; - } - - /* Next, move back down in the "whichway" direction. */ - q = p->Link[whichway]; - while( NULL != q ) - { - q = qFind( RootPtr->cmp, FindMe, q ); - if( q ) - { - p = q; - q = p->Link[whichway]; - } - } - return( p ); - } /* Border */ - - -/* ========================================================================== ** - * Exported utilities. - */ - -long ubi_btSgn( register long x ) - /* ------------------------------------------------------------------------ ** - * Return the sign of x; {negative,zero,positive} ==> {-1, 0, 1}. - * - * Input: x - a signed long integer value. - * - * Output: the "sign" of x, represented as follows: - * -1 == negative - * 0 == zero (no sign) - * 1 == positive - * - * Note: This utility is provided in order to facilitate the conversion - * of C comparison function return values into BinTree direction - * values: {LEFT, PARENT, EQUAL}. It is INCORPORATED into the - * ubi_trAbNormal() conversion macro! - * - * ------------------------------------------------------------------------ ** - */ - { - return( (x)?((x>0)?(1):(-1)):(0) ); - } /* ubi_btSgn */ - -ubi_btNodePtr ubi_btInitNode( ubi_btNodePtr NodePtr ) - /* ------------------------------------------------------------------------ ** - * Initialize a tree node. - * - * Input: a pointer to a ubi_btNode structure to be initialized. - * Output: a pointer to the initialized ubi_btNode structure (ie. the - * same as the input pointer). - * ------------------------------------------------------------------------ ** - */ - { - NodePtr->Link[ ubi_trLEFT ] = NULL; - NodePtr->Link[ ubi_trPARENT ] = NULL; - NodePtr->Link[ ubi_trRIGHT ] = NULL; - NodePtr->gender = ubi_trEQUAL; - NodePtr->balance = ubi_trEQUAL; - return( NodePtr ); - } /* ubi_btInitNode */ - -ubi_btRootPtr ubi_btInitTree( ubi_btRootPtr RootPtr, - ubi_btCompFunc CompFunc, - char Flags ) - /* ------------------------------------------------------------------------ ** - * Initialize the fields of a Tree Root header structure. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure to be - * initialized. - * CompFunc - a pointer to a comparison function that will be used - * whenever nodes in the tree must be compared against - * outside values. - * Flags - One bytes worth of flags. Flags include - * ubi_trOVERWRITE and ubi_trDUPKEY. See the header - * file for more info. - * - * Output: a pointer to the initialized ubi_btRoot structure (ie. the - * same value as RootPtr). - * - * Note: The interface to this function has changed from that of - * previous versions. The parameter replaces two - * boolean parameters that had the same basic effect. - * - * ------------------------------------------------------------------------ ** - */ - { - if( RootPtr ) - { - RootPtr->root = NULL; - RootPtr->count = 0L; - RootPtr->cmp = CompFunc; - RootPtr->flags = (Flags & ubi_trDUPKEY) ? ubi_trDUPKEY : Flags; - } /* There are only two supported flags, and they are - * mutually exclusive. ubi_trDUPKEY takes precedence - * over ubi_trOVERWRITE. - */ - return( RootPtr ); - } /* ubi_btInitTree */ - -ubi_trBool ubi_btInsert( ubi_btRootPtr RootPtr, - ubi_btNodePtr NewNode, - ubi_btItemPtr ItemPtr, - ubi_btNodePtr *OldNode ) - /* ------------------------------------------------------------------------ ** - * This function uses a non-recursive algorithm to add a new element to the - * tree. - * - * Input: RootPtr - a pointer to the ubi_btRoot structure that indicates - * the root of the tree to which NewNode is to be added. - * NewNode - a pointer to an ubi_btNode structure that is NOT - * part of any tree. - * ItemPtr - A pointer to the sort key that is stored within - * *NewNode. ItemPtr MUST point to information stored - * in *NewNode or an EXACT DUPLICATE. The key data - * indicated by ItemPtr is used to place the new node - * into the tree. - * OldNode - a pointer to an ubi_btNodePtr. When searching - * the tree, a duplicate node may be found. If - * duplicates are allowed, then the new node will - * be simply placed into the tree. If duplicates - * are not allowed, however, then one of two things - * may happen. - * 1) if overwritting *is not* allowed, this - * function will return FALSE (indicating that - * the new node could not be inserted), and - * *OldNode will point to the duplicate that is - * still in the tree. - * 2) if overwritting *is* allowed, then this - * function will swap **OldNode for *NewNode. - * In this case, *OldNode will point to the node - * that was removed (thus allowing you to free - * the node). - * ** If you are using overwrite mode, ALWAYS ** - * ** check the return value of this parameter! ** - * Note: You may pass NULL in this parameter, the - * function knows how to cope. If you do this, - * however, there will be no way to return a - * pointer to an old (ie. replaced) node (which is - * a problem if you are using overwrite mode). - * - * Output: a boolean value indicating success or failure. The function - * will return FALSE if the node could not be added to the tree. - * Such failure will only occur if duplicates are not allowed, - * nodes cannot be overwritten, AND a duplicate key was found - * within the tree. - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr OtherP, - parent = NULL; - char tmp; - - if( NULL == OldNode ) /* If they didn't give us a pointer, supply our own. */ - OldNode = &OtherP; - - (void)ubi_btInitNode( NewNode ); /* Init the new node's BinTree fields. */ - - /* Find a place for the new node. */ - *OldNode = TreeFind(ItemPtr, (RootPtr->root), &parent, &tmp, (RootPtr->cmp)); - - /* Now add the node to the tree... */ - if( NULL == (*OldNode) ) /* The easy one: we have a space for a new node! */ - { - if( NULL == parent ) - RootPtr->root = NewNode; - else - { - parent->Link[(int)tmp] = NewNode; - NewNode->Link[ubi_trPARENT] = parent; - NewNode->gender = tmp; - } - (RootPtr->count)++; - return( ubi_trTRUE ); - } - - /* If we reach this point, we know that a duplicate node exists. This - * section adds the node to the tree if duplicate keys are allowed. - */ - if( ubi_trDups_OK(RootPtr) ) /* Key exists, add duplicate */ - { - ubi_btNodePtr q; - - tmp = ubi_trRIGHT; - q = (*OldNode); - *OldNode = NULL; - while( NULL != q ) - { - parent = q; - if( tmp == ubi_trEQUAL ) - tmp = ubi_trRIGHT; - q = q->Link[(int)tmp]; - if ( q ) - tmp = ubi_trAbNormal( (*(RootPtr->cmp))(ItemPtr, q) ); - } - parent->Link[(int)tmp] = NewNode; - NewNode->Link[ubi_trPARENT] = parent; - NewNode->gender = tmp; - (RootPtr->count)++; - return( ubi_trTRUE ); - } - - /* If we get to *this* point, we know that we are not allowed to have - * duplicate nodes, but our node keys match, so... may we replace the - * old one? - */ - if( ubi_trOvwt_OK(RootPtr) ) /* Key exists, we replace */ - { - if( NULL == parent ) - ReplaceNode( &(RootPtr->root), *OldNode, NewNode ); - else - ReplaceNode( &(parent->Link[(int)((*OldNode)->gender)]), - *OldNode, NewNode ); - return( ubi_trTRUE ); - } - - return( ubi_trFALSE ); /* Failure: could not replace an existing node. */ - } /* ubi_btInsert */ - -ubi_btNodePtr ubi_btRemove( ubi_btRootPtr RootPtr, - ubi_btNodePtr DeadNode ) - /* ------------------------------------------------------------------------ ** - * This function removes the indicated node from the tree. - * - * Input: RootPtr - A pointer to the header of the tree that contains - * the node to be removed. - * DeadNode - A pointer to the node that will be removed. - * - * Output: This function returns a pointer to the node that was removed - * from the tree (ie. the same as DeadNode). - * - * Note: The node MUST be in the tree indicated by RootPtr. If not, - * strange and evil things will happen to your trees. - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p, - *parentp; - int tmp; - - /* if the node has both left and right subtrees, then we have to swap - * it with another node. The other node we choose will be the Prev()ious - * node, which is garunteed to have no RIGHT child. - */ - if( (NULL != DeadNode->Link[ubi_trLEFT]) - && (NULL != DeadNode->Link[ubi_trRIGHT]) ) - SwapNodes( RootPtr, DeadNode, ubi_btPrev( DeadNode ) ); - - /* The parent of the node to be deleted may be another node, or it may be - * the root of the tree. Since we're not sure, it's best just to have - * a pointer to the parent pointer, whatever it is. - */ - if( NULL == DeadNode->Link[ubi_trPARENT] ) - parentp = &( RootPtr->root ); - else - parentp = &((DeadNode->Link[ubi_trPARENT])->Link[(int)(DeadNode->gender)]); - - /* Now link the parent to the only grand-child and patch up the gender. */ - tmp = ((DeadNode->Link[ubi_trLEFT])?ubi_trLEFT:ubi_trRIGHT); - - p = (DeadNode->Link[tmp]); - if( NULL != p ) - { - p->Link[ubi_trPARENT] = DeadNode->Link[ubi_trPARENT]; - p->gender = DeadNode->gender; - } - (*parentp) = p; - - /* Finished, reduce the node count and return. */ - (RootPtr->count)--; - return( DeadNode ); - } /* ubi_btRemove */ - -ubi_btNodePtr ubi_btLocate( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe, - ubi_trCompOps CompOp ) - /* ------------------------------------------------------------------------ ** - * The purpose of ubi_btLocate() is to find a node or set of nodes given - * a target value and a "comparison operator". The Locate() function is - * more flexible and (in the case of trees that may contain dupicate keys) - * more precise than the ubi_btFind() function. The latter is faster, - * but it only searches for exact matches and, if the tree contains - * duplicates, Find() may return a pointer to any one of the duplicate- - * keyed records. - * - * Input: - * RootPtr - A pointer to the header of the tree to be searched. - * FindMe - An ubi_btItemPtr that indicates the key for which to - * search. - * CompOp - One of the following: - * CompOp Return a pointer to the node with - * ------ --------------------------------- - * ubi_trLT - the last key value that is less - * than FindMe. - * ubi_trLE - the first key matching FindMe, or - * the last key that is less than - * FindMe. - * ubi_trEQ - the first key matching FindMe. - * ubi_trGE - the first key matching FindMe, or the - * first key greater than FindMe. - * ubi_trGT - the first key greater than FindMe. - * Output: - * A pointer to the node matching the criteria listed above under - * CompOp, or NULL if no node matched the criteria. - * - * Notes: - * In the case of trees with duplicate keys, Locate() will behave as - * follows: - * - * Find: 3 Find: 3 - * Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6 - * ^ ^ ^ ^ ^ - * LT EQ GT LE GE - * - * That is, when returning a pointer to a node with a key that is LESS - * THAN the target key (FindMe), Locate() will return a pointer to the - * LAST matching node. - * When returning a pointer to a node with a key that is GREATER - * THAN the target key (FindMe), Locate() will return a pointer to the - * FIRST matching node. - * - * See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf(). - * ------------------------------------------------------------------------ ** - */ - { - register ubi_btNodePtr p; - ubi_btNodePtr parent; - char whichkid; - - /* Start by searching for a matching node. */ - p = TreeFind( FindMe, - RootPtr->root, - &parent, - &whichkid, - RootPtr->cmp ); - - if( NULL != p ) /* If we have found a match, we can resolve as follows: */ - { - switch( CompOp ) - { - case ubi_trLT: /* It's just a jump to the left... */ - p = Border( RootPtr, FindMe, p, ubi_trLEFT ); - return( Neighbor( p, ubi_trLEFT ) ); - case ubi_trGT: /* ...and then a jump to the right. */ - p = Border( RootPtr, FindMe, p, ubi_trRIGHT ); - return( Neighbor( p, ubi_trRIGHT ) ); - default: - p = Border( RootPtr, FindMe, p, ubi_trLEFT ); - return( p ); - } - } - - /* Else, no match. */ - if( ubi_trEQ == CompOp ) /* If we were looking for an exact match... */ - return( NULL ); /* ...forget it. */ - - /* We can still return a valid result for GT, GE, LE, and LT. - * points to a node with a value that is either just before or - * just after the target value. - * Remaining possibilities are LT and GT (including LE & GE). - */ - if( (ubi_trLT == CompOp) || (ubi_trLE == CompOp) ) - return( (ubi_trLEFT == whichkid) ? Neighbor( parent, whichkid ) : parent ); - else - return( (ubi_trRIGHT == whichkid) ? Neighbor( parent, whichkid ) : parent ); - } /* ubi_btLocate */ - -ubi_btNodePtr ubi_btFind( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe ) - /* ------------------------------------------------------------------------ ** - * This function performs a non-recursive search of a tree for any node - * matching a specific key. - * - * Input: - * RootPtr - a pointer to the header of the tree to be searched. - * FindMe - a pointer to the key value for which to search. - * - * Output: - * A pointer to a node with a key that matches the key indicated by - * FindMe, or NULL if no such node was found. - * - * Note: In a tree that allows duplicates, the pointer returned *might - * not* point to the (sequentially) first occurance of the - * desired key. In such a tree, it may be more useful to use - * ubi_btLocate(). - * ------------------------------------------------------------------------ ** - */ - { - return( qFind( RootPtr->cmp, FindMe, RootPtr->root ) ); - } /* ubi_btFind */ - -ubi_btNodePtr ubi_btNext( ubi_btNodePtr P ) - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Next node in the - * tree. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "next" node in the tree, or NULL if P pointed - * to the "last" node in the tree or was NULL. - * ------------------------------------------------------------------------ ** - */ - { - return( Neighbor( P, ubi_trRIGHT ) ); - } /* ubi_btNext */ - -ubi_btNodePtr ubi_btPrev( ubi_btNodePtr P ) - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Previous node in - * the tree. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "previous" node in the tree, or NULL if P - * pointed to the "first" node in the tree or was NULL. - * ------------------------------------------------------------------------ ** - */ - { - return( Neighbor( P, ubi_trLEFT ) ); - } /* ubi_btPrev */ - -ubi_btNodePtr ubi_btFirst( ubi_btNodePtr P ) - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) First node in the - * subtree of which *P is the root. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "first" node in a subtree that has *P as its - * root. This function will return NULL only if P is NULL. - * Note: In general, you will be passing in the value of the root field - * of an ubi_btRoot structure. - * ------------------------------------------------------------------------ ** - */ - { - return( SubSlide( P, ubi_trLEFT ) ); - } /* ubi_btFirst */ - -ubi_btNodePtr ubi_btLast( ubi_btNodePtr P ) - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Last node in the - * subtree of which *P is the root. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "last" node in a subtree that has *P as its - * root. This function will return NULL only if P is NULL. - * Note: In general, you will be passing in the value of the root field - * of an ubi_btRoot structure. - * ------------------------------------------------------------------------ ** - */ - { - return( SubSlide( P, ubi_trRIGHT ) ); - } /* ubi_btLast */ - -ubi_btNodePtr ubi_btFirstOf( ubi_btRootPtr RootPtr, - ubi_btItemPtr MatchMe, - ubi_btNodePtr p ) - /* ------------------------------------------------------------------------ ** - * Given a tree that a allows duplicate keys, and a pointer to a node in - * the tree, this function will return a pointer to the first (traversal - * order) node with the same key value. - * - * Input: RootPtr - A pointer to the root of the tree. - * MatchMe - A pointer to the key value. This should probably - * point to the key within node *p. - * p - A pointer to a node in the tree. - * Output: A pointer to the first node in the set of nodes with keys - * matching . - * Notes: Node *p MUST be in the set of nodes with keys matching - * . If not, this function will return NULL. - * - * 4.7: Bug found & fixed by Massimo Campostrini, - * Istituto Nazionale di Fisica Nucleare, Sezione di Pisa. - * - * ------------------------------------------------------------------------ ** - */ - { - /* If our starting point is invalid, return NULL. */ - if( (NULL == p) - || (ubi_trEQUAL != ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) )) ) - return( NULL ); - return( Border( RootPtr, MatchMe, p, ubi_trLEFT ) ); - } /* ubi_btFirstOf */ - -ubi_btNodePtr ubi_btLastOf( ubi_btRootPtr RootPtr, - ubi_btItemPtr MatchMe, - ubi_btNodePtr p ) - /* ------------------------------------------------------------------------ ** - * Given a tree that a allows duplicate keys, and a pointer to a node in - * the tree, this function will return a pointer to the last (traversal - * order) node with the same key value. - * - * Input: RootPtr - A pointer to the root of the tree. - * MatchMe - A pointer to the key value. This should probably - * point to the key within node *p. - * p - A pointer to a node in the tree. - * Output: A pointer to the last node in the set of nodes with keys - * matching . - * Notes: Node *p MUST be in the set of nodes with keys matching - * . If not, this function will return NULL. - * - * 4.7: Bug found & fixed by Massimo Campostrini, - * Istituto Nazionale di Fisica Nucleare, Sezione di Pisa. - * - * ------------------------------------------------------------------------ ** - */ - { - /* If our starting point is invalid, return NULL. */ - if( (NULL != p) - || (ubi_trEQUAL != ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) )) ) - return( NULL ); - return( Border( RootPtr, MatchMe, p, ubi_trRIGHT ) ); - } /* ubi_btLastOf */ - -unsigned long ubi_btTraverse( ubi_btRootPtr RootPtr, - ubi_btActionRtn EachNode, - void *UserData ) - /* ------------------------------------------------------------------------ ** - * Traverse a tree in sorted order (non-recursively). At each node, call - * (*EachNode)(), passing a pointer to the current node, and UserData as the - * second parameter. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure that indicates - * the tree to be traversed. - * EachNode - a pointer to a function to be called at each node - * as the node is visited. - * UserData - a generic pointer that may point to anything that - * you choose. - * - * Output: A count of the number of nodes visited. This will be zero - * if the tree is empty. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p = ubi_btFirst( RootPtr->root ); - unsigned long count = 0; - - while( NULL != p ) - { - (*EachNode)( p, UserData ); - count++; - p = ubi_btNext( p ); - } - return( count ); - } /* ubi_btTraverse */ - -unsigned long ubi_btKillTree( ubi_btRootPtr RootPtr, - ubi_btKillNodeRtn FreeNode ) - /* ------------------------------------------------------------------------ ** - * Delete an entire tree (non-recursively) and reinitialize the ubi_btRoot - * structure. Return a count of the number of nodes deleted. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure that indicates - * the root of the tree to delete. - * FreeNode - a function that will be called for each node in the - * tree to deallocate the memory used by the node. - * - * Output: The number of nodes removed from the tree. - * A value of 0 will be returned if: - * - The tree actually contains 0 entries. - * - the value of is NULL, in which case the tree is - * assumed to be empty - * - the value of is NULL, in which case entries - * cannot be removed, so 0 is returned. *Make sure that you - * provide a valid value for *. - * In all other cases, you should get a positive value equal to - * the value of RootPtr->count upon entry. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p, q; - unsigned long count = 0; - - if( (NULL == RootPtr) || (NULL == FreeNode) ) - return( 0 ); - - p = ubi_btFirst( RootPtr->root ); - while( NULL != p ) - { - q = p; - while( q->Link[ubi_trRIGHT] ) - q = SubSlide( q->Link[ubi_trRIGHT], ubi_trLEFT ); - p = q->Link[ubi_trPARENT]; - if( NULL != p ) - p->Link[ ((p->Link[ubi_trLEFT] == q)?ubi_trLEFT:ubi_trRIGHT) ] = NULL; - (*FreeNode)((void *)q); - count++; - } - - /* overkill... */ - (void)ubi_btInitTree( RootPtr, - RootPtr->cmp, - RootPtr->flags ); - return( count ); - } /* ubi_btKillTree */ - -ubi_btNodePtr ubi_btLeafNode( ubi_btNodePtr leader ) - /* ------------------------------------------------------------------------ ** - * Returns a pointer to a leaf node. - * - * Input: leader - Pointer to a node at which to start the descent. - * - * Output: A pointer to a leaf node, selected in a somewhat arbitrary - * manner but with an effort to dig deep. - * - * Notes: I wrote this function because I was using splay trees as a - * database cache. The cache had a maximum size on it, and I - * needed a way of choosing a node to sacrifice if the cache - * became full. In a splay tree, less recently accessed nodes - * tend toward the bottom of the tree, meaning that leaf nodes - * are good candidates for removal. (I really can't think of - * any other reason to use this function.) - * + In a simple binary tree, or in an AVL tree, the most recently - * added nodes tend to be nearer the bottom, making this a *bad* - * way to choose which node to remove from the cache. - * + Randomizing the traversal order is probably a good idea. You - * can improve the randomization of leaf node selection by passing - * in pointers to nodes other than the root node each time. A - * pointer to any node in the tree will do. Of course, if you - * pass a pointer to a leaf node you'll get the same thing back. - * + In an unbalanced splay tree, if you simply traverse downward - * until you hit a leaf node it is possible to accidentally - * stumble onto a short path. The result will be a leaf node - * that is actually very high in the tree--possibly a very - * recently accessed node. Not good. This function can follow - * multiple paths in an effort to find a leaf node deeper - * in the tree. Following a single path, of course, is the - * fastest way to find a leaf node. A complete traversal would - * be sure to find the deepest leaf but would be very costly in - * terms of time. This function uses a compromise that has - * worked well in testing. - * - * ------------------------------------------------------------------------ ** - */ - { - #define MAXPATHS 4 /* Set higher for more maximum paths, lower for fewer. */ - ubi_trNodePtr p[MAXPATHS]; - ubi_trNodePtr q[MAXPATHS]; - int whichway = ubi_trLEFT; - int paths; - int i, j; - - /* If the subtree is empty, return NULL. - */ - if( NULL == leader ) - return( NULL ); - - /* Initialize the p[] array with a pointer to the single node we've been - * given as a starting point. - */ - p[0] = leader; - paths = 1; - while( paths > 0 ) - { - for( i = 0; i < paths; i++ ) - q[i] = p[i]; - - for( i = j = 0; (i < paths) && (j < MAXPATHS); i++ ) - { - if( NULL != q[i]->Link[whichway] ) - p[j++] = q[i]->Link[whichway]; - whichway = ubi_trRevWay( whichway ); - if( (j < MAXPATHS) && (NULL != q[i]->Link[whichway]) ) - p[j++] = q[i]->Link[whichway]; - } - paths = j; - } - - return( q[0] ); - } /* ubi_btLeafNode */ - -int ubi_btModuleID( int size, char *list[] ) - /* ------------------------------------------------------------------------ ** - * Returns a set of strings that identify the module. - * - * Input: size - The number of elements in the array . - * list - An array of pointers of type (char *). This array - * should, initially, be empty. This function will fill - * in the array with pointers to strings. - * Output: The number of elements of that were used. If this value - * is less than , the values of the remaining elements are - * not guaranteed. - * - * Notes: Please keep in mind that the pointers returned indicate strings - * stored in static memory. Don't free() them, don't write over - * them, etc. Just read them. - * ------------------------------------------------------------------------ ** - */ - { - if( size > 0 ) - { - list[0] = ModuleID; - if( size > 1 ) - list[1] = NULL; - return( 1 ); - } - return( 0 ); - } /* ubi_btModuleID */ - - -/* ========================================================================== */ diff --git a/source/ubiqx/ubi_BinTree.h b/source/ubiqx/ubi_BinTree.h deleted file mode 100644 index 43ca1a98716..00000000000 --- a/source/ubiqx/ubi_BinTree.h +++ /dev/null @@ -1,887 +0,0 @@ -#ifndef UBI_BINTREE_H -#define UBI_BINTREE_H -/* ========================================================================== ** - * ubi_BinTree.h - * - * Copyright (C) 1991-1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements a simple binary tree. - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_BinTree.h,v - * Revision 4.12 2004/06/06 04:51:56 crh - * Fixed a small typo in ubi_BinTree.c (leftover testing cruft). - * Did a small amount of formatting touchup to ubi_BinTree.h. - * - * Revision 4.11 2004/06/06 03:14:09 crh - * Rewrote the ubi_btLeafNode() function. It now takes several paths in an - * effort to find a deeper leaf node. There is a small amount of extra - * overhead, but it is limited. - * - * Revision 4.10 2000/06/06 20:38:40 crh - * In the ReplaceNode() function, the old node header was being copied - * to the new node header using a byte-by-byte copy. This was causing - * the 'insure' software testing program to report a memory leak. The - * fix was to do a simple assignement: *newnode = *oldnode; - * This quieted the (errant) memory leak reports and is probably a bit - * faster than the bytewise copy. - * - * Revision 4.9 2000/01/08 23:24:30 crh - * Clarified a variety of if( pointer ) lines, replacing them with - * if( NULL != pointer ). This is more correct, and I have heard - * of at least one (obscure?) system out there that uses a non-zero - * value for NULL. - * Also, speed improvement in Neighbor(). It was comparing pointers - * when it could have compared two gender values. The pointer - * comparison was somewhat indirect (does pointer equal the pointer - * of the parent of the node pointed to by pointer). Urq. - * - * Revision 4.8 1999/09/22 03:40:30 crh - * Modified ubi_btTraverse() and ubi_btKillTree(). They now return an - * unsigned long indicating the number of nodes processed. The change - * is subtle. An empty tree formerly returned False, and now returns - * zero. - * - * Revision 4.7 1998/10/21 06:15:07 crh - * Fixed bugs in FirstOf() and LastOf() reported by Massimo Campostrini. - * See function comments. - * - * Revision 4.6 1998/07/25 17:02:10 crh - * Added the ubi_trNewTree() macro. - * - * Revision 4.5 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 4.4 1998/06/03 17:42:46 crh - * Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is - * included by all of the binary tree files. - * - * Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in - * ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping - * of tree types by simply changing a header. Unfortunately, the - * macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will - * conflict if used together. You must either choose a single tree - * type, or use the underlying function calls directly. Compare - * the two header files for more information. - * - * Revision 4.3 1998/06/02 01:28:43 crh - * Changed ubi_null.h to sys_include.h to make it more generic. - * - * Revision 4.2 1998/05/20 04:32:36 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * Also, the balance and gender fields of the node were declared as - * signed char. As I understand it, at least one SunOS or Solaris - * compiler doesn't like "signed char". The declarations were - * wrong anyway, so I changed them to simple "char". - * - * Revision 4.1 1998/03/31 06:13:47 crh - * Thomas Aglassinger sent E'mail pointing out errors in the - * dereferencing of function pointers, and a missing typecast. - * Thanks, Thomas! - * - * Revision 4.0 1998/03/10 03:16:04 crh - * Added the AVL field 'balance' to the ubi_btNode structure. This means - * that all BinTree modules now use the same basic node structure, which - * greatly simplifies the AVL module. - * Decided that this was a big enough change to justify a new major revision - * number. 3.0 was an error, so we're at 4.0. - * - * Revision 2.6 1998/01/24 06:27:30 crh - * Added ubi_trCount() macro. - * - * Revision 2.5 1997/12/23 03:59:21 crh - * In this version, all constants & macros defined in the header file have - * the ubi_tr prefix. Also cleaned up anything that gcc complained about - * when run with '-pedantic -fsyntax-only -Wall'. - * - * Revision 2.4 1997/07/26 04:11:14 crh - * + Just to be annoying I changed ubi_TRUE and ubi_FALSE to ubi_trTRUE - * and ubi_trFALSE. - * + There is now a type ubi_trBool to go with ubi_trTRUE and ubi_trFALSE. - * + There used to be something called "ubi_TypeDefs.h". I got rid of it. - * + Added function ubi_btLeafNode(). - * - * Revision 2.3 1997/06/03 05:15:27 crh - * Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid conflicts. - * Also changed the interface to function InitTree(). See the comments - * for this function for more information. - * - * Revision 2.2 1995/10/03 22:00:40 CRH - * Ubisized! - * - * Revision 2.1 95/03/09 23:43:46 CRH - * Added the ModuleID static string and function. These modules are now - * self-identifying. - * - * Revision 2.0 95/02/27 22:00:33 CRH - * Revision 2.0 of this program includes the following changes: - * - * 1) A fix to a major typo in the RepaceNode() function. - * 2) The addition of the static function Border(). - * 3) The addition of the public functions FirstOf() and LastOf(), which - * use Border(). These functions are used with trees that allow - * duplicate keys. - * 4) A complete rewrite of the Locate() function. Locate() now accepts - * a "comparison" operator. - * 5) Overall enhancements to both code and comments. - * - * I decided to give this a new major rev number because the interface has - * changed. In particular, there are two new functions, and changes to the - * Locate() function. - * - * Revision 1.0 93/10/15 22:55:04 CRH - * With this revision, I have added a set of #define's that provide a single, - * standard API to all existing tree modules. Until now, each of the three - * existing modules had a different function and typedef prefix, as follows: - * - * Module Prefix - * ubi_BinTree ubi_bt - * ubi_AVLtree ubi_avl - * ubi_SplayTree ubi_spt - * - * To further complicate matters, only those portions of the base module - * (ubi_BinTree) that were superceeded in the new module had the new names. - * For example, if you were using ubi_SplayTree, the locate function was - * called "ubi_sptLocate", but the next and previous functions remained - * "ubi_btNext" and "ubi_btPrev". - * - * This was not too terrible if you were familiar with the modules and knew - * exactly which tree model you wanted to use. If you wanted to be able to - * change modules (for speed comparisons, etc), things could get messy very - * quickly. - * - * So, I have added a set of defined names that get redefined in any of the - * descendant modules. To use this standardized interface in your code, - * simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with - * "ubi_tr". The "ubi_tr" names will resolve to the correct function or - * datatype names for the module that you are using. Just remember to - * include the header for that module in your program file. Because these - * names are handled by the preprocessor, there is no added run-time - * overhead. - * - * Note that the original names do still exist, and can be used if you wish - * to write code directly to a specific module. This should probably only be - * done if you are planning to implement a new descendant type, such as - * red/black trees. CRH - * - * V0.0 - June, 1991 - Written by Christopher R. Hertel (CRH). - * - * ========================================================================== ** - */ - -#include "sys_include.h" /* Global include file, used to adapt the ubiqx - * modules to the host environment and the project - * with which the modules will be used. See - * sys_include.h for more info. - */ - -/* -------------------------------------------------------------------------- ** - * Macros and constants. - * - * General purpose: - * ubi_trTRUE - Boolean TRUE. - * ubi_trFALSE - Boolean FALSE. - * - * Flags used in the tree header: - * ubi_trOVERWRITE - This flag indicates that an existing node may be - * overwritten by a new node with a matching key. - * ubi_trDUPKEY - This flag indicates that the tree allows duplicate - * keys. If the tree does allow duplicates, the - * overwrite flag is ignored. - * - * Node link array index constants: (Each node has an array of three - * pointers. One to the left, one to the right, and one back to the - * parent.) - * ubi_trLEFT - Left child pointer. - * ubi_trPARENT - Parent pointer. - * ubi_trRIGHT - Right child pointer. - * ubi_trEQUAL - Synonym for PARENT. - * - * ubi_trCompOps: These values are used in the ubi_trLocate() function. - * ubi_trLT - request the first instance of the greatest key less than - * the search key. - * ubi_trLE - request the first instance of the greatest key that is less - * than or equal to the search key. - * ubi_trEQ - request the first instance of key that is equal to the - * search key. - * ubi_trGE - request the first instance of a key that is greater than - * or equal to the search key. - * ubi_trGT - request the first instance of the first key that is greater - * than the search key. - * -------------------------------------------------------------------------- ** - */ - -#define ubi_trTRUE 0xFF -#define ubi_trFALSE 0x00 - -#define ubi_trOVERWRITE 0x01 /* Turn on allow overwrite */ -#define ubi_trDUPKEY 0x02 /* Turn on allow duplicate keys */ - -/* Pointer array index constants... */ -#define ubi_trLEFT 0x00 -#define ubi_trPARENT 0x01 -#define ubi_trRIGHT 0x02 -#define ubi_trEQUAL ubi_trPARENT - -typedef enum { - ubi_trLT = 1, - ubi_trLE, - ubi_trEQ, - ubi_trGE, - ubi_trGT - } ubi_trCompOps; - -/* -------------------------------------------------------------------------- ** - * These three macros allow simple manipulation of pointer index values (LEFT, - * RIGHT, and PARENT). - * - * Normalize() - converts {LEFT, PARENT, RIGHT} into {-1, 0 ,1}. C - * uses {negative, zero, positive} values to indicate - * {less than, equal to, greater than}. - * AbNormal() - converts {negative, zero, positive} to {LEFT, PARENT, - * RIGHT} (opposite of Normalize()). Note: C comparison - * functions, such as strcmp(), return {negative, zero, - * positive} values, which are not necessarily {-1, 0, - * 1}. This macro uses the the ubi_btSgn() function to - * compensate. - * RevWay() - converts LEFT to RIGHT and RIGHT to LEFT. PARENT (EQUAL) - * is left as is. - * -------------------------------------------------------------------------- ** - */ - -#define ubi_trNormalize(W) ((char)( (W) - ubi_trEQUAL )) -#define ubi_trAbNormal(W) ((char)( ((char)ubi_btSgn( (long)(W) )) \ - + ubi_trEQUAL )) -#define ubi_trRevWay(W) ((char)( ubi_trEQUAL - ((W) - ubi_trEQUAL) )) - -/* -------------------------------------------------------------------------- ** - * These macros allow us to quickly read the values of the OVERWRITE and - * DUPlicate KEY bits of the tree root flags field. - * -------------------------------------------------------------------------- ** - */ - -#define ubi_trDups_OK(A) \ - ((ubi_trDUPKEY & ((A)->flags))?(ubi_trTRUE):(ubi_trFALSE)) -#define ubi_trOvwt_OK(A) \ - ((ubi_trOVERWRITE & ((A)->flags))?(ubi_trTRUE):(ubi_trFALSE)) - -/* -------------------------------------------------------------------------- ** - * Additional Macros... - * - * ubi_trCount() - Given a pointer to a tree root, this macro returns the - * number of nodes currently in the tree. - * - * ubi_trNewTree() - This macro makes it easy to declare and initialize a - * tree header in one step. The line - * - * static ubi_trNewTree( MyTree, cmpfn, ubi_trDUPKEY ); - * - * is equivalent to - * - * static ubi_trRoot MyTree[1] - * = {{ NULL, cmpfn, 0, ubi_trDUPKEY }}; - * - * -------------------------------------------------------------------------- ** - */ - -#define ubi_trCount( R ) (((ubi_trRootPtr)(R))->count) - -#define ubi_trNewTree( N, C, F ) ubi_trRoot (N)[1] = {{ NULL, (C), 0, (F) }} - -/* -------------------------------------------------------------------------- ** - * Typedefs... - * - * ubi_trBool - Your typcial true or false... - * - * Item Pointer: The ubi_btItemPtr is a generic pointer. It is used to - * indicate a key that is being searched for within the tree. - * Searching occurs whenever the ubi_trFind(), ubi_trLocate(), - * or ubi_trInsert() functions are called. - * -------------------------------------------------------------------------- ** - */ - -typedef unsigned char ubi_trBool; - -typedef void *ubi_btItemPtr; /* A pointer to key data within a node. */ - -/* ------------------------------------------------------------------------- ** - * Binary Tree Node Structure: This structure defines the basic elements of - * the tree nodes. In general you *SHOULD NOT PLAY WITH THESE FIELDS*! - * But, of course, I have to put the structure into this header so that - * you can use it as a building block. - * - * The fields are as follows: - * Link - an array of pointers. These pointers are manipulated by - * the BT routines. The pointers indicate the left and right - * child nodes and the parent node. By keeping track of the - * parent pointer, we avoid the need for recursive routines or - * hand-tooled stacks to keep track of our path back to the - * root. The use of these pointers is subject to change without - * notice. - * gender - a one-byte field indicating whether the node is the RIGHT or - * LEFT child of its parent. If the node is the root of the - * tree, gender will be PARENT. - * balance - only used by the AVL tree module. This field indicates - * the height balance at a given node. See ubi_AVLtree for - * details. - * - * ------------------------------------------------------------------------- ** - */ - -typedef struct ubi_btNodeStruct { - struct ubi_btNodeStruct *Link[ 3 ]; - char gender; - char balance; - } ubi_btNode; - -typedef ubi_btNode *ubi_btNodePtr; /* Pointer to an ubi_btNode structure. */ - -/* ------------------------------------------------------------------------- ** - * The next three typedefs define standard function types used by the binary - * tree management routines. In particular: - * - * ubi_btCompFunc is a pointer to a comparison function. Comparison - * functions are passed an ubi_btItemPtr and an - * ubi_btNodePtr. They return a value that is (<0), 0, - * or (>0) to indicate that the Item is (respectively) - * "less than", "equal to", or "greater than" the Item - * contained within the node. (See ubi_btInitTree()). - * ubi_btActionRtn is a pointer to a function that may be called for each - * node visited when performing a tree traversal (see - * ubi_btTraverse()). The function will be passed two - * parameters: the first is a pointer to a node in the - * tree, the second is a generic pointer that may point to - * anything that you like. - * ubi_btKillNodeRtn is a pointer to a function that will deallocate the - * memory used by a node (see ubi_btKillTree()). Since - * memory management is left up to you, deallocation may - * mean anything that you want it to mean. Just remember - * that the tree *will* be destroyed and that none of the - * node pointers will be valid any more. - * ------------------------------------------------------------------------- ** - */ - -typedef int (*ubi_btCompFunc)( ubi_btItemPtr, ubi_btNodePtr ); - -typedef void (*ubi_btActionRtn)( ubi_btNodePtr, void * ); - -typedef void (*ubi_btKillNodeRtn)( ubi_btNodePtr ); - -/* -------------------------------------------------------------------------- ** - * Tree Root Structure: This structure gives us a convenient handle for - * accessing whole binary trees. The fields are: - * root - A pointer to the root node of the tree. - * count - A count of the number of nodes stored in the tree. - * cmp - A pointer to the comparison routine to be used when building or - * searching the tree. - * flags - A set of bit flags. Two flags are currently defined: - * - * ubi_trOVERWRITE - If set, this flag indicates that a new node should - * (bit 0x01) overwrite an old node if the two have identical - * keys (ie., the keys are equal). - * ubi_trDUPKEY - If set, this flag indicates that the tree is - * (bit 0x02) allowed to contain nodes with duplicate keys. - * - * NOTE: ubi_trInsert() tests ubi_trDUPKEY before ubi_trOVERWRITE. - * - * All of these values are set when you initialize the root structure by - * calling ubi_trInitTree(). - * -------------------------------------------------------------------------- ** - */ - -typedef struct { - ubi_btNodePtr root; /* A pointer to the root node of the tree */ - ubi_btCompFunc cmp; /* A pointer to the tree's comparison function */ - unsigned long count; /* A count of the number of nodes in the tree */ - char flags; /* Overwrite Y|N, Duplicate keys Y|N... */ - } ubi_btRoot; - -typedef ubi_btRoot *ubi_btRootPtr; /* Pointer to an ubi_btRoot structure. */ - - -/* -------------------------------------------------------------------------- ** - * Function Prototypes. - */ - -long ubi_btSgn( long x ); - /* ------------------------------------------------------------------------ ** - * Return the sign of x; {negative,zero,positive} ==> {-1, 0, 1}. - * - * Input: x - a signed long integer value. - * - * Output: the "sign" of x, represented as follows: - * -1 == negative - * 0 == zero (no sign) - * 1 == positive - * - * Note: This utility is provided in order to facilitate the conversion - * of C comparison function return values into BinTree direction - * values: {LEFT, PARENT, EQUAL}. It is INCORPORATED into the - * AbNormal() conversion macro! - * - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btInitNode( ubi_btNodePtr NodePtr ); - /* ------------------------------------------------------------------------ ** - * Initialize a tree node. - * - * Input: a pointer to a ubi_btNode structure to be initialized. - * Output: a pointer to the initialized ubi_btNode structure (ie. the - * same as the input pointer). - * ------------------------------------------------------------------------ ** - */ - -ubi_btRootPtr ubi_btInitTree( ubi_btRootPtr RootPtr, - ubi_btCompFunc CompFunc, - char Flags ); - /* ------------------------------------------------------------------------ ** - * Initialize the fields of a Tree Root header structure. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure to be - * initialized. - * CompFunc - a pointer to a comparison function that will be used - * whenever nodes in the tree must be compared against - * outside values. - * Flags - One bytes worth of flags. Flags include - * ubi_trOVERWRITE and ubi_trDUPKEY. See the header - * file for more info. - * - * Output: a pointer to the initialized ubi_btRoot structure (ie. the - * same value as RootPtr). - * - * Note: The interface to this function has changed from that of - * previous versions. The parameter replaces two - * boolean parameters that had the same basic effect. - * ------------------------------------------------------------------------ ** - */ - -ubi_trBool ubi_btInsert( ubi_btRootPtr RootPtr, - ubi_btNodePtr NewNode, - ubi_btItemPtr ItemPtr, - ubi_btNodePtr *OldNode ); - /* ------------------------------------------------------------------------ ** - * This function uses a non-recursive algorithm to add a new element to the - * tree. - * - * Input: RootPtr - a pointer to the ubi_btRoot structure that indicates - * the root of the tree to which NewNode is to be added. - * NewNode - a pointer to an ubi_btNode structure that is NOT - * part of any tree. - * ItemPtr - A pointer to the sort key that is stored within - * *NewNode. ItemPtr MUST point to information stored - * in *NewNode or an EXACT DUPLICATE. The key data - * indicated by ItemPtr is used to place the new node - * into the tree. - * OldNode - a pointer to an ubi_btNodePtr. When searching - * the tree, a duplicate node may be found. If - * duplicates are allowed, then the new node will - * be simply placed into the tree. If duplicates - * are not allowed, however, then one of two things - * may happen. - * 1) if overwritting *is not* allowed, this - * function will return FALSE (indicating that - * the new node could not be inserted), and - * *OldNode will point to the duplicate that is - * still in the tree. - * 2) if overwritting *is* allowed, then this - * function will swap **OldNode for *NewNode. - * In this case, *OldNode will point to the node - * that was removed (thus allowing you to free - * the node). - * ** If you are using overwrite mode, ALWAYS ** - * ** check the return value of this parameter! ** - * Note: You may pass NULL in this parameter, the - * function knows how to cope. If you do this, - * however, there will be no way to return a - * pointer to an old (ie. replaced) node (which is - * a problem if you are using overwrite mode). - * - * Output: a boolean value indicating success or failure. The function - * will return FALSE if the node could not be added to the tree. - * Such failure will only occur if duplicates are not allowed, - * nodes cannot be overwritten, AND a duplicate key was found - * within the tree. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btRemove( ubi_btRootPtr RootPtr, - ubi_btNodePtr DeadNode ); - /* ------------------------------------------------------------------------ ** - * This function removes the indicated node from the tree. - * - * Input: RootPtr - A pointer to the header of the tree that contains - * the node to be removed. - * DeadNode - A pointer to the node that will be removed. - * - * Output: This function returns a pointer to the node that was removed - * from the tree (ie. the same as DeadNode). - * - * Note: The node MUST be in the tree indicated by RootPtr. If not, - * strange and evil things will happen to your trees. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btLocate( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe, - ubi_trCompOps CompOp ); - /* ------------------------------------------------------------------------ ** - * The purpose of ubi_btLocate() is to find a node or set of nodes given - * a target value and a "comparison operator". The Locate() function is - * more flexible and (in the case of trees that may contain dupicate keys) - * more precise than the ubi_btFind() function. The latter is faster, - * but it only searches for exact matches and, if the tree contains - * duplicates, Find() may return a pointer to any one of the duplicate- - * keyed records. - * - * Input: - * RootPtr - A pointer to the header of the tree to be searched. - * FindMe - An ubi_btItemPtr that indicates the key for which to - * search. - * CompOp - One of the following: - * CompOp Return a pointer to the node with - * ------ --------------------------------- - * ubi_trLT - the last key value that is less - * than FindMe. - * ubi_trLE - the first key matching FindMe, or - * the last key that is less than - * FindMe. - * ubi_trEQ - the first key matching FindMe. - * ubi_trGE - the first key matching FindMe, or the - * first key greater than FindMe. - * ubi_trGT - the first key greater than FindMe. - * Output: - * A pointer to the node matching the criteria listed above under - * CompOp, or NULL if no node matched the criteria. - * - * Notes: - * In the case of trees with duplicate keys, Locate() will behave as - * follows: - * - * Find: 3 Find: 3 - * Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6 - * ^ ^ ^ ^ ^ - * LT EQ GT LE GE - * - * That is, when returning a pointer to a node with a key that is LESS - * THAN the target key (FindMe), Locate() will return a pointer to the - * LAST matching node. - * When returning a pointer to a node with a key that is GREATER - * THAN the target key (FindMe), Locate() will return a pointer to the - * FIRST matching node. - * - * See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf(). - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btFind( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe ); - /* ------------------------------------------------------------------------ ** - * This function performs a non-recursive search of a tree for any node - * matching a specific key. - * - * Input: - * RootPtr - a pointer to the header of the tree to be searched. - * FindMe - a pointer to the key value for which to search. - * - * Output: - * A pointer to a node with a key that matches the key indicated by - * FindMe, or NULL if no such node was found. - * - * Note: In a tree that allows duplicates, the pointer returned *might - * not* point to the (sequentially) first occurance of the - * desired key. In such a tree, it may be more useful to use - * ubi_btLocate(). - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btNext( ubi_btNodePtr P ); - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Next node in the - * tree. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "next" node in the tree, or NULL if P pointed - * to the "last" node in the tree or was NULL. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btPrev( ubi_btNodePtr P ); - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Previous node in - * the tree. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "previous" node in the tree, or NULL if P - * pointed to the "first" node in the tree or was NULL. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btFirst( ubi_btNodePtr P ); - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) First node in the - * subtree of which *P is the root. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "first" node in a subtree that has *P as its - * root. This function will return NULL only if P is NULL. - * Note: In general, you will be passing in the value of the root field - * of an ubi_btRoot structure. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btLast( ubi_btNodePtr P ); - /* ------------------------------------------------------------------------ ** - * Given the node indicated by P, find the (sorted order) Last node in the - * subtree of which *P is the root. - * Input: P - a pointer to a node that exists in a binary tree. - * Output: A pointer to the "last" node in a subtree that has *P as its - * root. This function will return NULL only if P is NULL. - * Note: In general, you will be passing in the value of the root field - * of an ubi_btRoot structure. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btFirstOf( ubi_btRootPtr RootPtr, - ubi_btItemPtr MatchMe, - ubi_btNodePtr p ); - /* ------------------------------------------------------------------------ ** - * Given a tree that a allows duplicate keys, and a pointer to a node in - * the tree, this function will return a pointer to the first (traversal - * order) node with the same key value. - * - * Input: RootPtr - A pointer to the root of the tree. - * MatchMe - A pointer to the key value. This should probably - * point to the key within node *p. - * p - A pointer to a node in the tree. - * Output: A pointer to the first node in the set of nodes with keys - * matching . - * Notes: Node *p MUST be in the set of nodes with keys matching - * . If not, this function will return NULL. - * - * 4.7: Bug found & fixed by Massimo Campostrini, - * Istituto Nazionale di Fisica Nucleare, Sezione di Pisa. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btLastOf( ubi_btRootPtr RootPtr, - ubi_btItemPtr MatchMe, - ubi_btNodePtr p ); - /* ------------------------------------------------------------------------ ** - * Given a tree that a allows duplicate keys, and a pointer to a node in - * the tree, this function will return a pointer to the last (traversal - * order) node with the same key value. - * - * Input: RootPtr - A pointer to the root of the tree. - * MatchMe - A pointer to the key value. This should probably - * point to the key within node *p. - * p - A pointer to a node in the tree. - * Output: A pointer to the last node in the set of nodes with keys - * matching . - * Notes: Node *p MUST be in the set of nodes with keys matching - * . If not, this function will return NULL. - * - * 4.7: Bug found & fixed by Massimo Campostrini, - * Istituto Nazionale di Fisica Nucleare, Sezione di Pisa. - * - * ------------------------------------------------------------------------ ** - */ - -unsigned long ubi_btTraverse( ubi_btRootPtr RootPtr, - ubi_btActionRtn EachNode, - void *UserData ); - /* ------------------------------------------------------------------------ ** - * Traverse a tree in sorted order (non-recursively). At each node, call - * (*EachNode)(), passing a pointer to the current node, and UserData as the - * second parameter. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure that indicates - * the tree to be traversed. - * EachNode - a pointer to a function to be called at each node - * as the node is visited. - * UserData - a generic pointer that may point to anything that - * you choose. - * - * Output: A count of the number of nodes visited. This will be zero - * if the tree is empty. - * - * ------------------------------------------------------------------------ ** - */ - - -unsigned long ubi_btKillTree( ubi_btRootPtr RootPtr, - ubi_btKillNodeRtn FreeNode ); - /* ------------------------------------------------------------------------ ** - * Delete an entire tree (non-recursively) and reinitialize the ubi_btRoot - * structure. Return a count of the number of nodes deleted. - * - * Input: RootPtr - a pointer to an ubi_btRoot structure that indicates - * the root of the tree to delete. - * FreeNode - a function that will be called for each node in the - * tree to deallocate the memory used by the node. - * - * Output: The number of nodes removed from the tree. - * A value of 0 will be returned if: - * - The tree actually contains 0 entries. - * - the value of is NULL, in which case the tree is - * assumed to be empty - * - the value of is NULL, in which case entries - * cannot be removed, so 0 is returned. *Make sure that you - * provide a valid value for *. - * In all other cases, you should get a positive value equal to - * the value of RootPtr->count upon entry. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_btLeafNode( ubi_btNodePtr leader ); - /* ------------------------------------------------------------------------ ** - * Returns a pointer to a leaf node. - * - * Input: leader - Pointer to a node at which to start the descent. - * - * Output: A pointer to a leaf node, selected in a somewhat arbitrary - * manner but with an effort to dig deep. - * - * Notes: I wrote this function because I was using splay trees as a - * database cache. The cache had a maximum size on it, and I - * needed a way of choosing a node to sacrifice if the cache - * became full. In a splay tree, less recently accessed nodes - * tend toward the bottom of the tree, meaning that leaf nodes - * are good candidates for removal. (I really can't think of - * any other reason to use this function.) - * + In a simple binary tree, or in an AVL tree, the most recently - * added nodes tend to be nearer the bottom, making this a *bad* - * way to choose which node to remove from the cache. - * + Randomizing the traversal order is probably a good idea. You - * can improve the randomization of leaf node selection by passing - * in pointers to nodes other than the root node each time. A - * pointer to any node in the tree will do. Of course, if you - * pass a pointer to a leaf node you'll get the same thing back. - * + In an unbalanced splay tree, if you simply traverse downward - * until you hit a leaf node it is possible to accidentally - * stumble onto a short path. The result will be a leaf node - * that is actually very high in the tree--possibly a very - * recently accessed node. Not good. This function can follow - * multiple paths in an effort to find a leaf node deeper - * in the tree. Following a single path, of course, is the - * fastest way to find a leaf node. A complete traversal would - * be sure to find the deepest leaf but would be very costly in - * terms of time. This function uses a compromise that has - * worked well in testing. - * - * ------------------------------------------------------------------------ ** - */ - - -int ubi_btModuleID( int size, char *list[] ); - /* ------------------------------------------------------------------------ ** - * Returns a set of strings that identify the module. - * - * Input: size - The number of elements in the array . - * list - An array of pointers of type (char *). This array - * should, initially, be empty. This function will fill - * in the array with pointers to strings. - * Output: The number of elements of that were used. If this value - * is less than , the values of the remaining elements are - * not guaranteed. - * - * Notes: Please keep in mind that the pointers returned indicate strings - * stored in static memory. Don't free() them, don't write over - * them, etc. Just read them. - * ------------------------------------------------------------------------ ** - */ - -/* -------------------------------------------------------------------------- ** - * Masquarade... - * - * This set of defines allows you to write programs that will use any of the - * implemented binary tree modules (currently BinTree, AVLtree, and SplayTree). - * Instead of using ubi_bt..., use ubi_tr..., and select the tree type by - * including the appropriate module header. - */ - -#define ubi_trItemPtr ubi_btItemPtr - -#define ubi_trNode ubi_btNode -#define ubi_trNodePtr ubi_btNodePtr - -#define ubi_trRoot ubi_btRoot -#define ubi_trRootPtr ubi_btRootPtr - -#define ubi_trCompFunc ubi_btCompFunc -#define ubi_trActionRtn ubi_btActionRtn -#define ubi_trKillNodeRtn ubi_btKillNodeRtn - -#define ubi_trSgn( x ) ubi_btSgn( x ) - -#define ubi_trInitNode( Np ) ubi_btInitNode( (ubi_btNodePtr)(Np) ) - -#define ubi_trInitTree( Rp, Cf, Fl ) \ - ubi_btInitTree( (ubi_btRootPtr)(Rp), (ubi_btCompFunc)(Cf), (Fl) ) - -#define ubi_trInsert( Rp, Nn, Ip, On ) \ - ubi_btInsert( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Nn), \ - (ubi_btItemPtr)(Ip), (ubi_btNodePtr *)(On) ) - -#define ubi_trRemove( Rp, Dn ) \ - ubi_btRemove( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Dn) ) - -#define ubi_trLocate( Rp, Ip, Op ) \ - ubi_btLocate( (ubi_btRootPtr)(Rp), \ - (ubi_btItemPtr)(Ip), \ - (ubi_trCompOps)(Op) ) - -#define ubi_trFind( Rp, Ip ) \ - ubi_btFind( (ubi_btRootPtr)(Rp), (ubi_btItemPtr)(Ip) ) - -#define ubi_trNext( P ) ubi_btNext( (ubi_btNodePtr)(P) ) - -#define ubi_trPrev( P ) ubi_btPrev( (ubi_btNodePtr)(P) ) - -#define ubi_trFirst( P ) ubi_btFirst( (ubi_btNodePtr)(P) ) - -#define ubi_trLast( P ) ubi_btLast( (ubi_btNodePtr)(P) ) - -#define ubi_trFirstOf( Rp, Ip, P ) \ - ubi_btFirstOf( (ubi_btRootPtr)(Rp), \ - (ubi_btItemPtr)(Ip), \ - (ubi_btNodePtr)(P) ) - -#define ubi_trLastOf( Rp, Ip, P ) \ - ubi_btLastOf( (ubi_btRootPtr)(Rp), \ - (ubi_btItemPtr)(Ip), \ - (ubi_btNodePtr)(P) ) - -#define ubi_trTraverse( Rp, En, Ud ) \ - ubi_btTraverse((ubi_btRootPtr)(Rp), (ubi_btActionRtn)(En), (void *)(Ud)) - -#define ubi_trKillTree( Rp, Fn ) \ - ubi_btKillTree( (ubi_btRootPtr)(Rp), (ubi_btKillNodeRtn)(Fn) ) - -#define ubi_trLeafNode( Nd ) \ - ubi_btLeafNode( (ubi_btNodePtr)(Nd) ) - -#define ubi_trModuleID( s, l ) ubi_btModuleID( s, l ) - -/* ========================================================================== */ -#endif /* UBI_BINTREE_H */ diff --git a/source/ubiqx/ubi_Cache.c b/source/ubiqx/ubi_Cache.c deleted file mode 100644 index f428dcefe97..00000000000 --- a/source/ubiqx/ubi_Cache.c +++ /dev/null @@ -1,505 +0,0 @@ -/* ========================================================================== ** - * ubi_Cache.c - * - * Copyright (C) 1997 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements a generic cache. - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * This module uses a splay tree to implement a simple cache. The cache - * module adds a thin layer of functionality to the splay tree. In - * particular: - * - * - The tree (cache) may be limited in size by the number of - * entries permitted or the amount of memory used. When either - * limit is exceeded cache entries are removed until the cache - * conforms. - * - Some statistical information is kept so that an approximate - * "hit ratio" can be calculated. - * - There are several functions available that provide access to - * and management of cache size limits, hit ratio, and tree - * trimming. - * - * The splay tree is used because recently accessed items tend toward the - * top of the tree and less recently accessed items tend toward the bottom. - * This makes it easy to purge less recently used items should the cache - * exceed its limits. - * - * To use this module, you will need to supply a comparison function of - * type ubi_trCompFunc and a node-freeing function of type - * ubi_trKillNodeRtn. See ubi_BinTree.h for more information on - * these. (This is all basic ubiqx tree management stuff.) - * - * Notes: - * - * - Cache performance will start to suffer dramatically if the - * cache becomes large enough to force the OS to start swapping - * memory to disk. This is because the nodes of the underlying tree - * will be scattered across memory in an order that is completely - * unrelated to their traversal order. As more and more of the - * cache is placed into swap space, more and more swaps will be - * required for a simple traversal (...and then there's the splay - * operation). - * - * In one simple test under Linux, the load and dump of a cache of - * 400,000 entries took only 1min, 40sec of real time. The same - * test with 450,000 records took 2 *hours* and eight minutes. - * - * - In an effort to save memory, I considered using an unsigned - * short to save the per-entry entry size. I would have tucked this - * value into some unused space in the tree node structure. On - * 32-bit word aligned systems this would have saved an additional - * four bytes per entry. I may revisit this issue, but for now I've - * decided against it. - * - * Using an unsigned short would limit the size of an entry to 64K - * bytes. That's probably more than enough for most applications. - * The key word in that last sentence, however, is "probably". I - * really dislike imposing such limits on things. - * - * - Each entry keeps track of the amount of memory it used and the - * cache header keeps the total. This information is provided via - * the EntrySize parameter in ubi_cachePut(), so it is up to you to - * make sure that the numbers are accurate. (The numbers don't even - * have to represent bytes used.) - * - * As you consider this, note that the strdup() function--as an - * example--will call malloc(). The latter generally allocates a - * multiple of the system word size, which may be more than the - * number of bytes needed to store the string. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_Cache.c,v - * Revision 0.4 1999/09/22 03:42:24 crh - * Fixed a minor typo. - * - * Revision 0.3 1998/06/03 18:00:15 crh - * Further fiddling with sys_include.h, which is no longer explicitly - * included by this module since it is inherited from ubi_BinTree.h. - * - * Revision 0.2 1998/06/02 01:36:18 crh - * Changed include name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.1 1998/05/20 04:36:02 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.0 1997/12/18 06:24:33 crh - * Initial Revision. - * - * ========================================================================== ** - */ - -#include "ubi_Cache.h" /* Header for *this* module. */ - -/* -------------------------------------------------------------------------- ** - * Static data... - */ - -/* commented out until I make use of it... -static char ModuleID[] = -"ubi_Cache\n\ -\tRevision: 0.4 \n\ -\tDate: 1999/09/22 03:42:24 \n\ -\tAuthor: crh \n"; -*/ - -/* -------------------------------------------------------------------------- ** - * Internal functions... - */ - -static void free_entry( ubi_cacheRootPtr CachePtr, ubi_cacheEntryPtr EntryPtr ) - /* ------------------------------------------------------------------------ ** - * Free a ubi_cacheEntry, and adjust the mem_used counter accordingly. - * - * Input: CachePtr - A pointer to the cache from which the entry has - * been removed. - * EntryPtr - A pointer to the already removed entry. - * - * Output: none. - * - * Notes: The entry must be removed from the cache *before* this function - * is called!!!! - * ------------------------------------------------------------------------ ** - */ - { - CachePtr->mem_used -= EntryPtr->entry_size; - (*CachePtr->free_func)( (void *)EntryPtr ); - } /* free_entry */ - -static void cachetrim( ubi_cacheRootPtr crptr ) - /* ------------------------------------------------------------------------ ** - * Remove entries from the cache until the number of entries and the amount - * of memory used are *both* below or at the maximum. - * - * Input: crptr - pointer to the cache to be trimmed. - * - * Output: None. - * - * ------------------------------------------------------------------------ ** - */ - { - while( ( crptr->max_entries && (crptr->max_entries < crptr->root.count) ) - || ( crptr->max_memory && (crptr->max_memory < crptr->mem_used) ) ) - { - if( !ubi_cacheReduce( crptr, 1 ) ) - return; - } - } /* cachetrim */ - - -/* -------------------------------------------------------------------------- ** - * Exported functions... - */ - -ubi_cacheRootPtr ubi_cacheInit( ubi_cacheRootPtr CachePtr, - ubi_trCompFunc CompFunc, - ubi_trKillNodeRtn FreeFunc, - unsigned long MaxEntries, - unsigned long MaxMemory ) - /* ------------------------------------------------------------------------ ** - * Initialize a cache header structure. - * - * Input: CachePtr - A pointer to a ubi_cacheRoot structure that is - * to be initialized. - * CompFunc - A pointer to the function that will be called - * to compare two cache values. See the module - * comments, above, for more information. - * FreeFunc - A pointer to a function that will be called - * to free a cache entry. If you allocated - * the cache entry using malloc(), then this - * will likely be free(). If you are allocating - * cache entries from a free list, then this will - * likely be a function that returns memory to the - * free list, etc. - * MaxEntries - The maximum number of entries that will be - * allowed to exist in the cache. If this limit - * is exceeded, then existing entries will be - * removed from the cache. A value of zero - * indicates that there is no limit on the number - * of cache entries. See ubi_cachePut(). - * MaxMemory - The maximum amount of memory, in bytes, to be - * allocated to the cache (excluding the cache - * header). If this is exceeded, existing entries - * in the cache will be removed until enough memory - * has been freed to meet the condition. See - * ubi_cachePut(). - * - * Output: A pointer to the initialized cache (i.e., the same as CachePtr). - * - * Notes: Both MaxEntries and MaxMemory may be changed after the cache - * has been created. See - * ubi_cacheSetMaxEntries() - * ubi_cacheSetMaxMemory() - * ubi_cacheGetMaxEntries() - * ubi_cacheGetMaxMemory() (the latter two are macros). - * - * - Memory is allocated in multiples of the word size. The - * return value of the strlen() function does not reflect - * this; it will allways be less than or equal to the amount - * of memory actually allocated. Keep this in mind when - * choosing a value for MaxMemory. - * - * ------------------------------------------------------------------------ ** - */ - { - if( CachePtr ) - { - (void)ubi_trInitTree( CachePtr, CompFunc, ubi_trOVERWRITE ); - CachePtr->free_func = FreeFunc; - CachePtr->max_entries = MaxEntries; - CachePtr->max_memory = MaxMemory; - CachePtr->mem_used = 0; - CachePtr->cache_hits = 0; - CachePtr->cache_trys = 0; - } - return( CachePtr ); - } /* ubi_cacheInit */ - -ubi_cacheRootPtr ubi_cacheClear( ubi_cacheRootPtr CachePtr ) - /* ------------------------------------------------------------------------ ** - * Remove and free all entries in an existing cache. - * - * Input: CachePtr - A pointer to the cache that is to be cleared. - * - * Output: A pointer to the cache header (i.e., the same as CachePtr). - * This function re-initializes the cache header. - * - * ------------------------------------------------------------------------ ** - */ - { - if( CachePtr ) - { - (void)ubi_trKillTree( CachePtr, CachePtr->free_func ); - CachePtr->mem_used = 0; - CachePtr->cache_hits = 0; - CachePtr->cache_trys = 0; - } - return( CachePtr ); - } /* ubi_cacheClear */ - -void ubi_cachePut( ubi_cacheRootPtr CachePtr, - unsigned long EntrySize, - ubi_cacheEntryPtr EntryPtr, - ubi_trItemPtr Key ) - /* ------------------------------------------------------------------------ ** - * Add an entry to the cache. - * - * Input: CachePtr - A pointer to the cache into which the entry - * will be added. - * EntrySize - The size, in bytes, of the memory block indicated - * by EntryPtr. This will be copied into the - * EntryPtr->entry_size field. - * EntryPtr - A pointer to a memory block that begins with a - * ubi_cacheEntry structure. The entry structure - * should be followed immediately by the data to be - * cached (even if that is a pointer to yet more data). - * Key - Pointer used to identify the lookup key within the - * Entry. - * - * Output: None. - * - * Notes: After adding the new node, the cache is "trimmed". This - * removes extra nodes if the tree has exceeded it's memory or - * entry count limits. It is unlikely that the newly added node - * will be purged from the cache (assuming a reasonably large - * cache), since new nodes in a splay tree (which is what this - * module was designed to use) are moved to the top of the tree - * and the cache purge process removes nodes from the bottom of - * the tree. - * - The underlying splay tree is opened in OVERWRITE mode. If - * the input key matches an existing key, the existing entry will - * be politely removed from the tree and freed. - * - Memory is allocated in multiples of the word size. The - * return value of the strlen() function does not reflect - * this; it will allways be less than or equal to the amount - * of memory actually allocated. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_trNodePtr OldNode; - - EntryPtr->entry_size = EntrySize; - CachePtr->mem_used += EntrySize; - (void)ubi_trInsert( CachePtr, EntryPtr, Key, &OldNode ); - if( OldNode ) - free_entry( CachePtr, (ubi_cacheEntryPtr)OldNode ); - - cachetrim( CachePtr ); - } /* ubi_cachePut */ - -ubi_cacheEntryPtr ubi_cacheGet( ubi_cacheRootPtr CachePtr, - ubi_trItemPtr FindMe ) - /* ------------------------------------------------------------------------ ** - * Attempt to retrieve an entry from the cache. - * - * Input: CachePtr - A ponter to the cache that is to be searched. - * FindMe - A ubi_trItemPtr that indicates the key for which - * to search. - * - * Output: A pointer to the cache entry that was found, or NULL if no - * matching entry was found. - * - * Notes: This function also updates the hit ratio counters. - * The counters are unsigned short. If the number of cache tries - * reaches 32768, then both the number of tries and the number of - * hits are divided by two. This prevents the counters from - * overflowing. See the comments in ubi_cacheHitRatio() for - * additional notes. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_trNodePtr FoundPtr; - - FoundPtr = ubi_trFind( CachePtr, FindMe ); - - if( FoundPtr ) - CachePtr->cache_hits++; - CachePtr->cache_trys++; - - if( CachePtr->cache_trys & 0x8000 ) - { - CachePtr->cache_hits = CachePtr->cache_hits / 2; - CachePtr->cache_trys = CachePtr->cache_trys / 2; - } - - return( (ubi_cacheEntryPtr)FoundPtr ); - } /* ubi_cacheGet */ - -ubi_trBool ubi_cacheDelete( ubi_cacheRootPtr CachePtr, ubi_trItemPtr DeleteMe ) - /* ------------------------------------------------------------------------ ** - * Find and delete the specified cache entry. - * - * Input: CachePtr - A pointer to the cache. - * DeleteMe - The key of the entry to be deleted. - * - * Output: TRUE if the entry was found & freed, else FALSE. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_trNodePtr FoundPtr; - - FoundPtr = ubi_trFind( CachePtr, DeleteMe ); - if( FoundPtr ) - { - (void)ubi_trRemove( CachePtr, FoundPtr ); - free_entry( CachePtr, (ubi_cacheEntryPtr)FoundPtr ); - return( ubi_trTRUE ); - } - return( ubi_trFALSE ); - } /* ubi_cacheDelete */ - -ubi_trBool ubi_cacheReduce( ubi_cacheRootPtr CachePtr, unsigned long count ) - /* ------------------------------------------------------------------------ ** - * Remove entries from the bottom of the cache. - * - * Input: CachePtr - A pointer to the cache which is to be reduced in - * size. - * count - The number of entries to remove. - * - * Output: The function will return TRUE if entries were removed, - * else FALSE. A return value of FALSE should indicate that - * there were less than entries in the cache, and that the - * cache is now empty. - * - * Notes: This function forces a reduction in the number of cache entries - * without requiring that the MaxMemory or MaxEntries values be - * changed. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_trNodePtr NodePtr; - - while( count ) - { - NodePtr = ubi_trLeafNode( CachePtr->root.root ); - if( NULL == NodePtr ) - return( ubi_trFALSE ); - else - { - (void)ubi_trRemove( CachePtr, NodePtr ); - free_entry( CachePtr, (ubi_cacheEntryPtr)NodePtr ); - } - count--; - } - return( ubi_trTRUE ); - } /* ubi_cacheReduce */ - -unsigned long ubi_cacheSetMaxEntries( ubi_cacheRootPtr CachePtr, - unsigned long NewSize ) - /* ------------------------------------------------------------------------ ** - * Change the maximum number of entries allowed to exist in the cache. - * - * Input: CachePtr - A pointer to the cache to be modified. - * NewSize - The new maximum number of cache entries. - * - * Output: The maximum number of entries previously allowed to exist in - * the cache. - * - * Notes: If the new size is less than the old size, this function will - * trim the cache (remove excess entries). - * - A value of zero indicates an unlimited number of entries. - * - * ------------------------------------------------------------------------ ** - */ - { - unsigned long oldsize = CachePtr->max_entries; /* Save the old value. */ - - CachePtr->max_entries = NewSize; /* Apply the new value. */ - if( (NewSize < oldsize) || (NewSize && !oldsize) ) /* If size is smaller, */ - cachetrim( CachePtr ); /* remove excess. */ - return( oldsize ); - } /* ubi_cacheSetMaxEntries */ - -unsigned long ubi_cacheSetMaxMemory( ubi_cacheRootPtr CachePtr, - unsigned long NewSize ) - /* ------------------------------------------------------------------------ ** - * Change the maximum amount of memory to be used for storing cache - * entries. - * - * Input: CachePtr - A pointer to the cache to be modified. - * NewSize - The new cache memory size. - * - * Output: The previous maximum memory size. - * - * Notes: If the new size is less than the old size, this function will - * trim the cache (remove excess entries). - * - A value of zero indicates that the cache has no memory limit. - * - * ------------------------------------------------------------------------ ** - */ - { - unsigned long oldsize = CachePtr->max_memory; /* Save the old value. */ - - CachePtr->max_memory = NewSize; /* Apply the new value. */ - if( (NewSize < oldsize) || (NewSize && !oldsize) ) /* If size is smaller, */ - cachetrim( CachePtr ); /* remove excess. */ - return( oldsize ); - } /* ubi_cacheSetMaxMemory */ - -int ubi_cacheHitRatio( ubi_cacheRootPtr CachePtr ) - /* ------------------------------------------------------------------------ ** - * Returns a value that is 10,000 times the slightly weighted average hit - * ratio for the cache. - * - * Input: CachePtr - Pointer to the cache to be queried. - * - * Output: An integer that is 10,000 times the number of successful - * cache hits divided by the number of cache lookups, or: - * (10000 * hits) / trys - * You can easily convert this to a float, or do something - * like this (where i is the return value of this function): - * - * printf( "Hit rate : %d.%02d%%\n", (i/100), (i%100) ); - * - * Notes: I say "slightly-weighted", because the numerator and - * denominator are both accumulated in locations of type - * 'unsigned short'. If the number of cache trys becomes - * large enough, both are divided by two. (See function - * ubi_cacheGet().) - * Dividing both numerator and denominator by two does not - * change the ratio (much...it is an integer divide), but it - * does mean that subsequent increments to either counter will - * have twice as much significance as previous ones. - * - * - The value returned by this function will be in the range - * [0..10000] because ( 0 <= cache_hits <= cache_trys ) will - * always be true. - * - * ------------------------------------------------------------------------ ** - */ - { - int tmp = 0; - - if( CachePtr->cache_trys ) - tmp = (int)( (10000 * (long)(CachePtr->cache_hits) ) - / (long)(CachePtr->cache_trys) ); - return( tmp ); - } /* ubi_cacheHitRatio */ - -/* -------------------------------------------------------------------------- */ diff --git a/source/ubiqx/ubi_Cache.h b/source/ubiqx/ubi_Cache.h deleted file mode 100644 index 0fc3a074f72..00000000000 --- a/source/ubiqx/ubi_Cache.h +++ /dev/null @@ -1,412 +0,0 @@ -#ifndef UBI_CACHE_H -#define UBI_CACHE_H -/* ========================================================================== ** - * ubi_Cache.h - * - * Copyright (C) 1997 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements a generic cache. - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * This module uses a splay tree to implement a simple cache. The cache - * module adds a thin layer of functionality to the splay tree. In - * particular: - * - * - The tree (cache) may be limited in size by the number of - * entries permitted or the amount of memory used. When either - * limit is exceeded cache entries are removed until the cache - * conforms. - * - Some statistical information is kept so that an approximate - * "hit ratio" can be calculated. - * - There are several functions available that provide access to - * and management of cache size limits, hit ratio, and tree - * trimming. - * - * The splay tree is used because recently accessed items tend toward the - * top of the tree and less recently accessed items tend toward the bottom. - * This makes it easy to purge less recently used items should the cache - * exceed its limits. - * - * To use this module, you will need to supply a comparison function of - * type ubi_trCompFunc and a node-freeing function of type - * ubi_trKillNodeRtn. See ubi_BinTree.h for more information on - * these. (This is all basic ubiqx tree management stuff.) - * - * Notes: - * - * - Cache performance will start to suffer dramatically if the - * cache becomes large enough to force the OS to start swapping - * memory to disk. This is because the nodes of the underlying tree - * will be scattered across memory in an order that is completely - * unrelated to their traversal order. As more and more of the - * cache is placed into swap space, more and more swaps will be - * required for a simple traversal (...and then there's the splay - * operation). - * - * In one simple test under Linux, the load and dump of a cache of - * 400,000 entries took only 1min, 40sec of real time. The same - * test with 450,000 records took 2 *hours* and eight minutes. - * - * - In an effort to save memory, I considered using an unsigned - * short to save the per-entry entry size. I would have tucked this - * value into some unused space in the tree node structure. On - * 32-bit word aligned systems this would have saved an additional - * four bytes per entry. I may revisit this issue, but for now I've - * decided against it. - * - * Using an unsigned short would limit the size of an entry to 64K - * bytes. That's probably more than enough for most applications. - * The key word in that last sentence, however, is "probably". I - * really dislike imposing such limits on things. - * - * - Each entry keeps track of the amount of memory it used and the - * cache header keeps the total. This information is provided via - * the EntrySize parameter in ubi_cachePut(), so it is up to you to - * make sure that the numbers are accurate. (The numbers don't even - * have to represent bytes used.) - * - * As you consider this, note that the strdup() function--as an - * example--will call malloc(). The latter generally allocates a - * multiple of the system word size, which may be more than the - * number of bytes needed to store the string. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_Cache.h,v - * Revision 0.4 1999/09/22 03:42:24 crh - * Fixed a minor typo. - * - * Revision 0.3 1998/06/03 18:00:15 crh - * Further fiddling with sys_include.h, which is no longer explicitly - * included by this module since it is inherited from ubi_BinTree.h. - * - * Revision 0.2 1998/06/02 01:36:18 crh - * Changed include name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.1 1998/05/20 04:36:02 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.0 1997/12/18 06:25:23 crh - * Initial Revision. - * - * ========================================================================== ** - */ - -#include "ubi_SplayTree.h" - -/* -------------------------------------------------------------------------- ** - * Typedefs... - * - * ubi_cacheRoot - Cache header structure, which consists of a binary - * tree root and other required housekeeping fields, as - * listed below. - * ubi_cacheRootPtr - Pointer to a Cache. - * - * ubi_cacheEntry - A cache Entry, which consists of a tree node - * structure and the size (in bytes) of the entry - * data. The entry size should be supplied via - * the EntrySize parameter of the ubi_cachePut() - * function. - * - * ubi_cacheEntryPtr - Pointer to a ubi_cacheEntry. - * - */ - -typedef struct - { - ubi_trRoot root; /* Splay tree control structure. */ - ubi_trKillNodeRtn free_func; /* Function used to free entries. */ - unsigned long max_entries; /* Max cache entries. 0 == unlimited */ - unsigned long max_memory; /* Max memory to use. 0 == unlimited */ - unsigned long mem_used; /* Memory currently in use (bytes). */ - unsigned short cache_hits; /* Incremented on succesful find. */ - unsigned short cache_trys; /* Incremented on cache lookup. */ - } ubi_cacheRoot; - -typedef ubi_cacheRoot *ubi_cacheRootPtr; - - -typedef struct - { - ubi_trNode node; /* Tree node structure. */ - unsigned long entry_size; /* Entry size. Used when managing - * caches with maximum memory limits. - */ - } ubi_cacheEntry; - -typedef ubi_cacheEntry *ubi_cacheEntryPtr; - - -/* -------------------------------------------------------------------------- ** - * Macros... - * - * ubi_cacheGetMaxEntries() - Report the current maximum number of entries - * allowed in the cache. Zero indicates no - * maximum. - * ubi_cacheGetMaxMemory() - Report the current maximum amount of memory - * that may be used in the cache. Zero - * indicates no maximum. - * ubi_cacheGetEntryCount() - Report the current number of entries in the - * cache. - * ubi_cacheGetMemUsed() - Report the amount of memory currently in use - * by the cache. - */ - -#define ubi_cacheGetMaxEntries( Cptr ) (((ubi_cacheRootPtr)(Cptr))->max_entries) -#define ubi_cacheGetMaxMemory( Cptr ) (((ubi_cacheRootPtr)(Cptr))->max_memory) - -#define ubi_cacheGetEntryCount( Cptr ) (((ubi_cacheRootPtr)(Cptr))->root.count) -#define ubi_cacheGetMemUsed( Cptr ) (((ubi_cacheRootPtr)(Cptr))->mem_used) - -/* -------------------------------------------------------------------------- ** - * Prototypes... - */ - -ubi_cacheRootPtr ubi_cacheInit( ubi_cacheRootPtr CachePtr, - ubi_trCompFunc CompFunc, - ubi_trKillNodeRtn FreeFunc, - unsigned long MaxEntries, - unsigned long MaxMemory ); - /* ------------------------------------------------------------------------ ** - * Initialize a cache header structure. - * - * Input: CachePtr - A pointer to a ubi_cacheRoot structure that is - * to be initialized. - * CompFunc - A pointer to the function that will be called - * to compare two cache values. See the module - * comments, above, for more information. - * FreeFunc - A pointer to a function that will be called - * to free a cache entry. If you allocated - * the cache entry using malloc(), then this - * will likely be free(). If you are allocating - * cache entries from a free list, then this will - * likely be a function that returns memory to the - * free list, etc. - * MaxEntries - The maximum number of entries that will be - * allowed to exist in the cache. If this limit - * is exceeded, then existing entries will be - * removed from the cache. A value of zero - * indicates that there is no limit on the number - * of cache entries. See ubi_cachePut(). - * MaxMemory - The maximum amount of memory, in bytes, to be - * allocated to the cache (excluding the cache - * header). If this is exceeded, existing entries - * in the cache will be removed until enough memory - * has been freed to meet the condition. See - * ubi_cachePut(). - * - * Output: A pointer to the initialized cache (i.e., the same as CachePtr). - * - * Notes: Both MaxEntries and MaxMemory may be changed after the cache - * has been created. See - * ubi_cacheSetMaxEntries() - * ubi_cacheSetMaxMemory() - * ubi_cacheGetMaxEntries() - * ubi_cacheGetMaxMemory() (the latter two are macros). - * - * - Memory is allocated in multiples of the word size. The - * return value of the strlen() function does not reflect - * this; it will allways be less than or equal to the amount - * of memory actually allocated. Keep this in mind when - * choosing a value for MaxMemory. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_cacheRootPtr ubi_cacheClear( ubi_cacheRootPtr CachePtr ); - /* ------------------------------------------------------------------------ ** - * Remove and free all entries in an existing cache. - * - * Input: CachePtr - A pointer to the cache that is to be cleared. - * - * Output: A pointer to the cache header (i.e., the same as CachePtr). - * This function re-initializes the cache header. - * - * ------------------------------------------------------------------------ ** - */ - -void ubi_cachePut( ubi_cacheRootPtr CachePtr, - unsigned long EntrySize, - ubi_cacheEntryPtr EntryPtr, - ubi_trItemPtr Key ); - /* ------------------------------------------------------------------------ ** - * Add an entry to the cache. - * - * Input: CachePtr - A pointer to the cache into which the entry - * will be added. - * EntrySize - The size, in bytes, of the memory block indicated - * by EntryPtr. This will be copied into the - * EntryPtr->entry_size field. - * EntryPtr - A pointer to a memory block that begins with a - * ubi_cacheEntry structure. The entry structure - * should be followed immediately by the data to be - * cached (even if that is a pointer to yet more data). - * Key - Pointer used to identify the lookup key within the - * Entry. - * - * Output: None. - * - * Notes: After adding the new node, the cache is "trimmed". This - * removes extra nodes if the tree has exceeded it's memory or - * entry count limits. It is unlikely that the newly added node - * will be purged from the cache (assuming a reasonably large - * cache), since new nodes in a splay tree (which is what this - * module was designed to use) are moved to the top of the tree - * and the cache purge process removes nodes from the bottom of - * the tree. - * - The underlying splay tree is opened in OVERWRITE mode. If - * the input key matches an existing key, the existing entry will - * be politely removed from the tree and freed. - * - Memory is allocated in multiples of the word size. The - * return value of the strlen() function does not reflect - * this; it will allways be less than or equal to the amount - * of memory actually allocated. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_cacheEntryPtr ubi_cacheGet( ubi_cacheRootPtr CachePtr, - ubi_trItemPtr FindMe ); - /* ------------------------------------------------------------------------ ** - * Attempt to retrieve an entry from the cache. - * - * Input: CachePtr - A ponter to the cache that is to be searched. - * FindMe - A ubi_trItemPtr that indicates the key for which - * to search. - * - * Output: A pointer to the cache entry that was found, or NULL if no - * matching entry was found. - * - * Notes: This function also updates the hit ratio counters. - * The counters are unsigned short. If the number of cache tries - * reaches 32768, then both the number of tries and the number of - * hits are divided by two. This prevents the counters from - * overflowing. See the comments in ubi_cacheHitRatio() for - * additional notes. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_trBool ubi_cacheDelete( ubi_cacheRootPtr CachePtr, ubi_trItemPtr DeleteMe ); - /* ------------------------------------------------------------------------ ** - * Find and delete the specified cache entry. - * - * Input: CachePtr - A pointer to the cache. - * DeleteMe - The key of the entry to be deleted. - * - * Output: TRUE if the entry was found & freed, else FALSE. - * - * ------------------------------------------------------------------------ ** - */ - -ubi_trBool ubi_cacheReduce( ubi_cacheRootPtr CachePtr, unsigned long count ); - /* ------------------------------------------------------------------------ ** - * Remove entries from the bottom of the cache. - * - * Input: CachePtr - A pointer to the cache which is to be reduced in - * size. - * count - The number of entries to remove. - * - * Output: The function will return TRUE if entries were removed, - * else FALSE. A return value of FALSE should indicate that - * there were less than entries in the cache, and that the - * cache is now empty. - * - * Notes: This function forces a reduction in the number of cache entries - * without requiring that the MaxMemory or MaxEntries values be - * changed. - * - * ------------------------------------------------------------------------ ** - */ - -unsigned long ubi_cacheSetMaxEntries( ubi_cacheRootPtr CachePtr, - unsigned long NewSize ); - /* ------------------------------------------------------------------------ ** - * Change the maximum number of entries allowed to exist in the cache. - * - * Input: CachePtr - A pointer to the cache to be modified. - * NewSize - The new maximum number of cache entries. - * - * Output: The maximum number of entries previously allowed to exist in - * the cache. - * - * Notes: If the new size is less than the old size, this function will - * trim the cache (remove excess entries). - * - A value of zero indicates an unlimited number of entries. - * - * ------------------------------------------------------------------------ ** - */ - -unsigned long ubi_cacheSetMaxMemory( ubi_cacheRootPtr CachePtr, - unsigned long NewSize ); - /* ------------------------------------------------------------------------ ** - * Change the maximum amount of memory to be used for storing cache - * entries. - * - * Input: CachePtr - A pointer to the cache to be modified. - * NewSize - The new cache memory size. - * - * Output: The previous maximum memory size. - * - * Notes: If the new size is less than the old size, this function will - * trim the cache (remove excess entries). - * - A value of zero indicates that the cache has no memory limit. - * - * ------------------------------------------------------------------------ ** - */ - -int ubi_cacheHitRatio( ubi_cacheRootPtr CachePtr ); - /* ------------------------------------------------------------------------ ** - * Returns a value that is 10,000 times the slightly weighted average hit - * ratio for the cache. - * - * Input: CachePtr - Pointer to the cache to be queried. - * - * Output: An integer that is 10,000 times the number of successful - * cache hits divided by the number of cache lookups, or: - * (10000 * hits) / trys - * You can easily convert this to a float, or do something - * like this (where i is the return value of this function): - * - * printf( "Hit rate : %d.%02d%%\n", (i/100), (i%100) ); - * - * Notes: I say "slightly-weighted", because the numerator and - * denominator are both accumulated in locations of type - * 'unsigned short'. If the number of cache trys becomes - * large enough, both are divided by two. (See function - * ubi_cacheGet().) - * Dividing both numerator and denominator by two does not - * change the ratio (much...it is an integer divide), but it - * does mean that subsequent increments to either counter will - * have twice as much significance as previous ones. - * - * - The value returned by this function will be in the range - * [0..10000] because ( 0 <= cache_hits <= cache_trys ) will - * always be true. - * - * ------------------------------------------------------------------------ ** - */ - -/* -------------------------------------------------------------------------- */ -#endif /* ubi_CACHE_H */ diff --git a/source/ubiqx/ubi_SplayTree.c b/source/ubiqx/ubi_SplayTree.c deleted file mode 100644 index 222506bd06b..00000000000 --- a/source/ubiqx/ubi_SplayTree.c +++ /dev/null @@ -1,512 +0,0 @@ -/* ========================================================================== ** - * ubi_SplayTree.c - * - * Copyright (C) 1993-1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements "splay" trees. Splay trees are binary trees - * that are rearranged (splayed) whenever a node is accessed. The - * splaying process *tends* to make the tree bushier (improves balance), - * and the nodes that are accessed most frequently *tend* to be closer to - * the top. - * - * References: "Self-Adjusting Binary Search Trees", by Daniel Sleator and - * Robert Tarjan. Journal of the Association for Computing - * Machinery Vol 32, No. 3, July 1985 pp. 652-686 - * - * See also: http://www.cs.cmu.edu/~sleator/ - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_SplayTree.c,v - * Revision 4.5 2000/01/08 23:26:49 crh - * Added ubi_trSplay() macro, which does a type cast for us. - * - * Revision 4.4 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 4.3 1998/06/03 17:45:05 crh - * Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is - * included by all of the binary tree files. - * - * Also fixed some warnings produced by lint on Irix 6.2, which doesn't seem - * to like syntax like this: - * - * if( (a = b) ) - * - * The fix was to change lines like the above to: - * - * if( 0 != (a=b) ) - * - * Which means the same thing. - * - * Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in - * ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping - * of tree types by simply changing a header. Unfortunately, the - * macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will - * conflict if used together. You must either choose a single tree - * type, or use the underlying function calls directly. Compare - * the two header files for more information. - * - * Revision 4.2 1998/06/02 01:29:14 crh - * Changed ubi_null.h to sys_include.h to make it more generic. - * - * Revision 4.1 1998/05/20 04:37:54 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 4.0 1998/03/10 03:41:33 crh - * Minor comment changes. The revision number is now 4.0 to match the - * BinTree and AVLtree modules. - * - * Revision 2.7 1998/01/24 06:37:08 crh - * Added a URL for more information. - * - * Revision 2.6 1997/12/23 04:01:12 crh - * In this version, all constants & macros defined in the header file have - * the ubi_tr prefix. Also cleaned up anything that gcc complained about - * when run with '-pedantic -fsyntax-only -Wall'. - * - * Revision 2.5 1997/07/26 04:15:42 crh - * + Cleaned up a few minor syntax annoyances that gcc discovered for me. - * + Changed ubi_TRUE and ubi_FALSE to ubi_trTRUE and ubi_trFALSE. - * - * Revision 2.4 1997/06/03 04:42:21 crh - * Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid causing - * problems. - * - * Revision 2.3 1995/10/03 22:19:07 CRH - * Ubisized! - * Also, added the function ubi_sptSplay(). - * - * Revision 2.1 95/03/09 23:54:42 CRH - * Added the ModuleID static string and function. These modules are now - * self-identifying. - * - * Revision 2.0 95/02/27 22:34:46 CRH - * This module was updated to match the interface changes made to the - * ubi_BinTree module. In particular, the interface to the Locate() function - * has changed. See ubi_BinTree for more information on changes and new - * functions. - * - * The revision number was also upped to match ubi_BinTree. - * - * Revision 1.1 93/10/18 20:35:16 CRH - * I removed the hard-coded logical device names from the include file - * specifications. CRH - * - * Revision 1.0 93/10/15 23:00:15 CRH - * With this revision, I have added a set of #define's that provide a single, - * standard API to all existing tree modules. Until now, each of the three - * existing modules had a different function and typedef prefix, as follows: - * - * Module Prefix - * ubi_BinTree ubi_bt - * ubi_AVLtree ubi_avl - * ubi_SplayTree ubi_spt - * - * To further complicate matters, only those portions of the base module - * (ubi_BinTree) that were superceeded in the new module had the new names. - * For example, if you were using ubi_SplayTree, the locate function was - * called "ubi_sptLocate", but the next and previous functions remained - * "ubi_btNext" and "ubi_btPrev". - * - * This was not too terrible if you were familiar with the modules and knew - * exactly which tree model you wanted to use. If you wanted to be able to - * change modules (for speed comparisons, etc), things could get messy very - * quickly. - * - * So, I have added a set of defined names that get redefined in any of the - * descendant modules. To use this standardized interface in your code, - * simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with - * "ubi_tr". The "ubi_tr" names will resolve to the correct function or - * datatype names for the module that you are using. Just remember to - * include the header for that module in your program file. Because these - * names are handled by the preprocessor, there is no added run-time - * overhead. - * - * Note that the original names do still exist, and can be used if you wish - * to write code directly to a specific module. This should probably only be - * done if you are planning to implement a new descendant type, such as - * red/black trees. CRH - * - * Revision 0.1 93/04/25 22:03:32 CRH - * Simply changed the #include reference the .c file to - * use instead. The latter is portable, the former is not. - * - * Revision 0.0 93/04/21 23:05:52 CRH - * Initial version, written by Christopher R. Hertel. - * This module implements Splay Trees using the ubi_BinTree module as a basis. - * - * ========================================================================== ** - */ - -#include "ubi_SplayTree.h" /* Header for THIS module. */ - -/* ========================================================================== ** - * Static data. - */ - -static char ModuleID[] = "ubi_SplayTree\n\ -\tRevision: 4.5 \n\ -\tDate: 2000/01/08 23:26:49 \n\ -\tAuthor: crh \n"; - - -/* ========================================================================== ** - * Private functions... - */ - -static void Rotate( ubi_btNodePtr p ) - /* ------------------------------------------------------------------------ ** - * This function performs a single rotation, moving node *p up one level - * in the tree. - * - * Input: p - a pointer to an ubi_btNode in a tree. - * - * Output: None. - * - * Notes: This implements a single rotation in either direction (left - * or right). This is the basic building block of all splay - * tree rotations. - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr parentp; - ubi_btNodePtr tmp; - char way; - char revway; - - parentp = p->Link[ubi_trPARENT]; /* Find parent. */ - - if( parentp ) /* If no parent, then we're already the root. */ - { - way = p->gender; - revway = ubi_trRevWay(way); - tmp = p->Link[(int)revway]; - - parentp->Link[(int)way] = tmp; - if( tmp ) - { - tmp->Link[ubi_trPARENT] = parentp; - tmp->gender = way; - } - - tmp = parentp->Link[ubi_trPARENT]; - p->Link[ubi_trPARENT] = tmp; - p->gender = parentp->gender; - if( tmp ) - tmp->Link[(int)(p->gender)] = p; - - parentp->Link[ubi_trPARENT] = p; - parentp->gender = revway; - p->Link[(int)revway] = parentp; - } - } /* Rotate */ - -static ubi_btNodePtr Splay( ubi_btNodePtr SplayWithMe ) - /* ------------------------------------------------------------------------ ** - * Move the node indicated by SplayWithMe to the root of the tree by - * splaying the tree. - * - * Input: SplayWithMe - A pointer to an ubi_btNode within a tree. - * - * Output: A pointer to the root of the splay tree (i.e., the same as - * SplayWithMe). - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr parent; - - while( NULL != (parent = SplayWithMe->Link[ubi_trPARENT]) ) - { - if( parent->gender == SplayWithMe->gender ) /* Zig-Zig */ - Rotate( parent ); - else - { - if( ubi_trEQUAL != parent->gender ) /* Zig-Zag */ - Rotate( SplayWithMe ); - } - Rotate( SplayWithMe ); /* Zig */ - } /* while */ - return( SplayWithMe ); - } /* Splay */ - -/* ========================================================================== ** - * Exported utilities. - */ - -ubi_trBool ubi_sptInsert( ubi_btRootPtr RootPtr, - ubi_btNodePtr NewNode, - ubi_btItemPtr ItemPtr, - ubi_btNodePtr *OldNode ) - /* ------------------------------------------------------------------------ ** - * This function uses a non-recursive algorithm to add a new element to the - * splay tree. - * - * Input: RootPtr - a pointer to the ubi_btRoot structure that indicates - * the root of the tree to which NewNode is to be added. - * NewNode - a pointer to an ubi_btNode structure that is NOT - * part of any tree. - * ItemPtr - A pointer to the sort key that is stored within - * *NewNode. ItemPtr MUST point to information stored - * in *NewNode or an EXACT DUPLICATE. The key data - * indicated by ItemPtr is used to place the new node - * into the tree. - * OldNode - a pointer to an ubi_btNodePtr. When searching - * the tree, a duplicate node may be found. If - * duplicates are allowed, then the new node will - * be simply placed into the tree. If duplicates - * are not allowed, however, then one of two things - * may happen. - * 1) if overwritting *is not* allowed, this - * function will return FALSE (indicating that - * the new node could not be inserted), and - * *OldNode will point to the duplicate that is - * still in the tree. - * 2) if overwritting *is* allowed, then this - * function will swap **OldNode for *NewNode. - * In this case, *OldNode will point to the node - * that was removed (thus allowing you to free - * the node). - * ** If you are using overwrite mode, ALWAYS ** - * ** check the return value of this parameter! ** - * Note: You may pass NULL in this parameter, the - * function knows how to cope. If you do this, - * however, there will be no way to return a - * pointer to an old (ie. replaced) node (which is - * a problem if you are using overwrite mode). - * - * Output: a boolean value indicating success or failure. The function - * will return FALSE if the node could not be added to the tree. - * Such failure will only occur if duplicates are not allowed, - * nodes cannot be overwritten, AND a duplicate key was found - * within the tree. - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr OtherP; - - if( !(OldNode) ) - OldNode = &OtherP; - - if( ubi_btInsert( RootPtr, NewNode, ItemPtr, OldNode ) ) - { - RootPtr->root = Splay( NewNode ); - return( ubi_trTRUE ); - } - - /* Splay the unreplacable, duplicate keyed, unique, old node. */ - RootPtr->root = Splay( (*OldNode) ); - return( ubi_trFALSE ); - } /* ubi_sptInsert */ - -ubi_btNodePtr ubi_sptRemove( ubi_btRootPtr RootPtr, ubi_btNodePtr DeadNode ) - /* ------------------------------------------------------------------------ ** - * This function removes the indicated node from the tree. - * - * Input: RootPtr - A pointer to the header of the tree that contains - * the node to be removed. - * DeadNode - A pointer to the node that will be removed. - * - * Output: This function returns a pointer to the node that was removed - * from the tree (ie. the same as DeadNode). - * - * Note: The node MUST be in the tree indicated by RootPtr. If not, - * strange and evil things will happen to your trees. - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p; - - (void)Splay( DeadNode ); /* Move dead node to root. */ - if( NULL != (p = DeadNode->Link[ubi_trLEFT]) ) - { /* If left subtree exists... */ - ubi_btNodePtr q = DeadNode->Link[ubi_trRIGHT]; - - p->Link[ubi_trPARENT] = NULL; /* Left subtree node becomes root.*/ - p->gender = ubi_trPARENT; - p = ubi_btLast( p ); /* Find rightmost left node... */ - p->Link[ubi_trRIGHT] = q; /* ...attach right tree. */ - if( q ) - q->Link[ubi_trPARENT] = p; - RootPtr->root = Splay( p ); /* Resplay at p. */ - } - else - { - if( NULL != (p = DeadNode->Link[ubi_trRIGHT]) ) - { /* No left, but right subtree exists... */ - p->Link[ubi_trPARENT] = NULL; /* Right subtree root becomes... */ - p->gender = ubi_trPARENT; /* ...overall tree root. */ - RootPtr->root = p; - } - else - RootPtr->root = NULL; /* No subtrees => empty tree. */ - } - - (RootPtr->count)--; /* Decrement node count. */ - return( DeadNode ); /* Return pointer to pruned node. */ - } /* ubi_sptRemove */ - -ubi_btNodePtr ubi_sptLocate( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe, - ubi_trCompOps CompOp ) - /* ------------------------------------------------------------------------ ** - * The purpose of ubi_btLocate() is to find a node or set of nodes given - * a target value and a "comparison operator". The Locate() function is - * more flexible and (in the case of trees that may contain dupicate keys) - * more precise than the ubi_btFind() function. The latter is faster, - * but it only searches for exact matches and, if the tree contains - * duplicates, Find() may return a pointer to any one of the duplicate- - * keyed records. - * - * Input: - * RootPtr - A pointer to the header of the tree to be searched. - * FindMe - An ubi_btItemPtr that indicates the key for which to - * search. - * CompOp - One of the following: - * CompOp Return a pointer to the node with - * ------ --------------------------------- - * ubi_trLT - the last key value that is less - * than FindMe. - * ubi_trLE - the first key matching FindMe, or - * the last key that is less than - * FindMe. - * ubi_trEQ - the first key matching FindMe. - * ubi_trGE - the first key matching FindMe, or the - * first key greater than FindMe. - * ubi_trGT - the first key greater than FindMe. - * Output: - * A pointer to the node matching the criteria listed above under - * CompOp, or NULL if no node matched the criteria. - * - * Notes: - * In the case of trees with duplicate keys, Locate() will behave as - * follows: - * - * Find: 3 Find: 3 - * Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6 - * ^ ^ ^ ^ ^ - * LT EQ GT LE GE - * - * That is, when returning a pointer to a node with a key that is LESS - * THAN the target key (FindMe), Locate() will return a pointer to the - * LAST matching node. - * When returning a pointer to a node with a key that is GREATER - * THAN the target key (FindMe), Locate() will return a pointer to the - * FIRST matching node. - * - * See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf(). - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p; - - p = ubi_btLocate( RootPtr, FindMe, CompOp ); - if( p ) - RootPtr->root = Splay( p ); - return( p ); - } /* ubi_sptLocate */ - -ubi_btNodePtr ubi_sptFind( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe ) - /* ------------------------------------------------------------------------ ** - * This function performs a non-recursive search of a tree for any node - * matching a specific key. - * - * Input: - * RootPtr - a pointer to the header of the tree to be searched. - * FindMe - a pointer to the key value for which to search. - * - * Output: - * A pointer to a node with a key that matches the key indicated by - * FindMe, or NULL if no such node was found. - * - * Note: In a tree that allows duplicates, the pointer returned *might - * not* point to the (sequentially) first occurance of the - * desired key. In such a tree, it may be more useful to use - * ubi_sptLocate(). - * ------------------------------------------------------------------------ ** - */ - { - ubi_btNodePtr p; - - p = ubi_btFind( RootPtr, FindMe ); - if( p ) - RootPtr->root = Splay( p ); - return( p ); - } /* ubi_sptFind */ - -void ubi_sptSplay( ubi_btRootPtr RootPtr, - ubi_btNodePtr SplayMe ) - /* ------------------------------------------------------------------------ ** - * This function allows you to splay the tree at a given node, thus moving - * the node to the top of the tree. - * - * Input: - * RootPtr - a pointer to the header of the tree to be splayed. - * SplayMe - a pointer to a node within the tree. This will become - * the new root node. - * Output: None. - * - * Notes: This is an uncharacteristic function for this group of modules - * in that it provides access to the internal balancing routines, - * which would normally be hidden. - * Splaying the tree will not damage it (assuming that I've done - * *my* job), but there is overhead involved. I don't recommend - * that you use this function unless you understand the underlying - * Splay Tree principles involved. - * ------------------------------------------------------------------------ ** - */ - { - RootPtr->root = Splay( SplayMe ); - } /* ubi_sptSplay */ - -int ubi_sptModuleID( int size, char *list[] ) - /* ------------------------------------------------------------------------ ** - * Returns a set of strings that identify the module. - * - * Input: size - The number of elements in the array . - * list - An array of pointers of type (char *). This array - * should, initially, be empty. This function will fill - * in the array with pointers to strings. - * Output: The number of elements of that were used. If this value - * is less than , the values of the remaining elements are - * not guaranteed. - * - * Notes: Please keep in mind that the pointers returned indicate strings - * stored in static memory. Don't free() them, don't write over - * them, etc. Just read them. - * ------------------------------------------------------------------------ ** - */ - { - if( size > 0 ) - { - list[0] = ModuleID; - if( size > 1 ) - return( 1 + ubi_btModuleID( --size, &(list[1]) ) ); - return( 1 ); - } - return( 0 ); - } /* ubi_sptModuleID */ - -/* ================================ The End ================================= */ - diff --git a/source/ubiqx/ubi_SplayTree.h b/source/ubiqx/ubi_SplayTree.h deleted file mode 100644 index e4fac796a91..00000000000 --- a/source/ubiqx/ubi_SplayTree.h +++ /dev/null @@ -1,377 +0,0 @@ -#ifndef UBI_SPLAYTREE_H -#define UBI_SPLAYTREE_H -/* ========================================================================== ** - * ubi_SplayTree.h - * - * Copyright (C) 1993-1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * - * This module implements "splay" trees. Splay trees are binary trees - * that are rearranged (splayed) whenever a node is accessed. The - * splaying process *tends* to make the tree bushier (improves balance), - * and the nodes that are accessed most frequently *tend* to be closer to - * the top. - * - * References: "Self-Adjusting Binary Search Trees", by Daniel Sleator and - * Robert Tarjan. Journal of the Association for Computing - * Machinery Vol 32, No. 3, July 1985 pp. 652-686 - * - * See also: http://www.cs.cmu.edu/~sleator/ - * - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_SplayTree.h,v - * Revision 4.5 2000/01/08 23:26:49 crh - * Added ubi_trSplay() macro, which does a type cast for us. - * - * Revision 4.4 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 4.3 1998/06/03 17:45:05 crh - * Further fiddling with sys_include.h. It's now in ubi_BinTree.h which is - * included by all of the binary tree files. - * - * Also fixed some warnings produced by lint on Irix 6.2, which doesn't seem - * to like syntax like this: - * - * if( (a = b) ) - * - * The fix was to change lines like the above to: - * - * if( 0 != (a=b) ) - * - * Which means the same thing. - * - * Reminder: Some of the ubi_tr* macros in ubi_BinTree.h are redefined in - * ubi_AVLtree.h and ubi_SplayTree.h. This allows easy swapping - * of tree types by simply changing a header. Unfortunately, the - * macro redefinitions in ubi_AVLtree.h and ubi_SplayTree.h will - * conflict if used together. You must either choose a single tree - * type, or use the underlying function calls directly. Compare - * the two header files for more information. - * - * Revision 4.2 1998/06/02 01:29:14 crh - * Changed ubi_null.h to sys_include.h to make it more generic. - * - * Revision 4.1 1998/05/20 04:37:54 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 4.0 1998/03/10 03:40:57 crh - * Minor comment changes. The revision number is now 4.0 to match the - * BinTree and AVLtree modules. - * - * Revision 2.7 1998/01/24 06:37:57 crh - * Added a URL for more information. - * - * Revision 2.6 1997/12/23 04:02:20 crh - * In this version, all constants & macros defined in the header file have - * the ubi_tr prefix. Also cleaned up anything that gcc complained about - * when run with '-pedantic -fsyntax-only -Wall'. - * - * Revision 2.5 1997/07/26 04:15:46 crh - * + Cleaned up a few minor syntax annoyances that gcc discovered for me. - * + Changed ubi_TRUE and ubi_FALSE to ubi_trTRUE and ubi_trFALSE. - * - * Revision 2.4 1997/06/03 05:22:56 crh - * Changed TRUE and FALSE to ubi_TRUE and ubi_FALSE to avoid causing - * problems. - * - * Revision 2.3 1995/10/03 22:19:37 CRH - * Ubisized! - * Also, added the function ubi_sptSplay(). - * - * Revision 2.1 95/03/09 23:55:04 CRH - * Added the ModuleID static string and function. These modules are now - * self-identifying. - * - * Revision 2.0 95/02/27 22:34:55 CRH - * This module was updated to match the interface changes made to the - * ubi_BinTree module. In particular, the interface to the Locate() function - * has changed. See ubi_BinTree for more information on changes and new - * functions. - * - * The revision number was also upped to match ubi_BinTree. - * - * - * Revision 1.0 93/10/15 22:59:36 CRH - * With this revision, I have added a set of #define's that provide a single, - * standard API to all existing tree modules. Until now, each of the three - * existing modules had a different function and typedef prefix, as follows: - * - * Module Prefix - * ubi_BinTree ubi_bt - * ubi_AVLtree ubi_avl - * ubi_SplayTree ubi_spt - * - * To further complicate matters, only those portions of the base module - * (ubi_BinTree) that were superceeded in the new module had the new names. - * For example, if you were using ubi_SplayTree, the locate function was - * called "ubi_sptLocate", but the next and previous functions remained - * "ubi_btNext" and "ubi_btPrev". - * - * This was not too terrible if you were familiar with the modules and knew - * exactly which tree model you wanted to use. If you wanted to be able to - * change modules (for speed comparisons, etc), things could get messy very - * quickly. - * - * So, I have added a set of defined names that get redefined in any of the - * descendant modules. To use this standardized interface in your code, - * simply replace all occurances of "ubi_bt", "ubi_avl", and "ubi_spt" with - * "ubi_tr". The "ubi_tr" names will resolve to the correct function or - * datatype names for the module that you are using. Just remember to - * include the header for that module in your program file. Because these - * names are handled by the preprocessor, there is no added run-time - * overhead. - * - * Note that the original names do still exist, and can be used if you wish - * to write code directly to a specific module. This should probably only be - * done if you are planning to implement a new descendant type, such as - * red/black trees. CRH - * - * Revision 0.0 93/04/21 23:07:13 CRH - * Initial version, written by Christopher R. Hertel. - * This module implements Splay Trees using the ubi_BinTree module as a basis. - * - * ========================================================================== ** - */ - -#include "ubi_BinTree.h" /* Base binary tree functions, types, etc. */ - -/* ========================================================================== ** - * Function prototypes... - */ - -ubi_trBool ubi_sptInsert( ubi_btRootPtr RootPtr, - ubi_btNodePtr NewNode, - ubi_btItemPtr ItemPtr, - ubi_btNodePtr *OldNode ); - /* ------------------------------------------------------------------------ ** - * This function uses a non-recursive algorithm to add a new element to the - * splay tree. - * - * Input: RootPtr - a pointer to the ubi_btRoot structure that indicates - * the root of the tree to which NewNode is to be added. - * NewNode - a pointer to an ubi_btNode structure that is NOT - * part of any tree. - * ItemPtr - A pointer to the sort key that is stored within - * *NewNode. ItemPtr MUST point to information stored - * in *NewNode or an EXACT DUPLICATE. The key data - * indicated by ItemPtr is used to place the new node - * into the tree. - * OldNode - a pointer to an ubi_btNodePtr. When searching - * the tree, a duplicate node may be found. If - * duplicates are allowed, then the new node will - * be simply placed into the tree. If duplicates - * are not allowed, however, then one of two things - * may happen. - * 1) if overwritting *is not* allowed, this - * function will return FALSE (indicating that - * the new node could not be inserted), and - * *OldNode will point to the duplicate that is - * still in the tree. - * 2) if overwritting *is* allowed, then this - * function will swap **OldNode for *NewNode. - * In this case, *OldNode will point to the node - * that was removed (thus allowing you to free - * the node). - * ** If you are using overwrite mode, ALWAYS ** - * ** check the return value of this parameter! ** - * Note: You may pass NULL in this parameter, the - * function knows how to cope. If you do this, - * however, there will be no way to return a - * pointer to an old (ie. replaced) node (which is - * a problem if you are using overwrite mode). - * - * Output: a boolean value indicating success or failure. The function - * will return FALSE if the node could not be added to the tree. - * Such failure will only occur if duplicates are not allowed, - * nodes cannot be overwritten, AND a duplicate key was found - * within the tree. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_sptRemove( ubi_btRootPtr RootPtr, ubi_btNodePtr DeadNode ); - /* ------------------------------------------------------------------------ ** - * This function removes the indicated node from the tree. - * - * Input: RootPtr - A pointer to the header of the tree that contains - * the node to be removed. - * DeadNode - A pointer to the node that will be removed. - * - * Output: This function returns a pointer to the node that was removed - * from the tree (ie. the same as DeadNode). - * - * Note: The node MUST be in the tree indicated by RootPtr. If not, - * strange and evil things will happen to your trees. - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_sptLocate( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe, - ubi_trCompOps CompOp ); - /* ------------------------------------------------------------------------ ** - * The purpose of ubi_btLocate() is to find a node or set of nodes given - * a target value and a "comparison operator". The Locate() function is - * more flexible and (in the case of trees that may contain dupicate keys) - * more precise than the ubi_btFind() function. The latter is faster, - * but it only searches for exact matches and, if the tree contains - * duplicates, Find() may return a pointer to any one of the duplicate- - * keyed records. - * - * Input: - * RootPtr - A pointer to the header of the tree to be searched. - * FindMe - An ubi_btItemPtr that indicates the key for which to - * search. - * CompOp - One of the following: - * CompOp Return a pointer to the node with - * ------ --------------------------------- - * ubi_trLT - the last key value that is less - * than FindMe. - * ubi_trLE - the first key matching FindMe, or - * the last key that is less than - * FindMe. - * ubi_trEQ - the first key matching FindMe. - * ubi_trGE - the first key matching FindMe, or the - * first key greater than FindMe. - * ubi_trGT - the first key greater than FindMe. - * Output: - * A pointer to the node matching the criteria listed above under - * CompOp, or NULL if no node matched the criteria. - * - * Notes: - * In the case of trees with duplicate keys, Locate() will behave as - * follows: - * - * Find: 3 Find: 3 - * Keys: 1 2 2 2 3 3 3 3 3 4 4 Keys: 1 1 2 2 2 4 4 5 5 5 6 - * ^ ^ ^ ^ ^ - * LT EQ GT LE GE - * - * That is, when returning a pointer to a node with a key that is LESS - * THAN the target key (FindMe), Locate() will return a pointer to the - * LAST matching node. - * When returning a pointer to a node with a key that is GREATER - * THAN the target key (FindMe), Locate() will return a pointer to the - * FIRST matching node. - * - * See Also: ubi_btFind(), ubi_btFirstOf(), ubi_btLastOf(). - * ------------------------------------------------------------------------ ** - */ - -ubi_btNodePtr ubi_sptFind( ubi_btRootPtr RootPtr, - ubi_btItemPtr FindMe ); - /* ------------------------------------------------------------------------ ** - * This function performs a non-recursive search of a tree for any node - * matching a specific key. - * - * Input: - * RootPtr - a pointer to the header of the tree to be searched. - * FindMe - a pointer to the key value for which to search. - * - * Output: - * A pointer to a node with a key that matches the key indicated by - * FindMe, or NULL if no such node was found. - * - * Note: In a tree that allows duplicates, the pointer returned *might - * not* point to the (sequentially) first occurance of the - * desired key. In such a tree, it may be more useful to use - * ubi_sptLocate(). - * ------------------------------------------------------------------------ ** - */ - -void ubi_sptSplay( ubi_btRootPtr RootPtr, - ubi_btNodePtr SplayMe ); - /* ------------------------------------------------------------------------ ** - * This function allows you to splay the tree at a given node, thus moving - * the node to the top of the tree. - * - * Input: - * RootPtr - a pointer to the header of the tree to be splayed. - * SplayMe - a pointer to a node within the tree. This will become - * the new root node. - * Output: None. - * - * Notes: This is an uncharacteristic function for this group of modules - * in that it provides access to the internal balancing routines, - * which would normally be hidden. - * Splaying the tree will not damage it (assuming that I've done - * *my* job), but there is overhead involved. I don't recommend - * that you use this function unless you understand the underlying - * Splay Tree principles involved. - * ------------------------------------------------------------------------ ** - */ - -int ubi_sptModuleID( int size, char *list[] ); - /* ------------------------------------------------------------------------ ** - * Returns a set of strings that identify the module. - * - * Input: size - The number of elements in the array . - * list - An array of pointers of type (char *). This array - * should, initially, be empty. This function will fill - * in the array with pointers to strings. - * Output: The number of elements of that were used. If this value - * is less than , the values of the remaining elements are - * not guaranteed. - * - * Notes: Please keep in mind that the pointers returned indicate strings - * stored in static memory. Don't free() them, don't write over - * them, etc. Just read them. - * ------------------------------------------------------------------------ ** - */ - -/* -------------------------------------------------------------------------- ** - * Masquarade... - * - * This set of defines allows you to write programs that will use any of the - * implemented binary tree modules (currently BinTree, AVLtree, and SplayTree). - * Instead of using ubi_bt..., use ubi_tr..., and select the tree type by - * including the appropriate module header. - */ - -#undef ubi_trInsert -#undef ubi_trRemove -#undef ubi_trLocate -#undef ubi_trFind -#undef ubi_trModuleID - -#define ubi_trInsert( Rp, Nn, Ip, On ) \ - ubi_sptInsert( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Nn), \ - (ubi_btItemPtr)(Ip), (ubi_btNodePtr *)(On) ) - -#define ubi_trRemove( Rp, Dn ) \ - ubi_sptRemove( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Dn) ) - -#define ubi_trLocate( Rp, Ip, Op ) \ - ubi_sptLocate( (ubi_btRootPtr)(Rp), \ - (ubi_btItemPtr)(Ip), \ - (ubi_trCompOps)(Op) ) - -#define ubi_trFind( Rp, Ip ) \ - ubi_sptFind( (ubi_btRootPtr)(Rp), (ubi_btItemPtr)(Ip) ) - -#define ubi_trSplay( Rp, Sm ) \ - ubi_sptSplay( (ubi_btRootPtr)(Rp), (ubi_btNodePtr)(Sm) ) - -#define ubi_trModuleID( s, l ) ubi_sptModuleID( s, l ) - -/* ================================ The End ================================= */ -#endif /* UBI_SPLAYTREE_H */ diff --git a/source/ubiqx/ubi_dLinkList.c b/source/ubiqx/ubi_dLinkList.c deleted file mode 100644 index eb95033c695..00000000000 --- a/source/ubiqx/ubi_dLinkList.c +++ /dev/null @@ -1,171 +0,0 @@ -/* ========================================================================== ** - * ubi_dLinkList.c - * - * Copyright (C) 1997, 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * This module implements simple doubly-linked lists. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_dLinkList.c,v - * Revision 0.11 1999/06/19 16:58:06 crh - * Renamed the ubi_slRemove() function in ubi_sLinkList to - * ubi_slRemoveNext(). I was bothered by the fact that it didn't - * match the functionality of the ubi_dlRemove() function in - * ubi_dLinkList. The new name is more 'correct'. - * - * Revision 0.10 1998/07/24 07:30:20 crh - * Added the ubi_dlNewList() macro. - * - * Revision 0.9 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 0.8 1998/06/03 18:06:03 crh - * Further fiddling with sys_include.h, which has been moved from the .c file - * to the .h file. - * - * Revision 0.7 1998/06/02 01:38:47 crh - * Changed include file name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.6 1998/05/20 04:38:05 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.5 1998/03/10 02:55:00 crh - * Simplified the code and added macros for stack & queue manipulations. - * - * Revision 0.4 1998/01/03 01:53:56 crh - * Added ubi_dlCount() macro. - * - * Revision 0.3 1997/10/15 03:05:39 crh - * Added some handy type casting to the macros. Added AddHere and RemThis - * macros. - * - * Revision 0.2 1997/10/08 03:07:21 crh - * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead() - * macro, which was passing the wrong value for to Insert(). - * - * Revision 0.1 1997/10/07 04:34:07 crh - * Initial Revision. - * - * -------------------------------------------------------------------------- ** - * This module is similar to the ubi_sLinkList module, but it is neither a - * descendant type nor an easy drop-in replacement for the latter. One key - * difference is that the ubi_dlRemove() function removes the indicated node, - * while the ubi_slRemoveNext() function (in ubi_sLinkList) removes the node - * *following* the indicated node. - * - * ========================================================================== ** - */ - -#include "ubi_dLinkList.h" /* Header for *this* module. */ - -/* ========================================================================== ** - * Functions... - */ - -ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr ) - /* ------------------------------------------------------------------------ ** - * Initialize a doubly-linked list header. - * - * Input: ListPtr - A pointer to the list structure that is to be - * initialized for use. - * - * Output: A pointer to the initialized list header (i.e., same as - * ). - * - * ------------------------------------------------------------------------ ** - */ - { - ListPtr->Head = NULL; - ListPtr->Tail = NULL; - ListPtr->count = 0; - return( ListPtr ); - } /* ubi_dlInitList */ - -ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr, - ubi_dlNodePtr New, - ubi_dlNodePtr After ) - /* ------------------------------------------------------------------------ ** - * Insert a new node into the list. - * - * Input: ListPtr - A pointer to the list into which the node is to - * be inserted. - * New - Pointer to the new node. - * After - NULL, or a pointer to a node that is already in the - * list. - * If NULL, then will be added at the head of the - * list, else it will be added following . - * - * Output: A pointer to the node that was inserted into the list (i.e., - * the same as ). - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_dlNodePtr PredNode = After ? After : (ubi_dlNodePtr)ListPtr; - - New->Next = PredNode->Next; - New->Prev = After; - PredNode->Next = New; - if( New->Next ) - New->Next->Prev = New; - else - ListPtr->Tail = New; - - (ListPtr->count)++; - - return( New ); - } /* ubi_dlInsert */ - -ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old ) - /* ------------------------------------------------------------------------ ** - * Remove a node from the list. - * - * Input: ListPtr - A pointer to the list from which is to be - * removed. - * Old - A pointer to the node that is to be removed from the - * list. - * - * Output: A pointer to the node that was removed (i.e., ). - * - * ------------------------------------------------------------------------ ** - */ - { - if( Old ) - { - if( Old->Next ) - Old->Next->Prev = Old->Prev; - else - ListPtr->Tail = Old->Prev; - - if( Old->Prev ) - Old->Prev->Next = Old->Next; - else - ListPtr->Head = Old->Next; - - (ListPtr->count)--; - } - - return( Old ); - } /* ubi_dlRemove */ - -/* ================================ The End ================================= */ diff --git a/source/ubiqx/ubi_dLinkList.h b/source/ubiqx/ubi_dLinkList.h deleted file mode 100644 index 682e566ee67..00000000000 --- a/source/ubiqx/ubi_dLinkList.h +++ /dev/null @@ -1,242 +0,0 @@ -#ifndef UBI_DLINKLIST_H -#define UBI_DLINKLIST_H -/* ========================================================================== ** - * ubi_dLinkList.h - * - * Copyright (C) 1997, 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * This module implements simple doubly-linked lists. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_dLinkList.h,v - * Revision 0.11 1999/06/19 16:58:06 crh - * Renamed the ubi_slRemove() function in ubi_sLinkList to - * ubi_slRemoveNext(). I was bothered by the fact that it didn't - * match the functionality of the ubi_dlRemove() function in - * ubi_dLinkList. The new name is more 'correct'. - * - * Revision 0.10 1998/07/24 07:30:20 crh - * Added the ubi_dlNewList() macro. - * - * Revision 0.9 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 0.8 1998/06/03 18:06:03 crh - * Further fiddling with sys_include.h, which has been moved from the .c file - * to the .h file. - * - * Revision 0.7 1998/06/02 01:38:47 crh - * Changed include file name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.6 1998/05/20 04:38:05 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.5 1998/03/10 02:54:04 crh - * Simplified the code and added macros for stack & queue manipulations. - * - * Revision 0.4 1998/01/03 01:53:44 crh - * Added ubi_dlCount() macro. - * - * Revision 0.3 1997/10/15 03:04:31 crh - * Added some handy type casting to the macros. Added AddHere and RemThis - * macros. - * - * Revision 0.2 1997/10/08 03:08:16 crh - * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead() - * macro, which was passing the wrong value for to Insert(). - * - * Revision 0.1 1997/10/07 04:34:38 crh - * Initial Revision. - * - * -------------------------------------------------------------------------- ** - * This module is similar to the ubi_sLinkList module, but it is neither a - * descendant type nor an easy drop-in replacement for the latter. One key - * difference is that the ubi_dlRemove() function removes the indicated node, - * while the ubi_slRemoveNext() function (in ubi_sLinkList) removes the node - * *following* the indicated node. - * - * ========================================================================== ** - */ - -#include "sys_include.h" /* System-specific includes. */ - -/* ========================================================================== ** - * Typedefs... - * - * ubi_dlNode - This is the basic node structure. - * ubi_dlNodePtr - Pointer to a node. - * ubi_dlList - This is the list header structure. - * ubi_dlListPtr - Pointer to a List (i.e., a list header structure). - * - */ - -typedef struct ubi_dlListNode - { - struct ubi_dlListNode *Next; - struct ubi_dlListNode *Prev; - } ubi_dlNode; - -typedef ubi_dlNode *ubi_dlNodePtr; - -typedef struct - { - ubi_dlNodePtr Head; - ubi_dlNodePtr Tail; - unsigned long count; - } ubi_dlList; - -typedef ubi_dlList *ubi_dlListPtr; - -/* ========================================================================== ** - * Macros... - * - * ubi_dlNewList - Macro used to declare and initialize a new list in one - * swell foop. It is used when defining a variable of - * type ubi_dlList. The definition - * static ubi_dlNewList( gerbil ); - * is translated to - * static ubi_dlList gerbil[1] = {{ NULL, NULL, 0 }}; - * - * ubi_dlCount - Return the number of entries currently in the list. - * - * ubi_dlAddHead - Add a new node at the head of the list. - * ubi_dlAddNext - Add a node following the given node. - * ubi_dlAddTail - Add a new node at the tail of the list. - * Note: AddTail evaluates the L parameter twice. - * - * ubi_dlRemHead - Remove the node at the head of the list, if any. - * Note: RemHead evaluates the L parameter twice. - * ubi_dlRemThis - Remove the indicated node. - * ubi_dlRemTail - Remove the node at the tail of the list, if any. - * Note: RemTail evaluates the L parameter twice. - * - * ubi_dlFirst - Return a pointer to the first node in the list, if any. - * ubi_dlLast - Return a pointer to the last node in the list, if any. - * ubi_dlNext - Given a node, return a pointer to the next node. - * ubi_dlPrev - Given a node, return a pointer to the previous node. - * - * ubi_dlPush - Add a node at the head of the list (synonym of AddHead). - * ubi_dlPop - Remove a node at the head of the list (synonym of RemHead). - * ubi_dlEnqueue - Add a node at the tail of the list (sysnonym of AddTail). - * ubi_dlDequeue - Remove a node at the head of the list (synonym of RemHead). - * - * Note that all of these provide type casting of the parameters. The - * Add and Rem macros are nothing more than nice front-ends to the - * Insert and Remove operations. - * - * Also note that the First, Next and Last macros do no parameter checking! - * - */ - -#define ubi_dlNewList( L ) ubi_dlList (L)[1] = {{ NULL, NULL, 0 }} - -#define ubi_dlCount( L ) (((ubi_dlListPtr)(L))->count) - -#define ubi_dlAddHead( L, N ) \ - ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL ) - -#define ubi_dlAddNext( L, N, A ) \ - ubi_dlInsert( (ubi_dlListPtr)(L), \ - (ubi_dlNodePtr)(N), \ - (ubi_dlNodePtr)(A) ) - -#define ubi_dlAddTail( L, N ) \ - ubi_dlInsert( (ubi_dlListPtr)(L), \ - (ubi_dlNodePtr)(N), \ - (((ubi_dlListPtr)(L))->Tail) ) - -#define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \ - (((ubi_dlListPtr)(L))->Head) ) - -#define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \ - (ubi_dlNodePtr)(N) ) - -#define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \ - (((ubi_dlListPtr)(L))->Tail) ) - -#define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head) - -#define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail) - -#define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next) - -#define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev) - -#define ubi_dlPush ubi_dlAddHead -#define ubi_dlPop ubi_dlRemHead -#define ubi_dlEnqueue ubi_dlAddTail -#define ubi_dlDequeue ubi_dlRemHead - -/* ========================================================================== ** - * Function prototypes... - */ - -ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr ); - /* ------------------------------------------------------------------------ ** - * Initialize a doubly-linked list header. - * - * Input: ListPtr - A pointer to the list structure that is to be - * initialized for use. - * - * Output: A pointer to the initialized list header (i.e., same as - * ). - * - * ------------------------------------------------------------------------ ** - */ - -ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr, - ubi_dlNodePtr New, - ubi_dlNodePtr After ); - /* ------------------------------------------------------------------------ ** - * Insert a new node into the list. - * - * Input: ListPtr - A pointer to the list into which the node is to - * be inserted. - * New - Pointer to the new node. - * After - NULL, or a pointer to a node that is already in the - * list. - * If NULL, then will be added at the head of the - * list, else it will be added following . - * - * Output: A pointer to the node that was inserted into the list (i.e., - * the same as ). - * - * ------------------------------------------------------------------------ ** - */ - -ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old ); - /* ------------------------------------------------------------------------ ** - * Remove a node from the list. - * - * Input: ListPtr - A pointer to the list from which is to be - * removed. - * Old - A pointer to the node that is to be removed from the - * list. - * - * Output: A pointer to the node that was removed (i.e., ). - * - * ------------------------------------------------------------------------ ** - */ - -/* ================================ The End ================================= */ -#endif /* UBI_DLINKLIST_H */ diff --git a/source/ubiqx/ubi_sLinkList.c b/source/ubiqx/ubi_sLinkList.c deleted file mode 100644 index ff75931b470..00000000000 --- a/source/ubiqx/ubi_sLinkList.c +++ /dev/null @@ -1,187 +0,0 @@ -/* ========================================================================== ** - * ubi_sLinkList.c - * - * Copyright (C) 1997, 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * This module implements a simple singly-linked list. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_sLinkList.c,v - * Revision 0.10 1999/06/19 16:58:06 crh - * Renamed the ubi_slRemove() function in ubi_sLinkList to - * ubi_slRemoveNext(). I was bothered by the fact that it didn't - * match the functionality of the ubi_dlRemove() function in - * ubi_dLinkList. The new name is more 'correct'. - * - * Revision 0.9 1998/07/24 07:30:20 crh - * Added the ubi_slNewList() macro. - * - * Revision 0.8 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 0.7 1998/06/03 18:06:03 crh - * Further fiddling with sys_include.h, which has been moved from the .c file - * to the .h file. - * - * Revision 0.6 1998/06/02 01:38:47 crh - * Changed include file name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.5 1998/05/20 04:38:05 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.4 1998/03/10 02:23:20 crh - * Combined ubi_StackQueue and ubi_sLinkList into one module. Redesigned - * the functions and macros. Not a complete rewrite but close to it. - * - * Revision 0.3 1998/01/03 01:59:52 crh - * Added ubi_slCount() macro. - * - * Revision 0.2 1997/10/21 03:35:18 crh - * Added parameter in function Insert(). Made necessary changes - * to macro AddHead() and added macro AddHere(). - * - * Revision 0.1 1997/10/16 02:53:45 crh - * Initial Revision. - * - * -------------------------------------------------------------------------- ** - * This module implements a singly-linked list which may also be used as a - * queue or a stack. For a queue, entries are added at the tail and removed - * from the head of the list. For a stack, the entries are entered and - * removed from the head of the list. A traversal of the list will always - * start at the head of the list and proceed toward the tail. This is all - * mind-numbingly simple, but I'm surprised by the number of programs out - * there which re-implement this a dozen or so times. - * - * Note: When the list header is initialized, the Tail pointer is set to - * point to the Head pointer. This simplifies things a great deal, - * except that you can't initialize a stack or queue by simply - * zeroing it out. One sure way to initialize the header is to call - * ubi_slInit(). Another option would be something like this: - * - * ubi_slNewList( MyList ); - * - * Which translates to: - * - * ubi_slList MyList[1] = { NULL, (ubi_slNodePtr)MyList, 0 }; - * - * See ubi_slInit(), ubi_slNewList(), and the ubi_slList structure - * for more info. - * - * + Also, note that this module is similar to the ubi_dLinkList - * module. There are three key differences: - * - This is a singly-linked list, the other is a doubly-linked - * list. - * - In this module, if the list is empty, the tail pointer will - * point back to the head of the list as described above. This - * is not done in ubi_dLinkList. - * - The ubi_slRemoveNext() function, by necessity, removes the - * 'next' node. In ubi_dLinkList, the ubi_dlRemove() function - * removes the 'current' node. - * - * ========================================================================== ** - */ - -#include "ubi_sLinkList.h" /* Header for *this* module. */ - -/* ========================================================================== ** - * Functions... - */ - -ubi_slListPtr ubi_slInitList( ubi_slListPtr ListPtr ) - /* ------------------------------------------------------------------------ ** - * Initialize a singly-linked list header. - * - * Input: ListPtr - A pointer to the list structure that is to be - * initialized for use. - * - * Output: A pointer to the initialized list header (i.e., same as - * ). - * - * ------------------------------------------------------------------------ ** - */ - { - ListPtr->Head = NULL; - ListPtr->Tail = (ubi_slNodePtr)ListPtr; - ListPtr->count = 0; - return( ListPtr ); - } /* ubi_slInitList */ - -ubi_slNodePtr ubi_slInsert( ubi_slListPtr ListPtr, - ubi_slNodePtr New, - ubi_slNodePtr After ) - /* ------------------------------------------------------------------------ ** - * Add a node to the list. - * - * Input: ListPtr - A pointer to the list into which the node is to - * be inserted. - * New - Pointer to the node that is to be added to the list. - * After - Pointer to a list in a node after which the new node - * will be inserted. If NULL, then the new node will - * be added at the head of the list. - * - * Output: A pointer to the node that was inserted into the list (i.e., - * the same as ). - * - * ------------------------------------------------------------------------ ** - */ - { - After = After ? After : (ubi_slNodePtr)ListPtr; - New->Next = After->Next; - After->Next = New; - if( !(New->Next) ) - ListPtr->Tail = New; - (ListPtr->count)++; - return( New ); - } /* ubi_slInsert */ - -ubi_slNodePtr ubi_slRemoveNext( ubi_slListPtr ListPtr, ubi_slNodePtr AfterMe ) - /* ------------------------------------------------------------------------ ** - * Remove the node followng . If is NULL, remove from - * the head of the list. - * - * Input: ListPtr - A pointer to the list from which the node is to be - * removed. - * AfterMe - Pointer to the node preceeding the node to be - * removed. - * - * Output: A pointer to the node that was removed, or NULL if the list is - * empty. - * - * ------------------------------------------------------------------------ ** - */ - { - ubi_slNodePtr DelNode; - - AfterMe = AfterMe ? AfterMe : (ubi_slNodePtr)ListPtr; - DelNode = AfterMe->Next; - if( DelNode ) - { - if( !(DelNode->Next) ) - ListPtr->Tail = AfterMe; - AfterMe->Next = DelNode->Next; - (ListPtr->count)--; - } - return( DelNode ); - } /* ubi_slRemoveNext */ - -/* ================================ The End ================================= */ diff --git a/source/ubiqx/ubi_sLinkList.h b/source/ubiqx/ubi_sLinkList.h deleted file mode 100644 index 53bfa400671..00000000000 --- a/source/ubiqx/ubi_sLinkList.h +++ /dev/null @@ -1,254 +0,0 @@ -#ifndef UBI_SLINKLIST_H -#define UBI_SLINKLIST_H -/* ========================================================================== ** - * ubi_sLinkList.h - * - * Copyright (C) 1997, 1998 by Christopher R. Hertel - * - * Email: crh@ubiqx.mn.org - * -------------------------------------------------------------------------- ** - * This module implements a simple singly-linked list. - * -------------------------------------------------------------------------- ** - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------------- ** - * - * Log: ubi_sLinkList.h,v - * Revision 0.10 1999/06/19 16:58:06 crh - * Renamed the ubi_slRemove() function in ubi_sLinkList to - * ubi_slRemoveNext(). I was bothered by the fact that it didn't - * match the functionality of the ubi_dlRemove() function in - * ubi_dLinkList. The new name is more 'correct'. - * - * Revision 0.9 1998/07/24 07:30:20 crh - * Added the ubi_slNewList() macro. - * - * Revision 0.8 1998/06/04 21:29:27 crh - * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files. - * This is more "standard", and is what people expect. Weird, eh? - * - * Revision 0.7 1998/06/03 18:06:03 crh - * Further fiddling with sys_include.h, which has been moved from the .c file - * to the .h file. - * - * Revision 0.6 1998/06/02 01:38:47 crh - * Changed include file name from ubi_null.h to sys_include.h to make it - * more generic. - * - * Revision 0.5 1998/05/20 04:38:05 crh - * The C file now includes ubi_null.h. See ubi_null.h for more info. - * - * Revision 0.4 1998/03/10 02:22:39 crh - * Combined ubi_StackQueue and ubi_sLinkList into one module. Redesigned - * the functions and macros. Not a complete rewrite but close to it. - * - * Revision 0.3 1998/01/03 02:00:02 crh - * Added ubi_slCount() macro. - * - * Revision 0.2 1997/10/21 03:36:14 crh - * Added parameter in function Insert(). Made necessary changes - * to macro AddHead() and added macro AddHere(). - * - * Revision 0.1 1997/10/16 02:54:08 crh - * Initial Revision. - * - * -------------------------------------------------------------------------- ** - * This module implements a singly-linked list which may also be used as a - * queue or a stack. For a queue, entries are added at the tail and removed - * from the head of the list. For a stack, the entries are entered and - * removed from the head of the list. A traversal of the list will always - * start at the head of the list and proceed toward the tail. This is all - * mind-numbingly simple, but I'm surprised by the number of programs out - * there which re-implement this a dozen or so times. - * - * Note: When the list header is initialized, the Tail pointer is set to - * point to the Head pointer. This simplifies things a great deal, - * except that you can't initialize a stack or queue by simply - * zeroing it out. One sure way to initialize the header is to call - * ubi_slInit(). Another option would be something like this: - * - * ubi_slNewList( MyList ); - * - * Which translates to: - * - * ubi_slList MyList[1] = { NULL, (ubi_slNodePtr)MyList, 0 }; - * - * See ubi_slInit(), ubi_slNewList(), and the ubi_slList structure - * for more info. - * - * + Also, note that this module is similar to the ubi_dLinkList - * module. There are three key differences: - * - This is a singly-linked list, the other is a doubly-linked - * list. - * - In this module, if the list is empty, the tail pointer will - * point back to the head of the list as described above. This - * is not done in ubi_dLinkList. - * - The ubi_slRemoveNext() function, by necessity, removes the - * 'next' node. In ubi_dLinkList, the ubi_dlRemove() function - * removes the 'current' node. - * - * ========================================================================== ** - */ - -#include "sys_include.h" /* System-specific includes. */ - -/* ========================================================================== ** - * Typedefs... - * - * ubi_slNode - This is the basic node structure. - * ubi_slNodePtr - Pointer to a node. - * ubi_slList - This is the list header structure. - * ubi_slListPtr - Pointer to a List (i.e., a list header structure). - * - */ - -typedef struct ubi_slListNode - { - struct ubi_slListNode *Next; - } ubi_slNode; - -typedef ubi_slNode *ubi_slNodePtr; - -typedef struct - { - ubi_slNodePtr Head; - ubi_slNodePtr Tail; - unsigned long count; - } ubi_slList; - -typedef ubi_slList *ubi_slListPtr; - - -/* ========================================================================== ** - * Macros... - * - * ubi_slNewList - Macro used to declare and initialize a list header in - * one step. - * - * ubi_slCount - Returns the current number of entries in the list. - * - * ubi_slAddHead - Add a new node at the head of the list. - * ubi_slAddNext - Add a new node following the indicated node. - * ubi_slAddTail - Add a new node to the tail of the list. - * Note: AddTail evaluates the L parameter twice. - * - * ubi_slRemHead - Remove the node at the head of the list, if any. - * ubi_slRemNext - Remove the node following the given node. - * - * ubi_slFirst - Return a pointer to the first node in the list, if any. - * ubi_slNext - Given a node, return a pointer to the next node. - * ubi_slLast - Return a pointer to the last node in the list, if any. - * - * ubi_slPush - Add a node at the head of the list (synonym of AddHead). - * ubi_slPop - Remove a node at the head of the list (synonym of RemHead). - * ubi_slEnqueue - Add a node at the tail of the list (sysnonym of AddTail). - * ubi_slDequeue - Remove a node at the head of the list (synonym of RemHead). - * - * Note that all of these provide type casting of the parameters. The - * Add and Rem macros are nothing more than nice front-ends to the - * Insert and Remove functions. - * - * Also note that the First, Next and Last macros do no parameter checking! - * - */ - -#define ubi_slNewList( L ) ubi_slList (L)[1] = {{ NULL, (ubi_slNodePtr)(L), 0 }} - -#define ubi_slCount( L ) (((ubi_slListPtr)(L))->count) - -#define ubi_slAddHead( L, N ) \ - ubi_slInsert( (ubi_slListPtr)(L), (ubi_slNodePtr)(N), NULL ) - -#define ubi_slAddNext( L, N, A ) \ - ubi_slInsert( (ubi_slListPtr)(L), \ - (ubi_slNodePtr)(N), \ - (ubi_slNodePtr)(A) ) - -#define ubi_slAddTail( L, N ) \ - ubi_slInsert( (ubi_slListPtr)(L), \ - (ubi_slNodePtr)(N), \ - ((ubi_slListPtr)(L))->Tail ) - -#define ubi_slRemHead( L ) ubi_slRemoveNext( (ubi_slListPtr)(L), NULL ) - -#define ubi_slRemNext( L, N ) \ - ubi_slRemoveNext( (ubi_slListPtr)(L), (ubi_slNodePtr)(N) ) - -#define ubi_slFirst( L ) (((ubi_slListPtr)(L))->Head) - -#define ubi_slNext( N ) (((ubi_slNodePtr)(N))->Next) - -#define ubi_slLast( L ) (((ubi_slListPtr)(L))->Tail) - -#define ubi_slPush ubi_slAddHead -#define ubi_slPop ubi_slRemHead -#define ubi_slEnqueue ubi_slAddTail -#define ubi_slDequeue ubi_slRemHead - -/* ========================================================================== ** - * Function prototypes... - */ - -ubi_slListPtr ubi_slInitList( ubi_slListPtr ListPtr ); - /* ------------------------------------------------------------------------ ** - * Initialize a singly-linked list header. - * - * Input: ListPtr - A pointer to the list structure that is to be - * initialized for use. - * - * Output: A pointer to the initialized list header (i.e., same as - * ). - * - * ------------------------------------------------------------------------ ** - */ - -ubi_slNodePtr ubi_slInsert( ubi_slListPtr ListPtr, - ubi_slNodePtr New, - ubi_slNodePtr After ); - /* ------------------------------------------------------------------------ ** - * Add a node to the list. - * - * Input: ListPtr - A pointer to the list into which the node is to - * be inserted. - * New - Pointer to the node that is to be added to the list. - * After - Pointer to a list in a node after which the new node - * will be inserted. If NULL, then the new node will - * be added at the head of the list. - * - * Output: A pointer to the node that was inserted into the list (i.e., - * the same as ). - * - * ------------------------------------------------------------------------ ** - */ - -ubi_slNodePtr ubi_slRemoveNext( ubi_slListPtr ListPtr, ubi_slNodePtr AfterMe ); - /* ------------------------------------------------------------------------ ** - * Remove the node followng . If is NULL, remove from - * the head of the list. - * - * Input: ListPtr - A pointer to the list from which the node is to be - * removed. - * AfterMe - Pointer to the node preceeding the node to be - * removed. - * - * Output: A pointer to the node that was removed, or NULL if the list is - * empty. - * - * ------------------------------------------------------------------------ ** - */ - -/* ================================ The End ================================= */ -#endif /* UBI_SLINKLIST_H */ -- cgit From 1668195642c0d91321f1c6f0ab2de75fc90e7752 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Dec 2005 23:31:33 +0000 Subject: r12111: Fix the "everything" build by re-adding debug2html. Oops. Jeremy. --- source/Makefile.in | 4 +- source/include/debugparse.h | 127 ++++++++++++++++++ source/utils/debugparse.c | 308 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 437 insertions(+), 2 deletions(-) create mode 100644 source/include/debugparse.h create mode 100644 source/utils/debugparse.c diff --git a/source/Makefile.in b/source/Makefile.in index bb3f72847b1..092d11bc80f 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -106,7 +106,7 @@ LIBSMBSHAREMODES=bin/libsmbsharemodes.a @LIBSMBSHAREMODES_SHARED@ LIBSMBSHAREMODES_MAJOR=0 LIBSMBSHAREMODES_MINOR=1 -FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ +FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ FLAGS2 = FLAGS3 = FLAGS4 = @@ -641,7 +641,7 @@ RPCTORTURE_OBJ = torture/rpctorture.o \ $(PARAM_OBJ) $(LIBSMB_OBJ) $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) \ $(RPC_CLIENT_OBJ) $(RPC_PARSE_OBJ) $(PASSDB_GET_SET_OBJ) -DEBUG2HTML_OBJ = utils/debug2html.o ubiqx/debugparse.o +DEBUG2HTML_OBJ = utils/debug2html.o utils/debugparse.o SMBFILTER_OBJ = utils/smbfilter.o $(PARAM_OBJ) $(LIBSMB_OBJ) $(SECRETS_OBJ) \ $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) diff --git a/source/include/debugparse.h b/source/include/debugparse.h new file mode 100644 index 00000000000..fb7f00f7792 --- /dev/null +++ b/source/include/debugparse.h @@ -0,0 +1,127 @@ +#ifndef DEBUGPARSE_H +#define DEBUGPARSE_H +/* ========================================================================== ** + * debugparse.c + * + * Copyright (C) 1998 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * -------------------------------------------------------------------------- ** + * This module is a very simple parser for Samba debug log files. + * -------------------------------------------------------------------------- ** + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * -------------------------------------------------------------------------- ** + * The important function in this module is dbg_char2token(). The rest is + * basically fluff. (Potentially useful fluff, but still fluff.) + * ========================================================================== ** + */ + +#include "includes.h" + +/* This module compiles quite nicely outside of the Samba environment. + * You'll need the following headers: +#include +#include +#include + */ + +/* -------------------------------------------------------------------------- ** + * These are the tokens returned by dbg_char2token(). + */ + +typedef enum + { + dbg_null = 0, + dbg_ignore, + dbg_header, + dbg_timestamp, + dbg_level, + dbg_sourcefile, + dbg_function, + dbg_lineno, + dbg_message, + dbg_eof + } dbg_Token; + +/* -------------------------------------------------------------------------- ** + * Function prototypes... + */ + + const char *dbg_token2string( dbg_Token tok ); + /* ------------------------------------------------------------------------ ** + * Given a token, return a string describing the token. + * + * Input: tok - One of the set of dbg_Tokens defined in debugparse.h. + * + * Output: A string identifying the token. This is useful for debugging, + * etc. + * + * Note: If the token is not known, this function will return the + * string "". + * + * ------------------------------------------------------------------------ ** + */ + + dbg_Token dbg_char2token( dbg_Token *state, int c ); + /* ------------------------------------------------------------------------ ** + * Parse input one character at a time. + * + * Input: state - A pointer to a token variable. This is used to + * maintain the parser state between calls. For + * each input stream, you should set up a separate + * state variable and initialize it to dbg_null. + * Pass a pointer to it into this function with each + * character in the input stream. See dbg_test() + * for an example. + * c - The "current" character in the input stream. + * + * Output: A token. + * The token value will change when delimiters are found, + * which indicate a transition between syntactical objects. + * Possible return values are: + * + * dbg_null - The input character was an end-of-line. + * This resets the parser to its initial state + * in preparation for parsing the next line. + * dbg_eof - Same as dbg_null, except that the character + * was an end-of-file. + * dbg_ignore - Returned for whitespace and delimiters. + * These lexical tokens are only of interest + * to the parser. + * dbg_header - Indicates the start of a header line. The + * input character was '[' and was the first on + * the line. + * dbg_timestamp - Indicates that the input character was part + * of a header timestamp. + * dbg_level - Indicates that the input character was part + * of the debug-level value in the header. + * dbg_sourcefile - Indicates that the input character was part + * of the sourcefile name in the header. + * dbg_function - Indicates that the input character was part + * of the function name in the header. + * dbg_lineno - Indicates that the input character was part + * of the DEBUG call line number in the header. + * dbg_message - Indicates that the input character was part + * of the DEBUG message text. + * + * ------------------------------------------------------------------------ ** + */ + + +/* -------------------------------------------------------------------------- */ +#endif /* DEBUGPARSE_H */ diff --git a/source/utils/debugparse.c b/source/utils/debugparse.c new file mode 100644 index 00000000000..c5fe3e2ee85 --- /dev/null +++ b/source/utils/debugparse.c @@ -0,0 +1,308 @@ +/* ========================================================================== ** + * debugparse.c + * + * Copyright (C) 1998 by Christopher R. Hertel + * + * Email: crh@ubiqx.mn.org + * + * -------------------------------------------------------------------------- ** + * This module is a very simple parser for Samba debug log files. + * -------------------------------------------------------------------------- ** + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * -------------------------------------------------------------------------- ** + * The important function in this module is dbg_char2token(). The rest is + * basically fluff. (Potentially useful fluff, but still fluff.) + * ========================================================================== ** + */ + +#include "debugparse.h" + +/* -------------------------------------------------------------------------- ** + * Constants... + * + * DBG_BSIZE - This internal constant is used only by dbg_test(). It is the + * size of the read buffer. I've tested the function using a + * DBG_BSIZE value of 2. + */ + +#define DBG_BSIZE 128 + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +const char *dbg_token2string( dbg_Token tok ) + /* ------------------------------------------------------------------------ ** + * Given a token, return a string describing the token. + * + * Input: tok - One of the set of dbg_Tokens defined in debugparse.h. + * + * Output: A string identifying the token. This is useful for debugging, + * etc. + * + * Note: If the token is not known, this function will return the + * string "". + * + * ------------------------------------------------------------------------ ** + */ + { + switch( tok ) + { + case dbg_null: + return( "null" ); + case dbg_ignore: + return( "ignore" ); + case dbg_header: + return( "header" ); + case dbg_timestamp: + return( "time stamp" ); + case dbg_level: + return( "level" ); + case dbg_sourcefile: + return( "source file" ); + case dbg_function: + return( "function" ); + case dbg_lineno: + return( "line number" ); + case dbg_message: + return( "message" ); + case dbg_eof: + return( "[EOF]" ); + } + return( "" ); + } /* dbg_token2string */ + +dbg_Token dbg_char2token( dbg_Token *state, int c ) + /* ------------------------------------------------------------------------ ** + * Parse input one character at a time. + * + * Input: state - A pointer to a token variable. This is used to + * maintain the parser state between calls. For + * each input stream, you should set up a separate + * state variable and initialize it to dbg_null. + * Pass a pointer to it into this function with each + * character in the input stream. See dbg_test() + * for an example. + * c - The "current" character in the input stream. + * + * Output: A token. + * The token value will change when delimiters are found, + * which indicate a transition between syntactical objects. + * Possible return values are: + * + * dbg_null - The input character was an end-of-line. + * This resets the parser to its initial state + * in preparation for parsing the next line. + * dbg_eof - Same as dbg_null, except that the character + * was an end-of-file. + * dbg_ignore - Returned for whitespace and delimiters. + * These lexical tokens are only of interest + * to the parser. + * dbg_header - Indicates the start of a header line. The + * input character was '[' and was the first on + * the line. + * dbg_timestamp - Indicates that the input character was part + * of a header timestamp. + * dbg_level - Indicates that the input character was part + * of the debug-level value in the header. + * dbg_sourcefile - Indicates that the input character was part + * of the sourcefile name in the header. + * dbg_function - Indicates that the input character was part + * of the function name in the header. + * dbg_lineno - Indicates that the input character was part + * of the DEBUG call line number in the header. + * dbg_message - Indicates that the input character was part + * of the DEBUG message text. + * + * ------------------------------------------------------------------------ ** + */ + { + /* The terminating characters that we see will greatly depend upon + * how they are read. For example, if gets() is used instead of + * fgets(), then we will not see newline characters. A lot also + * depends on the calling function, which may handle terminators + * itself. + * + * '\n', '\0', and EOF are all considered line terminators. The + * dbg_eof token is sent back if an EOF is encountered. + * + * Warning: only allow the '\0' character to be sent if you are + * using gets() to read whole lines (thus replacing '\n' + * with '\0'). Sending '\0' at the wrong time will mess + * up the parsing. + */ + switch( c ) + { + case EOF: + *state = dbg_null; /* Set state to null (initial state) so */ + return( dbg_eof ); /* that we can restart with new input. */ + case '\n': + case '\0': + *state = dbg_null; /* A newline or eoln resets to the null state. */ + return( dbg_null ); + } + + /* When within the body of the message, only a line terminator + * can cause a change of state. We've already checked for line + * terminators, so if the current state is dbg_msgtxt, simply + * return that as our current token. + */ + if( dbg_message == *state ) + return( dbg_message ); + + /* If we are at the start of a new line, and the input character + * is an opening bracket, then the line is a header line, otherwise + * it's a message body line. + */ + if( dbg_null == *state ) + { + if( '[' == c ) + { + *state = dbg_timestamp; + return( dbg_header ); + } + *state = dbg_message; + return( dbg_message ); + } + + /* We've taken care of terminators, text blocks and new lines. + * The remaining possibilities are all within the header line + * itself. + */ + + /* Within the header line, whitespace can be ignored *except* + * within the timestamp. + */ + if( isspace( c ) ) + { + /* Fudge. The timestamp may contain space characters. */ + if( (' ' == c) && (dbg_timestamp == *state) ) + return( dbg_timestamp ); + /* Otherwise, ignore whitespace. */ + return( dbg_ignore ); + } + + /* Okay, at this point we know we're somewhere in the header. + * Valid header *states* are: dbg_timestamp, dbg_level, + * dbg_sourcefile, dbg_function, and dbg_lineno. + */ + switch( c ) + { + case ',': + if( dbg_timestamp == *state ) + { + *state = dbg_level; + return( dbg_ignore ); + } + break; + case ']': + if( dbg_level == *state ) + { + *state = dbg_sourcefile; + return( dbg_ignore ); + } + break; + case ':': + if( dbg_sourcefile == *state ) + { + *state = dbg_function; + return( dbg_ignore ); + } + break; + case '(': + if( dbg_function == *state ) + { + *state = dbg_lineno; + return( dbg_ignore ); + } + break; + case ')': + if( dbg_lineno == *state ) + { + *state = dbg_null; + return( dbg_ignore ); + } + break; + } + + /* If the previous block did not result in a state change, then + * return the current state as the current token. + */ + return( *state ); + } /* dbg_char2token */ + +void dbg_test( void ) + /* ------------------------------------------------------------------------ ** + * Simple test function. + * + * Input: none. + * Output: none. + * Notes: This function was used to test dbg_char2token(). It reads a + * Samba log file from stdin and prints parsing info to stdout. + * It also serves as a simple example. + * + * ------------------------------------------------------------------------ ** + */ + { + char bufr[DBG_BSIZE]; + int i; + int linecount = 1; + dbg_Token old = dbg_null, + newtok= dbg_null, + state = dbg_null; + + while( fgets( bufr, DBG_BSIZE, stdin ) ) + { + for( i = 0; bufr[i]; i++ ) + { + old = newtok; + newtok = dbg_char2token( &state, bufr[i] ); + switch( newtok ) + { + case dbg_header: + if( linecount > 1 ) + (void)putchar( '\n' ); + break; + case dbg_null: + linecount++; + break; + case dbg_ignore: + break; + default: + if( old != newtok ) + (void)printf( "\n[%05d]%12s: ", linecount, dbg_token2string(newtok) ); + (void)putchar( bufr[i] ); + } + } + } + (void)putchar( '\n' ); + } /* dbg_test */ + + +/* -------------------------------------------------------------------------- ** + * This simple main line can be uncommented and used to test the parser. + */ + +/* + * int main( void ) + * { + * dbg_test(); + * return( 0 ); + * } + */ + +/* ========================================================================== */ -- cgit From f582b07d31f939d3dcd49c40f2496c8a280b0f13 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 8 Dec 2005 03:41:19 +0000 Subject: r12118: r10805@cabra: derrell | 2005-12-07 22:34:55 -0500 first go at supporting long file names. seeems to work; requires more testing --- source/libsmb/libsmbclient.c | 113 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 101 insertions(+), 12 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index e6906eb79ab..28e8ab4d345 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -855,8 +855,10 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, return NULL; } - if(pol) { - pipe_hnd = cli_rpc_pipe_open_noauth(ipc_cli, PI_LSARPC, &nt_status); + if (pol) { + pipe_hnd = cli_rpc_pipe_open_noauth(ipc_cli, + PI_LSARPC, + &nt_status); if (!pipe_hnd) { DEBUG(1, ("cli_nt_session_open fail!\n")); errno = ENOTSUP; @@ -864,14 +866,18 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, return NULL; } - /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED, - but NT sends 0x2000000 so we might as well do it too. */ + /* + * Some systems don't support + * SEC_RIGHTS_MAXIMUM_ALLOWED, but NT sends 0x2000000 + * so we might as well do it too. + */ - nt_status = rpccli_lsa_open_policy(pipe_hnd, - ipc_cli->mem_ctx, - True, - GENERIC_EXECUTE_ACCESS, - pol); + nt_status = rpccli_lsa_open_policy( + pipe_hnd, + ipc_cli->mem_ctx, + True, + GENERIC_EXECUTE_ACCESS, + pol); if (!NT_STATUS_IS_OK(nt_status)) { errno = smbc_errno(context, ipc_cli); @@ -2236,6 +2242,83 @@ dir_list_fn(const char *mnt, file_info *finfo, const char *mask, void *state) } +static int +net_share_enum_rpc(struct cli_state *cli, + void (*fn)(const char *name, + uint32 type, + const char *comment, + void *state), + void *state) +{ + int i; + WERROR result; + NTSTATUS nt_status; + ENUM_HND enum_hnd; + uint32 info_level = 1; + uint32 preferred_len = 0xffffffff; + SRV_SHARE_INFO_CTR ctr; + fstring name = ""; + fstring comment = ""; + void *mem_ctx; + struct rpc_pipe_client *pipe_hnd; + + /* Open the server service pipe */ + pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &nt_status); + if (!pipe_hnd) { + DEBUG(1, ("net_share_enum_rpc pipe open fail!\n")); + return -1; + } + + /* Allocate a context for parsing and for the entries in "ctr" */ + mem_ctx = talloc_init("libsmbclient: net_share_enum_rpc"); + if (mem_ctx == NULL) { + DEBUG(0, ("out of memory for net_share_enum_rpc!\n")); + return -1; + } + + /* Issue the NetShareEnum RPC call and retrieve the response */ + init_enum_hnd(&enum_hnd, 0); + result = rpccli_srvsvc_net_share_enum(pipe_hnd, + mem_ctx, + info_level, + &ctr, + preferred_len, + &enum_hnd); + + /* Was it successful? */ + if (!W_ERROR_IS_OK(result) || ctr.num_entries == 0) { + /* Nope. Go clean up. */ + goto done; + } + + /* For each returned entry... */ + for (i = 0; i < ctr.num_entries; i++) { + + /* pull out the share name */ + rpcstr_pull_unistr2_fstring( + name, &ctr.share.info1[i].info_1_str.uni_netname); + + /* pull out the share's comment */ + rpcstr_pull_unistr2_fstring( + comment, &ctr.share.info1[i].info_1_str.uni_remark); + + /* Add this share to the list */ + (*fn)(name, SMBC_FILE_SHARE, comment, state); + } + + /* We're done with the pipe */ + cli_rpc_pipe_close(pipe_hnd); + +done: + /* Free all memory which was allocated for this request */ + talloc_free(mem_ctx); + + /* Tell 'em if it worked */ + return W_ERROR_IS_OK(result) ? 0 : -1; +} + + + static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) { fstring server, share, user, password, options; @@ -2499,9 +2582,15 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) /* Now, list the servers ... */ - if (cli_RNetShareEnum(&srv->cli, list_fn, - (void *)dir) < 0) { - + if (net_share_enum_rpc( + &srv->cli, + list_fn, + (void *) dir) < 0 && + cli_RNetShareEnum( + &srv->cli, + list_fn, + (void *)dir) < 0) { + errno = cli_errno(&srv->cli); if (dir) { SAFE_FREE(dir->fname); -- cgit From 338999c51bfcd4f5eda974101a5f0f910c66f0bb Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 8 Dec 2005 03:44:40 +0000 Subject: r12119: r10812@cabra: derrell | 2005-12-07 22:44:26 -0500 sync to repository didn't work correctly...??? --- source/libsmb/libsmbclient.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 28e8ab4d345..32282cb6a64 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -2476,11 +2476,6 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) SV_TYPE_DOMAIN_ENUM, list_unique_wg_fn, (void *)dir)) { - if (dir) { - SAFE_FREE(dir->fname); - SAFE_FREE(dir); - } - continue; } } -- cgit From 57298468d3f61a3ac89b6b993b91e90e17f014c2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 Dec 2005 15:34:38 +0000 Subject: r12129: Fix uninitialized variables. Volker --- source/passdb/pdb_ldap.c | 2 +- source/utils/net_groupmap.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index fac95e37866..20cf2d328ec 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3193,7 +3193,7 @@ static NTSTATUS ldapsam_enum_aliasmem(struct pdb_methods *methods, char **values; int i; pstring filter; - size_t num_members; + size_t num_members = 0; *pp_members = NULL; *p_num_members = 0; diff --git a/source/utils/net_groupmap.c b/source/utils/net_groupmap.c index 12c3c79ef47..9e897d8efc7 100644 --- a/source/utils/net_groupmap.c +++ b/source/utils/net_groupmap.c @@ -678,6 +678,9 @@ static int net_groupmap_listmem(int argc, const char **argv) return -1; } + members = NULL; + num = 0; + if (!pdb_enum_aliasmem(&alias, &members, &num)) { d_printf("Could not list members for sid %s\n", argv[0]); return -1; -- cgit From 05431032f46ca40e912d37c93e1599fd2ba7511e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 Dec 2005 16:25:33 +0000 Subject: r12130: display domain GUID. Guenther --- source/rpcclient/cmd_lsarpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpcclient/cmd_lsarpc.c b/source/rpcclient/cmd_lsarpc.c index c79508de8d0..4f4687ebfd1 100644 --- a/source/rpcclient/cmd_lsarpc.c +++ b/source/rpcclient/cmd_lsarpc.c @@ -130,7 +130,7 @@ static NTSTATUS cmd_lsa_query_info_policy(struct rpc_pipe_client *cli, printf("forest name is %s\n", forest_name); if (info_class == 12) { - printf("domain GUID is "); + printf("domain GUID is %s\n"); smb_uuid_string_static(*dom_guid); } -- cgit From cb77d8d87363f841da763af861e390f418503656 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 8 Dec 2005 16:34:57 +0000 Subject: r12131: Fix it really, this time :) Guenther --- source/rpcclient/cmd_lsarpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/rpcclient/cmd_lsarpc.c b/source/rpcclient/cmd_lsarpc.c index 4f4687ebfd1..5adaf469818 100644 --- a/source/rpcclient/cmd_lsarpc.c +++ b/source/rpcclient/cmd_lsarpc.c @@ -130,8 +130,8 @@ static NTSTATUS cmd_lsa_query_info_policy(struct rpc_pipe_client *cli, printf("forest name is %s\n", forest_name); if (info_class == 12) { - printf("domain GUID is %s\n"); - smb_uuid_string_static(*dom_guid); + printf("domain GUID is %s\n", + smb_uuid_string_static(*dom_guid)); } rpccli_lsa_close(cli, mem_ctx, &pol); -- cgit From bd2f8241f557d3480add2ba1a7cae0ff7bbd225d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 Dec 2005 19:34:22 +0000 Subject: r12133: Fix an uninitialized variable in new code in rpc_server/srv_samr_nt.c. Fix winbind_lookup_name for the local domain, ie for aliases on a member server. Volker --- source/nsswitch/winbindd_util.c | 16 +++++++++++++++- source/rpc_server/srv_samr_nt.c | 13 ++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/source/nsswitch/winbindd_util.c b/source/nsswitch/winbindd_util.c index d934bc2927f..efae9568845 100644 --- a/source/nsswitch/winbindd_util.c +++ b/source/nsswitch/winbindd_util.c @@ -90,6 +90,14 @@ static BOOL is_internal_domain(const DOM_SID *sid) return (sid_check_is_domain(sid) || sid_check_is_builtin(sid)); } +static BOOL is_in_internal_domain(const DOM_SID *sid) +{ + if (sid == NULL) + return False; + + return (sid_check_is_in_our_domain(sid) || sid_check_is_in_builtin(sid)); +} + /* Add a trusted domain to our list of domains */ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const char *alt_name, @@ -648,12 +656,18 @@ struct winbindd_domain *find_lookup_domain_from_sid(const DOM_SID *sid) * one to contact the external DC's. On member servers the internal * domains are different: These are part of the local SAM. */ - if (IS_DC || is_internal_domain(sid)) + DEBUG(10, ("find_lookup_domain_from_sid(%s)\n", + sid_string_static(sid))); + + if (IS_DC || is_internal_domain(sid) || is_in_internal_domain(sid)) { + DEBUG(10, ("calling find_domain_from_sid\n")); return find_domain_from_sid(sid); + } /* On a member server a query for SID or name can always go to our * primary DC. */ + DEBUG(10, ("calling find_our_domain\n")); return find_our_domain(); } diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 13f3a3284b9..880e1db388d 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -2243,6 +2243,8 @@ static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name) enum SID_NAME_USE type; BOOL result; + DEBUG(10, ("Checking whether [%s] can be created\n", new_name)); + become_root(); /* Lookup in our local databases (only LOOKUP_NAME_ISOLATED set) * whether the name already exists */ @@ -2251,6 +2253,7 @@ static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name) unbecome_root(); if (!result) { + DEBUG(10, ("%s does not exist, can create it\n", new_name)); return NT_STATUS_OK; } @@ -4308,16 +4311,16 @@ NTSTATUS _samr_create_dom_alias(pipes_struct *p, SAMR_Q_CREATE_DOM_ALIAS *q_u, S if (!sid_equal(&dom_sid, get_global_sam_sid())) return NT_STATUS_ACCESS_DENIED; - r_u->status = can_create(p->mem_ctx, name); - if (!NT_STATUS_IS_OK(r_u->status)) { - return r_u->status; - } - unistr2_to_ascii(name, &q_u->uni_acct_desc, sizeof(name)-1); se_priv_copy( &se_rights, &se_add_users ); can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights ); + result = can_create(p->mem_ctx, name); + if (!NT_STATUS_IS_OK(result)) { + return result; + } + /******** BEGIN SeAddUsers BLOCK *********/ if ( can_add_accounts ) -- cgit From c05a1593f0dd4af94afb2fbaac6fe8e37d79d176 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 10 Dec 2005 01:33:58 +0000 Subject: r12160: The filename parameter to get_share_mode_lock is going to become very important as we fix #3303, so make sure we don't accidently set it here. Jeremy. --- source/smbd/close.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/smbd/close.c b/source/smbd/close.c index fcea62e1aa4..43049a46a4d 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -192,7 +192,7 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close) * This prevents race conditions with the file being created. JRA. */ - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, fsp->fsp_name); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); if (lck == NULL) { DEBUG(0, ("close_file: Could not get share mode lock for file %s\n", fsp->fsp_name)); @@ -305,7 +305,7 @@ static int close_directory(files_struct *fsp, BOOL normal_close) * reference to a directory also. */ - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, fsp->fsp_name); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); if (lck == NULL) { DEBUG(0, ("close_directory: Could not get share mode lock for %s\n", fsp->fsp_name)); -- cgit From 826c42d0ac08490c6af66c33d6913ec3eb592d00 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 10 Dec 2005 11:22:01 +0000 Subject: r12163: Change lookup_sid and lookup_name to return const char * instead of char *, use a temporary talloc_ctx for clarity. Volker --- source/nsswitch/wb_client.c | 2 +- source/passdb/lookup_sid.c | 125 ++++++++++++++++++++++------------------- source/passdb/passdb.c | 2 +- source/passdb/pdb_interface.c | 6 +- source/passdb/util_builtin.c | 2 +- source/passdb/util_wellknown.c | 4 +- source/rpc_server/srv_lsa_nt.c | 7 ++- source/smbd/lanman.c | 2 +- 8 files changed, 79 insertions(+), 71 deletions(-) diff --git a/source/nsswitch/wb_client.c b/source/nsswitch/wb_client.c index 6fe55e12098..0e49cd31f32 100644 --- a/source/nsswitch/wb_client.c +++ b/source/nsswitch/wb_client.c @@ -65,7 +65,7 @@ BOOL winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid, /* Call winbindd to convert sid to name */ BOOL winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, - char **domain, char **name, + const char **domain, const char **name, enum SID_NAME_USE *name_type) { struct winbindd_request request; diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c index bad5d278aed..4640eb6ae58 100644 --- a/source/passdb/lookup_sid.c +++ b/source/passdb/lookup_sid.c @@ -31,25 +31,32 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, const char *full_name, int flags, - char **ret_domain, char **ret_name, + const char **ret_domain, const char **ret_name, DOM_SID *ret_sid, enum SID_NAME_USE *ret_type) { - char *p, *tmp; - char *domain = NULL; - char *name = NULL; + char *p; + const char *tmp; + const char *domain = NULL; + const char *name = NULL; uint32 rid; DOM_SID sid; enum SID_NAME_USE type; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + + if (tmp_ctx == NULL) { + DEBUG(0, ("talloc_new failed\n")); + return False; + } p = strchr_m(full_name, '\\'); if (p != NULL) { - domain = talloc_strndup(mem_ctx, full_name, + domain = talloc_strndup(tmp_ctx, full_name, PTR_DIFF(p, full_name)); - name = talloc_strdup(mem_ctx, p+1); + name = talloc_strdup(tmp_ctx, p+1); } else { - domain = talloc_strdup(mem_ctx, ""); - name = talloc_strdup(mem_ctx, full_name); + domain = talloc_strdup(tmp_ctx, ""); + name = talloc_strdup(tmp_ctx, full_name); } if ((domain == NULL) || (name == NULL)) { @@ -65,7 +72,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, sid_append_rid(&sid, rid); goto ok; } - return False; + goto failed; } if (strequal(domain, builtin_domain_name())) { @@ -77,7 +84,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, type = SID_NAME_ALIAS; goto ok; } - return False; + goto failed; } if (domain[0] != '\0') { @@ -86,11 +93,11 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, if (winbind_lookup_name(domain, name, &sid, &type)) { goto ok; } - return False; + goto failed; } if (!(flags & LOOKUP_NAME_ISOLATED)) { - return False; + goto failed; } /* Now the guesswork begins, we haven't been given an explicit @@ -101,9 +108,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, /* 1. well-known names */ { - tmp = domain; - if (lookup_wellknown_name(mem_ctx, name, &sid, &domain)) { - talloc_free(tmp); + if (lookup_wellknown_name(tmp_ctx, name, &sid, &domain)) { type = SID_NAME_WKN_GRP; goto ok; } @@ -124,7 +129,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, if (strequal(name, get_global_sam_name())) { if (!secrets_fetch_domain_sid(name, &sid)) { DEBUG(3, ("Could not fetch my SID\n")); - return False; + goto failed; } /* Swap domain and name */ tmp = name; name = domain; domain = tmp; @@ -137,7 +142,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, if (!IS_DC && strequal(name, lp_workgroup())) { if (!secrets_fetch_domain_sid(name, &sid)) { DEBUG(3, ("Could not fetch the domain SID\n")); - return False; + goto failed; } /* Swap domain and name */ tmp = name; name = domain; domain = tmp; @@ -159,7 +164,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, /* 6. Builtin aliases */ if (lookup_builtin_name(name, &rid)) { - domain = talloc_strdup(mem_ctx, builtin_domain_name()); + domain = talloc_strdup(tmp_ctx, builtin_domain_name()); sid_copy(&sid, &global_sid_Builtin); sid_append_rid(&sid, rid); type = SID_NAME_ALIAS; @@ -172,7 +177,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, /* Both cases are done by looking at our passdb */ if (lookup_global_sam_name(name, &rid, &type)) { - domain = talloc_strdup(mem_ctx, get_global_sam_name()); + domain = talloc_strdup(tmp_ctx, get_global_sam_name()); sid_copy(&sid, get_global_sam_sid()); sid_append_rid(&sid, rid); goto ok; @@ -181,7 +186,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, /* Now our local possibilities are exhausted. */ if (!(flags & LOOKUP_NAME_REMOTE)) { - return False; + goto failed; } /* If we are not a DC, we have to ask in our primary domain. Let @@ -189,7 +194,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, if (!IS_DC && (winbind_lookup_name(lp_workgroup(), name, &sid, &type))) { - domain = talloc_strdup(mem_ctx, lp_workgroup()); + domain = talloc_strdup(tmp_ctx, lp_workgroup()); goto ok; } @@ -209,8 +214,6 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, goto ok; } - talloc_free(domain); - /* Here we have to cope with a little deficiency in the * winbind API: We have to ask it again for the name of the * domain it figured out itself. Maybe fix that later... */ @@ -218,40 +221,36 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, sid_copy(&dom_sid, &sid); sid_split_rid(&dom_sid, &tmp_rid); - if (!winbind_lookup_sid(mem_ctx, &dom_sid, &domain, NULL, + if (!winbind_lookup_sid(tmp_ctx, &dom_sid, &domain, NULL, &domain_type) || (domain_type != SID_NAME_DOMAIN)) { - DEBUG(2, ("winbind could not find the domain's name it " - "just looked up for us\n")); - return False; + DEBUG(2, ("winbind could not find the domain's name " + "it just looked up for us\n")); + goto failed; } - - talloc_free(domain); goto ok; } /* 10. Don't translate */ - + failed: + talloc_free(tmp_ctx); return False; ok: if ((domain == NULL) || (name == NULL)) { DEBUG(0, ("talloc failed\n")); + talloc_free(tmp_ctx); return False; } - strupper_m(domain); - if (ret_name != NULL) { - *ret_name = name; - } else { - talloc_free(name); + *ret_name = talloc_steal(mem_ctx, name); } if (ret_domain != NULL) { - *ret_domain = domain; - } else { - talloc_free(domain); + char *tmp_dom = talloc_strdup(tmp_ctx, domain); + strupper_m(tmp_dom); + *ret_domain = talloc_steal(mem_ctx, tmp_dom); } if (ret_sid != NULL) { @@ -262,6 +261,7 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, *ret_type = type; } + talloc_free(tmp_ctx); return True; } @@ -271,18 +271,25 @@ BOOL lookup_name(TALLOC_CTX *mem_ctx, *****************************************************************/ BOOL lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, - char **ret_domain, char **ret_name, + const char **ret_domain, const char **ret_name, enum SID_NAME_USE *ret_type) { - char *domain = NULL; - char *name = NULL; + const char *domain = NULL; + const char *name = NULL; enum SID_NAME_USE type; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + /* Check if this is our own sid. This should perhaps be done by winbind? For the moment handle it here. */ + if (tmp_ctx == NULL) { + DEBUG(0, ("talloc_new failed\n")); + return False; + } + if (sid_check_is_domain(sid)) { - domain = talloc_strdup(mem_ctx, get_global_sam_name()); - name = talloc_strdup(mem_ctx, ""); + domain = talloc_strdup(tmp_ctx, get_global_sam_name()); + name = talloc_strdup(tmp_ctx, ""); type = SID_NAME_DOMAIN; goto ok; } @@ -292,20 +299,20 @@ BOOL lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, SMB_ASSERT(sid_peek_rid(sid, &rid)); /* For our own domain passdb is responsible */ - if (!lookup_global_sam_rid(mem_ctx, rid, &name, &type)) { - return False; + if (!lookup_global_sam_rid(tmp_ctx, rid, &name, &type)) { + goto failed; } - domain = talloc_strdup(mem_ctx, get_global_sam_name()); + domain = talloc_strdup(tmp_ctx, get_global_sam_name()); goto ok; } if (sid_check_is_builtin(sid)) { - domain = talloc_strdup(mem_ctx, builtin_domain_name()); + domain = talloc_strdup(tmp_ctx, builtin_domain_name()); /* Yes, W2k3 returns "BUILTIN" both as domain and name here */ - name = talloc_strdup(mem_ctx, builtin_domain_name()); + name = talloc_strdup(tmp_ctx, builtin_domain_name()); type = SID_NAME_DOMAIN; goto ok; } @@ -315,55 +322,55 @@ BOOL lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, SMB_ASSERT(sid_peek_rid(sid, &rid)); - if (!lookup_builtin_rid(mem_ctx, rid, &name)) { - return False; + if (!lookup_builtin_rid(tmp_ctx, rid, &name)) { + goto failed; } /* There's only aliases in S-1-5-32 */ type = SID_NAME_ALIAS; - domain = talloc_strdup(mem_ctx, builtin_domain_name()); + domain = talloc_strdup(tmp_ctx, builtin_domain_name()); goto ok; } - if (winbind_lookup_sid(mem_ctx, sid, &domain, &name, &type)) { + if (winbind_lookup_sid(tmp_ctx, sid, &domain, &name, &type)) { goto ok; } DEBUG(10,("lookup_sid: winbind lookup for SID %s failed - trying " "special SIDs.\n", sid_string_static(sid))); - if (lookup_wellknown_sid(mem_ctx, sid, &domain, &name)) { + if (lookup_wellknown_sid(tmp_ctx, sid, &domain, &name)) { type = SID_NAME_WKN_GRP; goto ok; } + failed: DEBUG(10, ("Failed to lookup sid %s\n", sid_string_static(sid))); + talloc_free(tmp_ctx); return False; ok: if ((domain == NULL) || (name == NULL)) { DEBUG(0, ("talloc failed\n")); + talloc_free(tmp_ctx); return False; } if (ret_domain != NULL) { - *ret_domain = domain; - } else { - talloc_free(domain); + *ret_domain = talloc_steal(mem_ctx, domain); } if (ret_name != NULL) { - *ret_name = name; - } else { - talloc_free(name); + *ret_name = talloc_steal(mem_ctx, name); } if (ret_type != NULL) { *ret_type = type; } + talloc_free(tmp_ctx); return True; } diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index 3ca26a57c74..006161b6639 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -735,7 +735,7 @@ BOOL algorithmic_pdb_rid_is_user(uint32 rid) Look up a rid in the SAM we're responsible for (i.e. passdb) ********************************************************************/ -BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid, char **name, +BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid, const char **name, enum SID_NAME_USE *psid_name_use) { SAM_ACCOUNT *sam_account = NULL; diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c index 6ac5a3e9654..4808af39081 100644 --- a/source/passdb/pdb_interface.c +++ b/source/passdb/pdb_interface.c @@ -1691,7 +1691,7 @@ NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods, if (sid_check_is_builtin(domain_sid)) { for (i=0; imem_ctx, &sids[i], NULL, &grp_name, NULL) ) { -- cgit From 6b81958b7eaf1f8ba2c1be86aaca1c0d052766de Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 10 Dec 2005 23:29:39 +0000 Subject: r12169: Remove an unused function --- source/lib/util_sid.c | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/source/lib/util_sid.c b/source/lib/util_sid.c index 92bc2fb8931..b94be474a9e 100644 --- a/source/lib/util_sid.c +++ b/source/lib/util_sid.c @@ -156,41 +156,6 @@ const char *get_global_sam_name(void) return global_myname(); } -/************************************************************************** - Splits a name of format \DOMAIN\name or name into its two components. - Sets the DOMAIN name to global_myname() if it has not been specified. -***************************************************************************/ - -void split_domain_name(const char *fullname, char *domain, char *name) -{ - pstring full_name; - const char *sep; - char *p; - - sep = lp_winbind_separator(); - - *domain = *name = '\0'; - - if (fullname[0] == sep[0] || fullname[0] == '\\') - fullname++; - - pstrcpy(full_name, fullname); - p = strchr_m(full_name+1, '\\'); - if (!p) p = strchr_m(full_name+1, sep[0]); - - if (p != NULL) { - *p = 0; - fstrcpy(domain, full_name); - fstrcpy(name, p+1); - } else { - fstrcpy(domain, get_global_sam_name()); - fstrcpy(name, full_name); - } - - DEBUG(10,("split_domain_name:name '%s' split into domain :'%s' and user :'%s'\n", - fullname, domain, name)); -} - /***************************************************************** Convert a SID to an ascii string. *****************************************************************/ -- cgit From 8d29af27d27eb41f505cc09f2a6f7797638b3dd3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 10 Dec 2005 23:56:42 +0000 Subject: r12170: Fix a segfault -- this is post-3.0.21 code --- source/nsswitch/wb_client.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/wb_client.c b/source/nsswitch/wb_client.c index 0e49cd31f32..fcab76b033a 100644 --- a/source/nsswitch/wb_client.c +++ b/source/nsswitch/wb_client.c @@ -108,7 +108,8 @@ BOOL winbind_lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid, *name_type = (enum SID_NAME_USE)response.data.name.type; DEBUG(10, ("winbind_lookup_sid: SUCCESS: SID %s -> %s %s\n", - sid_string_static(sid), *domain, *name)); + sid_string_static(sid), response.data.name.dom_name, + response.data.name.name)); return True; } -- cgit From 68119e7c485fdaf54d6ea0564c11df188b04926c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 04:21:34 +0000 Subject: r12173: doing some service control work * Add a few new error codes for disabled services * dump some more details about service status in 'net rpc service' * disable the WINS and NetLogon services if not configured in smb.conf Still trying to figure out how to disable the start button on the NetLogon and WINS services. --- source/include/doserr.h | 2 ++ source/include/rpc_svcctl.h | 3 ++- source/libsmb/doserr.c | 1 + source/rpc_server/srv_svcctl_nt.c | 13 ++++++++++++- source/services/svc_netlogon.c | 33 +++++++++++++++++++++------------ source/services/svc_wins.c | 32 +++++++++++++++++++------------- source/utils/net_rpc_service.c | 1 + 7 files changed, 58 insertions(+), 27 deletions(-) diff --git a/source/include/doserr.h b/source/include/doserr.h index 60c450c819d..62c1e4fa22d 100644 --- a/source/include/doserr.h +++ b/source/include/doserr.h @@ -196,6 +196,8 @@ #define WERR_REG_FILE_INVALID W_ERROR(1017) #define WERR_NO_SUCH_SERVICE W_ERROR(1060) #define WERR_INVALID_SERVICE_CONTROL W_ERROR(1052) +#define WERR_SERVICE_DISABLED W_ERROR(1058) +#define WERR_SERVICE_NEVER_STARTED W_ERROR(1077) #define WERR_MACHINE_LOCKED W_ERROR(1271) #define WERR_INVALID_SECURITY_DESCRIPTOR W_ERROR(1338) #define WERR_EVENTLOG_FILE_CORRUPT W_ERROR(1500) diff --git a/source/include/rpc_svcctl.h b/source/include/rpc_svcctl.h index f5ad2afa1c7..4a058999a38 100644 --- a/source/include/rpc_svcctl.h +++ b/source/include/rpc_svcctl.h @@ -69,6 +69,7 @@ /* SERVER_STATUS - ControlAccepted */ +#define SVCCTL_ACCEPT_NONE 0x00000000 #define SVCCTL_ACCEPT_STOP 0x00000001 #define SVCCTL_ACCEPT_PAUSE_CONTINUE 0x00000002 #define SVCCTL_ACCEPT_SHUTDOWN 0x00000004 @@ -126,7 +127,7 @@ typedef struct { uint32 type; uint32 state; uint32 controls_accepted; - uint32 win32_exit_code; + WERROR win32_exit_code; uint32 service_exit_code; uint32 check_point; uint32 wait_hint; diff --git a/source/libsmb/doserr.c b/source/libsmb/doserr.c index dd0358f69a5..253164963a4 100644 --- a/source/libsmb/doserr.c +++ b/source/libsmb/doserr.c @@ -76,6 +76,7 @@ werror_code_struct dos_errs[] = { "WERR_REG_CORRUPT", WERR_REG_CORRUPT }, { "WERR_REG_IO_FAILURE", WERR_REG_IO_FAILURE }, { "WERR_REG_FILE_INVALID", WERR_REG_FILE_INVALID }, + { "WERR_SERVICE_DISABLED", WERR_SERVICE_DISABLED }, { NULL, W_ERROR(0) } }; diff --git a/source/rpc_server/srv_svcctl_nt.c b/source/rpc_server/srv_svcctl_nt.c index bbf313f7fa1..97c38753c33 100644 --- a/source/rpc_server/srv_svcctl_nt.c +++ b/source/rpc_server/srv_svcctl_nt.c @@ -615,9 +615,20 @@ static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name, SERVICE_CONFIG config->tag_id = 0x00000000; /* unassigned loadorder group */ config->service_type = SVCCTL_WIN32_OWN_PROC; - config->start_type = SVCCTL_DEMAND_START; config->error_control = SVCCTL_SVC_ERROR_NORMAL; + /* set the start type. NetLogon and WINS are disabled to prevent + the client from showing the "Start" button (if of course the services + are not running */ + + if ( strequal( name, "NETLOGON" ) && ( lp_servicenumber(name) == -1 ) ) + config->start_type = SVCCTL_DISABLED; + else if ( strequal( name, "WINS" ) && ( !lp_wins_support() )) + config->start_type = SVCCTL_DISABLED; + else + config->start_type = SVCCTL_DEMAND_START; + + TALLOC_FREE( values ); return WERR_OK; diff --git a/source/services/svc_netlogon.c b/source/services/svc_netlogon.c index 2aa5a31cde3..1bbef325ac3 100644 --- a/source/services/svc_netlogon.c +++ b/source/services/svc_netlogon.c @@ -25,33 +25,42 @@ /********************************************************************* *********************************************************************/ -static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status ) +static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_status ) { - return WERR_ACCESS_DENIED; + ZERO_STRUCTP( service_status ); + + service_status->type = 0x20; + service_status->controls_accepted = SVCCTL_ACCEPT_NONE; + + if ( lp_servicenumber("NETLOGON") != -1 ) { + service_status->state = SVCCTL_RUNNING; + service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; + } + else + service_status->state = SVCCTL_STOPPED; + + return WERR_OK; } /********************************************************************* *********************************************************************/ -static WERROR netlogon_start( const char *service ) +static WERROR netlogon_stop( const char *service, SERVICE_STATUS *service_status ) { + netlogon_status( service, service_status ); + return WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR netlogon_status( const char *service, SERVICE_STATUS *service_status ) +static WERROR netlogon_start( const char *service ) { - ZERO_STRUCTP( service_status ); + if ( lp_servicenumber("NETLOGON") == -1 ) + return WERR_SERVICE_DISABLED; - service_status->type = 0x20; - if ( lp_servicenumber("NETLOGON") != -1 ) - service_status->state = SVCCTL_RUNNING; - else - service_status->state = SVCCTL_STOPPED; - - return WERR_OK; + return WERR_ACCESS_DENIED; } /********************************************************************* diff --git a/source/services/svc_wins.c b/source/services/svc_wins.c index 3a4650664df..37cfc99c06e 100644 --- a/source/services/svc_wins.c +++ b/source/services/svc_wins.c @@ -25,33 +25,39 @@ /********************************************************************* *********************************************************************/ -static WERROR wins_stop( const char *service, SERVICE_STATUS *service_status ) +static WERROR wins_status( const char *service, SERVICE_STATUS *service_status ) { - return WERR_ACCESS_DENIED; + ZERO_STRUCTP( service_status ); + + service_status->type = 0x10; + service_status->controls_accepted = SVCCTL_ACCEPT_NONE; + + if ( lp_wins_support() ) + service_status->state = SVCCTL_RUNNING; + else { + service_status->state = SVCCTL_STOPPED; + service_status->win32_exit_code = WERR_SERVICE_NEVER_STARTED; + } + + return WERR_OK; } /********************************************************************* *********************************************************************/ -static WERROR wins_start( const char *service ) +static WERROR wins_stop( const char *service, SERVICE_STATUS *service_status ) { + wins_status( service, service_status ); + return WERR_ACCESS_DENIED; } /********************************************************************* *********************************************************************/ -static WERROR wins_status( const char *service, SERVICE_STATUS *service_status ) +static WERROR wins_start( const char *service ) { - ZERO_STRUCTP( service_status ); - - service_status->type = 0x10; - if ( lp_wins_support() ) - service_status->state = SVCCTL_RUNNING; - else - service_status->state = SVCCTL_STOPPED; - - return WERR_OK; + return WERR_ACCESS_DENIED; } /********************************************************************* diff --git a/source/utils/net_rpc_service.c b/source/utils/net_rpc_service.c index 3cc4790884c..ed7d1dfab1f 100644 --- a/source/utils/net_rpc_service.c +++ b/source/utils/net_rpc_service.c @@ -254,6 +254,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, /* print out the configuration information for the service */ d_printf("Configuration details:\n"); + d_printf("\tControls Accepted = 0x%x\n", service_status.controls_accepted); d_printf("\tService Type = 0x%x\n", config.service_type); d_printf("\tStart Type = 0x%x\n", config.start_type); d_printf("\tError Control = 0x%x\n", config.error_control); -- cgit From f1ffc75983dba67cc53ba59675753dc48e323936 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 04:39:33 +0000 Subject: r12174: Simple patch to work around the current lack of BUILTIN nested group support. Always add the BUILTIN\Administrators SID to a Domain Admins token. This solves the extra steps of establishing a group map for the local Administrators SID in order to control services. Windows also tends to expect the Administrators group to be usable when setting up security permissions on shares. Volker's work will probably fix this long term, but this gets us past some of the setup hurdles for 3.0.21. --- source/auth/auth_util.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/source/auth/auth_util.c b/source/auth/auth_util.c index ce1ce31d08a..497f16adf2b 100644 --- a/source/auth/auth_util.c +++ b/source/auth/auth_util.c @@ -471,9 +471,12 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro NT_USER_TOKEN *ptoken; int i; int sid_ndx; + DOM_SID domadm; + BOOL is_domain_admin = False; + BOOL domain_mode = False; if ((ptoken = SMB_MALLOC_P(NT_USER_TOKEN)) == NULL) { - DEBUG(0, ("create_nt_token: Out of memory allocating token\n")); + DEBUG(0, ("create_nt_user_token: Out of memory allocating token\n")); nt_status = NT_STATUS_NO_MEMORY; return nt_status; } @@ -483,7 +486,7 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro ptoken->num_sids = n_groupSIDs + 5; if ((ptoken->user_sids = SMB_MALLOC_ARRAY( DOM_SID, ptoken->num_sids )) == NULL) { - DEBUG(0, ("create_nt_token: Out of memory allocating SIDs\n")); + DEBUG(0, ("create_nt_user_token: Out of memory allocating SIDs\n")); nt_status = NT_STATUS_NO_MEMORY; return nt_status; } @@ -517,6 +520,27 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro sid_ndx = 5; /* next available spot */ + /* this is where we construct the domain admins SID if we can + so that we can add the BUILTIN\Administrators SID to the token */ + + ZERO_STRUCT( domadm ); + if ( IS_DC || lp_server_role()==ROLE_DOMAIN_MEMBER ) { + domain_mode = True; + + if ( IS_DC ) + sid_copy( &domadm, get_global_sam_sid() ); + else { + /* if we a re a member server and cannot find + out domain SID then reset the domain_mode flag */ + if ( !secrets_fetch_domain_sid( lp_workgroup(), &domadm ) ) + domain_mode = False; + } + + sid_append_rid( &domadm, DOMAIN_GROUP_RID_ADMINS ); + } + + /* add the group SIDs to teh token */ + for (i = 0; i < n_groupSIDs; i++) { size_t check_sid_idx; for (check_sid_idx = 1; check_sid_idx < ptoken->num_sids; check_sid_idx++) { @@ -531,6 +555,30 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro } else { ptoken->num_sids--; } + + /* here we check if the user is a domain admin and add the + BUILTIN\Administrators SID to the token the group membership + check succeeds. */ + + if ( domain_mode ) { + if ( sid_equal( &domadm, &groupSIDs[i] ) ) + is_domain_admin = True; + } + + } + + /* finally realloc the SID array and add the BUILTIN\Administrators + SID if necessary */ + + if ( is_domain_admin ) { + DOM_SID *sids; + + if ( !(sids = SMB_REALLOC_ARRAY( ptoken->user_sids, DOM_SID, ptoken->num_sids+1 )) ) + DEBUG(0,("create_nt_user_token: Failed to realloc SID arry of size %d\n", ptoken->num_sids+1)); + else { + ptoken->user_sids = sids; + sid_copy( &(ptoken->user_sids)[ptoken->num_sids++], &global_sid_Builtin_Administrators ); + } } /* add privileges assigned to this user */ @@ -602,6 +650,8 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups, return NULL; } + /* convert the Unix group ids to SIDS */ + for (i = 0; i < ngroups; i++) { if (!NT_STATUS_IS_OK(gid_to_sid(&(group_sids)[i], (groups)[i]))) { DEBUG(1, ("create_nt_token: failed to convert gid %ld to a sid!\n", (long int)groups[i])); @@ -640,7 +690,7 @@ NT_USER_TOKEN *get_root_nt_token( void ) return token; if ( !(pw = getpwnam( "root" )) ) { - DEBUG(0,("create_root_nt_token: getpwnam\"root\") failed!\n")); + DEBUG(0,("get_root_nt_token: getpwnam\"root\") failed!\n")); return NULL; } -- cgit From 7412289b345b328b83de732513cd55702bcdbba1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 04:41:54 +0000 Subject: r12176: fix type mismatch after rpc structure change in rpc_svcctl.h --- source/rpc_parse/parse_svcctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_parse/parse_svcctl.c b/source/rpc_parse/parse_svcctl.c index e1a7ad84273..dd0c68bd797 100644 --- a/source/rpc_parse/parse_svcctl.c +++ b/source/rpc_parse/parse_svcctl.c @@ -41,7 +41,7 @@ static BOOL svcctl_io_service_status( const char *desc, SERVICE_STATUS *status, if(!prs_uint32("controls_accepted", ps, depth, &status->controls_accepted)) return False; - if(!prs_uint32("win32_exit_code", ps, depth, &status->win32_exit_code)) + if(!prs_werror("win32_exit_code", ps, depth, &status->win32_exit_code)) return False; if(!prs_uint32("service_exit_code", ps, depth, &status->service_exit_code)) -- cgit From 04fd0ca5061899c32a8a30f874e7accb9110321d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 05:06:35 +0000 Subject: r12177: last of outstanding patches in my queue to deal with MMC. Validate the share name and fail when trying to creating a share with bad characters. --- source/rpc_server/srv_srvsvc_nt.c | 46 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index 0e7ded39f57..1d574d82fb1 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -29,6 +29,26 @@ extern struct generic_mapping file_generic_mapping; #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV +#define INVALID_SHARENAME_CHARS "<>*?|" + +/******************************************************************** + Check a string for any occurrences of a specified list of invalid + characters. +********************************************************************/ + +static BOOL validate_net_name( const char *name, const char *invalid_chars, int max_len ) +{ + int i; + + for ( i=0; istatus; } +/******************************************************************** +********************************************************************/ + WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u) { - fstring share_name; + fstring sharename; switch ( q_u->type ) { case 0x9: - /* check if share name is ok. - TODO: check for invalid characters in name? */ - - unistr2_to_ascii(share_name, &q_u->uni_name, sizeof(share_name)); + /* Run the name through alpha_strcpy() to remove any unsafe + shell characters. Compare the copied string with the original + and fail if the strings don't match */ + + unistr2_to_ascii(sharename, &q_u->uni_name, sizeof(sharename)); + if ( !validate_net_name( sharename, INVALID_SHARENAME_CHARS, sizeof(sharename) ) ) { + DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", sharename)); + return WERR_INVALID_NAME; + } break; + default: return WERR_UNKNOWN_LEVEL; } -- cgit From c1ff6d880b9161e65fee680f887d73082b54ab2a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 Dec 2005 16:55:28 +0000 Subject: r12182: Cosmetic cleanup --- source/groupdb/mapping.c | 60 +++++++++++++++++++-------------------------- source/utils/net_groupmap.c | 14 ++++------- 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 14040e4f52b..9e547aa69c6 100644 --- a/source/groupdb/mapping.c +++ b/source/groupdb/mapping.c @@ -35,43 +35,34 @@ static TDB_CONTEXT *tdb; /* used for driver files */ */ #define MEMBEROF_PREFIX "MEMBEROF/" +static struct sid_name_mapping { + enum SID_NAME_USE type; + const char *name; +} sid_name_use_strings[] = { + { SID_NAME_USE_NONE, "Not initialized" }, + { SID_NAME_USER, "User" }, + { SID_NAME_DOM_GRP, "Domain group" }, + { SID_NAME_DOMAIN, "Domain" }, + { SID_NAME_ALIAS, "Local group" }, + { SID_NAME_WKN_GRP, "Builtin group" }, + { SID_NAME_DELETED, "Deleted" }, + { SID_NAME_INVALID, "Invalid" }, + { 0, NULL } +}; + /**************************************************************************** dump the mapping group mapping to a text file ****************************************************************************/ -char *decode_sid_name_use(fstring group, enum SID_NAME_USE name_use) -{ - static fstring group_type; +const char *decode_sid_name_use(enum SID_NAME_USE name_use) +{ + struct sid_name_mapping *m; - switch(name_use) { - case SID_NAME_USER: - fstrcpy(group_type,"User"); - break; - case SID_NAME_DOM_GRP: - fstrcpy(group_type,"Domain group"); - break; - case SID_NAME_DOMAIN: - fstrcpy(group_type,"Domain"); - break; - case SID_NAME_ALIAS: - fstrcpy(group_type,"Local group"); - break; - case SID_NAME_WKN_GRP: - fstrcpy(group_type,"Builtin group"); - break; - case SID_NAME_DELETED: - fstrcpy(group_type,"Deleted"); - break; - case SID_NAME_INVALID: - fstrcpy(group_type,"Invalid"); - break; - case SID_NAME_UNKNOWN: - default: - fstrcpy(group_type,"Unknown type"); - break; + for (m = sid_name_use_strings; m->name != NULL; m++) { + if (m->type == name_use) + return m->name; } - - fstrcpy(group, group_type); - return group_type; + + return "Unknown type"; } /**************************************************************************** @@ -405,7 +396,6 @@ static BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **pp_rm { TDB_DATA kbuf, dbuf, newkey; fstring string_sid; - fstring group_type; GROUP_MAP map; GROUP_MAP *mapt; int ret; @@ -455,8 +445,8 @@ static BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **pp_rm string_to_sid(&map.sid, string_sid); - decode_sid_name_use(group_type, map.sid_name_use); - DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", map.nt_name ,group_type)); + DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", + map.nt_name, decode_sid_name_use(map.sid_name_use))); mapt= SMB_REALLOC_ARRAY((*pp_rmap), GROUP_MAP, entries+1); if (!mapt) { diff --git a/source/utils/net_groupmap.c b/source/utils/net_groupmap.c index 9e897d8efc7..f12668a85a4 100644 --- a/source/utils/net_groupmap.c +++ b/source/utils/net_groupmap.c @@ -87,19 +87,15 @@ static BOOL get_sid_from_input(DOM_SID *sid, char *input) static void print_map_entry ( GROUP_MAP map, BOOL long_list ) { - fstring string_sid; - fstring group_type; - - decode_sid_name_use(group_type, map.sid_name_use); - sid_to_string(string_sid, &map.sid); - if (!long_list) - d_printf("%s (%s) -> %s\n", map.nt_name, string_sid, gidtoname(map.gid)); + d_printf("%s (%s) -> %s\n", map.nt_name, + sid_string_static(&map.sid), gidtoname(map.gid)); else { d_printf("%s\n", map.nt_name); - d_printf("\tSID : %s\n", string_sid); + d_printf("\tSID : %s\n", sid_string_static(&map.sid)); d_printf("\tUnix group: %s\n", gidtoname(map.gid)); - d_printf("\tGroup type: %s\n", group_type); + d_printf("\tGroup type: %s\n", + decode_sid_name_use(map.sid_name_use)); d_printf("\tComment : %s\n", map.comment); } -- cgit From 5ca77f40f59148fdaced1ada410ff589daac4e14 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 11 Dec 2005 21:59:58 +0000 Subject: r12185: Cosmetic cleanup --- source/groupdb/mapping.c | 35 +++-------------------------------- source/utils/net_groupmap.c | 2 +- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 9e547aa69c6..97a3d6ab0e9 100644 --- a/source/groupdb/mapping.c +++ b/source/groupdb/mapping.c @@ -35,36 +35,6 @@ static TDB_CONTEXT *tdb; /* used for driver files */ */ #define MEMBEROF_PREFIX "MEMBEROF/" -static struct sid_name_mapping { - enum SID_NAME_USE type; - const char *name; -} sid_name_use_strings[] = { - { SID_NAME_USE_NONE, "Not initialized" }, - { SID_NAME_USER, "User" }, - { SID_NAME_DOM_GRP, "Domain group" }, - { SID_NAME_DOMAIN, "Domain" }, - { SID_NAME_ALIAS, "Local group" }, - { SID_NAME_WKN_GRP, "Builtin group" }, - { SID_NAME_DELETED, "Deleted" }, - { SID_NAME_INVALID, "Invalid" }, - { 0, NULL } -}; - -/**************************************************************************** -dump the mapping group mapping to a text file -****************************************************************************/ -const char *decode_sid_name_use(enum SID_NAME_USE name_use) -{ - struct sid_name_mapping *m; - - for (m = sid_name_use_strings; m->name != NULL; m++) { - if (m->type == name_use) - return m->name; - } - - return "Unknown type"; -} - /**************************************************************************** initialise first time the mapping list - called from init_group_mapping() ****************************************************************************/ @@ -445,8 +415,9 @@ static BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **pp_rm string_to_sid(&map.sid, string_sid); - DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", - map.nt_name, decode_sid_name_use(map.sid_name_use))); + DEBUG(11,("enum_group_mapping: returning group %s of " + "type %s\n", map.nt_name, + sid_type_lookup(map.sid_name_use))); mapt= SMB_REALLOC_ARRAY((*pp_rmap), GROUP_MAP, entries+1); if (!mapt) { diff --git a/source/utils/net_groupmap.c b/source/utils/net_groupmap.c index f12668a85a4..89bad6ea519 100644 --- a/source/utils/net_groupmap.c +++ b/source/utils/net_groupmap.c @@ -95,7 +95,7 @@ static void print_map_entry ( GROUP_MAP map, BOOL long_list ) d_printf("\tSID : %s\n", sid_string_static(&map.sid)); d_printf("\tUnix group: %s\n", gidtoname(map.gid)); d_printf("\tGroup type: %s\n", - decode_sid_name_use(map.sid_name_use)); + sid_type_lookup(map.sid_name_use)); d_printf("\tComment : %s\n", map.comment); } -- cgit From 1446a3f2278deb07e97690d731438f8758984947 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 12 Dec 2005 14:08:42 +0000 Subject: r12193: Fix some typos. Guenther --- source/nsswitch/winbindd_cache.c | 2 +- source/nsswitch/winbindd_cm.c | 2 +- source/nsswitch/winbindd_misc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 2d03e452ad6..841b114a785 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -1146,7 +1146,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, if (NT_STATUS_V(domain->last_status) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED) && netsamlogon_cache_have(user_sid)) { - DEBUG(10, ("query_user: cached access denied and have cached info3\n")); + DEBUG(10, ("lookup_usergroups: cached access denied and have cached info3\n")); domain->last_status = NT_STATUS_OK; centry_free(centry); goto do_query; diff --git a/source/nsswitch/winbindd_cm.c b/source/nsswitch/winbindd_cm.c index 77278e8c34d..6ac2520f44d 100644 --- a/source/nsswitch/winbindd_cm.c +++ b/source/nsswitch/winbindd_cm.c @@ -209,7 +209,7 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain, WINBIND_SERVER_MUTEX_WAIT_TIME); if (!got_mutex) { - DEBUG(0,("cm_open_connection: mutex grab failed for %s\n", + DEBUG(0,("cm_prepare_connection: mutex grab failed for %s\n", controller)); result = NT_STATUS_POSSIBLE_DEADLOCK; goto done; diff --git a/source/nsswitch/winbindd_misc.c b/source/nsswitch/winbindd_misc.c index ec8bacc4745..1fbf4b33df2 100644 --- a/source/nsswitch/winbindd_misc.c +++ b/source/nsswitch/winbindd_misc.c @@ -179,7 +179,7 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain, result = cm_connect_netlogon(domain, &netlogon_pipe); if (!NT_STATUS_IS_OK(result)) { - DEBUG(1, ("Can't contact our the NETLOGON pipe\n")); + DEBUG(1, ("Can't contact the NETLOGON pipe\n")); return WINBINDD_ERROR; } -- cgit From a10ce5b866b9432a75de097d5240beebfa87faea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Dec 2005 18:21:59 +0000 Subject: r12194: Ensure that when we set a connection path we've canonicalized the name (must be abolute - start with /, must not end in /, must have ./ and ../ removed). Of course for realpath resolved paths this won't be the case but for others we need this name to be canonicalized. This name is going into the sharemode db for #3303 so needs to be in a normalized format. Jeremy. --- source/smbd/msdfs.c | 2 +- source/smbd/posix_acls.c | 6 +-- source/smbd/reply.c | 2 +- source/smbd/service.c | 105 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/source/smbd/msdfs.c b/source/smbd/msdfs.c index a4f371b18ff..1279fe185d2 100644 --- a/source/smbd/msdfs.c +++ b/source/smbd/msdfs.c @@ -146,7 +146,7 @@ static BOOL create_conn_struct(connection_struct *conn, int snum, char *path) return False; } - string_set(&conn->connectpath, connpath); + set_conn_connectpath(conn, connpath); if (!smbd_vfs_init(conn)) { DEBUG(0,("create_conn_struct: smbd_vfs_init failed.\n")); diff --git a/source/smbd/posix_acls.c b/source/smbd/posix_acls.c index 91a3f5ed481..1b8e1d62143 100644 --- a/source/smbd/posix_acls.c +++ b/source/smbd/posix_acls.c @@ -4220,7 +4220,7 @@ SEC_DESC* get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname) connection_struct conn; files_struct finfo; struct fd_handle fh; - fstring path; + pstring path; pstring filename; ZERO_STRUCT( conn ); @@ -4231,8 +4231,8 @@ SEC_DESC* get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname) return NULL; } - fstrcpy( path, "/" ); - string_set(&conn.connectpath, path); + pstrcpy( path, "/" ); + set_conn_connectpath(&conn, path); if (!smbd_vfs_init(&conn)) { DEBUG(0,("novfs_get_nt_acl: Unable to create a fake connection struct!\n")); diff --git a/source/smbd/reply.c b/source/smbd/reply.c index 81240fcb92d..d3739c8847f 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -4954,7 +4954,7 @@ int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size } else { ok = vfs_directory_exist(conn,newdir,NULL); if (ok) - string_set(&conn->connectpath,newdir); + set_conn_connectpath(conn,newdir); } if (!ok) { diff --git a/source/smbd/service.c b/source/smbd/service.c index 52f9229ee1c..210edde5d8f 100644 --- a/source/smbd/service.c +++ b/source/smbd/service.c @@ -23,6 +23,105 @@ extern struct timeval smb_last_time; extern userdom_struct current_user_info; +/**************************************************************************** + Ensure when setting connectpath it is a canonicalized (no ./ // or ../) + absolute path stating in / and not ending in /. + Observent people will notice a similarity between this and check_path_syntax :-). +****************************************************************************/ + +void set_conn_connectpath(connection_struct *conn, const pstring connectpath) +{ + pstring destname; + char *d = destname; + const char *s = connectpath; + BOOL start_of_name_component = True; + + *d++ = '/'; /* Always start with root. */ + + while (*s) { + if (*s == '/') { + /* Eat multiple '/' */ + while (*s == '/') { + s++; + } + if ((d != destname) && (*s != '\0')) { + *d++ = '/'; + } + start_of_name_component = True; + continue; + } + + if (start_of_name_component) { + if ((s[0] == '.') && (s[1] == '.') && (s[2] == '/' || s[2] == '\0')) { + /* Uh oh - "/../" or "/..\0" ! */ + + /* Go past the ../ or .. */ + if (s[2] == '/') { + s += 3; + } else { + s += 2; /* Go past the .. */ + } + + /* If we just added a '/' - delete it */ + if ((d > destname) && (*(d-1) == '/')) { + *(d-1) = '\0'; + d--; + } + + /* Are we at the start ? Can't go back further if so. */ + if (d <= destname) { + *d++ = '/'; /* Can't delete root */ + continue; + } + /* Go back one level... */ + /* Decrement d first as d points to the *next* char to write into. */ + for (d--; d > destname; d--) { + if (*d == '/') { + break; + } + } + /* We're still at the start of a name component, just the previous one. */ + continue; + } else if ((s[0] == '.') && ((s[1] == '\0') || s[1] == '/')) { + /* Component of pathname can't be "." only - skip the '.' . */ + if (s[1] == '/') { + s += 2; + } else { + s++; + } + continue; + } + } + + if (!(*s & 0x80)) { + *d++ = *s++; + } else { + switch(next_mb_char_size(s)) { + case 4: + *d++ = *s++; + case 3: + *d++ = *s++; + case 2: + *d++ = *s++; + case 1: + *d++ = *s++; + break; + default: + break; + } + } + start_of_name_component = False; + } + *d = '\0'; + + /* And must not end in '/' */ + if (d > destname + 1 && (*(d-1) == '/')) { + *(d-1) = '\0'; + } + + string_set(&conn->connectpath, destname); +} + /**************************************************************************** Load parameters specific to a connection/service. ****************************************************************************/ @@ -474,7 +573,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, pstring s; pstrcpy(s,lp_pathname(snum)); standard_sub_conn(conn,s,sizeof(s)); - string_set(&conn->connectpath,s); + set_conn_connectpath(conn,s); DEBUG(3,("Connect path is '%s' for service [%s]\n",s, lp_servicename(snum))); } @@ -537,7 +636,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, pstring s; pstrcpy(s,conn->connectpath); canonicalize_path(conn, s); - string_set(&conn->connectpath,s); + set_conn_connectpath(conn,s); } /* ROOT Activities: */ @@ -652,7 +751,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, pstring s; pstrcpy(s,conn->connectpath); vfs_GetWd(conn,s); - string_set(&conn->connectpath,s); + set_conn_connectpath(conn,s); vfs_ChDir(conn,conn->connectpath); } #endif -- cgit From 4f49cd46cb3451166ff0d198e06fa66f3e199f1d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 12 Dec 2005 18:55:54 +0000 Subject: r12196: patch from Krishna Ganugapati Use the subtree delete ldap control when running 'net ads leave' to ensure that the machine account is actually deleted. --- source/libads/ldap.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source/libads/ldap.c b/source/libads/ldap.c index fa2a8b5ea57..8c8401dff9c 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -37,6 +37,9 @@ * codepoints in UTF-8). This may have to change at some point **/ + +#define LDAP_SERVER_TREE_DELETE_OID "1.2.840.113556.1.4.805" + static SIG_ATOMIC_T gotalarm; /*************************************************************** @@ -1796,6 +1799,11 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname) void *res, *msg; char *hostnameDN, *host; int rc; + LDAPControl ldap_control; + LDAPControl * pldap_control[] = {&ldap_control, 0}; + + memset(&ldap_control, 0, sizeof(LDAPControl)); + ldap_control.ldctl_oid = (char *)LDAP_SERVER_TREE_DELETE_OID; /* hostname must be lowercase */ host = SMB_STRDUP(hostname); @@ -1813,7 +1821,15 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname) } hostnameDN = ads_get_dn(ads, (LDAPMessage *)msg); - rc = ldap_delete_s(ads->ld, hostnameDN); + + + rc = ldap_delete_ext_s(ads->ld, hostnameDN, pldap_control, NULL); + if (rc) { + DEBUG(3,("ldap_delete_ext_s failed with error code %d\n", rc)); + }else { + DEBUG(3,("ldap_delete_ext_s succeeded with error code %d\n", rc)); + } + ads_memfree(ads, hostnameDN); if (rc != LDAP_SUCCESS) { return ADS_ERROR(rc); -- cgit From 437da5ac5bcc1b340b74e81768d1836351429fab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Dec 2005 22:07:36 +0000 Subject: r12203: Add the share path into the sharemode db. This involves revving the minor version number for libsmbsharemodes (we now have a new _ex interface that takes the share path as well as the filename). Needed for #3303. Some code written by SATOH Fumiyasu included in the changes to locking/locking.c. The smbstatus output is a bit of a mess and needs overhauling... Jeremy. --- source/Makefile.in | 2 +- source/include/smb.h | 1 + source/libsmb/smb_share_modes.c | 37 ++++++++++++++++-- source/locking/locking.c | 84 ++++++++++++++++++++++++++++++++--------- source/smbd/close.c | 4 +- source/smbd/open.c | 15 +++++--- source/smbd/oplock.c | 6 +-- source/smbd/trans2.c | 14 ++----- source/utils/status.c | 8 ++-- source/web/statuspage.c | 2 +- 10 files changed, 124 insertions(+), 49 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index 092d11bc80f..9d00cb72a1d 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -104,7 +104,7 @@ LIBMSRPC_MINOR=1 LIBSMBSHAREMODES=bin/libsmbsharemodes.a @LIBSMBSHAREMODES_SHARED@ LIBSMBSHAREMODES_MAJOR=0 -LIBSMBSHAREMODES_MINOR=1 +LIBSMBSHAREMODES_MINOR=2 FLAGS1 = $(CFLAGS) @FLAGS1@ -Iinclude -I$(srcdir)/include -I$(srcdir)/tdb @SMBWRAP_INC@ -I. $(CPPFLAGS) -I$(srcdir) -D_SAMBA_BUILD_ FLAGS2 = diff --git a/source/include/smb.h b/source/include/smb.h index a3dce53a4ca..6e995b81988 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -629,6 +629,7 @@ struct share_mode_entry { }; struct share_mode_lock { + const char *servicepath; /* canonicalized. */ const char *filename; SMB_DEV_T dev; SMB_INO_T ino; diff --git a/source/libsmb/smb_share_modes.c b/source/libsmb/smb_share_modes.c index 40ccf15f946..43f25cd3787 100644 --- a/source/libsmb/smb_share_modes.c +++ b/source/libsmb/smb_share_modes.c @@ -255,11 +255,12 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, * Create an entry in the Samba share mode db. */ -int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, +int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *new_entry, - const char *filename) /* Must be abolute utf8 path. */ + const char *sharepath, /* Must be absolute utf8 path. */ + const char *filename) /* Must be relative utf8 path. */ { TDB_DATA db_data; TDB_DATA locking_key = get_locking_key(dev, ino); @@ -272,7 +273,9 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + strlen(filename) + 1); + db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + + strlen(sharepath) + 1 + + strlen(filename) + 1); if (!db_data.dptr) { return -1; } @@ -281,11 +284,18 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, ld->u.s.delete_on_close = 0; shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); + memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry), + sharepath, + strlen(sharepath) + 1); + memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry) + + strlen(sharepath) + 1, filename, strlen(filename) + 1); - db_data.dsize = 2*sizeof(struct share_mode_entry) + strlen(filename) + 1; + db_data.dsize = 2*sizeof(struct share_mode_entry) + + strlen(sharepath) + 1 + + strlen(filename) + 1; if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) { free(db_data.dptr); return -1; @@ -336,6 +346,25 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, return 0; } +/* + * Create an entry in the Samba share mode db. Original interface - doesn't + * Distinguish between share path and filename. Fudge this by using a + * sharepath of / and a relative filename of (filename+1). + */ + +int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + const struct smb_share_mode_entry *new_entry, + const char *filename) /* Must be absolute utf8 path. */ +{ + if (*filename != '/') { + abort(); + } + return smb_create_share_mode_entry_ex(db_ctx, dev, ino, new_entry, + "/", &filename[1]); +} + int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, diff --git a/source/locking/locking.c b/source/locking/locking.c index 322824ea2f4..2debc2c23e5 100644 --- a/source/locking/locking.c +++ b/source/locking/locking.c @@ -464,10 +464,15 @@ static BOOL parse_share_modes(TDB_DATA dbuf, struct share_mode_lock *lck) } } - /* Save off the associated filename. */ + /* Save off the associated service path and filename. */ + lck->servicepath = talloc_strdup(lck, dbuf.dptr + sizeof(*data) + + (lck->num_share_modes * + sizeof(struct share_mode_entry))); + lck->filename = talloc_strdup(lck, dbuf.dptr + sizeof(*data) + - lck->num_share_modes * - sizeof(struct share_mode_entry)); + (lck->num_share_modes * + sizeof(struct share_mode_entry)) + + strlen(lck->servicepath) + 1 ); /* * Ensure that each entry has a real process attached. @@ -495,6 +500,7 @@ static TDB_DATA unparse_share_modes(struct share_mode_lock *lck) int i; struct locking_data *data; ssize_t offset; + ssize_t sp_len; result.dptr = NULL; result.dsize = 0; @@ -509,8 +515,11 @@ static TDB_DATA unparse_share_modes(struct share_mode_lock *lck) return result; } + sp_len = strlen(lck->servicepath); + result.dsize = sizeof(*data) + lck->num_share_modes * sizeof(struct share_mode_entry) + + sp_len + 1 + strlen(lck->filename) + 1; result.dptr = talloc_size(lck, result.dsize); @@ -529,6 +538,9 @@ static TDB_DATA unparse_share_modes(struct share_mode_lock *lck) sizeof(struct share_mode_entry)*lck->num_share_modes); offset = sizeof(*data) + sizeof(struct share_mode_entry)*lck->num_share_modes; + safe_strcpy(result.dptr + offset, lck->servicepath, + result.dsize - offset - 1); + offset += sp_len + 1; safe_strcpy(result.dptr + offset, lck->filename, result.dsize - offset - 1); print_share_mode_table(data); @@ -569,8 +581,9 @@ static int share_mode_lock_destructor(void *p) } struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, - SMB_DEV_T dev, SMB_INO_T ino, - const char *fname) + SMB_DEV_T dev, SMB_INO_T ino, + const char *servicepath, + const char *fname) { struct share_mode_lock *lck; TDB_DATA key = locking_key(dev, ino); @@ -599,13 +612,15 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, lck->fresh = (data.dptr == NULL); if (lck->fresh) { - if (fname == NULL) { - DEBUG(0, ("New file, but no filename supplied\n")); + + if (fname == NULL || servicepath == NULL) { + DEBUG(0, ("New file, but no filename or servicepath supplied\n")); talloc_free(lck); return NULL; } lck->filename = talloc_strdup(lck, fname); - if (lck->filename == NULL) { + lck->servicepath = talloc_strdup(lck, servicepath); + if (lck->filename == NULL || lck->servicepath == NULL) { DEBUG(0, ("talloc failed\n")); talloc_free(lck); return NULL; @@ -625,12 +640,41 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, return lck; } -BOOL get_delete_on_close_flag(SMB_DEV_T dev, SMB_INO_T inode, - const char *fname) +/******************************************************************* + Sets the service name and filename for rename. + At this point we should emit "rename" smbd messages to all + interested process id's. +********************************************************************/ + +BOOL rename_share_filename(struct share_mode_lock *lck, + const char *servicepath, + const char *newname) +{ + /* + * rename_internal_fsp() and rename_internals() add './' to + * head of newname if newname does not contain a '/'. + */ + while (newname[0] && newname[1] && newname[0] == '.' && newname[1] == '/') { + newname += 2; + } + + lck->filename = talloc_strdup(lck, newname); + lck->servicepath = talloc_strdup(lck, servicepath); + if (lck->filename == NULL || lck->servicepath == NULL) { + DEBUG(0, ("rename_share_filename: talloc failed\n")); + return False; + } + lck->modified = True; + return True; +} + +BOOL get_delete_on_close_flag(SMB_DEV_T dev, SMB_INO_T inode) { BOOL result; - struct share_mode_lock *lck = get_share_mode_lock(NULL, dev, inode, - fname); + struct share_mode_lock *lck = get_share_mode_lock(NULL, dev, inode, NULL, NULL); + if (!lck) { + return False; + } result = lck->delete_on_close; talloc_free(lck); return result; @@ -964,7 +1008,7 @@ BOOL set_delete_on_close(files_struct *fsp, BOOL delete_on_close) return True; } - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { return False; } @@ -982,9 +1026,10 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, { struct locking_data *data; struct share_mode_entry *shares; - char *name; + const char *sharepath; + const char *fname; int i; - void (*traverse_callback)(struct share_mode_entry *, char *) = state; + void (*traverse_callback)(struct share_mode_entry *, const char *, const char *) = state; /* Ensure this is a locking_key record. */ if (kbuf.dsize != sizeof(struct locking_key)) @@ -992,11 +1037,14 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, data = (struct locking_data *)dbuf.dptr; shares = (struct share_mode_entry *)(dbuf.dptr + sizeof(*data)); - name = dbuf.dptr + sizeof(*data) + + sharepath = dbuf.dptr + sizeof(*data) + data->u.s.num_share_mode_entries*sizeof(*shares); + fname = dbuf.dptr + sizeof(*data) + + data->u.s.num_share_mode_entries*sizeof(*shares) + + strlen(sharepath) + 1; for (i=0;iu.s.num_share_mode_entries;i++) { - traverse_callback(&shares[i], name); + traverse_callback(&shares[i], sharepath, fname); } return 0; } @@ -1006,7 +1054,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, share mode system. ********************************************************************/ -int share_mode_forall(void (*fn)(const struct share_mode_entry *, char *)) +int share_mode_forall(void (*fn)(const struct share_mode_entry *, const char *, const char *)) { if (tdb == NULL) return 0; diff --git a/source/smbd/close.c b/source/smbd/close.c index 43049a46a4d..d84b9f925bf 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -192,7 +192,7 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close) * This prevents race conditions with the file being created. JRA. */ - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { DEBUG(0, ("close_file: Could not get share mode lock for file %s\n", fsp->fsp_name)); @@ -305,7 +305,7 @@ static int close_directory(files_struct *fsp, BOOL normal_close) * reference to a directory also. */ - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { DEBUG(0, ("close_directory: Could not get share mode lock for %s\n", fsp->fsp_name)); diff --git a/source/smbd/open.c b/source/smbd/open.c index 42e1da839fb..b3f0589dc7b 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -1123,8 +1123,7 @@ files_struct *open_file_ntcreate(connection_struct *conn, spurious oplock break. */ /* Now remove the deferred open entry under lock. */ - lck = get_share_mode_lock(NULL, state->dev, state->inode, - fname); + lck = get_share_mode_lock(NULL, state->dev, state->inode, NULL, NULL); if (lck == NULL) { DEBUG(0, ("could not get share mode lock\n")); } else { @@ -1334,7 +1333,9 @@ files_struct *open_file_ntcreate(connection_struct *conn, dev = psbuf->st_dev; inode = psbuf->st_ino; - lck = get_share_mode_lock(NULL, dev, inode, fname); + lck = get_share_mode_lock(NULL, dev, inode, + conn->connectpath, + fname); if (lck == NULL) { DEBUG(0, ("Could not get share mode lock\n")); @@ -1533,7 +1534,9 @@ files_struct *open_file_ntcreate(connection_struct *conn, dev = fsp->dev; inode = fsp->inode; - lck = get_share_mode_lock(NULL, dev, inode, fname); + lck = get_share_mode_lock(NULL, dev, inode, + conn->connectpath, + fname); if (lck == NULL) { DEBUG(0, ("open_file_ntcreate: Could not get share mode lock for %s\n", fname)); @@ -1940,7 +1943,9 @@ files_struct *open_directory(connection_struct *conn, fsp->is_stat = False; string_set(&fsp->fsp_name,fname); - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, fname); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, + conn->connectpath, + fname); if (lck == NULL) { DEBUG(0, ("open_directory: Could not get share mode lock for %s\n", fname)); diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c index 385f998b1ce..f6c97c3df48 100644 --- a/source/smbd/oplock.c +++ b/source/smbd/oplock.c @@ -182,7 +182,7 @@ BOOL remove_oplock(files_struct *fsp) struct share_mode_lock *lck; /* Remove the oplock flag from the sharemode. */ - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { DEBUG(0,("remove_oplock: failed to lock share entry for " "file %s\n", fsp->fsp_name )); @@ -210,7 +210,7 @@ BOOL downgrade_oplock(files_struct *fsp) BOOL ret; struct share_mode_lock *lck; - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { DEBUG(0,("downgrade_oplock: failed to lock share entry for " "file %s\n", fsp->fsp_name )); @@ -627,7 +627,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp) if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) return; - lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL); + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); if (lck == NULL) { DEBUG(0,("release_level_2_oplocks_on_change: failed to lock " "share mode entry for file %s.\n", fsp->fsp_name )); diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c index ee6bed9afdf..c165ea18629 100644 --- a/source/smbd/trans2.c +++ b/source/smbd/trans2.c @@ -2824,10 +2824,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char * return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath); } - delete_pending = - get_delete_on_close_flag(sbuf.st_dev, - sbuf.st_ino, - fname); + delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino); } else { /* * Original code - this is an open file. @@ -2840,10 +2837,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char * return(UNIXERROR(ERRDOS,ERRbadfid)); } pos = fsp->fh->position_information; - delete_pending = - get_delete_on_close_flag(sbuf.st_dev, - sbuf.st_ino, - fname); + delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino); access_mask = fsp->access_mask; } } else { @@ -2885,9 +2879,7 @@ static int call_trans2qfilepathinfo(connection_struct *conn, char *inbuf, char * return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath); } - delete_pending = get_delete_on_close_flag(sbuf.st_dev, - sbuf.st_ino, - fname); + delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino); if (delete_pending) { return ERROR_NT(NT_STATUS_DELETE_PENDING); } diff --git a/source/utils/status.c b/source/utils/status.c index a495d07f047..2c5756106a2 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -98,13 +98,13 @@ static BOOL Ucrit_addPid( pid_t pid ) return True; } -static void print_share_mode(const struct share_mode_entry *e, char *fname) +static void print_share_mode(const struct share_mode_entry *e, const char *sharepath, const char *fname) { static int count; if (count==0) { d_printf("Locked files:\n"); - d_printf("Pid DenyMode Access R/W Oplock Name\n"); - d_printf("--------------------------------------------------------------\n"); + d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); + d_printf("----------------------------------------------------------------------------------\n"); } count++; @@ -150,7 +150,7 @@ static void print_share_mode(const struct share_mode_entry *e, char *fname) d_printf("NONE "); } - d_printf(" %s %s",fname, asctime(localtime((time_t *)&e->time.tv_sec))); + d_printf(" %s %s %s",sharepath, fname, asctime(localtime((time_t *)&e->time.tv_sec))); } } diff --git a/source/web/statuspage.c b/source/web/statuspage.c index 6447f95bac4..24d7eaf72e7 100644 --- a/source/web/statuspage.c +++ b/source/web/statuspage.c @@ -106,7 +106,7 @@ static char *tstring(time_t t) return buf; } -static void print_share_mode(const struct share_mode_entry *e, char *fname) +static void print_share_mode(const struct share_mode_entry *e, const char *sharepath, const char *fname) { char *utf8_fname; int deny_mode = map_share_mode_to_deny_mode(e->share_access, -- cgit From 79abeca82bce37a2e5e3ad50434d3a5f10add378 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Dec 2005 18:11:50 +0000 Subject: r12213: Final fix for #3303 - send rename messages to smbd's that have open file handles to allow them to correctly implement delete on close. There is a further correctness fix I'm intending to add to this to cope with different share paths, but not right now... Jeremy. --- source/include/messages.h | 1 + source/include/smb.h | 6 +++++ source/locking/locking.c | 56 ++++++++++++++++++++++++++++++++++++++++++++--- source/smbd/close.c | 45 +++++++++++++++++++++++++++---------- source/smbd/open.c | 47 +++++++++++++++++++++++++++++++++++++++ source/smbd/reply.c | 28 +++++++++++++++++++----- source/smbd/server.c | 1 + source/smbd/service.c | 5 ++++- 8 files changed, 169 insertions(+), 20 deletions(-) diff --git a/source/include/messages.h b/source/include/messages.h index abe219374ed..4b1732d42d1 100644 --- a/source/include/messages.h +++ b/source/include/messages.h @@ -68,6 +68,7 @@ #define MSG_SMB_ASYNC_LEVEL2_BREAK 3008 #define MSG_SMB_OPEN_RETRY 3009 #define MSG_SMB_KERNEL_BREAK 3010 +#define MSG_SMB_FILE_RENAME 3011 /* winbind messages */ #define MSG_WINBIND_FINISHED 4001 diff --git a/source/include/smb.h b/source/include/smb.h index 6e995b81988..fc256c6f698 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -1459,6 +1459,12 @@ struct kernel_oplock_message { unsigned long file_id; }; +struct file_renamed_message { + SMB_DEV_T dev; + SMB_INO_T inode; + char names[1]; /* A variable area containing sharepath and filename. */ +}; + /* * On the wire return values for oplock types. */ diff --git a/source/locking/locking.c b/source/locking/locking.c index 2debc2c23e5..d89fe931ef6 100644 --- a/source/locking/locking.c +++ b/source/locking/locking.c @@ -642,14 +642,24 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, /******************************************************************* Sets the service name and filename for rename. - At this point we should emit "rename" smbd messages to all - interested process id's. + At this point we emit "file renamed" messages to all + process id's that have this file open. + Based on an initial code idea from SATOH Fumiyasu ********************************************************************/ BOOL rename_share_filename(struct share_mode_lock *lck, const char *servicepath, const char *newname) { + struct file_renamed_message *frm = NULL; + size_t sp_len; + size_t fn_len; + size_t msg_len; + int i; + + DEBUG(10, ("rename_share_filename: servicepath %s newname %s\n", + servicepath, newname)); + /* * rename_internal_fsp() and rename_internals() add './' to * head of newname if newname does not contain a '/'. @@ -658,13 +668,53 @@ BOOL rename_share_filename(struct share_mode_lock *lck, newname += 2; } - lck->filename = talloc_strdup(lck, newname); lck->servicepath = talloc_strdup(lck, servicepath); + lck->filename = talloc_strdup(lck, newname); if (lck->filename == NULL || lck->servicepath == NULL) { DEBUG(0, ("rename_share_filename: talloc failed\n")); return False; } lck->modified = True; + + sp_len = strlen(lck->servicepath); + fn_len = strlen(lck->filename); + + msg_len = sizeof(*frm) + sp_len + 1 + fn_len + 1; + + /* Set up the name changed message. */ + frm = TALLOC(lck, msg_len); + if (!frm) { + return False; + } + frm->dev = lck->dev; + frm->inode = lck->ino; + + DEBUG(10,("rename_share_filename: msg_len = %d\n", msg_len )); + + safe_strcpy(&frm->names[0], lck->servicepath, sp_len); + safe_strcpy(&frm->names[sp_len + 1], lck->filename, fn_len); + + /* Send the messages. */ + for (i=0; inum_share_modes; i++) { + struct share_mode_entry *se = &lck->share_modes[i]; + if (!is_valid_share_mode_entry(se)) { + continue; + } + /* But not to ourselves... */ + if (procid_is_me(&se->pid)) { + continue; + } + + DEBUG(10,("rename_share_filename: sending rename message to pid %u " + "dev %x, inode %.0f sharepath %s newname %s\n", + (unsigned int)procid_to_pid(&se->pid), + (unsigned int)frm->dev, (double)frm->inode, + lck->servicepath, lck->filename )); + + message_send_pid(se->pid, MSG_SMB_FILE_RENAME, + frm, msg_len, True); + } + return True; } diff --git a/source/smbd/close.c b/source/smbd/close.c index d84b9f925bf..407c6078385 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -227,20 +227,43 @@ static int close_normal_file(files_struct *fsp, BOOL normal_close) */ if (normal_close && delete_file) { + SMB_STRUCT_STAT sbuf; + DEBUG(5,("close_file: file %s. Delete on close was set - deleting file.\n", fsp->fsp_name)); - if(SMB_VFS_UNLINK(conn,fsp->fsp_name) != 0) { - /* - * This call can potentially fail as another smbd may have - * had the file open with delete on close set and deleted - * it when its last reference to this file went away. Hence - * we log this but not at debug level zero. - */ - - DEBUG(5,("close_file: file %s. Delete on close was set and unlink failed \ -with error %s\n", fsp->fsp_name, strerror(errno) )); + + /* We can only delete the file if the name we have + is still valid and hasn't been renamed. */ + + if(SMB_VFS_STAT(conn,fsp->fsp_name,&sbuf) != 0) { + DEBUG(5,("close_file: file %s. Delete on close was set " + "and stat failed with error %s\n", + fsp->fsp_name, strerror(errno) )); + } else { + if(sbuf.st_dev != fsp->dev || sbuf.st_ino != fsp->inode) { + DEBUG(5,("close_file: file %s. Delete on close was set and " + "dev and/or inode does not match\n", + fsp->fsp_name )); + DEBUG(5,("close_file: file %s. stored dev = %x, inode = %.0f " + "stat dev = %x, inode = %.0f\n", + fsp->fsp_name, + (unsigned int)fsp->dev, (double)fsp->inode, + (unsigned int)sbuf.st_dev, (double)sbuf.st_ino )); + + } else if(SMB_VFS_UNLINK(conn,fsp->fsp_name) != 0) { + /* + * This call can potentially fail as another smbd may have + * had the file open with delete on close set and deleted + * it when its last reference to this file went away. Hence + * we log this but not at debug level zero. + */ + + DEBUG(5,("close_file: file %s. Delete on close was set " + "and unlink failed with error %s\n", + fsp->fsp_name, strerror(errno) )); + } + process_pending_change_notify_queue((time_t)0); } - process_pending_change_notify_queue((time_t)0); } talloc_free(lck); diff --git a/source/smbd/open.c b/source/smbd/open.c index b3f0589dc7b..7621ee001dd 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -2042,3 +2042,50 @@ files_struct *open_file_stat(connection_struct *conn, char *fname, return fsp; } + +/**************************************************************************** + Receive notification that one of our open files has been renamed by another + smbd process. +****************************************************************************/ + +void msg_file_was_renamed(int msg_type, struct process_id src, void *buf, size_t len) +{ + files_struct *fsp; + struct file_renamed_message *frm = (struct file_renamed_message *)buf; + const char *sharepath; + const char *newname; + size_t sp_len; + + if (buf == NULL || len < sizeof(*frm)) { + DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n", (int)len)); + return; + } + + sharepath = &frm->names[0]; + newname = sharepath + strlen(sharepath) + 1; + sp_len = strlen(sharepath); + + DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, " + "dev %x, inode %.0f\n", + sharepath, newname, (unsigned int)frm->dev, (double)frm->inode )); + + for(fsp = file_find_di_first(frm->dev, frm->inode); fsp; fsp = file_find_di_next(fsp)) { + if (memcmp(fsp->conn->connectpath, sharepath, sp_len) == 0) { + DEBUG(10,("msg_file_was_renamed: renaming file fnum %d from %s -> %s\n", + fsp->fnum, fsp->fsp_name, newname )); + string_set(&fsp->fsp_name, newname); + } else { + /* TODO. JRA. */ + /* Now we have the complete path we can work out if this is + actually within this share and adjust newname accordingly. */ + DEBUG(10,("msg_file_was_renamed: share mismatch (sharepath %s " + "not sharepath %s) " + "fnum %d from %s -> %s\n", + fsp->conn->connectpath, + sharepath, + fsp->fnum, + fsp->fsp_name, + newname )); + } + } +} diff --git a/source/smbd/reply.c b/source/smbd/reply.c index d3739c8847f..5ddba4c2bf3 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -4082,13 +4082,15 @@ static BOOL resolve_wildcards(const char *name1, char *name2) } /**************************************************************************** - Ensure open files have their names updates. + Ensure open files have their names updated. Updated to notify other smbd's + asynchronously. ****************************************************************************/ -static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T inode, char *newname) +static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T inode, const char *newname) { files_struct *fsp; BOOL did_rename = False; + struct share_mode_lock *lck = NULL; for(fsp = file_find_di_first(dev, inode); fsp; fsp = file_find_di_next(fsp)) { DEBUG(10,("rename_open_files: renaming file fnum %d (dev = %x, inode = %.0f) from %s -> %s\n", @@ -4098,9 +4100,24 @@ static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T did_rename = True; } - if (!did_rename) + if (!did_rename) { DEBUG(10,("rename_open_files: no open files on dev %x, inode %.0f for %s\n", (unsigned int)dev, (double)inode, newname )); + } + + /* Notify all remote smbd's. */ + lck = get_share_mode_lock(NULL, dev, inode, NULL, NULL); + if (lck == NULL) { + DEBUG(5,("rename_open_files: Could not get share mode lock for file %s\n", + fsp->fsp_name)); + return; + } + + /* Change the stored filename. */ + rename_share_filename(lck, conn->connectpath, newname); + + /* Send messages to all smbd's (not ourself) that the name has changed. */ + talloc_free(lck); } /**************************************************************************** @@ -4238,10 +4255,11 @@ NTSTATUS rename_internals_fsp(connection_struct *conn, files_struct *fsp, char * return NT_STATUS_OK; } - if (errno == ENOTDIR || errno == EISDIR) + if (errno == ENOTDIR || errno == EISDIR) { error = NT_STATUS_OBJECT_NAME_COLLISION; - else + } else { error = map_nt_error_from_unix(errno); + } DEBUG(3,("rename_internals_fsp: Error %s rename %s -> %s\n", nt_errstr(error), fsp->fsp_name,newname)); diff --git a/source/smbd/server.c b/source/smbd/server.c index 1bf9dbc374a..304f1b588e2 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -330,6 +330,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_ message_register(MSG_SMB_SAM_SYNC, msg_sam_sync); message_register(MSG_SMB_SAM_REPL, msg_sam_repl); message_register(MSG_SHUTDOWN, msg_exit_server); + message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed); /* now accept incoming connections - forking a new process for each incoming connection */ diff --git a/source/smbd/service.c b/source/smbd/service.c index 210edde5d8f..c9e2cdcf50c 100644 --- a/source/smbd/service.c +++ b/source/smbd/service.c @@ -44,7 +44,7 @@ void set_conn_connectpath(connection_struct *conn, const pstring connectpath) while (*s == '/') { s++; } - if ((d != destname) && (*s != '\0')) { + if ((d > destname + 1) && (*s != '\0')) { *d++ = '/'; } start_of_name_component = True; @@ -119,6 +119,9 @@ void set_conn_connectpath(connection_struct *conn, const pstring connectpath) *(d-1) = '\0'; } + DEBUG(10,("set_conn_connectpath: service %s, connectpath = %s\n", + lp_servicename(SNUM(conn)), destname )); + string_set(&conn->connectpath, destname); } -- cgit From 21395dedf6481e413383e6c62ab90d05302d4f13 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Dec 2005 19:37:05 +0000 Subject: r12214: Fix compile if SYNC_DNS is set. Jeremy. --- source/nmbd/asyncdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/nmbd/asyncdns.c b/source/nmbd/asyncdns.c index c0626d11619..c8caa3fee29 100644 --- a/source/nmbd/asyncdns.c +++ b/source/nmbd/asyncdns.c @@ -323,7 +323,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) struct in_addr dns_ip; unstring qname; - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); -- cgit From e2c4837c58bbbfcaabebeec513c3cf1796a9b123 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Dec 2005 00:42:40 +0000 Subject: r12221: Fix error code paths that can potentially leave a dangling lock. Jeremy. --- source/locking/locking.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/locking/locking.c b/source/locking/locking.c index d89fe931ef6..b823b4712e7 100644 --- a/source/locking/locking.c +++ b/source/locking/locking.c @@ -595,12 +595,18 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, return NULL; } + /* Ensure we set every field here as the destructor must be + valid even if parse_share_modes fails. */ + + lck->servicepath = NULL; + lck->filename = NULL; lck->dev = dev; lck->ino = ino; - lck->delete_on_close = False; lck->num_share_modes = 0; lck->share_modes = NULL; + lck->delete_on_close = False; lck->modified = False; + lck->fresh = False; if (tdb_chainlock(tdb, key) != 0) { DEBUG(3, ("Could not lock share entry\n")); @@ -608,6 +614,12 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, return NULL; } + /* We must set the destructor immediately after the chainlock + ensure the lock is cleaned up on any of the error return + paths below. */ + + talloc_set_destructor(lck, share_mode_lock_destructor); + data = tdb_fetch(tdb, key); lck->fresh = (data.dptr == NULL); @@ -634,7 +646,6 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, } } - talloc_set_destructor(lck, share_mode_lock_destructor); SAFE_FREE(data.dptr); return lck; -- cgit From 5a6cef8dccef985c4e48d58919a17d92a3b61dd7 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 14 Dec 2005 01:09:46 +0000 Subject: r12224: adding more characters to the invalid share name string --- source/rpc_server/srv_srvsvc_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index 1d574d82fb1..090aa4c9ff2 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -29,7 +29,7 @@ extern struct generic_mapping file_generic_mapping; #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV -#define INVALID_SHARENAME_CHARS "<>*?|" +#define INVALID_SHARENAME_CHARS "<>*?|/\\+=;:\"," /******************************************************************** Check a string for any occurrences of a specified list of invalid -- cgit From 2fa58d4c218401afa894dd9ed8d93edd8710cd6a Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 14 Dec 2005 04:00:58 +0000 Subject: r12225: r11729@cabra: derrell | 2005-12-13 22:59:45 -0500 1. Fix a crash bug which should have reared its ugly head ages ago, but for some reason, remained dormant until recently. The bug pertained to libsmbclient doing a structure assignment of a cli after having opened a pipe. The pipe open code makes a copy of the cli pointer that was passed to it. If the cli is later copied (and that cli pointer that was saved is no longer valid), the pipe code will cause a crash during shutdown or when the copied cli is closed. 2. The 'type' field in enumerated shares was not being set correctly with the new RPC-based mechanism for enumerating shares. --- examples/libsmbclient/testbrowse2.c | 2 +- source/libsmb/clientgen.c | 12 +++--- source/libsmb/libsmbclient.c | 73 +++++++++++++++++++++++-------------- source/rpc_client/cli_pipe.c | 9 +++++ 4 files changed, 63 insertions(+), 33 deletions(-) diff --git a/examples/libsmbclient/testbrowse2.c b/examples/libsmbclient/testbrowse2.c index a3d2cf3b8e2..76d98b9602a 100644 --- a/examples/libsmbclient/testbrowse2.c +++ b/examples/libsmbclient/testbrowse2.c @@ -85,7 +85,7 @@ void smbc_auth_fn( strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; strncpy(user, username, userlen - 1); user[userlen - 1] = 0; - strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; + strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; } SMBCCTX* create_smbctx(){ diff --git a/source/libsmb/clientgen.c b/source/libsmb/clientgen.c index 6dc7386c03b..2f980adcf87 100644 --- a/source/libsmb/clientgen.c +++ b/source/libsmb/clientgen.c @@ -358,11 +358,13 @@ struct cli_state *cli_initialise(struct cli_state *cli) void cli_rpc_pipe_close(struct rpc_pipe_client *cli) { if (!cli_close(cli->cli, cli->fnum)) { - DEBUG(0,("cli_rpc_pipe_close: cli_close failed on pipe %s " - "to machine %s. Error was %s\n", - cli->pipe_name, - cli->cli->desthost, - cli_errstr(cli->cli))); + DEBUG(0,("cli_rpc_pipe_close: cli_close failed on pipe %s, " + "fnum 0x%x " + "to machine %s. Error was %s\n", + cli->pipe_name, + (int) cli->fnum, + cli->cli->desthost, + cli_errstr(cli->cli))); } if (cli->auth.cli_auth_data_free_func) { diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 32282cb6a64..ba57c03abad 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -82,7 +82,6 @@ static int DLIST_CONTAINS(SMBCFILE * list, SMBCFILE *p) { /* * Find an lsa pipe handle associated with a cli struct. */ - static struct rpc_pipe_client *find_lsa_pipe_hnd(struct cli_state *ipc_cli) { struct rpc_pipe_client *pipe_hnd; @@ -855,14 +854,27 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, return NULL; } + ipc_srv = SMB_MALLOC_P(SMBCSRV); + if (!ipc_srv) { + errno = ENOMEM; + cli_shutdown(ipc_cli); + return NULL; + } + + ZERO_STRUCTP(ipc_srv); + ipc_srv->cli = *ipc_cli; + + free(ipc_cli); + if (pol) { - pipe_hnd = cli_rpc_pipe_open_noauth(ipc_cli, + pipe_hnd = cli_rpc_pipe_open_noauth(&ipc_srv->cli, PI_LSARPC, &nt_status); if (!pipe_hnd) { DEBUG(1, ("cli_nt_session_open fail!\n")); errno = ENOTSUP; - cli_shutdown(ipc_cli); + cli_shutdown(&ipc_srv->cli); + free(ipc_srv); return NULL; } @@ -874,30 +886,18 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, nt_status = rpccli_lsa_open_policy( pipe_hnd, - ipc_cli->mem_ctx, + ipc_srv->cli.mem_ctx, True, GENERIC_EXECUTE_ACCESS, pol); if (!NT_STATUS_IS_OK(nt_status)) { - errno = smbc_errno(context, ipc_cli); - cli_shutdown(ipc_cli); + errno = smbc_errno(context, &ipc_srv->cli); + cli_shutdown(&ipc_srv->cli); return NULL; } } - ipc_srv = SMB_MALLOC_P(SMBCSRV); - if (!ipc_srv) { - errno = ENOMEM; - cli_shutdown(ipc_cli); - return NULL; - } - - ZERO_STRUCTP(ipc_srv); - ipc_srv->cli = *ipc_cli; - - free(ipc_cli); - /* now add it to the cache (internal or external) */ errno = 0; /* let cache function set errno if it likes */ @@ -2191,12 +2191,23 @@ list_fn(const char *name, uint32 type, const char *comment, void *state) SMBCFILE *dir = (SMBCFILE *)state; int dirent_type; - /* We need to process the type a little ... */ - + /* + * We need to process the type a little ... + * + * Disk share = 0x00000000 + * Print share = 0x00000001 + * Comms share = 0x00000002 (obsolete?) + * IPC$ share = 0x00000003 + * + * administrative shares: + * ADMIN$, IPC$, C$, D$, E$ ... are type |= 0x80000000 + */ + if (dir->dir_type == SMBC_FILE_SHARE) { switch (type) { - case 0: /* Directory tree */ + case 0 | 0x80000000: + case 0: dirent_type = SMBC_FILE_SHARE; break; @@ -2208,6 +2219,7 @@ list_fn(const char *name, uint32 type, const char *comment, void *state) dirent_type = SMBC_COMMS_SHARE; break; + case 3 | 0x80000000: case 3: dirent_type = SMBC_IPC_SHARE; break; @@ -2217,7 +2229,9 @@ list_fn(const char *name, uint32 type, const char *comment, void *state) break; } } - else dirent_type = dir->dir_type; + else { + dirent_type = dir->dir_type; + } if (add_dirent(dir, name, comment, dirent_type) < 0) { @@ -2252,15 +2266,16 @@ net_share_enum_rpc(struct cli_state *cli, { int i; WERROR result; - NTSTATUS nt_status; ENUM_HND enum_hnd; uint32 info_level = 1; uint32 preferred_len = 0xffffffff; + uint32 type; SRV_SHARE_INFO_CTR ctr; fstring name = ""; fstring comment = ""; void *mem_ctx; struct rpc_pipe_client *pipe_hnd; + NTSTATUS nt_status; /* Open the server service pipe */ pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &nt_status); @@ -2273,6 +2288,7 @@ net_share_enum_rpc(struct cli_state *cli, mem_ctx = talloc_init("libsmbclient: net_share_enum_rpc"); if (mem_ctx == NULL) { DEBUG(0, ("out of memory for net_share_enum_rpc!\n")); + cli_rpc_pipe_close(pipe_hnd); return -1; } @@ -2302,14 +2318,17 @@ net_share_enum_rpc(struct cli_state *cli, rpcstr_pull_unistr2_fstring( comment, &ctr.share.info1[i].info_1_str.uni_remark); + /* Get the type value */ + type = ctr.share.info1[i].info_1.type; + /* Add this share to the list */ - (*fn)(name, SMBC_FILE_SHARE, comment, state); + (*fn)(name, type, comment, state); } - /* We're done with the pipe */ - cli_rpc_pipe_close(pipe_hnd); - done: + /* Close the server service pipe */ + cli_rpc_pipe_close(pipe_hnd); + /* Free all memory which was allocated for this request */ talloc_free(mem_ctx); diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c index 7965aee8074..41266838a87 100644 --- a/source/rpc_client/cli_pipe.c +++ b/source/rpc_client/cli_pipe.c @@ -2150,6 +2150,15 @@ static NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli, /**************************************************************************** Open a named pipe over SMB to a remote server. + * + * CAVEAT CALLER OF THIS FUNCTION: + * The returned rpc_pipe_client saves a copy of the cli_state cli pointer, + * so be sure that this function is called AFTER any structure (vs pointer) + * assignment of the cli. In particular, libsmbclient does structure + * assignments of cli, which invalidates the data in the returned + * rpc_pipe_client if this function is called before the structure assignment + * of cli. + * ****************************************************************************/ static struct rpc_pipe_client *cli_rpc_pipe_open(struct cli_state *cli, int pipe_idx, NTSTATUS *perr) -- cgit From 9073054c4b984fbd5c9f40a37aa2cefcde087a92 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Dec 2005 17:46:29 +0000 Subject: r12234: Reduce the race condition for renames by holding the lock longer. Instigated by complaints on the fix for #3303 from SATOH Fumiyasu . Jeremy. --- source/locking/locking.c | 6 +++++- source/smbd/reply.c | 48 +++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/source/locking/locking.c b/source/locking/locking.c index b823b4712e7..07377831b4a 100644 --- a/source/locking/locking.c +++ b/source/locking/locking.c @@ -605,8 +605,8 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx, lck->num_share_modes = 0; lck->share_modes = NULL; lck->delete_on_close = False; - lck->modified = False; lck->fresh = False; + lck->modified = False; if (tdb_chainlock(tdb, key) != 0) { DEBUG(3, ("Could not lock share entry\n")); @@ -668,6 +668,10 @@ BOOL rename_share_filename(struct share_mode_lock *lck, size_t msg_len; int i; + if (!lck) { + return False; + } + DEBUG(10, ("rename_share_filename: servicepath %s newname %s\n", servicepath, newname)); diff --git a/source/smbd/reply.c b/source/smbd/reply.c index 5ddba4c2bf3..063cdf2974e 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -4086,13 +4086,20 @@ static BOOL resolve_wildcards(const char *name1, char *name2) asynchronously. ****************************************************************************/ -static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T inode, const char *newname) +static void rename_open_files(connection_struct *conn, struct share_mode_lock *lck, + SMB_DEV_T dev, SMB_INO_T inode, const char *newname) { files_struct *fsp; BOOL did_rename = False; - struct share_mode_lock *lck = NULL; for(fsp = file_find_di_first(dev, inode); fsp; fsp = file_find_di_next(fsp)) { + /* fsp_name is a relative path under the fsp. To change this for other + sharepaths we need to manipulate relative paths. */ + /* TODO - create the absolute path and manipulate the newname + relative to the sharepath. */ + if (fsp->conn != conn) { + continue; + } DEBUG(10,("rename_open_files: renaming file fnum %d (dev = %x, inode = %.0f) from %s -> %s\n", fsp->fnum, (unsigned int)fsp->dev, (double)fsp->inode, fsp->fsp_name, newname )); @@ -4105,19 +4112,8 @@ static void rename_open_files(connection_struct *conn, SMB_DEV_T dev, SMB_INO_T (unsigned int)dev, (double)inode, newname )); } - /* Notify all remote smbd's. */ - lck = get_share_mode_lock(NULL, dev, inode, NULL, NULL); - if (lck == NULL) { - DEBUG(5,("rename_open_files: Could not get share mode lock for file %s\n", - fsp->fsp_name)); - return; - } - - /* Change the stored filename. */ - rename_share_filename(lck, conn->connectpath, newname); - /* Send messages to all smbd's (not ourself) that the name has changed. */ - talloc_free(lck); + rename_share_filename(lck, conn->connectpath, newname); } /**************************************************************************** @@ -4161,6 +4157,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn, files_struct *fsp, char * NTSTATUS error = NT_STATUS_OK; BOOL dest_exists; BOOL rcdest = True; + struct share_mode_lock *lck = NULL; ZERO_STRUCT(sbuf); rcdest = unix_convert(newname,conn,newname_last_component,&bad_path,&sbuf); @@ -4248,13 +4245,18 @@ NTSTATUS rename_internals_fsp(connection_struct *conn, files_struct *fsp, char * return NT_STATUS_ACCESS_DENIED; } + lck = get_share_mode_lock(NULL, fsp->dev, fsp->inode, NULL, NULL); + if(SMB_VFS_RENAME(conn,fsp->fsp_name, newname) == 0) { DEBUG(3,("rename_internals_fsp: succeeded doing rename on %s -> %s\n", fsp->fsp_name,newname)); - rename_open_files(conn, fsp->dev, fsp->inode, newname); + rename_open_files(conn, lck, fsp->dev, fsp->inode, newname); + talloc_free(lck); return NT_STATUS_OK; } + talloc_free(lck); + if (errno == ENOTDIR || errno == EISDIR) { error = NT_STATUS_OBJECT_NAME_COLLISION; } else { @@ -4286,6 +4288,7 @@ NTSTATUS rename_internals(connection_struct *conn, char *name, char *newname, ui BOOL rc = True; BOOL rcdest = True; SMB_STRUCT_STAT sbuf1, sbuf2; + struct share_mode_lock *lck = NULL; *directory = *mask = 0; @@ -4456,7 +4459,7 @@ directory = %s, newname = %s, last_component_dest = %s, is_8_3 = %d\n", */ if (strcsequal(directory, newname)) { - rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname); + rename_open_files(conn, NULL, sbuf1.st_dev, sbuf1.st_ino, newname); DEBUG(3,("rename_internals: identical names in rename %s - returning success\n", directory)); return NT_STATUS_OK; } @@ -4471,13 +4474,17 @@ directory = %s, newname = %s, last_component_dest = %s, is_8_3 = %d\n", return NT_STATUS_SHARING_VIOLATION; } + lck = get_share_mode_lock(NULL, sbuf1.st_dev, sbuf1.st_ino, NULL, NULL); + if(SMB_VFS_RENAME(conn,directory, newname) == 0) { DEBUG(3,("rename_internals: succeeded doing rename on %s -> %s\n", directory,newname)); - rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname); + rename_open_files(conn, lck, sbuf1.st_dev, sbuf1.st_ino, newname); + talloc_free(lck); return NT_STATUS_OK; } + talloc_free(lck); if (errno == ENOTDIR || errno == EISDIR) error = NT_STATUS_OBJECT_NAME_COLLISION; else @@ -4555,7 +4562,7 @@ directory = %s, newname = %s, last_component_dest = %s, is_8_3 = %d\n", } if (strcsequal(fname,destname)) { - rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname); + rename_open_files(conn, NULL, sbuf1.st_dev, sbuf1.st_ino, newname); DEBUG(3,("rename_internals: identical names in wildcard rename %s - success\n", fname)); count++; error = NT_STATUS_OK; @@ -4573,11 +4580,14 @@ directory = %s, newname = %s, last_component_dest = %s, is_8_3 = %d\n", return NT_STATUS_SHARING_VIOLATION; } + lck = get_share_mode_lock(NULL, sbuf1.st_dev, sbuf1.st_ino, NULL, NULL); + if (!SMB_VFS_RENAME(conn,fname,destname)) { - rename_open_files(conn, sbuf1.st_dev, sbuf1.st_ino, newname); + rename_open_files(conn, lck, sbuf1.st_dev, sbuf1.st_ino, newname); count++; error = NT_STATUS_OK; } + talloc_free(lck); DEBUG(3,("rename_internals: doing rename on %s -> %s\n",fname,destname)); } CloseDir(dir_hnd); -- cgit From bdda2dfd5c0794398985cf2a0cde6002b0315308 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 14 Dec 2005 18:15:54 +0000 Subject: r12235: r11738@cabra: derrell | 2005-12-14 13:15:14 -0500 Ensure that when libsmbclient copies a cli, it prevents the cli from later being freed, by turning off the 'allocated' flag. Change a DEBUG message in pipe_open code from level 0 to level 1 since libsmbclient is now regularly attempting to open a pipe for share enumeration, and falling back to RAP if RPC is unavailable (e.g. win98). We don't want the debug message to display when the pipe open fails, under these normal circumstances. --- source/libsmb/libsmbclient.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index ba57c03abad..15210664b07 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -774,6 +774,7 @@ SMBCSRV *smbc_server(SMBCCTX *context, ZERO_STRUCTP(srv); srv->cli = c; + srv->cli.allocated = False; srv->dev = (dev_t)(str_checksum(server) ^ str_checksum(share)); srv->no_pathinfo = False; srv->no_pathinfo2 = False; @@ -863,6 +864,7 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, ZERO_STRUCTP(ipc_srv); ipc_srv->cli = *ipc_cli; + ipc_srv->cli.allocated = False; free(ipc_cli); -- cgit From d21e0563b738cfb9ebe5366c917862bf248dee6f Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 14 Dec 2005 18:17:05 +0000 Subject: r12236: r11740@cabra: derrell | 2005-12-14 13:16:58 -0500 check in the DEBUG message referenced in the previous commit --- source/rpc_client/cli_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c index 41266838a87..e1143e63423 100644 --- a/source/rpc_client/cli_pipe.c +++ b/source/rpc_client/cli_pipe.c @@ -2189,7 +2189,7 @@ static struct rpc_pipe_client *cli_rpc_pipe_open(struct cli_state *cli, int pipe fnum = cli_nt_create(cli, result->pipe_name, DESIRED_ACCESS_PIPE); if (fnum == -1) { - DEBUG(0,("cli_rpc_pipe_open: cli_nt_create failed on pipe %s " + DEBUG(1,("cli_rpc_pipe_open: cli_nt_create failed on pipe %s " "to machine %s. Error was %s\n", result->pipe_name, cli->desthost, cli_errstr(cli))); -- cgit From d2953944e0c812b2a6e3ba953b1308b1460100c8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Dec 2005 20:39:42 +0000 Subject: r12245: eDirectory returns LDAP_UNWILLING_TO_PERFORM if the account is disabled. If we get this we can't check the password so have to tell the client the account was disabled. Jeremy. --- source/passdb/pdb_nds.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/passdb/pdb_nds.c b/source/passdb/pdb_nds.c index c6d644827c7..1ec96932231 100644 --- a/source/passdb/pdb_nds.c +++ b/source/passdb/pdb_nds.c @@ -824,6 +824,15 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods, case LDAP_INVALID_CREDENTIALS: nt_status = NT_STATUS_WRONG_PASSWORD; break; + case LDAP_UNWILLING_TO_PERFORM: + /* eDir returns this if the account was disabled. */ + /* The problem is we don't know if the given + password was correct for this account or + not. We have to return more info than we + should and tell the client NT_STATUS_ACCOUNT_DISABLED + so they don't think the password was bad. JRA. */ + nt_status = NT_STATUS_ACCOUNT_DISABLED; + break; default: break; } -- cgit From 7c73d046e3f10e2c3e129677e686ac7900efe0d5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Dec 2005 23:52:58 +0000 Subject: r12250: Patch from Martin Koeppe for #3287 to make the dev/inode numbers match what SFU expects. If we're using 8 byte inodes we'll lose the top 4 bytes and replace them with a dev_t instead, but this seem reasonable to ensure uniqueness. Jeremy. --- source/smbd/trans2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c index c165ea18629..6a4b7111cdb 100644 --- a/source/smbd/trans2.c +++ b/source/smbd/trans2.c @@ -1436,8 +1436,8 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn, p +=4; } SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */ - SIVAL(p,0,sbuf.st_dev); p += 4; - SIVAL(p,0,sbuf.st_ino); p += 4; + SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */ + SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */ len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII); SIVAL(q, 0, len); p += len; @@ -1486,8 +1486,8 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn, } p += 26; SSVAL(p,0,0); p += 2; /* Reserved ? */ - SIVAL(p,0,sbuf.st_dev); p += 4; - SIVAL(p,0,sbuf.st_ino); p += 4; + SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */ + SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */ len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII); SIVAL(q,0,len); p += len; @@ -3216,8 +3216,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd BasicFileInformationTest. -tpot */ DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n")); - SIVAL(pdata,0,sbuf.st_dev); - SIVAL(pdata,4,sbuf.st_ino); + SIVAL(pdata,4,sbuf.st_ino); /* FileIndexLow */ + SIVAL(pdata,0,sbuf.st_dev); /* FileIndexHigh */ data_size = 8; break; -- cgit From 54f9c969187c55fecb40fa57b68154c7b2738406 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 15 Dec 2005 18:39:28 +0000 Subject: r12262: * patch from Brian Moran to fix segv in eventlogadm when not eventlogs are listed in smb.conf * initialize the local group description in set_alias_info() --- source/rpc_server/srv_samr_nt.c | 2 ++ source/utils/eventlogadm.c | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index 880e1db388d..c90b4d36600 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -4516,6 +4516,8 @@ NTSTATUS _samr_set_aliasinfo(pipes_struct *p, SAMR_Q_SET_ALIASINFO *q_u, SAMR_R_ ctr->alias.info3.description.string, sizeof(info.acct_desc)-1 ); } + else + fstrcpy( info.acct_desc, "" ); break; default: return NT_STATUS_INVALID_INFO_CLASS; diff --git a/source/utils/eventlogadm.c b/source/utils/eventlogadm.c index 1d60d6b7ea8..a0fc4bcf9d4 100644 --- a/source/utils/eventlogadm.c +++ b/source/utils/eventlogadm.c @@ -51,9 +51,13 @@ static void display_eventlog_names( void ) elogs = lp_eventlog_list( ); printf( "Active eventlog names (from smb.conf):\n" ); printf( "--------------------------------------\n" ); - for ( i = 0; elogs[i]; i++ ) { - printf( "\t%s\n", elogs[i] ); - } + if ( elogs ) { + for ( i = 0; elogs[i]; i++ ) { + printf( "\t%s\n", elogs[i] ); + } + } + else + printf( "\t\n"); } int DoAddSourceCommand( int argc, char **argv, BOOL debugflag, char *exename ) -- cgit From 57d02505e370e4abc150aad813c9e3c435b95bad Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 16 Dec 2005 00:01:15 +0000 Subject: r12273: Fix copy paste error. Guenther --- source/nsswitch/winbindd_sid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/nsswitch/winbindd_sid.c b/source/nsswitch/winbindd_sid.c index 2685e98555c..fc878cb5ccb 100644 --- a/source/nsswitch/winbindd_sid.c +++ b/source/nsswitch/winbindd_sid.c @@ -83,10 +83,10 @@ void winbindd_lookupname(struct winbindd_cli_state *state) char *p; /* Ensure null termination */ - state->request.data.sid[sizeof(state->request.data.name.dom_name)-1]='\0'; + state->request.data.name.dom_name[sizeof(state->request.data.name.dom_name)-1]='\0'; /* Ensure null termination */ - state->request.data.sid[sizeof(state->request.data.name.name)-1]='\0'; + state->request.data.name.name[sizeof(state->request.data.name.name)-1]='\0'; /* cope with the name being a fully qualified name */ p = strstr(state->request.data.name.name, lp_winbind_separator()); -- cgit From b7282c63471835b5ad4dd0e7de4556b2645361be Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Dec 2005 00:10:59 +0000 Subject: r12275: Fix memory leak found by Mikhail Kshevetskiy and followed up by derrell@samba.org. Jeremy. --- source/libsmb/clilist.c | 16 ++++++++++++++-- source/rpc_client/cli_pipe.c | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/libsmb/clilist.c b/source/libsmb/clilist.c index e09a6514ad9..252dafcfa8b 100644 --- a/source/libsmb/clilist.c +++ b/source/libsmb/clilist.c @@ -271,6 +271,10 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, it gives ERRSRV/ERRerror temprarily */ uint8 eclass; uint32 ecode; + + SAFE_FREE(rdata); + SAFE_FREE(rparam); + cli_dos_error(cli, &eclass, &ecode); if (eclass != ERRSRV || ecode != ERRerror) break; @@ -278,8 +282,11 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, continue; } - if (cli_is_error(cli) || !rdata || !rparam) + if (cli_is_error(cli) || !rdata || !rparam) { + SAFE_FREE(rdata); + SAFE_FREE(rparam); break; + } if (total_received == -1) total_received = 0; @@ -297,8 +304,11 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, ff_lastname = SVAL(p,6); } - if (ff_searchcount == 0) + if (ff_searchcount == 0) { + SAFE_FREE(rdata); + SAFE_FREE(rparam); break; + } /* point to the data bytes */ p = rdata; @@ -332,6 +342,8 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, if (!tdl) { DEBUG(0,("cli_list_new: Failed to expand dirlist\n")); + SAFE_FREE(rdata); + SAFE_FREE(rparam); break; } else { dirlist = tdl; diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c index e1143e63423..23c66acf26e 100644 --- a/source/rpc_client/cli_pipe.c +++ b/source/rpc_client/cli_pipe.c @@ -789,6 +789,8 @@ static NTSTATUS rpc_api_pipe(struct rpc_pipe_client *cli, (unsigned int)cli->fnum, cli_errstr(cli->cli))); ret = cli_get_nt_error(cli->cli); + SAFE_FREE(rparam); + SAFE_FREE(prdata); goto err; } -- cgit From a131e56b3b75b55f163ea659e38a67ecca5236f5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Dec 2005 01:41:12 +0000 Subject: r12279: unix_mask_match has been broken for *ever*... (How). Ensure it returns a BOOL. Jerry (and anyone else) please check this, I think all uses are now correct but could do with another set of eyes. Essential for 3.0.21 release. Jeremy. --- source/auth/pampass.c | 4 ++-- source/lib/util.c | 3 ++- source/modules/vfs_recycle.c | 2 +- source/smbd/chgpasswd.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/auth/pampass.c b/source/auth/pampass.c index 18d83ee3648..26b45c5ff8a 100644 --- a/source/auth/pampass.c +++ b/source/auth/pampass.c @@ -310,7 +310,7 @@ static int smb_pam_passchange_conv(int num_msg, DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: trying to match |%s| to |%s|\n", t->prompt, current_prompt )); - if (unix_wild_match(t->prompt, current_prompt) == 0) { + if (unix_wild_match(t->prompt, current_prompt)) { fstrcpy(current_reply, t->reply); DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_ON: We sent: %s\n", current_reply)); pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword); @@ -341,7 +341,7 @@ static int smb_pam_passchange_conv(int num_msg, DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: trying to match |%s| to |%s|\n", t->prompt, current_prompt )); - if (unix_wild_match(t->prompt, current_prompt) == 0) { + if (unix_wild_match(t->prompt, current_prompt)) { fstrcpy(current_reply, t->reply); DEBUG(10,("smb_pam_passchange_conv: PAM_PROMPT_ECHO_OFF: We sent: %s\n", current_reply)); pwd_sub(current_reply, udp->PAM_username, udp->PAM_password, udp->PAM_newpassword); diff --git a/source/lib/util.c b/source/lib/util.c index 677871e2d06..38878befc77 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -2640,6 +2640,7 @@ static BOOL unix_do_match(const char *regexp, const char *str) /******************************************************************* Simple case insensitive interface to a UNIX wildcard matcher. + Returns True if match, False if not. *******************************************************************/ BOOL unix_wild_match(const char *pattern, const char *string) @@ -2660,7 +2661,7 @@ BOOL unix_wild_match(const char *pattern, const char *string) if (strequal(p2,"*")) return True; - return unix_do_match(p2, s2) == 0; + return unix_do_match(p2, s2); } /********************************************************************** diff --git a/source/modules/vfs_recycle.c b/source/modules/vfs_recycle.c index 0abcc29bcf9..28593f4fbb7 100644 --- a/source/modules/vfs_recycle.c +++ b/source/modules/vfs_recycle.c @@ -319,7 +319,7 @@ static BOOL matchparam(const char **haystack_list, const char *needle) } for(i=0; haystack_list[i] ; i++) { - if(!unix_wild_match(haystack_list[i], needle)) { + if(unix_wild_match(haystack_list[i], needle)) { return True; } } diff --git a/source/smbd/chgpasswd.c b/source/smbd/chgpasswd.c index c1168583ae7..fed73db043f 100644 --- a/source/smbd/chgpasswd.c +++ b/source/smbd/chgpasswd.c @@ -263,7 +263,7 @@ static int expect(int master, char *issue, char *expected) pstrcpy( str, buffer); trim_char( str, ' ', ' '); - if ((match = (unix_wild_match(expected, str) == 0))) { + if ((match = unix_wild_match(expected, str)) == True) { /* Now data has started to return, lower timeout. */ timeout = lp_passwd_chat_timeout() * 100; } -- cgit From b5a7d2908699f1d5a04209f0fd3ee0c7a5449928 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 16 Dec 2005 01:41:25 +0000 Subject: r12281: adding a note about WINS and NetLogon not being remotely manageable --- source/services/services_db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/services/services_db.c b/source/services/services_db.c index c75cb38c48b..b3ba7fcc966 100644 --- a/source/services/services_db.c +++ b/source/services/services_db.c @@ -36,11 +36,11 @@ struct service_display_info { struct service_display_info builtin_svcs[] = { { "Spooler", "smbd", "Print Spooler", "Internal service for spooling files to print devices" }, - { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data" }, + { "NETLOGON", "smbd", "Net Logon", "File service providing access to policy and profile data (not remotely manageable)" }, { "RemoteRegistry", "smbd", "Remote Registry Service", "Internal service providing remote access to " "the Samba registry" }, { "WINS", "nmbd", "Windows Internet Name Service (WINS)", "Internal service providing a " - "NetBIOS point-to-point name server" }, + "NetBIOS point-to-point name server (not remotely manageable)" }, { NULL, NULL, NULL, NULL } }; -- cgit From ae16c88c495f8b4558b6b7bf1be6f0cda34706d0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 16 Dec 2005 15:58:31 +0000 Subject: r12290: Typo --- source/param/loadparm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index cdef0340618..ca47e48d8c8 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -2532,7 +2532,7 @@ BOOL lp_add_home(const char *pszHomename, int iDefaultService, string_set(&ServicePtrs[i]->comment, comment); } - /* set the browseable flag from the gloabl default */ + /* set the browseable flag from the global default */ ServicePtrs[i]->bBrowseable = sDefault.bBrowseable; -- cgit From 8731d7db4dd332afcb558f5b29caea589f2fea13 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 16 Dec 2005 16:16:52 +0000 Subject: r12291: Make getgroups_user static. Jeremy, there's a #ifdef'ed 0 call to this in your usershare code. We need to talk about what exactly what you intend to do here and in what scenarios. Volker --- source/lib/system_smbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lib/system_smbd.c b/source/lib/system_smbd.c index 1afd44b7091..6c65f61ad7a 100644 --- a/source/lib/system_smbd.c +++ b/source/lib/system_smbd.c @@ -190,8 +190,8 @@ static int sys_getgrouplist(const char *user, gid_t gid, gid_t *groups, int *grp return retval; } -BOOL getgroups_user(const char *user, gid_t primary_gid, - gid_t **ret_groups, size_t *p_ngroups) +static BOOL getgroups_user(const char *user, gid_t primary_gid, + gid_t **ret_groups, size_t *p_ngroups) { size_t ngrp; int max_grp; -- cgit From 22aa47d074cf90efeb168060fc4e057e53888796 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 17 Dec 2005 15:38:41 +0000 Subject: r12303: Move split_domain_and_name to util_getent.c and make it static there. Volker --- source/lib/username.c | 28 ---------------------------- source/lib/util_getent.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/source/lib/username.c b/source/lib/username.c index 1973a8c7c60..403a0bc09f3 100644 --- a/source/lib/username.c +++ b/source/lib/username.c @@ -35,34 +35,6 @@ static BOOL name_is_local(const char *name) return !(strchr_m(name, *lp_winbind_separator())); } -/***************************************************************** - Splits passed user or group name to domain and user/group name parts - Returns True if name was splitted and False otherwise. -*****************************************************************/ - -BOOL split_domain_and_name(const char *name, char *domain, char* username) -{ - char *p = strchr(name,*lp_winbind_separator()); - - - /* Parse a string of the form DOMAIN/user into a domain and a user */ - DEBUG(10,("split_domain_and_name: checking whether name |%s| local or not\n", name)); - - if (p) { - fstrcpy(username, p+1); - fstrcpy(domain, name); - domain[PTR_DIFF(p, name)] = 0; - } else if (lp_winbind_use_default_domain()) { - fstrcpy(username, name); - fstrcpy(domain, lp_workgroup()); - } else { - return False; - } - - DEBUG(10,("split_domain_and_name: all is fine, domain is |%s| and name is |%s|\n", domain, username)); - return True; -} - /**************************************************************************** Get a users home directory. ****************************************************************************/ diff --git a/source/lib/util_getent.c b/source/lib/util_getent.c index 475b0da87bf..7c045fccb22 100644 --- a/source/lib/util_getent.c +++ b/source/lib/util_getent.c @@ -239,6 +239,37 @@ static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_he return list_head; } +/***************************************************************** + Splits passed user or group name to domain and user/group name parts + Returns True if name was splitted and False otherwise. +*****************************************************************/ + +static BOOL split_domain_and_name(const char *name, char *domain, + char* username) +{ + char *p = strchr(name,*lp_winbind_separator()); + + + /* Parse a string of the form DOMAIN/user into a domain and a user */ + DEBUG(10,("split_domain_and_name: checking whether name |%s| local or " + "not\n", name)); + + if (p) { + fstrcpy(username, p+1); + fstrcpy(domain, name); + domain[PTR_DIFF(p, name)] = 0; + } else if (lp_winbind_use_default_domain()) { + fstrcpy(username, name); + fstrcpy(domain, lp_workgroup()); + } else { + return False; + } + + DEBUG(10,("split_domain_and_name: all is fine, domain is |%s| and " + "name is |%s|\n", domain, username)); + return True; +} + /**************************************************************** Get the list of UNIX users in a group. We have to enumerate the /etc/group file as some UNIX getgrnam() -- cgit From 808608bce7bd4f66be761c7cc4433d034c9eaf41 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 17 Dec 2005 16:31:04 +0000 Subject: r12305: Reformatting --- source/smbd/password.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/source/smbd/password.c b/source/smbd/password.c index 9ee721089c9..e4516be32bc 100644 --- a/source/smbd/password.c +++ b/source/smbd/password.c @@ -381,9 +381,14 @@ BOOL user_ok(const char *user,int snum, gid_t *groups, size_t n_groups) if (lp_invalid_users(snum)) { str_list_copy(&invalid, lp_invalid_users(snum)); - if (invalid && str_list_substitute(invalid, "%S", lp_servicename(snum))) { - if ( invalid && str_list_sub_basic(invalid, current_user_info.smb_name) ) { - ret = !user_in_list(user, (const char **)invalid, groups, n_groups); + if (invalid && + str_list_substitute(invalid, "%S", lp_servicename(snum))) { + if ( invalid && + str_list_sub_basic(invalid, + current_user_info.smb_name) ) { + ret = !user_in_list(user, + (const char **)invalid, + groups, n_groups); } } } @@ -392,9 +397,13 @@ BOOL user_ok(const char *user,int snum, gid_t *groups, size_t n_groups) if (ret && lp_valid_users(snum)) { str_list_copy(&valid, lp_valid_users(snum)); - if ( valid && str_list_substitute(valid, "%S", lp_servicename(snum)) ) { - if ( valid && str_list_sub_basic(valid, current_user_info.smb_name) ) { - ret = user_in_list(user, (const char **)valid, groups, n_groups); + if ( valid && + str_list_substitute(valid, "%S", lp_servicename(snum)) ) { + if ( valid && + str_list_sub_basic(valid, + current_user_info.smb_name) ) { + ret = user_in_list(user, (const char **)valid, + groups, n_groups); } } } @@ -403,8 +412,11 @@ BOOL user_ok(const char *user,int snum, gid_t *groups, size_t n_groups) if (ret && lp_onlyuser(snum)) { char **user_list = str_list_make (lp_username(snum), NULL); - if (user_list && str_list_substitute(user_list, "%S", lp_servicename(snum))) { - ret = user_in_list(user, (const char **)user_list, groups, n_groups); + if (user_list && + str_list_substitute(user_list, "%S", + lp_servicename(snum))) { + ret = user_in_list(user, (const char **)user_list, + groups, n_groups); } if (user_list) str_list_free (&user_list); } -- cgit From 6241a7b775e85fd8d469d5cc49202dfca8af06ac Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 17 Dec 2005 16:56:24 +0000 Subject: r12306: Reformatting --- source/lib/username.c | 107 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 38 deletions(-) diff --git a/source/lib/username.c b/source/lib/username.c index 403a0bc09f3..ecfd5fef9ef 100644 --- a/source/lib/username.c +++ b/source/lib/username.c @@ -238,7 +238,8 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) /* Try as given, if username wasn't originally lowercase */ if(strcmp(user, user2) != 0) { - DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n", user)); + DEBUG(5,("Trying _Get_Pwnam(), username as given is %s\n", + user)); ret = getpwnam_alloc(user); if(ret) goto done; @@ -247,7 +248,8 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) /* Try as uppercase, if username wasn't originally uppercase */ strupper_m(user2); if(strcmp(user, user2) != 0) { - DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n", user2)); + DEBUG(5,("Trying _Get_Pwnam(), username as uppercase is %s\n", + user2)); ret = getpwnam_alloc(user2); if(ret) goto done; @@ -255,11 +257,14 @@ static struct passwd *Get_Pwnam_internals(const char *user, char *user2) /* Try all combinations up to usernamelevel */ strlower_m(user2); - DEBUG(5,("Checking combinations of %d uppercase letters in %s\n", lp_usernamelevel(), user2)); - ret = uname_string_combinations(user2, getpwnam_alloc, lp_usernamelevel()); + DEBUG(5,("Checking combinations of %d uppercase letters in %s\n", + lp_usernamelevel(), user2)); + ret = uname_string_combinations(user2, getpwnam_alloc, + lp_usernamelevel()); done: - DEBUG(5,("Get_Pwnam_internals %s find user [%s]!\n",ret ? "did":"didn't", user)); + DEBUG(5,("Get_Pwnam_internals %s find user [%s]!\n",ret ? + "did":"didn't", user)); return ret; } @@ -374,7 +379,8 @@ static BOOL user_in_netgroup_list(const char *user, const char *ngname) Check if a user is in a winbind group. ****************************************************************************/ -static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL *winbind_answered) +static BOOL user_in_winbind_group_list(const char *user, const char *gname, + BOOL *winbind_answered) { int i; gid_t gid, gid_low, gid_high; @@ -386,13 +392,14 @@ static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL *winbind_answered = False; if ((gid = nametogid(gname)) == (gid_t)-1) { - DEBUG(0,("user_in_winbind_group_list: nametogid for group %s failed.\n", - gname )); + DEBUG(0,("user_in_winbind_group_list: nametogid for group %s " + "failed.\n", gname )); goto err; } if (!lp_idmap_gid(&gid_low, &gid_high)) { - DEBUG(4, ("winbind gid range not configured, therefore %s cannot be a winbind group\n", gname)); + DEBUG(4, ("winbind gid range not configured, therefore %s " + "cannot be a winbind group\n", gname)); goto err; } @@ -432,7 +439,8 @@ static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL } else - DEBUG(10,("user_in_winbind_group_list: using cached user groups for [%s]\n", user)); + DEBUG(10,("user_in_winbind_group_list: using cached user " + "groups for [%s]\n", user)); if ( DEBUGLEVEL >= 10 ) { DEBUG(10,("user_in_winbind_group_list: using groups -- ")); @@ -442,8 +450,9 @@ static BOOL user_in_winbind_group_list(const char *user, const char *gname, BOOL } /* - * Now we have the gid list for this user - convert the gname - * to a gid_t via either winbind or the local UNIX lookup and do the comparison. + * Now we have the gid list for this user - convert the gname to a + * gid_t via either winbind or the local UNIX lookup and do the + * comparison. */ for (i = 0; i < num_groups; i++) { @@ -474,7 +483,8 @@ BOOL user_in_unix_group_list(const char *user,const char *gname) struct sys_userlist *user_list; struct sys_userlist *member; - DEBUG(10,("user_in_unix_group_list: checking user %s in group %s\n", user, gname)); + DEBUG(10,("user_in_unix_group_list: checking user %s in group %s\n", + user, gname)); /* * We need to check the users primary group as this @@ -483,20 +493,22 @@ BOOL user_in_unix_group_list(const char *user,const char *gname) if (pass) { if (strequal(gname,gidtoname(pass->pw_gid))) { - DEBUG(10,("user_in_unix_group_list: group %s is primary group.\n", gname )); + DEBUG(10,("user_in_unix_group_list: group %s is " + "primary group.\n", gname )); return True; } } user_list = get_users_in_group(gname); if (user_list == NULL) { - DEBUG(10,("user_in_unix_group_list: no such group %s\n", gname )); + DEBUG(10,("user_in_unix_group_list: no such group %s\n", + gname )); return False; } for (member = user_list; member; member = member->next) { - DEBUG(10,("user_in_unix_group_list: checking user %s against member %s\n", - user, member->unix_name )); + DEBUG(10,("user_in_unix_group_list: checking user %s against " + "member %s\n", user, member->unix_name )); if (strequal(member->unix_name,user)) { free_userlist(user_list); return(True); @@ -511,7 +523,8 @@ BOOL user_in_unix_group_list(const char *user,const char *gname) Check if a user is in a group list. Ask winbind first, then use UNIX. ****************************************************************************/ -BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, size_t n_groups) +BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, + size_t n_groups) { BOOL winbind_answered = False; BOOL ret; @@ -538,7 +551,8 @@ BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, size ret = user_in_unix_group_list(user, gname); if (ret) - DEBUG(10,("user_in_group_list: user |%s| is in group |%s|\n", user, gname)); + DEBUG(10,("user_in_group_list: user |%s| is in group |%s|\n", + user, gname)); return ret; } @@ -547,7 +561,8 @@ BOOL user_in_group_list(const char *user, const char *gname, gid_t *groups, size and netgroup lists. ****************************************************************************/ -BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_groups) +BOOL user_in_list(const char *user,const char **list, gid_t *groups, + size_t n_groups) { if (!list || !*list) return False; @@ -556,7 +571,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr while (*list) { - DEBUG(10,("user_in_list: checking user |%s| against |%s|\n", user, *list)); + DEBUG(10,("user_in_list: checking user |%s| against |%s|\n", + user, *list)); /* * Check raw username. @@ -576,7 +592,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr */ if(user_in_netgroup_list(user, *list +1)) return True; - if(user_in_group_list(user, *list +1, groups, n_groups)) + if(user_in_group_list(user, *list +1, groups, + n_groups)) return True; } else if (**list == '+') { @@ -584,7 +601,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr /* * Search UNIX list followed by netgroup. */ - if(user_in_group_list(user, *list +2, groups, n_groups)) + if(user_in_group_list(user, *list +2, groups, + n_groups)) return True; if(user_in_netgroup_list(user, *list +2)) return True; @@ -595,7 +613,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr * Just search UNIX list. */ - if(user_in_group_list(user, *list +1, groups, n_groups)) + if(user_in_group_list(user, *list +1, groups, + n_groups)) return True; } @@ -607,7 +626,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr */ if(user_in_netgroup_list(user, *list +2)) return True; - if(user_in_group_list(user, *list +2, groups, n_groups)) + if(user_in_group_list(user, *list +2, groups, + n_groups)) return True; } else { /* @@ -618,8 +638,8 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr } } else if (!name_is_local(*list)) { /* - * If user name did not match and token is not - * a unix group and the token has a winbind separator in the + * If user name did not match and token is not a unix + * group and the token has a winbind separator in the * name then see if it is a Windows group. */ @@ -629,31 +649,42 @@ BOOL user_in_list(const char *user,const char **list, gid_t *groups, size_t n_gr BOOL ret; fstring groupname, domain; - /* Parse a string of the form DOMAIN/user into a domain and a user */ + /* Parse a string of the form DOMAIN/user into a + * domain and a user */ char *p = strchr(*list,*lp_winbind_separator()); - DEBUG(10,("user_in_list: checking if user |%s| is in winbind group |%s|\n", user, *list)); + DEBUG(10,("user_in_list: checking if user |%s| is in " + "winbind group |%s|\n", user, *list)); if (p) { fstrcpy(groupname, p+1); fstrcpy(domain, *list); domain[PTR_DIFF(p, *list)] = 0; - /* Check to see if name is a Windows group; Win2k native mode DCs - will return domain local groups; while NT4 or mixed mode 2k DCs - will not */ + /* Check to see if name is a Windows group; + Win2k native mode DCs will return domain + local groups; while NT4 or mixed mode 2k + DCs will not */ - if ( winbind_lookup_name(domain, groupname, &g_sid, &name_type) - && ( name_type==SID_NAME_DOM_GRP || - (strequal(lp_workgroup(), domain) && name_type==SID_NAME_ALIAS) ) ) + if ( winbind_lookup_name(domain, groupname, + &g_sid, &name_type) + && ( name_type==SID_NAME_DOM_GRP || + (strequal(lp_workgroup(), domain) && + name_type==SID_NAME_ALIAS) ) ) { - /* Check if user name is in the Windows group */ - ret = user_in_winbind_group_list(user, *list, &winbind_answered); + /* Check if user name is in the + * Windows group */ + ret = user_in_winbind_group_list( + user, *list, + &winbind_answered); if (winbind_answered && ret == True) { - DEBUG(10,("user_in_list: user |%s| is in winbind group |%s|\n", user, *list)); + DEBUG(10,("user_in_list: user " + "|%s| is in winbind " + "group |%s|\n", + user, *list)); return ret; } } -- cgit From c4c420fd76310ec8bbc67755c8c06d980559d59a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 17 Dec 2005 17:13:45 +0000 Subject: r12307: Reformatting plus a trivial if/else simplification. There's no point in doing an else branch that only returns NULL. Volker --- source/smbd/service.c | 194 +++++++++++++++++++++++++++++++------------------- 1 file changed, 122 insertions(+), 72 deletions(-) diff --git a/source/smbd/service.c b/source/smbd/service.c index c9e2cdcf50c..c5fba5b50eb 100644 --- a/source/smbd/service.c +++ b/source/smbd/service.c @@ -366,7 +366,8 @@ static NTSTATUS share_sanity_checks(int snum, fstring dev) static connection_struct *make_connection_snum(int snum, user_struct *vuser, DATA_BLOB password, - const char *pdev, NTSTATUS *status) + const char *pdev, + NTSTATUS *status) { struct passwd *pass = NULL; BOOL guest = False; @@ -396,7 +397,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, guest = True; pass = getpwnam_alloc(guestname); if (!pass) { - DEBUG(0,("make_connection_snum: Invalid guest account %s??\n",guestname)); + DEBUG(0,("make_connection_snum: Invalid guest " + "account %s??\n",guestname)); conn_free(conn); *status = NT_STATUS_NO_SUCH_USER; return NULL; @@ -411,14 +413,20 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, } else if (vuser) { if (vuser->guest) { if (!lp_guest_ok(snum)) { - DEBUG(2, ("guest user (from session setup) not permitted to access this share (%s)\n", lp_servicename(snum))); + DEBUG(2, ("guest user (from session setup) " + "not permitted to access this share " + "(%s)\n", lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; return NULL; } } else { - if (!user_ok(vuser->user.unix_name, snum, vuser->groups, vuser->n_groups)) { - DEBUG(2, ("user '%s' (from session setup) not permitted to access this share (%s)\n", vuser->user.unix_name, lp_servicename(snum))); + if (!user_ok(vuser->user.unix_name, snum, + vuser->groups, vuser->n_groups)) { + DEBUG(2, ("user '%s' (from session setup) not " + "permitted to access this share " + "(%s)\n", vuser->user.unix_name, + lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; return NULL; @@ -465,12 +473,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, conn->service = snum; conn->used = True; conn->printer = (strncmp(dev,"LPT",3) == 0); - conn->ipc = ( (strncmp(dev,"IPC",3) == 0) || ( lp_enable_asu_support() && strequal(dev,"ADMIN$")) ); + conn->ipc = ( (strncmp(dev,"IPC",3) == 0) || + ( lp_enable_asu_support() && strequal(dev,"ADMIN$")) ); conn->dirptr = NULL; /* Case options for the share. */ if (lp_casesensitive(snum) == Auto) { - /* We will be setting this per packet. Set to be case insensitive for now. */ + /* We will be setting this per packet. Set to be case + * insensitive for now. */ conn->case_sensitive = False; } else { conn->case_sensitive = (BOOL)lp_casesensitive(snum); @@ -545,30 +555,30 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, pstring_sub(gname,"%S",lp_servicename(snum)); gid = nametogid(gname); - if (gid != (gid_t)-1) { - - /* - * If the user has been forced and the forced group starts - * with a '+', then we only set the group to be the forced - * group if the forced user is a member of that group. - * Otherwise, the meaning of the '+' would be ignored. - */ - if (conn->force_user && user_must_be_member) { - if (user_in_group_list( user, gname, NULL, 0)) { - conn->gid = gid; - DEBUG(3,("Forced group %s for member %s\n",gname,user)); - } - } else { - conn->gid = gid; - DEBUG(3,("Forced group %s\n",gname)); - } - conn->force_group = True; - } else { + if (gid == (gid_t)-1) { DEBUG(1,("Couldn't find group %s\n",gname)); conn_free(conn); *status = NT_STATUS_NO_SUCH_GROUP; return NULL; } + + /* + * If the user has been forced and the forced group starts + * with a '+', then we only set the group to be the forced + * group if the forced user is a member of that group. + * Otherwise, the meaning of the '+' would be ignored. + */ + if (conn->force_user && user_must_be_member) { + if (user_in_group_list( user, gname, NULL, 0)) { + conn->gid = gid; + DEBUG(3,("Forced group %s for member %s\n", + gname,user)); + } + } else { + conn->gid = gid; + DEBUG(3,("Forced group %s\n",gname)); + } + conn->force_group = True; } #endif /* HAVE_GETGRNAM */ @@ -577,7 +587,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, pstrcpy(s,lp_pathname(snum)); standard_sub_conn(conn,s,sizeof(s)); set_conn_connectpath(conn,s); - DEBUG(3,("Connect path is '%s' for service [%s]\n",s, lp_servicename(snum))); + DEBUG(3,("Connect path is '%s' for service [%s]\n",s, + lp_servicename(snum))); } if (conn->force_user || conn->force_group) { @@ -591,9 +602,10 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, initialise_groups(conn->user, conn->uid, conn->gid); get_current_groups(conn->gid, &conn->ngroups,&conn->groups); - conn->nt_user_token = create_nt_token(conn->uid, conn->gid, - conn->ngroups, conn->groups, - guest); + conn->nt_user_token = + create_nt_token(conn->uid, conn->gid, + conn->ngroups, conn->groups, + guest); } /* @@ -604,12 +616,16 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, */ { - BOOL can_write = share_access_check(conn, snum, vuser, FILE_WRITE_DATA); + BOOL can_write = share_access_check(conn, snum, vuser, + FILE_WRITE_DATA); if (!can_write) { - if (!share_access_check(conn, snum, vuser, FILE_READ_DATA)) { + if (!share_access_check(conn, snum, vuser, + FILE_READ_DATA)) { /* No access, read or write. */ - DEBUG(0,( "make_connection: connection to %s denied due to security descriptor.\n", + DEBUG(0,("make_connection: connection to %s " + "denied due to security " + "descriptor.\n", lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; @@ -622,18 +638,19 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, /* Initialise VFS function pointers */ if (!smbd_vfs_init(conn)) { - DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(snum))); + DEBUG(0, ("vfs_init failed for service %s\n", + lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_BAD_NETWORK_NAME; return NULL; } /* - * If widelinks are disallowed we need to canonicalise the - * connect path here to ensure we don't have any symlinks in - * the connectpath. We will be checking all paths on this - * connection are below this directory. We must do this after - * the VFS init as we depend on the realpath() pointer in the vfs table. JRA. + * If widelinks are disallowed we need to canonicalise the connect + * path here to ensure we don't have any symlinks in the + * connectpath. We will be checking all paths on this connection are + * below this directory. We must do this after the VFS init as we + * depend on the realpath() pointer in the vfs table. JRA. */ if (!lp_widelinks(snum)) { pstring s; @@ -654,7 +671,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, return NULL; } - /* Preexecs are done here as they might make the dir we are to ChDir to below */ + /* Preexecs are done here as they might make the dir we are to ChDir + * to below */ /* execute any "root preexec = " line */ if (*lp_rootpreexec(snum)) { pstring cmd; @@ -663,7 +681,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, DEBUG(5,("cmd=%s\n",cmd)); ret = smbrun(cmd,NULL); if (ret != 0 && lp_rootpreexec_close(snum)) { - DEBUG(1,("root preexec gave %d - failing connection\n", ret)); + DEBUG(1,("root preexec gave %d - failing " + "connection\n", ret)); yield_connection(conn, lp_servicename(snum)); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; @@ -681,9 +700,12 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, return NULL; } - /* Remember that a different vuid can connect later without these checks... */ + /* Remember that a different vuid can connect later without these + * checks... */ - /* Preexecs are done here as they might make the dir we are to ChDir to below */ + /* Preexecs are done here as they might make the dir we are to ChDir + * to below */ + /* execute any "preexec = " line */ if (*lp_preexec(snum)) { pstring cmd; @@ -691,7 +713,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, standard_sub_conn(conn,cmd,sizeof(cmd)); ret = smbrun(cmd,NULL); if (ret != 0 && lp_preexec_close(snum)) { - DEBUG(1,("preexec gave %d - failing connection\n", ret)); + DEBUG(1,("preexec gave %d - failing connection\n", + ret)); change_to_root_user(); yield_connection(conn, lp_servicename(snum)); conn_free(conn); @@ -713,8 +736,9 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, set_namearray( &conn->veto_oplock_list, lp_veto_oplocks(snum)); } - /* Invoke VFS make connection hook - do this before the VFS_STAT call to allow - any filesystems needing user credentials to initialize themselves. */ + /* Invoke VFS make connection hook - do this before the VFS_STAT call + to allow any filesystems needing user credentials to initialize + themselves. */ if (SMB_VFS_CONNECT(conn, lp_servicename(snum), user) < 0) { DEBUG(0,("make_connection: VFS make connection failed!\n")); @@ -730,12 +754,17 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, check during individual operations. To match this behaviour I have disabled this chdir check (tridge) */ /* the alternative is just to check the directory exists */ - if ((ret = SMB_VFS_STAT(conn, conn->connectpath, &st)) != 0 || !S_ISDIR(st.st_mode)) { + if ((ret = SMB_VFS_STAT(conn, conn->connectpath, &st)) != 0 || + !S_ISDIR(st.st_mode)) { if (ret == 0 && !S_ISDIR(st.st_mode)) { - DEBUG(0,("'%s' is not a directory, when connecting to [%s]\n", conn->connectpath, lp_servicename(snum))); + DEBUG(0,("'%s' is not a directory, when connecting to " + "[%s]\n", conn->connectpath, + lp_servicename(snum))); } else { - DEBUG(0,("'%s' does not exist or permission denied when connecting to [%s] " - "Error was %s\n", conn->connectpath, lp_servicename(snum), strerror(errno) )); + DEBUG(0,("'%s' does not exist or permission denied " + "when connecting to [%s] Error was %s\n", + conn->connectpath, lp_servicename(snum), + strerror(errno) )); } change_to_root_user(); /* Call VFS disconnect hook */ @@ -766,7 +795,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, */ if( DEBUGLVL( IS_IPC(conn) ? 3 : 1 ) ) { - dbgtext( "%s (%s) ", get_remote_machine_name(), conn->client_address ); + dbgtext( "%s (%s) ", get_remote_machine_name(), + conn->client_address ); dbgtext( "%s", srv_is_signing_active() ? "signed " : ""); dbgtext( "connect to service %s ", lp_servicename(snum) ); dbgtext( "initially as user %s ", user ); @@ -784,8 +814,10 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, vfs_chdir() **************************************************************************************/ -connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB password, - const char *dev, uint16 vuid, NTSTATUS *status) +connection_struct *make_connection_with_chdir(const char *service_in, + DATA_BLOB password, + const char *dev, uint16 vuid, + NTSTATUS *status) { connection_struct *conn = NULL; @@ -797,7 +829,8 @@ connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB */ if ( conn && vfs_ChDir(conn,conn->connectpath) != 0 ) { - DEBUG(0,("move_driver_to_download_area: Can't change directory to %s for [print$] (%s)\n", + DEBUG(0,("move_driver_to_download_area: Can't change " + "directory to %s for [print$] (%s)\n", conn->connectpath,strerror(errno))); yield_connection(conn, lp_servicename(SNUM(conn))); conn_free(conn); @@ -815,7 +848,8 @@ connection_struct *make_connection_with_chdir(const char *service_in, DATA_BLOB ****************************************************************************/ connection_struct *make_connection(const char *service_in, DATA_BLOB password, - const char *pdev, uint16 vuid, NTSTATUS *status) + const char *pdev, uint16 vuid, + NTSTATUS *status) { uid_t euid; user_struct *vuser = NULL; @@ -825,43 +859,52 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, fstrcpy(dev, pdev); - /* This must ONLY BE CALLED AS ROOT. As it exits this function as root. */ + /* This must ONLY BE CALLED AS ROOT. As it exits this function as + * root. */ if (!non_root_mode() && (euid = geteuid()) != 0) { - DEBUG(0,("make_connection: PANIC ERROR. Called as nonroot (%u)\n", (unsigned int)euid )); + DEBUG(0,("make_connection: PANIC ERROR. Called as nonroot " + "(%u)\n", (unsigned int)euid )); smb_panic("make_connection: PANIC ERROR. Called as nonroot\n"); } if(lp_security() != SEC_SHARE) { vuser = get_valid_user_struct(vuid); if (!vuser) { - DEBUG(1,("make_connection: refusing to connect with no session setup\n")); + DEBUG(1,("make_connection: refusing to connect with " + "no session setup\n")); *status = NT_STATUS_ACCESS_DENIED; return NULL; } } - /* Logic to try and connect to the correct [homes] share, preferably without too many - getpwnam() lookups. This is particulary nasty for winbind usernames, where the - share name isn't the same as unix username. + /* Logic to try and connect to the correct [homes] share, preferably + without too many getpwnam() lookups. This is particulary nasty for + winbind usernames, where the share name isn't the same as unix + username. - The snum of the homes share is stored on the vuser at session setup time. + The snum of the homes share is stored on the vuser at session setup + time. */ if (strequal(service_in,HOMES_NAME)) { if(lp_security() != SEC_SHARE) { DATA_BLOB no_pw = data_blob(NULL, 0); if (vuser->homes_snum == -1) { - DEBUG(2, ("[homes] share not available for this user because it was not found or created at session setup time\n")); + DEBUG(2, ("[homes] share not available for " + "this user because it was not found " + "or created at session setup " + "time\n")); *status = NT_STATUS_BAD_NETWORK_NAME; return NULL; } - DEBUG(5, ("making a connection to [homes] service created at session setup time\n")); + DEBUG(5, ("making a connection to [homes] service " + "created at session setup time\n")); return make_connection_snum(vuser->homes_snum, vuser, no_pw, dev, status); } else { - /* Security = share. Try with current_user_info.smb_name - * as the username. */ + /* Security = share. Try with + * current_user_info.smb_name as the username. */ if (*current_user_info.smb_name) { fstring unix_username; fstrcpy(unix_username, @@ -870,16 +913,20 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, snum = find_service(unix_username); } if (snum != -1) { - DEBUG(5, ("making a connection to 'homes' service %s based on security=share\n", service_in)); + DEBUG(5, ("making a connection to 'homes' " + "service %s based on " + "security=share\n", service_in)); return make_connection_snum(snum, NULL, password, dev, status); } } } else if ((lp_security() != SEC_SHARE) && (vuser->homes_snum != -1) - && strequal(service_in, lp_servicename(vuser->homes_snum))) { + && strequal(service_in, + lp_servicename(vuser->homes_snum))) { DATA_BLOB no_pw = data_blob(NULL, 0); - DEBUG(5, ("making a connection to 'homes' service [%s] created at session setup time\n", service_in)); + DEBUG(5, ("making a connection to 'homes' service [%s] " + "created at session setup time\n", service_in)); return make_connection_snum(vuser->homes_snum, vuser, no_pw, dev, status); @@ -893,7 +940,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, if (snum < 0) { if (strequal(service,"IPC$") - || (lp_enable_asu_support() && strequal(service,"ADMIN$"))) + || (lp_enable_asu_support() && + strequal(service,"ADMIN$"))) { DEBUG(3,("refusing IPC connection to %s\n", service)); *status = NT_STATUS_ACCESS_DENIED; @@ -908,7 +956,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, /* Handle non-Dfs clients attempting connections to msdfs proxy */ if (lp_host_msdfs() && (*lp_msdfs_proxy(snum) != '\0')) { - DEBUG(3, ("refusing connection to dfs proxy share '%s' (pointing to %s)\n", + DEBUG(3, ("refusing connection to dfs proxy share '%s' " + "(pointing to %s)\n", service, lp_msdfs_proxy(snum))); *status = NT_STATUS_BAD_NETWORK_NAME; return NULL; @@ -937,7 +986,8 @@ void close_cnum(connection_struct *conn, uint16 vuid) change_to_root_user(); DEBUG(IS_IPC(conn)?3:1, ("%s (%s) closed connection to service %s\n", - get_remote_machine_name(),conn->client_address, + get_remote_machine_name(), + conn->client_address, lp_servicename(SNUM(conn)))); /* Call VFS disconnect hook */ -- cgit From 0b0d370bc25e84de92fb79da77feb52051449080 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 17 Dec 2005 17:19:21 +0000 Subject: r12308: Reformatting --- source/smbd/service.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/smbd/service.c b/source/smbd/service.c index c5fba5b50eb..fb9dbf0489c 100644 --- a/source/smbd/service.c +++ b/source/smbd/service.c @@ -939,10 +939,8 @@ connection_struct *make_connection(const char *service_in, DATA_BLOB password, snum = find_service(service); if (snum < 0) { - if (strequal(service,"IPC$") - || (lp_enable_asu_support() && - strequal(service,"ADMIN$"))) - { + if (strequal(service,"IPC$") || + (lp_enable_asu_support() && strequal(service,"ADMIN$"))) { DEBUG(3,("refusing IPC connection to %s\n", service)); *status = NT_STATUS_ACCESS_DENIED; return NULL; -- cgit From 2eab3ad91c3128fcaacab04022bdec1093591972 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Dec 2005 13:54:53 +0000 Subject: r12311: Reformatting --- source/smbd/password.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/source/smbd/password.c b/source/smbd/password.c index e4516be32bc..764fbe8a2e9 100644 --- a/source/smbd/password.c +++ b/source/smbd/password.c @@ -521,19 +521,21 @@ BOOL authorise_login(int snum, fstring user, DATA_BLOB password, BOOL ok = False; #ifdef DEBUG_PASSWORD - DEBUG(100,("authorise_login: checking authorisation on user=%s pass=%s\n", - user,password.data)); + DEBUG(100,("authorise_login: checking authorisation on " + "user=%s pass=%s\n", user,password.data)); #endif *guest = False; /* there are several possibilities: 1) login as the given user with given password - 2) login as a previously registered username with the given password + 2) login as a previously registered username with the given + password 3) login as a session list username with the given password 4) login as a previously validated user/password pair 5) login as the "user =" user with given password - 6) login as the "user =" user with no password (guest connection) + 6) login as the "user =" user with no password + (guest connection) 7) login as guest user with no password if the service is guest_only then steps 1 to 5 are skipped @@ -562,11 +564,12 @@ BOOL authorise_login(int snum, fstring user, DATA_BLOB password, if (password_ok(user2,password)) { ok = True; fstrcpy(user,user2); - DEBUG(3,("authorise_login: ACCEPTED: session list username (%s) \ -and given password ok\n", user)); + DEBUG(3,("authorise_login: ACCEPTED: session " + "list username (%s) and given " + "password ok\n", user)); } } - + SAFE_FREE(user_list); } @@ -585,17 +588,21 @@ and given password ok\n", user)); if (auser) { ok = True; fstrcpy(user,auser); - DEBUG(3,("authorise_login: ACCEPTED: group username \ -and given password ok (%s)\n", user)); + DEBUG(3,("authorise_login: ACCEPTED: " + "group username and given " + "password ok (%s)\n", user)); } } else { fstring user2; fstrcpy(user2,auser); - if (user_ok(user2,snum, NULL, 0) && password_ok(user2,password)) { + if (user_ok(user2,snum, NULL, 0) && + password_ok(user2,password)) { ok = True; fstrcpy(user,user2); - DEBUG(3,("authorise_login: ACCEPTED: user list username \ -and given password ok (%s)\n", user)); + DEBUG(3,("authorise_login: ACCEPTED: " + "user list username and " + "given password ok (%s)\n", + user)); } } } @@ -608,10 +615,11 @@ and given password ok (%s)\n", user)); if (Get_Pwnam(guestname)) { fstrcpy(user,guestname); ok = True; - DEBUG(3,("authorise_login: ACCEPTED: guest account and guest ok (%s)\n", - user)); + DEBUG(3,("authorise_login: ACCEPTED: guest account " + "and guest ok (%s)\n", user)); } else { - DEBUG(0,("authorise_login: Invalid guest account %s??\n",guestname)); + DEBUG(0,("authorise_login: Invalid guest account " + "%s??\n",guestname)); } *guest = True; } -- cgit From d7489c327fee65703380bf0cc5ef62f5ee9855c8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Dec 2005 14:23:23 +0000 Subject: r12312: Reformatting and a trivial change: is_share_read_only_for_user only uses conn->service, so there's no point in passing down the whole conn struct. Volker --- source/smbd/uid.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/source/smbd/uid.c b/source/smbd/uid.c index d1ecaf6625f..458eb3a2c86 100644 --- a/source/smbd/uid.c +++ b/source/smbd/uid.c @@ -81,45 +81,53 @@ BOOL change_to_guest(void) Readonly share for this user ? ****************************************************************************/ -static BOOL is_share_read_only_for_user(connection_struct *conn, user_struct *vuser) +static BOOL is_share_read_only_for_user(int snum, user_struct *vuser) { char **list; - const char *service = lp_servicename(conn->service); - BOOL read_only_ret = lp_readonly(conn->service); + const char *service = lp_servicename(snum); + BOOL read_only_ret = lp_readonly(snum); if (!service) return read_only_ret; - str_list_copy(&list, lp_readlist(conn->service)); + str_list_copy(&list, lp_readlist(snum)); if (list) { if (!str_list_sub_basic(list, vuser->user.smb_name) ) { - DEBUG(0, ("is_share_read_only_for_user: ERROR: read list substitution failed\n")); + DEBUG(0, ("is_share_read_only_for_user: ERROR: read " + "list substitution failed\n")); } if (!str_list_substitute(list, "%S", service)) { - DEBUG(0, ("is_share_read_only_for_user: ERROR: read list service substitution failed\n")); + DEBUG(0, ("is_share_read_only_for_user: ERROR: read " + "list service substitution failed\n")); } - if (user_in_list(vuser->user.unix_name, (const char **)list, vuser->groups, vuser->n_groups)) { + if (user_in_list(vuser->user.unix_name, (const char **)list, + vuser->groups, vuser->n_groups)) { read_only_ret = True; } str_list_free(&list); } - str_list_copy(&list, lp_writelist(conn->service)); + str_list_copy(&list, lp_writelist(snum)); if (list) { if (!str_list_sub_basic(list, vuser->user.smb_name) ) { - DEBUG(0, ("is_share_read_only_for_user: ERROR: write list substitution failed\n")); + DEBUG(0, ("is_share_read_only_for_user: ERROR: write " + "list substitution failed\n")); } if (!str_list_substitute(list, "%S", service)) { - DEBUG(0, ("is_share_read_only_for_user: ERROR: write list service substitution failed\n")); + DEBUG(0, ("is_share_read_only_for_user: ERROR: write " + "list service substitution failed\n")); } - if (user_in_list(vuser->user.unix_name, (const char **)list, vuser->groups, vuser->n_groups)) { + if (user_in_list(vuser->user.unix_name, (const char **)list, + vuser->groups, vuser->n_groups)) { read_only_ret = False; } str_list_free(&list); } - DEBUG(10,("is_share_read_only_for_user: share %s is %s for unix user %s\n", - service, read_only_ret ? "read-only" : "read-write", vuser->user.unix_name )); + DEBUG(10,("is_share_read_only_for_user: share %s is %s for unix user " + "%s\n", service, + read_only_ret ? "read-only" : "read-write", + vuser->user.unix_name )); return read_only_ret; } @@ -146,7 +154,7 @@ static BOOL check_user_ok(connection_struct *conn, user_struct *vuser,int snum) if (!user_ok(vuser->user.unix_name,snum, vuser->groups, vuser->n_groups)) return(False); - readonly_share = is_share_read_only_for_user(conn, vuser); + readonly_share = is_share_read_only_for_user(conn->service, vuser); if (!readonly_share && !share_access_check(conn, snum, vuser, FILE_WRITE_DATA)) { -- cgit From 02bdf550a0bf4ec33ddd03f952afb18ce7ce632e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 18 Dec 2005 18:06:15 +0000 Subject: r12313: Introduce yet another copy of the string_sub function: talloc_string_sub. Someone with time on his hands could convert all the callers of all_string_sub to this. realloc_string_sub is *only* called from within substitute.c, it could be moved there I think. Volker --- source/auth/auth_util.c | 27 ++++++++------- source/lib/util_str.c | 74 +++++++++++++++++++++++++++++++++++++++++- source/nsswitch/winbindd_pam.c | 18 ++++++---- source/passdb/pdb_ldap.c | 3 +- 4 files changed, 101 insertions(+), 21 deletions(-) diff --git a/source/auth/auth_util.c b/source/auth/auth_util.c index 497f16adf2b..eb15fff7c8d 100644 --- a/source/auth/auth_util.c +++ b/source/auth/auth_util.c @@ -591,33 +591,36 @@ static NTSTATUS create_nt_user_token(const DOM_SID *user_sid, const DOM_SID *gro (strlen(lp_log_nt_token_command()) > 0)) { TALLOC_CTX *mem_ctx; char *command; - fstring sidstr; - char *user_sidstr, *group_sidstr; + char *group_sidstr; mem_ctx = talloc_init("setnttoken"); if (mem_ctx == NULL) return NT_STATUS_NO_MEMORY; - sid_to_string(sidstr, &ptoken->user_sids[0]); - user_sidstr = talloc_strdup(mem_ctx, sidstr); - group_sidstr = talloc_strdup(mem_ctx, ""); for (i=1; inum_sids; i++) { - sid_to_string(sidstr, &ptoken->user_sids[i]); - group_sidstr = talloc_asprintf(mem_ctx, "%s %s", - group_sidstr, sidstr); + group_sidstr = talloc_asprintf( + mem_ctx, "%s %s", group_sidstr, + sid_string_static(&ptoken->user_sids[i])); + } + + command = talloc_string_sub( + mem_ctx, lp_log_nt_token_command(), + "%s", sid_string_static(&ptoken->user_sids[0])); + command = talloc_string_sub( + mem_ctx, command, "%t", group_sidstr); + + if (command == NULL) { + talloc_destroy(mem_ctx); + return NT_STATUS_NO_MEMORY; } - command = SMB_STRDUP(lp_log_nt_token_command()); - command = realloc_string_sub(command, "%s", user_sidstr); - command = realloc_string_sub(command, "%t", group_sidstr); DEBUG(8, ("running command: [%s]\n", command)); if (smbrun(command, NULL) != 0) { DEBUG(0, ("Could not log NT token\n")); nt_status = NT_STATUS_ACCESS_DENIED; } talloc_destroy(mem_ctx); - SAFE_FREE(command); } *token = ptoken; diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 9b14dcfaf0f..80bb2ff2ad7 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -1003,7 +1003,8 @@ void pstring_sub(char *s,const char *pattern,const char *insert) as string. **/ -char *realloc_string_sub(char *string, const char *pattern, const char *insert) +char *realloc_string_sub(char *string, const char *pattern, + const char *insert) { char *p, *in; char *s; @@ -1063,6 +1064,77 @@ char *realloc_string_sub(char *string, const char *pattern, const char *insert) return string; } +/* Same as string_sub, but returns a talloc'ed string */ + +char *talloc_string_sub(TALLOC_CTX *mem_ctx, const char *src, + const char *pattern, const char *insert) +{ + char *p, *in; + char *s; + char *string; + ssize_t ls,lp,li,ld, i; + + if (!insert || !pattern || !*pattern || !src || !*src) + return NULL; + + string = talloc_strdup(mem_ctx, src); + if (string == NULL) { + DEBUG(0, ("talloc_strdup failed\n")); + return NULL; + } + + s = string; + + in = SMB_STRDUP(insert); + if (!in) { + DEBUG(0, ("talloc_string_sub: out of memory!\n")); + return NULL; + } + ls = (ssize_t)strlen(s); + lp = (ssize_t)strlen(pattern); + li = (ssize_t)strlen(insert); + ld = li - lp; + for (i=0;i 0) { + int offset = PTR_DIFF(s,string); + char *t = TALLOC_REALLOC(mem_ctx, string, ls + ld + 1); + if (!t) { + DEBUG(0, ("talloc_string_sub: out of " + "memory!\n")); + SAFE_FREE(in); + return NULL; + } + string = t; + p = t + offset + (p - s); + } + if (li != lp) { + memmove(p+li,p+lp,strlen(p+lp)+1); + } + memcpy(p, in, li); + s = p + li; + ls += ld; + } + SAFE_FREE(in); + return string; +} + /** Similar to string_sub() but allows for any character to be substituted. Use with caution! diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index e683f397b66..1d9b77afee1 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -419,16 +419,21 @@ done: if ( NT_STATUS_IS_OK(result) && (state->request.flags & WBFLAG_PAM_AFS_TOKEN) ) { - char *afsname = SMB_STRDUP(lp_afs_username_map()); + char *afsname = talloc_strdup(state->mem_ctx, + lp_afs_username_map()); char *cell; if (afsname == NULL) { goto no_token; } - afsname = realloc_string_sub(afsname, "%D", name_domain); - afsname = realloc_string_sub(afsname, "%u", name_user); - afsname = realloc_string_sub(afsname, "%U", name_user); + afsname = talloc_string_sub(state->mem_ctx, + lp_afs_username_map(), + "%D", name_domain); + afsname = talloc_string_sub(state->mem_ctx, afsname, + "%u", name_user); + afsname = talloc_string_sub(state->mem_ctx, afsname, + "%U", name_user); { DOM_SID user_sid; @@ -437,7 +442,8 @@ done: sid_copy(&user_sid, &info3.dom_sid.sid); sid_append_rid(&user_sid, info3.user_rid); sid_to_string(sidstr, &user_sid); - afsname = realloc_string_sub(afsname, "%s", sidstr); + afsname = talloc_string_sub(state->mem_ctx, afsname, + "%s", sidstr); } if (afsname == NULL) { @@ -466,7 +472,7 @@ done: strlen(state->response.extra_data)+1; no_token: - SAFE_FREE(afsname); + talloc_free(afsname); } return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR; diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 20cf2d328ec..cb0bc8eeb68 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3708,8 +3708,7 @@ char *get_ldap_filter(TALLOC_CTX *mem_ctx, const char *username) escaped = escape_ldap_string_alloc(username); if (escaped == NULL) goto done; - filter = realloc_string_sub(filter, "%u", username); - result = talloc_strdup(mem_ctx, filter); + result = talloc_string_sub(mem_ctx, filter, "%u", username); done: SAFE_FREE(filter); -- cgit From b62258ef42baf5f84a5b899aeb14377100138033 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 19 Dec 2005 02:15:13 +0000 Subject: r12336: A couple of fixes and enhancements for adssearch.pl (espc. to debug GPOs). sid2string fix from Michael James . Guenther --- examples/misc/adssearch.pl | 369 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 293 insertions(+), 76 deletions(-) diff --git a/examples/misc/adssearch.pl b/examples/misc/adssearch.pl index 9bfc9e8a055..f9a7f949262 100755 --- a/examples/misc/adssearch.pl +++ b/examples/misc/adssearch.pl @@ -55,6 +55,7 @@ my $realm = ""; # parse input my ( + $opt_asq, $opt_base, $opt_binddn, $opt_debug, @@ -77,10 +78,12 @@ my ( $opt_simpleauth, $opt_starttls, $opt_user, + $opt_verbose, $opt_workgroup, ); GetOptions( + 'asq=s' => \$opt_asq, 'base|b=s' => \$opt_base, 'D|DN=s' => \$opt_binddn, 'debug=i' => \$opt_debug, @@ -102,6 +105,7 @@ GetOptions( 'simpleauth|x' => \$opt_simpleauth, 'tls|Z' => \$opt_starttls, 'user|U=s' => \$opt_user, + 'verbose|v' => \$opt_verbose, 'wknguid' => \$opt_dump_wknguid, 'workgroup|k=s' => \$opt_workgroup, ); @@ -129,11 +133,12 @@ my ($sasl_hd, $async_ldap_hd, $sync_ldap_hd); my ($mesg, $usn); my (%entry_store); my $async_search; -my (%ads_atype, %ads_gtype, %ads_uf); +my (%ads_atype, %ads_gtype, %ads_grouptype, %ads_uf); # fixed values and vars my $set = "X"; my $unset = "-"; +my $tabsize = "\t\t\t"; # get defaults my $scope = $opt_scope || "sub"; @@ -219,9 +224,112 @@ my %ads_instance_type = ( ); my %ads_uacc = ( - "ACCOUNT_NEVER_EXPIRES" => 0x000000, # 0 - "ACCOUNT_OK" => 0x800000, # 8388608 - "ACCOUNT_LOCKED_OUT" => 0x800010, # 8388624 + "ACCOUNT_NEVER_EXPIRES" => 0x000000, # 0 + "ACCOUNT_OK" => 0x800000, # 8388608 + "ACCOUNT_LOCKED_OUT" => 0x800010, # 8388624 +); + +my %ads_gpoptions = ( + "GPOPTIONS_INHERIT" => 0, + "GPOPTIONS_BLOCK_INHERITANCE" => 1, +); + +my %ads_gplink_opts = ( + "GPLINK_OPT_NONE" => 0, + "GPLINK_OPT_DISABLED" => 1, + "GPLINK_OPT_ENFORCED" => 2, +); + +my %ads_gpflags = ( + "GPFLAGS_ALL_ENABLED" => 0, + "GPFLAGS_USER_SETTINGS_DISABLED" => 1, + "GPFLAGS_MACHINE_SETTINGS_DISABLED" => 2, + "GPFLAGS_ALL_DISABLED" => 3, +); + +my %ads_serverstate = ( + "SERVER_ENABLED" => 1, + "SERVER_DISABLED" => 2, +); + +my %ads_sdeffective = ( + "OWNER_SECURITY_INFORMATION" => 0x01, + "DACL_SECURITY_INFORMATION" => 0x04, + "SACL_SECURITY_INFORMATION" => 0x10, +); + +my %ads_trustattrs = ( + "TRUST_ATTRIBUTE_NON_TRANSITIVE" => 1, + "TRUST_ATTRIBUTE_TREE_PARENT" => 2, + "TRUST_ATTRIBUTE_TREE_ROOT" => 3, + "TRUST_ATTRIBUTE_UPLEVEL_ONLY" => 4, +); + +my %ads_trustdirection = ( + "TRUST_DIRECTION_INBOUND" => 1, + "TRUST_DIRECTION_OUTBOUND" => 2, + "TRUST_DIRECTION_BIDIRECTIONAL" => 3, +); + +my %ads_trusttype = ( + "TRUST_TYPE_DOWNLEVEL" => 1, + "TRUST_TYPE_UPLEVEL" => 2, + "TRUST_TYPE_KERBEROS" => 3, + "TRUST_TYPE_DCE" => 4, +); + +my %ads_pwdproperties = ( + "DOMAIN_PASSWORD_COMPLEX" => 1, + "DOMAIN_PASSWORD_NO_ANON_CHANGE" => 2, + "DOMAIN_PASSWORD_NO_CLEAR_CHANGE" => 4, + "DOMAIN_LOCKOUT_ADMINS" => 8, + "DOMAIN_PASSWORD_STORE_CLEARTEXT" => 16, + "DOMAIN_REFUSE_PASSWORD_CHANGE" => 32, +); + +my %ads_uascompat = ( + "LANMAN_USER_ACCOUNT_SYSTEM_NOLIMITS" => 0, + "LANMAN_USER_ACCOUNT_SYSTEM_COMPAT" => 1, +); + +my %ads_frstypes = ( + "REPLICA_SET_SYSVOL" => 2, # unsure + "REPLICA_SET_DFS" => 1, # unsure + "REPLICA_SET_OTHER" => 0, # unsure +); + +my %ads_gp_cse_extensions = ( +"Administrative Templates Extension" => "35378EAC-683F-11D2-A89A-00C04FBBCFA2", +"Disk Quotas" => "3610EDA5-77EF-11D2-8DC5-00C04FA31A66", +"EFS Recovery" => "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A", +"Folder Redirection" => "25537BA6-77A8-11D2-9B6C-0000F8080861", +"IP Security" => "E437BC1C-AA7D-11D2-A382-00C04F991E27", +"Internet Explorer Maintenance" => "A2E30F80-D7DE-11d2-BBDE-00C04F86AE3B", +"QoS Packet Scheduler" => "426031c0-0b47-4852-b0ca-ac3d37bfcb39", +"Scripts" => "42B5FAAE-6536-11D2-AE5A-0000F87571E3", +"Security" => "827D319E-6EAC-11D2-A4EA-00C04F79F83A", +"Software Installation" => "C6DC5466-785A-11D2-84D0-00C04FB169F7", +); + +# guess work +my %ads_gpcextensions = ( +"Administrative Templates" => "0F6B957D-509E-11D1-A7CC-0000F87571E3", +"Certificates" => "53D6AB1D-2488-11D1-A28C-00C04FB94F17", +"EFS recovery policy processing" => "B1BE8D72-6EAC-11D2-A4EA-00C04F79F83A", +"Folder Redirection policy processing" => "25537BA6-77A8-11D2-9B6C-0000F8080861", +"Folder Redirection" => "88E729D6-BDC1-11D1-BD2A-00C04FB9603F", +"Registry policy processing" => "35378EAC-683F-11D2-A89A-00C04FBBCFA2", +"Remote Installation Services" => "3060E8CE-7020-11D2-842D-00C04FA372D4", +"Security Settings" => "803E14A0-B4FB-11D0-A0D0-00A0C90F574B", +"Security policy processing" => "827D319E-6EAC-11D2-A4EA-00C04F79F83A", +"unknown" => "3060E8D0-7020-11D2-842D-00C04FA372D4", +"unknown2" => "53D6AB1B-2488-11D1-A28C-00C04FB94F17", +); + +my %ads_gpo_default_guids = ( +"Default Domain Policy" => "31B2F340-016D-11D2-945F-00C04FB984F9", +"Default Domain Controllers Policy" => "6AC1786C-016F-11D2-945F-00C04fB984F9", +"mist" => "61718096-3D3F-4398-8318-203A48976F9E", ); my %munged_dial = ( @@ -243,7 +351,6 @@ my %munged_dial = ( "CtxCallbackNumber" => \&dump_string, ); - $SIG{__WARN__} = sub { use Carp; Carp::cluck (shift); @@ -299,45 +406,67 @@ if (!$password) { } my %attr_handler = ( + "Token-Groups-No-GC-Acceptable" => \&dump_sid, #wrong name "accountExpires" => \&dump_nttime, "badPasswordTime" => \&dump_nttime, "creationTime" => \&dump_nttime, "currentTime" => \&dump_timestr, "domainControllerFunctionality" => \&dump_ds_func, "domainFunctionality" => \&dump_ds_func, - "dSCorePropagationData" => \&dump_timestr, + "fRSReplicaSetGUID" => \&dump_guid, + "fRSReplicaSetType" => \&dump_frstype, + "fRSVersionGUID" => \&dump_guid, + "flags" => \&dump_gpflags, # fixme: possibly only on gpos! "forceLogoff" => \&dump_nttime_abs, "forestFunctionality" => \&dump_ds_func, +# "gPCMachineExtensionNames" => \&dump_gpcextensions, +# "gPCUserExtensionNames" => \&dump_gpcextensions, + "gPLink" => \&dump_gplink, + "gPOptions" => \&dump_gpoptions, "groupType" => \&dump_gtype, "instanceType" => \&dump_instance_type, "lastLogon" => \&dump_nttime, "lastLogonTimestamp" => \&dump_nttime, - "lockoutTime" => \&dump_nttime, - "lockoutDuration" => \&dump_nttime_abs, "lockOutObservationWindow" => \&dump_nttime_abs, -# "logonHours" => \&dump_not_yet, + "lockoutDuration" => \&dump_nttime_abs, + "lockoutTime" => \&dump_nttime, +# "logonHours" => \&dump_logonhours, "maxPwdAge" => \&dump_nttime_abs, "minPwdAge" => \&dump_nttime_abs, "modifyTimeStamp" => \&dump_timestr, + "msDS-Behavior-Version" => \&dump_ds_func, #unsure + "msDS-User-Account-Control-Computed" => \&dump_uacc, # "msRADIUSFramedIPAddress" => \&dump_ipaddr, # "msRASSavedFramedIPAddress" => \&dump_ipaddr, - "ntMixedDomain" => \&dump_mixed_domain, + "nTMixedDomain" => \&dump_mixed_domain, "nTSecurityDescriptor" => \&dump_secdesc, "objectGUID" => \&dump_guid, "objectSid" => \&dump_sid, + "pKT" => \&dump_pkt, + "pKTGuid" => \&dump_guid, "pwdLastSet" => \&dump_nttime, + "pwdProperties" => \&dump_pwdproperties, "sAMAccountType" => \&dump_atype, - "systemFlags" => \&dump_systemflags, - "supportedControl", => \&dump_controls, + "sDRightsEffective" => \&dump_sdeffective, + "securityIdentifier" => \&dump_sid, + "serverState" => \&dump_serverstate, "supportedCapabilities", => \&dump_capabilities, + "supportedControl", => \&dump_controls, "supportedExtension", => \&dump_extension, + "systemFlags" => \&dump_systemflags, "tokenGroups", => \&dump_sid, + "tokenGroupsGlobalAndUniversal" => \&dump_sid, + "trustAttributes" => \&dump_trustattr, + "trustDirection" => \&dump_trustdirection, + "trustType" => \&dump_trusttype, + "uASCompat" => \&dump_uascompat, "userAccountControl" => \&dump_uac, - "msDS-User-Account-Control-Computed" => \&dump_uacc, + "userCertificate" => \&dump_cert, "userFlags" => \&dump_uf, "userParameters" => \&dump_munged_dial, "whenChanged" => \&dump_timestr, "whenCreated" => \&dump_timestr, +# "dSCorePropagationData" => \&dump_timestr, ); @@ -347,7 +476,8 @@ my %attr_handler = ( ################ sub usage { - print "usage: $0 [--base|-b base] [--debug level] [--debug level] [--DN|-D binddn] [--extendeddn|-e] [--help] [--host|-h host] [--machine|-P] [--metadata|-m] [--nodiffs] [--notify|-n] [--password|-w password] [--port port] [--rawdisplay] [--realm|-R realm] [--rootdse] [--saslmech|-Y saslmech] [--schema|-c] [--scope|-s scope] [--simpleauth|-x] [--starttls|-Z] [--user|-U user] [--wknguid] [--workgroup|-k workgroup] filter [attrs]\n"; + print "usage: $0 [--asq] [--base|-b base] [--debug level] [--debug level] [--DN|-D binddn] [--extendeddn|-e] [--help] [--host|-h host] [--machine|-P] [--metadata|-m] [--nodiffs] [--notify|-n] [--password|-w password] [--port port] [--rawdisplay] [--realm|-R realm] [--rootdse] [--saslmech|-Y saslmech] [--schema|-c] [--scope|-s scope] [--simpleauth|-x] [--starttls|-Z] [--user|-U user] [--wknguid] [--workgroup|-k workgroup] filter [attrs]\n"; + print "\t--asq [attribute]\n\t\tAttribute to use for a attribute scoped query (LDAP_SERVER_ASQ_OID)\n"; print "\t--base|-b [base]\n\t\tUse base [base]\n"; print "\t--debug [level]\n\t\tUse debuglevel (for Net::LDAP)\n"; print "\t--DN|-D [binddn]\n\t\tUse binddn or principal\n"; @@ -547,6 +677,8 @@ sub prompt_user { } sub check_ticket { + return 0; + # works only for heimdal return system("$klist -t"); } @@ -740,18 +872,32 @@ sub parse_ads_h { chomp($line); if ($line =~ /#define.UF.*0x/) { my ($tmp, $name, $val) = split(/\s+/,$line); - next if ($name =~ /UNUSED/); + next if ($name =~ /UNUSED/); +# $ads_uf{$name} = sprintf("%d", hex $val); $ads_uf{$name} = hex $val; } - if ($line =~ /#define.GTYPE.*0x/) { + if ($line =~ /#define.GROUP_TYPE.*0x/) { my ($tmp, $name, $val) = split(/\s+/,$line); - $ads_gtype{$name} = hex $val; + $ads_grouptype{$name} = hex $val; } if ($line =~ /#define.ATYPE.*0x/) { my ($tmp, $name, $val) = split(/\s+/,$line); $ads_atype{$name} = (exists $ads_atype{$val}) ? $ads_atype{$val} : hex $val; } + if ($line =~ /#define.GTYPE.*0x/) { + my ($val, $i); + my ($tmp, $name, @val) = split(/\s+/,$line); + foreach my $tempval (@val) { + if ($tempval =~ /^0x/) { + $val = $tempval; + last; + } + } + next if (!$val); + $ads_gtype{$name} = sprintf("%d", hex $val); + } + } close(ADSH); } @@ -825,52 +971,12 @@ sub display_result_diff ($) { sub sid2string ($) { + # Fix from Michael James my $binary_sid = shift; - my $inbuf2; - my $sid_rev; # [1] - my $num_auths; # [1] - my @id_auth; # [6] - my @sub_auths; - my $subauth; # [16] - my $sid_strout; - my $ia; - - my $tmp_sid = unpack 'H*', $binary_sid; - - # split the binary string - ($sid_rev, $num_auths, - $id_auth[0], $id_auth[1], $id_auth[2], $id_auth[3], $id_auth[4], $id_auth[5], - $sub_auths[0], $sub_auths[1], $sub_auths[2], $sub_auths[3], $sub_auths[4], $inbuf2) - = unpack 'H2 H2 H2 H2 H2 H2 H2 H2 h8 h8 h8 h8 h8 h*',"$binary_sid"; - - # don't ask... - for ( my $i = 0; $i < $num_auths; $i++ ) { - $sub_auths[$i] = reverse $sub_auths[$i]; - } - - # build the identifier authority - if ( ($id_auth[0] != 0) || ($id_auth[1] != 0) ) { - $ia = $id_auth[0]. - $id_auth[1]. - $id_auth[2]. - $id_auth[3]. - $id_auth[4]. - $id_auth[5]; - } else { - $ia = ($id_auth[5]) + - ($id_auth[4] << 8) + - ($id_auth[3] << 16) + - ($id_auth[2] << 24); - } - - # build the sid - $sid_strout = sprintf("S-%lu-%lu",hex($sid_rev),hex($ia)); - - for (my $i = 0; $i < $num_auths; $i++ ) { - $sid_strout .= sprintf( "-%lu", hex($sub_auths[$i]) ); - } - - return $sid_strout; + my($sid_rev, $num_auths, $id1, $id2, @ids) = unpack("H2 H2 n N V*", $binary_sid); + my $sid_string = join("-", "S", hex($sid_rev), ($id1<<32)+$id2, @ids); + return $sid_string; + } sub string_to_guid { @@ -959,9 +1065,10 @@ sub gen_bitmask_string_format($%) { foreach my $key (sort keys %tmp) { push(@list, sprintf("%s %s", $tmp{$key}, $key)); } - return join("\n$mod\t\t\t",@list); + return join("\n$mod$tabsize",@list); } + sub nt_to_unixtime ($) { # the number of 100 nanosecond intervals since jan. 1. 1601 (utc) my $t64 = shift; @@ -994,7 +1101,7 @@ sub dump_bitmask { my (%header) = @_; my %tmp; $tmp{""} = $val; - foreach my $key (sort keys %header) { + foreach my $key (sort keys %header) { # sort by val ! if ($op eq "&") { $tmp{$key} = ( $val & $header{$key} ) ? $set:$unset; } elsif ($op eq "==") { @@ -1019,6 +1126,18 @@ sub dump_uac { return dump_bitmask_and(@_,%ads_uf); # ads_uf ? } +sub dump_uascompat { + return dump_bitmask_equal(@_,%ads_uascompat); +} + +sub dump_gpoptions { + return dump_bitmask_equal(@_,%ads_gpoptions); +} + +sub dump_gpflags { + return dump_bitmask_equal(@_,%ads_gpflags); +} + sub dump_uacc { return dump_bitmask_equal(@_,%ads_uacc); } @@ -1028,7 +1147,10 @@ sub dump_uf { } sub dump_gtype { - return dump_bitmask_and(@_,%ads_gtype); + my $ret = dump_bitmask_and(@_,%ads_grouptype); + $ret .= "\n$tabsize\t"; + $ret .= dump_bitmask_equal(@_,%ads_gtype); + return $ret; } sub dump_atype { @@ -1059,6 +1181,34 @@ sub dump_ds_func { return dump_bitmask_equal(@_,%ads_ds_func); } +sub dump_serverstate { + return dump_bitmask_equal(@_,%ads_serverstate); +} + +sub dump_sdeffective { + return dump_bitmask_and(@_,%ads_sdeffective); +} + +sub dump_trustattr { + return dump_bitmask_equal(@_,%ads_trustattrs); +} + +sub dump_trusttype { + return dump_bitmask_equal(@_,%ads_trusttype); +} + +sub dump_trustdirection { + return dump_bitmask_equal(@_,%ads_trustdirection); +} + +sub dump_pwdproperties { + return dump_bitmask_and(@_,%ads_pwdproperties); +} + +sub dump_frstype { + return dump_bitmask_equal(@_,%ads_frstypes) +} + sub dump_mixed_domain { return dump_bitmask_equal(@_,%ads_mixed_domain); } @@ -1100,6 +1250,9 @@ sub dump_nttime_abs { sub dump_timestr { my $time = shift; + if ($time eq "16010101000010.0Z") { + return sprintf("%s (%s)", "never", $time); + } my ($year,$mon,$mday,$hour,$min,$sec,$zone) = unpack('a4 a2 a2 a2 a2 a2 a4', $time); $mon -= 1; @@ -1120,6 +1273,37 @@ sub dump_munged_dial { return "FIXME! decode this"; } +sub dump_cert { + + my $cert = shift; + open(OPENSSL, "| /usr/bin/openssl x509 -text -inform der"); + print OPENSSL $cert; + close(OPENSSL); + return ""; +} + +sub dump_pkt { + my $pkt = shift; + return "not yet"; + printf("%s: ", $pkt); + printf("%02X", $pkt); + +} + +sub dump_gplink { + + my $gplink = shift; + my $gplink_mod = $gplink; + my @links = split("\\]\\[", $gplink_mod); + foreach my $link (@links) { + $link =~ s/^\[|\]$//g; + my ($ldap_link, $opt) = split(";", $link); + my @array = ( "$opt", "\t" ); + printf("%slink: %s, opt: %s\n", $tabsize, $ldap_link, dump_bitmask_and(@array, %ads_gplink_opts)); + } + return $gplink; +} + sub construct_filter { my $tmp = shift; @@ -1154,10 +1338,12 @@ sub construct_attrs { push(@attrs,"replPropertyMetaData"); } - push(@attrs,"nTSecurityDescriptor"); - push(@attrs,"msDS-KeyVersionNumber"); - push(@attrs,"msDS-User-Account-Control-Computed"); - push(@attrs,"modifyTimeStamp"); + if ($opt_verbose) { + push(@attrs,"nTSecurityDescriptor"); + push(@attrs,"msDS-KeyVersionNumber"); + push(@attrs,"msDS-User-Account-Control-Computed"); + push(@attrs,"modifyTimeStamp"); + } return sort @attrs; } @@ -1183,29 +1369,50 @@ sub print_header { sub gen_controls { - my $asn = Convert::ASN1->new; - $asn->prepare( + # setup attribute-scoped query control + my $asq_asn = Convert::ASN1->new; + $asq_asn->prepare( + q< asq ::= SEQUENCE { + sourceAttribute OCTET_STRING + } + > + ); + my $ctl_asq_val = $asq_asn->encode( sourceAttribute => $opt_asq); + my $ctl_asq = Net::LDAP::Control->new( + type => $ads_controls{'LDAP_SERVER_ASQ_OID'}, + critical => 'true', + value => $ctl_asq_val); + + + # setup extended dn control + my $asn_extended_dn = Convert::ASN1->new; + $asn_extended_dn->prepare( q< ExtendedDn ::= SEQUENCE { mode INTEGER } > ); - my $ctl_extended_dn_val = $asn->encode( mode => '1'); + my $ctl_extended_dn_val = $asn_extended_dn->encode( mode => '1'); my $ctl_extended_dn =Net::LDAP::Control->new( type => $ads_controls{'LDAP_SERVER_EXTENDED_DN_OID'}, critical => 'true', value => $ctl_extended_dn_val); + + # setup notify control my $ctl_notification = Net::LDAP::Control->new( type => $ads_controls{'LDAP_SERVER_NOTIFICATION_OID'}, critical => 'true'); + + # setup paging control $ctl_paged = Net::LDAP::Control->new( type => $ads_controls{'LDAP_PAGED_RESULT_OID_STRING'}, critical => 'true', size => $page_size); + if ($paging) { push(@ctrls, $ctl_paged); push(@ctrls_s, "LDAP_PAGED_RESULT_OID_STRING" ); @@ -1220,6 +1427,11 @@ sub gen_controls { push(@ctrls_s, "LDAP_SERVER_NOTIFICATION_OID"); } + if ($opt_asq) { + push(@ctrls, $ctl_asq); + push(@ctrls_s, "LDAP_SERVER_ASQ_OID"); + } + return @ctrls; } @@ -1244,7 +1456,7 @@ sub display_attr_generic ($$$) { my $ref = $entry->get_value($attr, asref => 1); my @values = @$ref; - foreach my $value (@values) { + foreach my $value ( sort @values) { display_value_generic($mod,$attr,$value); } } @@ -1254,14 +1466,14 @@ sub display_entry_generic ($) { my $entry = shift; return if (!$entry); - foreach my $attr ( $entry->attributes) { + foreach my $attr ( sort $entry->attributes) { display_attr_generic("\t",$entry,$attr); } } sub display_ldap_err ($) { - my $msg = shift; + my $msg = shift; print_header(); my ($package, $filename, $line, $subroutine) = caller(0); @@ -1342,6 +1554,11 @@ sub notify_callback { while (1) { my $async_entry = $async_search->pop_entry; + + if (!$async_entry->dn) { + print "very weird. entry has no dn\n"; + next; + } printf("\ngot changenotify for dn: [%s]\n%s\n", $async_entry->dn, ("-" x 80)); @@ -1450,7 +1667,7 @@ sub main () { if ($opt_notify) { - print "[$base] is registered now for change-notify\n"; + print "Base [$base] is registered now for change-notify\n"; print "\nWaiting for change-notify...\n"; my $sync_ldap_hd = get_ldap_hd($server,0); -- cgit From f3a053efbd26b085378966032186aaf10bec5ec1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 19 Dec 2005 02:22:13 +0000 Subject: r12338: add ifdef DEBUG_PASSWORD before printing clear text password. Guenther --- source/utils/net_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/utils/net_rpc.c b/source/utils/net_rpc.c index 33eac56a925..d2cecd24350 100644 --- a/source/utils/net_rpc.c +++ b/source/utils/net_rpc.c @@ -5293,8 +5293,10 @@ static NTSTATUS vampire_trusted_domain(struct rpc_pipe_client *pipe_hnd, goto done; } +#ifdef DEBUG_PASSWORD DEBUG(100,("sucessfully vampired trusted domain [%s], sid: [%s], password: [%s]\n", trusted_dom_name, sid_string_static(&dom_sid), cleartextpwd)); +#endif done: SAFE_FREE(cleartextpwd); -- cgit From f7642b2f5b0c9b0d1dd105569c90784b91c6a0c6 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 19 Dec 2005 03:02:56 +0000 Subject: r12341: add DEBUG statement. Guenther --- source/nsswitch/winbindd_cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 841b114a785..81dd85e588b 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -546,8 +546,10 @@ static void centry_put_string(struct cache_entry *centry, const char *s) len = strlen(s); /* can't handle more than 254 char strings. Truncating is probably best */ - if (len > 254) + if (len > 254) { + DEBUG(10,("centry_put_string: truncating len (%d) to: 254\n", len)); len = 254; + } centry_put_uint8(centry, len); centry_expand(centry, len); memcpy(centry->data + centry->ofs, s, len); -- cgit From 47c0f2201012690bfe1fd2d17bbe3b7076dee3a1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Dec 2005 23:07:25 +0000 Subject: r12376: Second patch from Martin Koeppe for #3287. Jeremy. --- source/smbd/trans2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c index 6a4b7111cdb..191ccdcf8bd 100644 --- a/source/smbd/trans2.c +++ b/source/smbd/trans2.c @@ -3216,8 +3216,8 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd BasicFileInformationTest. -tpot */ DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n")); - SIVAL(pdata,4,sbuf.st_ino); /* FileIndexLow */ - SIVAL(pdata,0,sbuf.st_dev); /* FileIndexHigh */ + SIVAL(pdata,0,sbuf.st_ino); /* FileIndexLow */ + SIVAL(pdata,4,sbuf.st_dev); /* FileIndexHigh */ data_size = 8; break; -- cgit From 5a4457e4185f05f362a84b0795d83fed43f5faab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Dec 2005 00:16:18 +0000 Subject: r12387: Make string_to_sid a little more silent. Jeremy. --- source/lib/util_sid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lib/util_sid.c b/source/lib/util_sid.c index b94be474a9e..f3fc5af9eaa 100644 --- a/source/lib/util_sid.c +++ b/source/lib/util_sid.c @@ -213,7 +213,7 @@ BOOL string_to_sid(DOM_SID *sidout, const char *sidstr) uint32 conv; if ((sidstr[0] != 'S' && sidstr[0] != 's') || sidstr[1] != '-') { - DEBUG(0,("string_to_sid: Sid %s does not start with 'S-'.\n", sidstr)); + DEBUG(3,("string_to_sid: Sid %s does not start with 'S-'.\n", sidstr)); return False; } @@ -223,7 +223,7 @@ BOOL string_to_sid(DOM_SID *sidout, const char *sidstr) p = sidstr + 2; conv = (uint32) strtoul(p, &q, 10); if (!q || (*q != '-')) { - DEBUG(0,("string_to_sid: Sid %s is not in a valid format.\n", sidstr)); + DEBUG(3,("string_to_sid: Sid %s is not in a valid format.\n", sidstr)); return False; } sidout->sid_rev_num = (uint8) conv; -- cgit From e1251723170a52e828c27ccec28a0dba873a4833 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 20 Dec 2005 02:23:51 +0000 Subject: r12393: cleaning up swat bugs. *no one* tests swat it seems. This has been broken since r10656 --- source/script/installswat.sh | 20 ++---- source/web/diagnose.c | 4 +- source/web/swat.c | 142 +++++++++++++------------------------------ 3 files changed, 48 insertions(+), 118 deletions(-) diff --git a/source/script/installswat.sh b/source/script/installswat.sh index c5c285894e7..c66fd29485d 100755 --- a/source/script/installswat.sh +++ b/source/script/installswat.sh @@ -3,7 +3,7 @@ SWATDIR=`echo $1 | sed 's/\/\//\//g'` SRCDIR=$2/ -BOOKDIR=$SWATDIR/using_samba +BOOKDIR=$SWATDIR/help/using_samba echo Installing SWAT in $SWATDIR echo Installing the Samba Web Administration Tool @@ -14,7 +14,7 @@ echo Installing langs are `cd $SRCDIR../swat/lang/; /bin/echo ??` for ln in $LANGS; do SWATLANGDIR=$SWATDIR/$ln for d in $SWATLANGDIR $SWATLANGDIR/help $SWATLANGDIR/images \ - $SWATLANGDIR/include $SWATLANGDIR/js; do + $SWATLANGDIR/include; do if [ ! -d $d ]; then mkdir -p $d if [ ! -d $d ]; then @@ -28,7 +28,7 @@ done # Install images for ln in $LANGS; do - for f in $SRCDIR../swat/$ln/images/*.png; do + for f in $SRCDIR../swat/$ln/images/*.gif; do if [ ! -f $f ] ; then continue fi @@ -59,7 +59,7 @@ for ln in $LANGS; do # Install "server-side" includes - for f in $SRCDIR../swat/$ln/include/*; do + for f in $SRCDIR../swat/$ln/include/*.html; do if [ ! -f $f ] ; then continue fi @@ -69,18 +69,6 @@ for ln in $LANGS; do chmod 0644 $FNAME done - # Install javascripts - - for f in $SRCDIR../swat/$ln/js/*.js; do - if [ ! -f $f ] ; then - continue - fi - FNAME=$SWATDIR/$ln/js/`basename $f` - echo $FNAME - cp $f $FNAME || echo Cannot install $FNAME. Does $USER have privileges? - chmod 0644 $FNAME - done - done # Install html documentation (if html documentation tree is here) diff --git a/source/web/diagnose.c b/source/web/diagnose.c index c7a7a3598ee..d259717da0b 100644 --- a/source/web/diagnose.c +++ b/source/web/diagnose.c @@ -21,6 +21,8 @@ #include "includes.h" #include "web/swat_proto.h" +extern struct in_addr loopback_ip; + #ifdef WITH_WINBIND /* check to see if winbind is running by pinging it */ @@ -35,7 +37,6 @@ BOOL winbindd_running(void) response */ BOOL nmbd_running(void) { - extern struct in_addr loopback_ip; int fd, count, flags; struct in_addr *ip_list; @@ -60,7 +61,6 @@ BOOL nmbd_running(void) BOOL smbd_running(void) { static struct cli_state cli; - extern struct in_addr loopback_ip; if (!cli_initialise(&cli)) return False; diff --git a/source/web/swat.c b/source/web/swat.c index 4082574e442..15612484a35 100644 --- a/source/web/swat.c +++ b/source/web/swat.c @@ -188,12 +188,12 @@ static const char* get_parm_translated( if(strcmp(pLabel, pTranslated) != 0) { pstr_sprintf(output, - " %s       %s
%s", + " %s       %s
%s", pAnchor, pHelp, pLabel, pTranslated); return output; } pstr_sprintf(output, - " %s %s", + " %s       %s", pAnchor, pHelp, pLabel); return output; } @@ -220,7 +220,7 @@ static void show_parameter(int snum, struct parm_struct *parm) ptr = lp_local_ptr(snum, ptr); } - printf("%s", get_parm_translated(stripspaceupper(parm->label), _("Help"), parm->label)); + printf("%s", get_parm_translated(stripspaceupper(parm->label), _("Help"), parm->label)); switch (parm->type) { case P_CHAR: printf("", @@ -230,7 +230,7 @@ static void show_parameter(int snum, struct parm_struct *parm) break; case P_LIST: - printf("label)); if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) { char **list = *(char ***)ptr; @@ -268,7 +268,7 @@ static void show_parameter(int snum, struct parm_struct *parm) case P_STRING: case P_USTRING: push_utf8_allocate(&utf8_s1, *(char **)ptr); - printf("", + printf("", make_parm_name(parm->label), fix_quotes(utf8_s1)); SAFE_FREE(utf8_s1); printf("", @@ -278,7 +278,7 @@ static void show_parameter(int snum, struct parm_struct *parm) case P_GSTRING: case P_UGSTRING: push_utf8_allocate(&utf8_s1, (char *)ptr); - printf("", + printf("", make_parm_name(parm->label), fix_quotes(utf8_s1)); SAFE_FREE(utf8_s1); printf("", @@ -523,50 +523,42 @@ static void commit_parameters(int snum) } /**************************************************************************** - generate html for rollovers + spit out the html for a link with an image ****************************************************************************/ -static void rollover_link(const char *name, const char *id, const char *page) +static void image_link(const char *name, const char *hlink, const char *src) { - if ( strcmp(page, id)==0 ) { - printf(" \"%s\"\n", - id, name); - } else { - printf(" \"%s\"\n", - cgi_baseurl(), id, id, id, id, id, id, id, name); - } + printf("\"%s\"\n", + cgi_baseurl(), hlink, src, name); } /**************************************************************************** display the main navigation controls at the top of each page along with a title ****************************************************************************/ -static void show_main_buttons(const char *page) +static void show_main_buttons(void) { char *p; - printf("

\n"); + if ((p = cgi_user_name()) && strcmp(p, "root")) { + printf(_("Logged in as %s"), p); + printf("

\n"); + } + image_link(_("Home"), "", "images/home.gif"); if (have_write_access) { - rollover_link(_("Configure"), "conf", page); - rollover_link(_("Services"), "services", page); + image_link(_("Globals"), "globals", "images/globals.gif"); + image_link(_("Shares"), "shares", "images/shares.gif"); + image_link(_("Printers"), "printers", "images/printers.gif"); + image_link(_("Wizard"), "wizard", "images/wizard.gif"); } - - /* root always gets all buttons, otherwise look for -P */ + /* root always gets all buttons, otherwise look for -P */ if ( have_write_access || (!passwd_only && have_read_access) ) { - rollover_link(_("Status"), "status", page); - } - rollover_link(_("Password Management"), "passwd", page); - - printf("

\n\n"); - - /* Wrap the rest in a control div */ - printf("
\n\n"); - - if ((p = cgi_user_name()) && strcmp(p, "root")) { - printf(_("Logged in as %s"), p); - printf("

\n"); + image_link(_("Status"), "status", "images/status.gif"); + image_link(_("View Config"), "viewconfig", "images/viewconfig.gif"); } + image_link(_("Password Management"), "passwd", "images/passwd.gif"); + printf("


\n"); } /**************************************************************************** @@ -584,47 +576,11 @@ static void ViewModeBoxes(int mode) } /**************************************************************************** - display a welcome page (Read-only users under passwd only get a unique welcome) + display a welcome page ****************************************************************************/ static void welcome_page(void) { - if (passwd_only && !have_write_access) { - include_html("help/welcome_passwd_only.html"); - } else { - include_html("help/welcome.html"); - } -} - -/**************************************************************************** - display help page -****************************************************************************/ -static void help_page(void) -{ - include_html("help/docs.html"); -} - -/**************************************************************************** - display shares and printers links from an overall services page -****************************************************************************/ -static void services_page(void) -{ - printf("
\n"); - printf("

File and Printer Shares

\n\n"); - printf("

Follow the links below to edit service-level parameters for file and printer shares.

\n"); - printf("
\n\n"); - - printf(" \n\n"); - - printf("
\n"); - printf(" \n"); - printf("
\n\n"); - - printf("
\n"); - printf("

Shares may also be added via the links above.

\n"); - printf("
\n\n"); + include_html("help/welcome.html"); } /**************************************************************************** @@ -692,9 +648,7 @@ static void rewritecfg_file(void) { commit_parameters(GLOBAL_SECTION_SNUM); save_reload(0); - printf("

Samba Configuration Saved

"); - printf("

%s

\n", _("Note: smb.conf file has been read and rewritten")); - printf("

Return to the previous page.\n"); + printf("

%s

\n", _("Note: smb.conf file has been read and rewritten")); } /**************************************************************************** @@ -806,7 +760,7 @@ static void wizard_page(void) printf("
\n"); if (have_write_access) { - printf("%s\n", _("The "Rewrite smb.conf file" button will clear the smb.conf file of all default values and of comments.")); + printf("%s\n", _("The \"Rewrite smb.conf file\" button will clear the smb.conf file of all default values and of comments.")); printf("%s", _("The same will happen if you press the commit button.")); printf("

\n"); printf("
"); @@ -866,19 +820,14 @@ static void wizard_page(void) /**************************************************************************** - display a conf page for editing global parameters + display a globals editing page ****************************************************************************/ -static void conf_page(void) +static void globals_page(void) { unsigned int parm_filter = FLAG_BASIC; int mode = 0; - printf("
\n"); - printf("

Configuring Samba

\n\n"); - printf("

The following menu allows for editing of global parameters affecting your Samba configuration.

\n"); - printf("
\n\n"); - - printf(" \n\n"); + printf("

%s

\n", _("Global Parameters")); if (cgi_variable("Commit")) { commit_parameters(GLOBAL_SECTION_SNUM); @@ -892,7 +841,7 @@ static void conf_page(void) if ( cgi_variable("AdvMode")) mode = 1; - printf("\n"); + printf("\n"); ViewModeBoxes( mode ); switch ( mode ) { @@ -936,8 +885,6 @@ static void shares_page(void) snum = lp_servicenumber(share); printf("

%s

\n", _("Share Parameters")); - - printf(" \n\n"); if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); @@ -1279,8 +1226,6 @@ static void printers_page(void) snum = lp_servicenumber(share); printf("

%s

\n", _("Printer Parameters")); - - printf(" \n\n"); printf("

%s

\n", _("Important Note:")); printf(_("Printer names marked with [*] in the Choose Printer drop-down box ")); @@ -1450,32 +1395,29 @@ static void printers_page(void) have_read_access = (access(dyn_CONFIGFILE,R_OK) == 0); } - page = cgi_pathinfo(); + show_main_buttons(); - show_main_buttons(page); + page = cgi_pathinfo(); - if (have_read_access && strcmp(page,"conf")==0) { - conf_page(); - } else if (have_read_access && strcmp(page,"viewconfig")==0) { - viewconfig_page(); - } else if (have_read_access && strcmp(page,"rewritecfg")==0) { - rewritecfg_file(); - } else if (have_read_access && strcmp(page,"services")==0) { - services_page(); + /* Root gets full functionality */ + if (have_read_access && strcmp(page, "globals")==0) { + globals_page(); } else if (have_read_access && strcmp(page,"shares")==0) { shares_page(); } else if (have_read_access && strcmp(page,"printers")==0) { printers_page(); } else if (have_read_access && strcmp(page,"status")==0) { status_page(); + } else if (have_read_access && strcmp(page,"viewconfig")==0) { + viewconfig_page(); } else if (strcmp(page,"passwd")==0) { passwd_page(); } else if (have_read_access && strcmp(page,"wizard")==0) { wizard_page(); } else if (have_read_access && strcmp(page,"wizard_params")==0) { wizard_params_page(); - } else if (have_read_access && strcmp(page,"help")==0) { - help_page(); + } else if (have_read_access && strcmp(page,"rewritecfg")==0) { + rewritecfg_file(); } else { welcome_page(); } -- cgit From a15d17362a53b30f0f17a4bfd782c9e59ace8f3b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 20 Dec 2005 15:10:41 +0000 Subject: r12398: adding Guenther's account policy migration fix --- source/lib/account_pol.c | 85 +++++++++++++++++++++++++++++++++++++++++------- source/passdb/pdb_ldap.c | 29 +++++++++++++---- source/utils/pdbedit.c | 51 ++++++++++++++++++++++++++++- 3 files changed, 145 insertions(+), 20 deletions(-) diff --git a/source/lib/account_pol.c b/source/lib/account_pol.c index b02edc5b401..75a1d62ee79 100644 --- a/source/lib/account_pol.c +++ b/source/lib/account_pol.c @@ -73,7 +73,7 @@ static const struct ap_table account_policy_names[] = { "Lockout users after bad logon attempts (default: 0 => off)", "sambaLockoutThreshold" }, - {AP_TIME_TO_LOGOUT, "disconnect time", -1, + {AP_TIME_TO_LOGOUT, "disconnect time", (uint32) -1, "Disconnect Users outside logon hours (default: -1 => off, 0 => on)", "sambaForceLogoff" }, @@ -116,8 +116,9 @@ const char *decode_account_policy_name(int field) { int i; for (i=0; account_policy_names[i].string; i++) { - if (field == account_policy_names[i].field) + if (field == account_policy_names[i].field) { return account_policy_names[i].string; + } } return NULL; } @@ -130,8 +131,9 @@ const char *get_account_policy_attr(int field) { int i; for (i=0; account_policy_names[i].field; i++) { - if (field == account_policy_names[i].field) + if (field == account_policy_names[i].field) { return account_policy_names[i].ldap_attr; + } } return NULL; } @@ -144,8 +146,9 @@ const char *account_policy_get_desc(int field) { int i; for (i=0; account_policy_names[i].string; i++) { - if (field == account_policy_names[i].field) + if (field == account_policy_names[i].field) { return account_policy_names[i].description; + } } return NULL; } @@ -158,8 +161,9 @@ int account_policy_name_to_fieldnum(const char *name) { int i; for (i=0; account_policy_names[i].string; i++) { - if (strcmp(name, account_policy_names[i].string) == 0) + if (strcmp(name, account_policy_names[i].string) == 0) { return account_policy_names[i].field; + } } return 0; } @@ -180,8 +184,9 @@ static BOOL account_policy_cache_timestamp(uint32 *value, BOOL update, slprintf(key, sizeof(key)-1, "%s/%s", ap_name, AP_LASTSET); - if (!init_account_policy()) + if (!init_account_policy()) { return False; + } if (!tdb_fetch_uint32(tdb, key, &val) && !update) { DEBUG(10,("failed to get last set timestamp of cache\n")); @@ -253,8 +258,9 @@ BOOL init_account_policy(void) uint32 version; int i; - if (tdb) + if (tdb) { return True; + } tdb = tdb_open_log(lock_path("account_policy.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (!tdb) { @@ -300,23 +306,28 @@ BOOL account_policy_get(int field, uint32 *value) fstring name; uint32 regval; - if (!init_account_policy()) + if (!init_account_policy()) { return False; + } - if (value) + if (value) { *value = 0; + } fstrcpy(name, decode_account_policy_name(field)); if (!*name) { DEBUG(1, ("account_policy_get: Field %d is not a valid account policy type! Cannot get, returning 0.\n", field)); return False; } + if (!tdb_fetch_uint32(tdb, name, ®val)) { DEBUG(1, ("account_policy_get: tdb_fetch_uint32 failed for field %d (%s), returning 0\n", field, name)); return False; } - if (value) + + if (value) { *value = regval; + } DEBUG(10,("account_policy_get: name: %s, val: %d\n", name, regval)); return True; @@ -331,8 +342,9 @@ BOOL account_policy_set(int field, uint32 value) { fstring name; - if (!init_account_policy()) + if (!init_account_policy()) { return False; + } fstrcpy(name, decode_account_policy_name(field)); if (!*name) { @@ -382,6 +394,54 @@ BOOL cache_account_policy_set(int field, uint32 value) return True; } +/***************************************************************************** +Check whether account policies have been migrated to passdb +*****************************************************************************/ + +BOOL account_policy_migrated(BOOL init) +{ + pstring key; + uint32 val; + time_t now; + + slprintf(key, sizeof(key)-1, "AP_MIGRATED_TO_PASSDB"); + + if (!init_account_policy()) { + return False; + } + + if (init) { + now = time(NULL); + + if (!tdb_store_uint32(tdb, key, (uint32)now)) { + DEBUG(1, ("tdb_store_uint32 failed for %s\n", key)); + return False; + } + + return True; + } + + if (!tdb_fetch_uint32(tdb, key, &val)) { + return False; + } + + return True; +} + +/***************************************************************************** + Remove marker that informs that account policies have been migrated to passdb +*****************************************************************************/ + +BOOL remove_account_policy_migrated(void) +{ + if (!init_account_policy()) { + return False; + } + + return tdb_delete_bystring(tdb, "AP_MIGRATED_TO_PASSDB"); +} + + /***************************************************************************** Get an account policy from the cache *****************************************************************************/ @@ -413,8 +473,9 @@ TDB_CONTEXT *get_account_pol_tdb( void ) { if ( !tdb ) { - if ( !init_account_policy() ) + if ( !init_account_policy() ) { return NULL; + } } return tdb; diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index cb0bc8eeb68..0c0128176b7 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3331,7 +3331,7 @@ static NTSTATUS ldapsam_alias_memberships(struct pdb_methods *methods, return NT_STATUS_OK; } -static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int policy_index, uint32 value) +static NTSTATUS ldapsam_set_account_policy_in_ldap(struct pdb_methods *methods, int policy_index, uint32 value) { NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL; int rc; @@ -3344,7 +3344,7 @@ static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int poli const char *attrs[2]; - DEBUG(10,("ldapsam_set_account_policy\n")); + DEBUG(10,("ldapsam_set_account_policy_in_ldap\n")); if (!ldap_state->domain_dn) { return NT_STATUS_INVALID_PARAMETER; @@ -3352,7 +3352,7 @@ static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int poli policy_attr = get_account_policy_attr(policy_index); if (policy_attr == NULL) { - DEBUG(0,("ldapsam_set_account_policy: invalid policy\n")); + DEBUG(0,("ldapsam_set_account_policy_in_ldap: invalid policy\n")); return ntstatus; } @@ -3372,7 +3372,7 @@ static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int poli ldap_get_option(ldap_state->smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,&ld_error); - DEBUG(0, ("ldapsam_set_account_policy: Could not set account policy " + DEBUG(0, ("ldapsam_set_account_policy_in_ldap: Could not set account policy " "for %s, error: %s (%s)\n", ldap_state->domain_dn, ldap_err2string(rc), ld_error?ld_error:"unknown")); SAFE_FREE(ld_error); @@ -3380,13 +3380,22 @@ static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int poli } if (!cache_account_policy_set(policy_index, value)) { - DEBUG(0,("ldapsam_set_account_policy: failed to update local tdb cache\n")); + DEBUG(0,("ldapsam_set_account_policy_in_ldap: failed to update local tdb cache\n")); return ntstatus; } return NT_STATUS_OK; } +static NTSTATUS ldapsam_set_account_policy(struct pdb_methods *methods, int policy_index, uint32 value) +{ + if (!account_policy_migrated(False)) { + return (account_policy_set(policy_index, value)) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; + } + + return ldapsam_set_account_policy_in_ldap(methods, policy_index, value); +} + static NTSTATUS ldapsam_get_account_policy_from_ldap(struct pdb_methods *methods, int policy_index, uint32 *value) { NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL; @@ -3425,7 +3434,7 @@ static NTSTATUS ldapsam_get_account_policy_from_ldap(struct pdb_methods *methods ldap_get_option(ldap_state->smbldap_state->ldap_struct, LDAP_OPT_ERROR_STRING,&ld_error); - DEBUG(0, ("ldapsam_get_account_policy_from_ldap: Could not get account policy " + DEBUG(3, ("ldapsam_get_account_policy_from_ldap: Could not get account policy " "for %s, error: %s (%s)\n", ldap_state->domain_dn, ldap_err2string(rc), ld_error?ld_error:"unknown")); SAFE_FREE(ld_error); @@ -3461,6 +3470,8 @@ out: /* wrapper around ldapsam_get_account_policy_from_ldap(), handles tdb as cache + - if user hasn't decided to use account policies inside LDAP just reuse the old tdb values + - if there is a valid cache entry, return that - if there is an LDAP entry, update cache and return - otherwise set to default, update cache and return @@ -3471,6 +3482,10 @@ static NTSTATUS ldapsam_get_account_policy(struct pdb_methods *methods, int poli { NTSTATUS ntstatus = NT_STATUS_UNSUCCESSFUL; + if (!account_policy_migrated(False)) { + return (account_policy_get(policy_index, value)) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; + } + if (cache_account_policy_get(policy_index, value)) { DEBUG(11,("ldapsam_get_account_policy: got valid value from cache\n")); return NT_STATUS_OK; @@ -3481,7 +3496,7 @@ static NTSTATUS ldapsam_get_account_policy(struct pdb_methods *methods, int poli goto update_cache; } - DEBUG(10,("ldapsam_get_account_policy: failed to retrieve from ldap, returning default.\n")); + DEBUG(10,("ldapsam_get_account_policy: failed to retrieve from ldap\n")); #if 0 /* should we automagically migrate old tdb value here ? */ diff --git a/source/utils/pdbedit.c b/source/utils/pdbedit.c index e120b8ec640..9c292bd212a 100644 --- a/source/utils/pdbedit.c +++ b/source/utils/pdbedit.c @@ -118,6 +118,35 @@ static int export_groups (struct pdb_context *in, struct pdb_context *out) { return 0; } +/********************************************************* + Reset account policies to their default values and remove marker + ********************************************************/ + +static int reinit_account_policies (void) +{ + int i; + + for (i=1; decode_account_policy_name(i) != NULL; i++) { + uint32 policy_value; + if (!account_policy_get_default(i, &policy_value)) { + fprintf(stderr, "Can't get default account policy\n"); + return -1; + } + if (!account_policy_set(i, policy_value)) { + fprintf(stderr, "Can't set account policy in tdb\n"); + return -1; + } + } + + if (!remove_account_policy_migrated()) { + fprintf(stderr, "Can't remove marker from tdb\n"); + return -1; + } + + return 0; +} + + /********************************************************* Add all currently available account policy from tdb to one backend ********************************************************/ @@ -126,13 +155,23 @@ static int export_account_policies (struct pdb_context *in, struct pdb_context * { int i; + if (!account_policy_migrated(True)) { + fprintf(stderr, "Can't set account policy marker in tdb\n"); + return -1; + } + for (i=1; decode_account_policy_name(i) != NULL; i++) { uint32 policy_value; if (NT_STATUS_IS_ERR(in->pdb_get_account_policy(in, i, &policy_value))) { fprintf(stderr, "Can't get account policy from tdb\n"); + remove_account_policy_migrated(); + return -1; + } + if (NT_STATUS_IS_ERR(out->pdb_set_account_policy(out, i, policy_value))) { + fprintf(stderr, "Can't set account policy in passdb\n"); + remove_account_policy_migrated(); return -1; } - out->pdb_set_account_policy(out, i, policy_value); } return 0; @@ -677,6 +716,7 @@ int main (int argc, char **argv) static char *backend_out = NULL; static BOOL transfer_groups = False; static BOOL transfer_account_policies = False; + static BOOL reset_account_policies = False; static BOOL force_initialised_password = False; static char *logon_script = NULL; static char *profile_path = NULL; @@ -721,6 +761,7 @@ int main (int argc, char **argv) {"export", 'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL}, {"group", 'g', POPT_ARG_NONE, &transfer_groups, 0, "use -i and -e for groups", NULL}, {"policies", 'y', POPT_ARG_NONE, &transfer_account_policies, 0, "use -i and -e to move account policies between backends", NULL}, + {"policies-reset", 0, POPT_ARG_NONE, &reset_account_policies, 0, "restore default policies", NULL}, {"account-policy", 'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL}, {"value", 'C', POPT_ARG_LONG, &account_policy_value, 'C',"set the account policy to this value", NULL}, {"account-control", 'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL}, @@ -841,6 +882,14 @@ int main (int argc, char **argv) } } + if (reset_account_policies) { + if (!reinit_account_policies()) { + exit(1); + } + + exit(0); + } + /* import and export operations */ if (((checkparms & BIT_IMPORT) || (checkparms & BIT_EXPORT)) && !(checkparms & ~(BIT_IMPORT +BIT_EXPORT +BIT_USER))) { -- cgit From fff59de8ae966ad8950e227d0a8eb179b9016858 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 20 Dec 2005 18:20:39 +0000 Subject: r12400: one line patch for Sun LDAP libs pointed out by Nicholas Brealey --- source/passdb/pdb_ldap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 0c0128176b7..74ed907a870 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -1736,7 +1736,7 @@ static NTSTATUS ldapsam_modify_entry(struct pdb_methods *my_methods, if (retdata) ber_bvfree(retdata); if (retoid) - ber_memfree(retoid); + ldap_memfree(retoid); } ber_bvfree(bv); } -- cgit From 66ab154c79b3cc780ef7cdceecc54a3519f37a27 Mon Sep 17 00:00:00 2001 From: Deryck Hodge Date: Wed, 21 Dec 2005 04:47:57 +0000 Subject: r12403: Update url on the docs directory README. deryck --- docs/README-NOW | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/README-NOW b/docs/README-NOW index 340336bee8b..cb9a4a68d50 100644 --- a/docs/README-NOW +++ b/docs/README-NOW @@ -3,8 +3,7 @@ --------------------------------------------------- This docs tree has been moved to a separate SVN -module on svn.samba.org name 'samba-docs'. -See http://svnanon.samba.org/ for details on accessing -Samba svn trees. - +module on svn.samba.org named 'samba-docs'. +See http://svn.samba.org/samba/subversion.html +for details on accessing Samba svn trees. -- cgit From e15f4954c9ee4a812477e88da516721d18a0aba3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 21 Dec 2005 10:05:39 +0000 Subject: r12406: Since w2k3 sp1 we fail to create user accounts using e.g. "net ads user add" with "Server is unwilling to perform". Seems we have to put in the same userAccountControl bits the server would pick when we wouldn't send them at all. Guenther --- source/libads/ldap_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libads/ldap_user.c b/source/libads/ldap_user.c index 56a0d8013b2..3ff6acc9e83 100644 --- a/source/libads/ldap_user.c +++ b/source/libads/ldap_user.c @@ -65,7 +65,7 @@ ADS_STATUS ads_add_user_acct(ADS_STRUCT *ads, const char *user, if (!(new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", name, container, ads->config.bind_path))) goto done; - if (!(controlstr = talloc_asprintf(ctx, "%u", UF_NORMAL_ACCOUNT))) + if (!(controlstr = talloc_asprintf(ctx, "%u", (UF_NORMAL_ACCOUNT | UF_ACCOUNTDISABLE)))) goto done; if (!(mods = ads_init_mods(ctx))) goto done; -- cgit From c30ef29b2d0fc844087154462a30a40f1640336c Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 21 Dec 2005 12:52:04 +0000 Subject: r12407: Fix returning wrong error codes and better sort out errors and stdout messages. Guenther --- source/nsswitch/wbinfo.c | 90 ++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c index aae76e44238..c55f4bb4319 100644 --- a/source/nsswitch/wbinfo.c +++ b/source/nsswitch/wbinfo.c @@ -45,7 +45,7 @@ static char winbind_separator_int(BOOL strict) if (winbindd_request_response(WINBINDD_INFO, NULL, &response) != NSS_STATUS_SUCCESS) { - d_printf("could not obtain winbind separator!\n"); + d_fprintf(stderr, "could not obtain winbind separator!\n"); if (strict) { return -1; } @@ -57,7 +57,7 @@ static char winbind_separator_int(BOOL strict) got_sep = True; if (!sep) { - d_printf("winbind separator was NULL!\n"); + d_fprintf(stderr, "winbind separator was NULL!\n"); if (strict) { return -1; } @@ -84,7 +84,7 @@ static const char *get_winbind_domain(void) if (winbindd_request_response(WINBINDD_DOMAIN_NAME, NULL, &response) != NSS_STATUS_SUCCESS) { - d_printf("could not obtain winbind domain name!\n"); + d_fprintf(stderr, "could not obtain winbind domain name!\n"); /* HACK: (this module should not call lp_ funtions) */ return lp_workgroup(); @@ -199,7 +199,7 @@ static BOOL wbinfo_get_userdomgroups(const char *user_sid) return False; if (response.data.num_entries != 0) - printf("%s", (char *)response.extra_data); + d_printf("%s", (char *)response.extra_data); SAFE_FREE(response.extra_data); @@ -227,7 +227,7 @@ static BOOL wbinfo_wins_byname(char *name) /* Display response */ - printf("%s\n", response.data.winsresp); + d_printf("%s\n", response.data.winsresp); return True; } @@ -253,7 +253,7 @@ static BOOL wbinfo_wins_byip(char *ip) /* Display response */ - printf("%s\n", response.data.winsresp); + d_printf("%s\n", response.data.winsresp); return True; } @@ -282,7 +282,7 @@ static BOOL wbinfo_list_domains(void) while(next_token(&extra_data, name, "\n", sizeof(fstring))) { p = strchr(name, '\\'); if (p == 0) { - d_printf("Got invalid response: %s\n", + d_fprintf(stderr, "Got invalid response: %s\n", extra_data); return False; } @@ -379,7 +379,7 @@ static BOOL wbinfo_getdcname(const char *domain_name) if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) != NSS_STATUS_SUCCESS) { - d_printf("Could not get dc name for %s\n", domain_name); + d_fprintf(stderr, "Could not get dc name for %s\n", domain_name); return False; } @@ -405,7 +405,7 @@ static BOOL wbinfo_check_secret(void) (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (result != NSS_STATUS_SUCCESS) - d_printf("error code was %s (0x%x)\n", + d_fprintf(stderr, "error code was %s (0x%x)\n", response.data.auth.nt_status_string, response.data.auth.nt_status); @@ -607,7 +607,7 @@ static BOOL wbinfo_auth(char *username) (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (response.data.auth.nt_status) - d_printf("error code was %s (0x%x)\nerror messsage was: %s\n", + d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n", response.data.auth.nt_status_string, response.data.auth.nt_status, response.data.auth.error_string); @@ -707,7 +707,7 @@ static BOOL wbinfo_auth_crap(char *username) (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (response.data.auth.nt_status) - d_printf("error code was %s (0x%x)\nerror messsage was: %s\n", + d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n", response.data.auth.nt_status_string, response.data.auth.nt_status, response.data.auth.error_string); @@ -751,7 +751,7 @@ static BOOL wbinfo_klog(char *username) (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed"); if (response.data.auth.nt_status) - d_printf("error code was %s (0x%x)\nerror messsage was: %s\n", + d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n", response.data.auth.nt_status_string, response.data.auth.nt_status, response.data.auth.error_string); @@ -760,12 +760,12 @@ static BOOL wbinfo_klog(char *username) return False; if (response.extra_data == NULL) { - d_printf("Did not get token data\n"); + d_fprintf(stderr, "Did not get token data\n"); return False; } if (!afs_settoken_str((char *)response.extra_data)) { - d_printf("Could not set token\n"); + d_fprintf(stderr, "Could not set token\n"); return False; } @@ -1058,114 +1058,114 @@ int main(int argc, char **argv) switch (opt) { case 'u': if (!print_domain_users(opt_domain_name)) { - d_printf("Error looking up domain users\n"); + d_fprintf(stderr, "Error looking up domain users\n"); goto done; } break; case 'g': if (!print_domain_groups(opt_domain_name)) { - d_printf("Error looking up domain groups\n"); + d_fprintf(stderr, "Error looking up domain groups\n"); goto done; } break; case 's': if (!wbinfo_lookupsid(string_arg)) { - d_printf("Could not lookup sid %s\n", string_arg); + d_fprintf(stderr, "Could not lookup sid %s\n", string_arg); goto done; } break; case 'n': if (!wbinfo_lookupname(string_arg)) { - d_printf("Could not lookup name %s\n", string_arg); + d_fprintf(stderr, "Could not lookup name %s\n", string_arg); goto done; } break; case 'N': if (!wbinfo_wins_byname(string_arg)) { - d_printf("Could not lookup WINS by name %s\n", string_arg); + d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg); goto done; } break; case 'I': if (!wbinfo_wins_byip(string_arg)) { - d_printf("Could not lookup WINS by IP %s\n", string_arg); + d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg); goto done; } break; case 'U': if (!wbinfo_uid_to_sid(int_arg)) { - d_printf("Could not convert uid %d to sid\n", int_arg); + d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg); goto done; } break; case 'G': if (!wbinfo_gid_to_sid(int_arg)) { - d_printf("Could not convert gid %d to sid\n", + d_fprintf(stderr, "Could not convert gid %d to sid\n", int_arg); goto done; } break; case 'S': if (!wbinfo_sid_to_uid(string_arg)) { - d_printf("Could not convert sid %s to uid\n", + d_fprintf(stderr, "Could not convert sid %s to uid\n", string_arg); goto done; } break; case 'Y': if (!wbinfo_sid_to_gid(string_arg)) { - d_printf("Could not convert sid %s to gid\n", + d_fprintf(stderr, "Could not convert sid %s to gid\n", string_arg); goto done; } break; case 'A': if (!wbinfo_allocate_rid()) { - d_printf("Could not allocate a RID\n"); + d_fprintf(stderr, "Could not allocate a RID\n"); goto done; } break; case 't': if (!wbinfo_check_secret()) { - d_printf("Could not check secret\n"); + d_fprintf(stderr, "Could not check secret\n"); goto done; } break; case 'm': if (!wbinfo_list_domains()) { - d_printf("Could not list trusted domains\n"); + d_fprintf(stderr, "Could not list trusted domains\n"); goto done; } break; case OPT_SEQUENCE: if (!wbinfo_show_sequence(opt_domain_name)) { - d_printf("Could not show sequence numbers\n"); + d_fprintf(stderr, "Could not show sequence numbers\n"); goto done; } break; case 'D': if (!wbinfo_domain_info(string_arg)) { - d_printf("Could not get domain info\n"); + d_fprintf(stderr, "Could not get domain info\n"); goto done; } break; case 'r': if (!wbinfo_get_usergroups(string_arg)) { - d_printf("Could not get groups for user %s\n", + d_fprintf(stderr, "Could not get groups for user %s\n", string_arg); goto done; } break; case OPT_USERSIDS: if (!wbinfo_get_usersids(string_arg)) { - d_printf("Could not get group SIDs for user SID %s\n", + d_fprintf(stderr, "Could not get group SIDs for user SID %s\n", string_arg); goto done; } break; case OPT_USERDOMGROUPS: if (!wbinfo_get_userdomgroups(string_arg)) { - d_printf("Could not get user's domain groups " + d_fprintf(stderr, "Could not get user's domain groups " "for user SID %s\n", string_arg); goto done; } @@ -1174,13 +1174,13 @@ int main(int argc, char **argv) BOOL got_error = False; if (!wbinfo_auth(string_arg)) { - d_printf("Could not authenticate user %s with " + d_fprintf(stderr, "Could not authenticate user %s with " "plaintext password\n", string_arg); got_error = True; } if (!wbinfo_auth_crap(string_arg)) { - d_printf("Could not authenticate user %s with " + d_fprintf(stderr, "Could not authenticate user %s with " "challenge/response\n", string_arg); got_error = True; } @@ -1191,29 +1191,37 @@ int main(int argc, char **argv) } case 'k': if (!wbinfo_klog(string_arg)) { - d_printf("Could not klog user\n"); + d_fprintf(stderr, "Could not klog user\n"); goto done; } break; case 'p': if (!wbinfo_ping()) { - d_printf("could not ping winbindd!\n"); + d_fprintf(stderr, "Could not ping winbindd!\n"); goto done; } break; case OPT_SET_AUTH_USER: - wbinfo_set_auth_user(string_arg); + if (!wbinfo_set_auth_user(string_arg)) { + goto done; + } break; case OPT_GET_AUTH_USER: wbinfo_get_auth_user(); break; case OPT_GETDCNAME: - wbinfo_getdcname(string_arg); + if (!wbinfo_getdcname(string_arg)) { + goto done; + } break; - case OPT_SEPARATOR: - d_printf("%c\n", winbind_separator_int(True)); + case OPT_SEPARATOR: { + const char sep = winbind_separator_int(True); + if (sep == -1) { + goto done; + } + d_printf("%c\n", sep); break; - + } /* generic configuration options */ case OPT_DOMAIN_NAME: break; -- cgit From 119b53bcde917396b0c3d63e817590186e462e5e Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 21 Dec 2005 23:15:57 +0000 Subject: r12414: Remove the unnecessary SMB_STRDUP in server_role_str() + reuse the role translation elsewhere. Guenther --- source/param/loadparm.c | 39 +++++++++++++++++++++++---------------- source/rpcclient/cmd_samr.c | 21 --------------------- source/utils/testparm.c | 19 +------------------ 3 files changed, 24 insertions(+), 55 deletions(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index ca47e48d8c8..fa61a8aedb4 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -4098,6 +4098,28 @@ static void lp_save_defaults(void) Set the server type we will announce as via nmbd. ********************************************************************/ +static const struct srv_role_tab { + uint32 role; + const char *role_str; +} srv_role_tab [] = { + { ROLE_STANDALONE, "ROLE_STANDALONE" }, + { ROLE_DOMAIN_MEMBER, "ROLE_DOMAIN_MEMBER" }, + { ROLE_DOMAIN_BDC, "ROLE_DOMAIN_BDC" }, + { ROLE_DOMAIN_PDC, "ROLE_DOMAIN_PDC" }, + { 0, NULL } +}; + +const char* server_role_str(uint32 role) +{ + int i = 0; + for (i=0; srv_role_tab[i].role_str; i++) { + if (role == srv_role_tab[i].role) { + return srv_role_tab[i].role_str; + } + } + return NULL; +} + static void set_server_role(void) { server_role = ROLE_STANDALONE; @@ -4141,22 +4163,7 @@ static void set_server_role(void) break; } - DEBUG(10, ("set_server_role: role = ")); - - switch(server_role) { - case ROLE_STANDALONE: - DEBUGADD(10, ("ROLE_STANDALONE\n")); - break; - case ROLE_DOMAIN_MEMBER: - DEBUGADD(10, ("ROLE_DOMAIN_MEMBER\n")); - break; - case ROLE_DOMAIN_BDC: - DEBUGADD(10, ("ROLE_DOMAIN_BDC\n")); - break; - case ROLE_DOMAIN_PDC: - DEBUGADD(10, ("ROLE_DOMAIN_PDC\n")); - break; - } + DEBUG(10, ("set_server_role: role = %s", server_role_str(server_role))); } /*********************************************************** diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 2050f2a7796..e711cc7d1c0 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -141,27 +141,6 @@ static const char *display_time(NTTIME nttime) return (string); } -static const char* server_role_str(uint32 server_role) -{ - switch(server_role) { - case ROLE_STANDALONE: - return SMB_STRDUP("ROLE_STANDALONE"); - break; - case ROLE_DOMAIN_MEMBER: - return SMB_STRDUP("ROLE_DOMAIN_MEMBER"); - break; - case ROLE_DOMAIN_BDC: - return SMB_STRDUP("ROLE_DOMAIN_BDC"); - break; - case ROLE_DOMAIN_PDC: - return SMB_STRDUP("ROLE_DOMAIN_PDC"); - break; - default: - return SMB_STRDUP("Unknown -- internal error?"); - break; - } -} - static void display_sam_unk_info_1(SAM_UNK_INFO_1 *info1) { diff --git a/source/utils/testparm.c b/source/utils/testparm.c index 0ce838e5c76..8490c850091 100644 --- a/source/utils/testparm.c +++ b/source/utils/testparm.c @@ -348,24 +348,7 @@ print command parameter is ignored when using CUPS libraries.\n", if (!silent_mode && !section_name && !parameter_name) { - fprintf(stderr,"Server role: "); - switch(lp_server_role()) { - case ROLE_STANDALONE: - fprintf(stderr,"ROLE_STANDALONE\n"); - break; - case ROLE_DOMAIN_MEMBER: - fprintf(stderr,"ROLE_DOMAIN_MEMBER\n"); - break; - case ROLE_DOMAIN_BDC: - fprintf(stderr,"ROLE_DOMAIN_BDC\n"); - break; - case ROLE_DOMAIN_PDC: - fprintf(stderr,"ROLE_DOMAIN_PDC\n"); - break; - default: - fprintf(stderr,"Unknown -- internal error?\n"); - break; - } + fprintf(stderr,"Server role: %s", server_role_str(lp_server_role())); } if (!cname) { -- cgit From 27e6eb0a48594fe48e7d13727f60b93f1934ead0 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 21 Dec 2005 23:26:23 +0000 Subject: r12415: Forgot newlines. Guenther --- source/param/loadparm.c | 2 +- source/utils/testparm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index fa61a8aedb4..526bce9b60e 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -4163,7 +4163,7 @@ static void set_server_role(void) break; } - DEBUG(10, ("set_server_role: role = %s", server_role_str(server_role))); + DEBUG(10, ("set_server_role: role = %s\n", server_role_str(server_role))); } /*********************************************************** diff --git a/source/utils/testparm.c b/source/utils/testparm.c index 8490c850091..e097ea34d61 100644 --- a/source/utils/testparm.c +++ b/source/utils/testparm.c @@ -348,7 +348,7 @@ print command parameter is ignored when using CUPS libraries.\n", if (!silent_mode && !section_name && !parameter_name) { - fprintf(stderr,"Server role: %s", server_role_str(lp_server_role())); + fprintf(stderr,"Server role: %s\n", server_role_str(lp_server_role())); } if (!cname) { -- cgit From 699ede29ab378dc83d1c52b88371de037280dc30 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 22 Dec 2005 20:57:47 +0000 Subject: r12438: Remove an unused function --- source/groupdb/mapping.c | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 97a3d6ab0e9..7dc0426c449 100644 --- a/source/groupdb/mapping.c +++ b/source/groupdb/mapping.c @@ -887,34 +887,6 @@ BOOL get_builtin_group_from_sid(DOM_SID *sid, GROUP_MAP *map) return True; } - - -/**************************************************************************** -Returns a GROUP_MAP struct based on the gid. -****************************************************************************/ -BOOL get_group_from_gid(gid_t gid, GROUP_MAP *map) -{ - BOOL ret; - - if(!init_group_mapping()) { - DEBUG(0,("failed to initialize group mapping\n")); - return(False); - } - - if ( getgrgid(gid) == NULL) - return False; - - become_root(); - ret = pdb_getgrgid(map, gid); - unbecome_root(); - - if ( !ret ) { - return False; - } - - return True; -} - /**************************************************************************** Create a UNIX group on demand. ****************************************************************************/ -- cgit From a60360b953b54bc45eac929e375196d4f3581b66 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 22 Dec 2005 22:15:52 +0000 Subject: r12441: Fix python build. Guenther --- source/python/setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/python/setup.py b/source/python/setup.py index 18f1f2648ab..ffdafd70877 100755 --- a/source/python/setup.py +++ b/source/python/setup.py @@ -63,8 +63,10 @@ for lib in string.split(samba_libs): next_is_flag = 0; elif lib == "-Wl,-rpath": next_is_path = 1; - elif lib[0:2] in ("-l","-pthread"): + elif lib[0:2] in ("-l"): libraries.append(lib[2:]) + elif lib[0:8] in ("-pthread"): + pass # Skip linker flags elif lib[0:2] == "-L": library_dirs.append(lib[2:]) elif lib[0:2] in ("-W","-s"): -- cgit From 8d76dcc41508b28b1d6c53b143b8095f6b7625fd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 23 Dec 2005 14:45:56 +0000 Subject: r12452: Fix Bug #3053 to allow esp. older eDirectory releases to load our LDAP schema. Maybe "Base64 encoded user parameter string" is not much clearer then "munged dial" - anyone got a better description ? Guenther --- examples/LDAP/samba-nds.schema | 2 +- examples/LDAP/samba-schema-netscapeds5.x | 2 +- examples/LDAP/samba.schema | 2 +- examples/LDAP/samba.schema.at.IBM-DS | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/LDAP/samba-nds.schema b/examples/LDAP/samba-nds.schema index bb03a67d4dc..7bfa5040f87 100644 --- a/examples/LDAP/samba-nds.schema +++ b/examples/LDAP/samba-nds.schema @@ -123,7 +123,7 @@ attributeTypes: ( 1.3.6.1.4.1.7165.2.1.38 NAME 'sambaDomainName' DESC 'Windows N dn: cn=schema changetype: modify add: attributetypes -attributeTypes: ( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC '' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) +attributeTypes: ( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC 'Base64 encoded user parameter string' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) dn: cn=schema changetype: modify diff --git a/examples/LDAP/samba-schema-netscapeds5.x b/examples/LDAP/samba-schema-netscapeds5.x index 1e0d18b6ba4..efc528b7864 100644 --- a/examples/LDAP/samba-schema-netscapeds5.x +++ b/examples/LDAP/samba-schema-netscapeds5.x @@ -48,7 +48,7 @@ attributeTypes: ( 1.3.6.1.4.1.7165.2.1.35 NAME 'sambaProfilePath' DESC 'Roaming attributeTypes: ( 1.3.6.1.4.1.7165.2.1.36 NAME 'sambaUserWorkstations' DESC 'List of user workstations the user is allowed to logon to' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{255} SINGLE-VALUE X-ORIGIN 'user defined' ) attributeTypes: ( 1.3.6.1.4.1.7165.2.1.37 NAME 'sambaHomePath' DESC 'Home directory UNC path' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{128} ) attributeTypes: ( 1.3.6.1.4.1.7165.2.1.38 NAME 'sambaDomainName' DESC 'Windows NT domain to which the user belongs' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{128} ) -attributeTypes: ( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC '' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) +attributeTypes: ( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC 'Base64 encoded user parameter string' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) attributeTypes: ( 1.3.6.1.4.1.7165.2.1.48 NAME 'sambaBadPasswordCount' DESC 'Bad password attempt count' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) attributeTypes: ( 1.3.6.1.4.1.7165.2.1.49 NAME 'sambaBadPasswordTime' DESC 'Time of the last bad password attempt' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) attributeTypes: ( 1.3.6.1.4.1.7165.2.1.54 NAME 'sambaPasswordHistory' DESC 'Concatenated MD4 hashes of the unicode passwords used on this account' EQUALITY caseIgnoreIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32} ) diff --git a/examples/LDAP/samba.schema b/examples/LDAP/samba.schema index daf4588ead5..e7ecc9e070e 100644 --- a/examples/LDAP/samba.schema +++ b/examples/LDAP/samba.schema @@ -279,7 +279,7 @@ attributetype ( 1.3.6.1.4.1.7165.2.1.38 NAME 'sambaDomainName' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{128} ) attributetype ( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' - DESC '' + DESC 'Base64 encoded user parameter string' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) diff --git a/examples/LDAP/samba.schema.at.IBM-DS b/examples/LDAP/samba.schema.at.IBM-DS index f14d8e164df..375a0baede6 100644 --- a/examples/LDAP/samba.schema.at.IBM-DS +++ b/examples/LDAP/samba.schema.at.IBM-DS @@ -58,7 +58,7 @@ attributetypes=( 1.3.6.1.4.1.7165.2.1.45 NAME 'sambaStringOption' DESC 'A string attributetypes=( 1.3.6.1.4.1.7165.2.1.46 NAME 'sambaStringListOption' DESC 'A string list option' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) -attributetypes=( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC 'munged dial' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) +attributetypes=( 1.3.6.1.4.1.7165.2.1.47 NAME 'sambaMungedDial' DESC 'Base64 encoded user parameter string' EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1050} ) attributetypes=( 1.3.6.1.4.1.7165.2.1.48 NAME 'sambaBadPasswordCount' DESC 'Bad password attempt count' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE ) -- cgit From 877621cc4cd64ad784e76ceb1a45e525f2671810 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Dec 2005 21:06:41 +0000 Subject: r12460: Fixes for bug 3349 --- source/smbd/close.c | 2 ++ source/smbd/open.c | 8 ++++++-- source/smbd/oplock.c | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/smbd/close.c b/source/smbd/close.c index 407c6078385..f8348699359 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -130,8 +130,10 @@ static void notify_deferred_opens(struct share_mode_lock *lck) */ schedule_deferred_open_smb_message(e->op_mid); } else { + become_root(); message_send_pid(e->pid, MSG_SMB_OPEN_RETRY, e, sizeof(*e), True); + unbecome_root(); } } } diff --git a/source/smbd/open.c b/source/smbd/open.c index 7621ee001dd..e6c749fab9c 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -682,11 +682,15 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck, files_struct *fsp) } if (delay_it) { + BOOL ret; DEBUG(10, ("Sending break request to PID %s\n", procid_str_static(&exclusive->pid))); exclusive->op_mid = get_current_mid(); - if (!message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST, - exclusive, sizeof(*exclusive), True)) { + become_root(); + ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST, + exclusive, sizeof(*exclusive), True); + unbecome_root(); + if (!ret) { DEBUG(3, ("Could not send oplock break message\n")); } file_free(fsp); diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c index f6c97c3df48..54e7da11afe 100644 --- a/source/smbd/oplock.c +++ b/source/smbd/oplock.c @@ -398,8 +398,10 @@ static void process_oplock_break_message(int msg_type, struct process_id src, * get to process this message, we have closed the file. Reply * with 'ok, oplock broken' */ DEBUG(3, ("Did not find fsp\n")); + become_root(); message_send_pid(src, MSG_SMB_BREAK_RESPONSE, msg, sizeof(*msg), True); + unbecome_root(); return; } @@ -418,8 +420,10 @@ static void process_oplock_break_message(int msg_type, struct process_id src, DEBUG(3, ("Already downgraded oplock on %.0f/%.0f: %s\n", (double)fsp->dev, (double)fsp->inode, fsp->fsp_name)); + become_root(); message_send_pid(src, MSG_SMB_BREAK_RESPONSE, msg, sizeof(*msg), True); + unbecome_root(); return; } @@ -545,11 +549,13 @@ void reply_to_oplock_break_requests(files_struct *fsp) { int i; + become_root(); for (i=0; inum_pending_break_messages; i++) { struct share_mode_entry *msg = &fsp->pending_break_messages[i]; message_send_pid(msg->pid, MSG_SMB_BREAK_RESPONSE, msg, sizeof(*msg), True); } + unbecome_root(); SAFE_FREE(fsp->pending_break_messages); fsp->num_pending_break_messages = 0; @@ -686,8 +692,10 @@ void release_level_2_oplocks_on_change(files_struct *fsp) abort(); } + become_root(); message_send_pid(share_entry->pid, MSG_SMB_ASYNC_LEVEL2_BREAK, share_entry, sizeof(*share_entry), True); + unbecome_root(); } remove_all_share_oplocks(lck, fsp); -- cgit From ff08e131e3644689a7c549be837ec70834e25648 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 02:00:21 +0000 Subject: r12466: r12028@cabra: derrell | 2005-12-24 20:25:38 -0500 parse dates correctly. w_time and m_time were reversed. --- source/libsmb/clirap.c | 10 +++++----- source/libsmb/libsmbclient.c | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/source/libsmb/clirap.c b/source/libsmb/clirap.c index 172dea4090a..6716971fe2c 100644 --- a/source/libsmb/clirap.c +++ b/source/libsmb/clirap.c @@ -592,18 +592,18 @@ BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, if (!rdata || data_len < 22) { return False; } - + if (c_time) { *c_time = interpret_long_date(rdata+0); } if (a_time) { *a_time = interpret_long_date(rdata+8); } - if (m_time) { - *m_time = interpret_long_date(rdata+16); - } if (w_time) { - *w_time = interpret_long_date(rdata+24); + *w_time = interpret_long_date(rdata+16); + } + if (m_time) { + *m_time = interpret_long_date(rdata+24); } if (mode) { *mode = SVAL(rdata, 32); diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 15210664b07..623977b39e7 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -1380,8 +1380,10 @@ static BOOL smbc_getatr(SMBCCTX * context, SMBCSRV *srv, char *path, } if (!srv->no_pathinfo2 && - cli_qpathinfo2(targetcli, targetpath, c_time, a_time, m_time, NULL, - size, mode, ino)) return True; + cli_qpathinfo2(targetcli, targetpath, + c_time, a_time, m_time, NULL, size, mode, ino)) { + return True; + } /* if this is NT then don't bother with the getatr */ if (targetcli->capabilities & CAP_NT_SMBS) { -- cgit From 83d5355e3f77c9397dd2f290c4004cc53c6eb49c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 02:00:35 +0000 Subject: r12467: r12029@cabra: derrell | 2005-12-24 20:25:59 -0500 add another libsmbclient test program --- examples/libsmbclient/Makefile | 5 +++++ examples/libsmbclient/teststat.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/libsmbclient/Makefile b/examples/libsmbclient/Makefile index c324a578d14..a88f4a240cd 100644 --- a/examples/libsmbclient/Makefile +++ b/examples/libsmbclient/Makefile @@ -17,6 +17,7 @@ TESTS= testsmbc \ testbrowse \ testbrowse2 \ teststat \ + teststat2 \ testchmod \ testutime \ testread @@ -47,6 +48,10 @@ teststat: teststat.o @echo Linking teststat @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< +teststat2: teststat2.o + @echo Linking teststat2 + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< + testchmod: testchmod.o @echo Linking testchmod @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ /usr/local/samba/lib/libsmbclient.so -lpopt $< diff --git a/examples/libsmbclient/teststat.c b/examples/libsmbclient/teststat.c index 29517efb6f6..86c69e4e2cd 100644 --- a/examples/libsmbclient/teststat.c +++ b/examples/libsmbclient/teststat.c @@ -48,7 +48,7 @@ int main(int argc, char * argv[]) return 1; } - printf("SAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + printf("\nSAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", st.st_mtime, ctime_r(&st.st_mtime, mtime), st.st_ctime, ctime_r(&st.st_ctime, ctime), st.st_atime, ctime_r(&st.st_atime, atime)); -- cgit From d1d6a83921ae8ff09dddd87ef95e2aa6012c2c7d Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 02:03:51 +0000 Subject: r12468: r12033@cabra: derrell | 2005-12-24 21:03:45 -0500 actually add the new test program --- examples/libsmbclient/teststat2.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/libsmbclient/teststat2.c diff --git a/examples/libsmbclient/teststat2.c b/examples/libsmbclient/teststat2.c new file mode 100644 index 00000000000..d1cdf285014 --- /dev/null +++ b/examples/libsmbclient/teststat2.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include "get_auth_data_fn.h" + +/* + * This test is intended to ensure that the timestamps returned by + * libsmbclient are the same as timestamps returned by the local system. To + * test this, we assume a working Samba environment, and and access the same + * file via SMB and locally (or NFS). + * + */ + + +static int gettime(const char * pUrl, + const char * pLocalPath); + + +int main(int argc, char* argv[]) +{ + if(argc != 3) + { + printf("usage: %s \n", argv[0]); + return 1; + } + + gettime(argv[1], argv[2]); + return 0; +} + + +static int gettime(const char * pUrl, + const char * pLocalPath) +{ + //char *pSmbPath = 0; + struct stat st; + char mtime[32]; + char ctime[32]; + char atime[32]; + + smbc_init(get_auth_data_fn, 0); + + if (smbc_stat(pUrl, &st) < 0) + { + perror("smbc_stat"); + return 1; + } + + printf("SAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); + + + // check the stat on this file + if (stat(pLocalPath, &st) < 0) + { + perror("stat"); + return 1; + } + + printf("LOCAL\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", + st.st_mtime, ctime_r(&st.st_mtime, mtime), + st.st_ctime, ctime_r(&st.st_ctime, ctime), + st.st_atime, ctime_r(&st.st_atime, atime)); + + + return 0; +} + -- cgit From e31c87327eb97b1a1fc2cb5c2b7d4dff6f798a12 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 04:17:32 +0000 Subject: r12471: r12038@cabra: derrell | 2005-12-24 23:17:16 -0500 libsmbclient was not loading the global configuration file. This should fix 3336. --- source/libsmb/libsmbclient.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 623977b39e7..635f280bee1 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -5673,6 +5673,11 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) /* Here we would open the smb.conf file if needed ... */ + if (!lp_load(dyn_CONFIGFILE, True, False, False)) { + DEBUG(5, ("Could not load config file: %s\n", + dyn_CONFIGFILE)); + } + load_interfaces(); /* Load the list of interfaces ... */ in_client = True; /* FIXME, make a param */ -- cgit From afc34b29cf0d9c92c7b6ec2dce23a53b7ef8b1ce Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 04:26:59 +0000 Subject: r12472: r12040@cabra: derrell | 2005-12-24 23:26:55 -0500 revert immediately previous change and fix problem correctly. Interfaces were being loaded before all configuration files had been read. *This* should fix byg 3336. --- source/libsmb/libsmbclient.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 635f280bee1..d2d45a72284 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -5673,13 +5673,6 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) /* Here we would open the smb.conf file if needed ... */ - if (!lp_load(dyn_CONFIGFILE, True, False, False)) { - DEBUG(5, ("Could not load config file: %s\n", - dyn_CONFIGFILE)); - } - - load_interfaces(); /* Load the list of interfaces ... */ - in_client = True; /* FIXME, make a param */ home = getenv("HOME"); @@ -5721,6 +5714,8 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) } } + load_interfaces(); /* Load the list of interfaces ... */ + reopen_logs(); /* Get logging working ... */ /* -- cgit From d085d437cd488ba13ea1f928fcbd48b6ef970a31 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Dec 2005 09:49:10 +0000 Subject: r12474: Fix a warning --- source/profile/profile.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/profile/profile.c b/source/profile/profile.c index 0cf8c8e15bf..c3399f874d9 100644 --- a/source/profile/profile.c +++ b/source/profile/profile.c @@ -44,7 +44,7 @@ struct timeval profile_endtime_nested; /**************************************************************************** receive a set profile level message ****************************************************************************/ -void profile_message(int msg_type, pid_t src, void *buf, size_t len) +void profile_message(int msg_type, struct process_id src, void *buf, size_t len) { int level; @@ -54,21 +54,25 @@ void profile_message(int msg_type, pid_t src, void *buf, size_t len) case 0: /* turn off profiling */ do_profile_flag = False; do_profile_times = False; - DEBUG(1,("INFO: Profiling turned OFF from pid %d\n", (int)src)); + DEBUG(1,("INFO: Profiling turned OFF from pid %d\n", + (int)procid_to_pid(src))); break; case 1: /* turn on counter profiling only */ do_profile_flag = True; do_profile_times = False; - DEBUG(1,("INFO: Profiling counts turned ON from pid %d\n", (int)src)); + DEBUG(1,("INFO: Profiling counts turned ON from pid %d\n", + (int)procid_to_pid(src))); break; case 2: /* turn on complete profiling */ do_profile_flag = True; do_profile_times = True; - DEBUG(1,("INFO: Full profiling turned ON from pid %d\n", (int)src)); + DEBUG(1,("INFO: Full profiling turned ON from pid %d\n", + (int)procid_to_pid(src))); break; case 3: /* reset profile values */ memset((char *)profile_p, 0, sizeof(*profile_p)); - DEBUG(1,("INFO: Profiling values cleared from pid %d\n", (int)src)); + DEBUG(1,("INFO: Profiling values cleared from pid %d\n", + (int)procid_to_pid(src))); break; } #else /* WITH_PROFILE */ -- cgit From 048fda6642721280cd25a6f81f33f8d44a92b31c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Dec 2005 10:06:05 +0000 Subject: r12475: Actually configure with profile support this time ... --- source/profile/profile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/profile/profile.c b/source/profile/profile.c index c3399f874d9..838383b1afe 100644 --- a/source/profile/profile.c +++ b/source/profile/profile.c @@ -55,24 +55,24 @@ void profile_message(int msg_type, struct process_id src, void *buf, size_t len) do_profile_flag = False; do_profile_times = False; DEBUG(1,("INFO: Profiling turned OFF from pid %d\n", - (int)procid_to_pid(src))); + (int)procid_to_pid(&src))); break; case 1: /* turn on counter profiling only */ do_profile_flag = True; do_profile_times = False; DEBUG(1,("INFO: Profiling counts turned ON from pid %d\n", - (int)procid_to_pid(src))); + (int)procid_to_pid(&src))); break; case 2: /* turn on complete profiling */ do_profile_flag = True; do_profile_times = True; DEBUG(1,("INFO: Full profiling turned ON from pid %d\n", - (int)procid_to_pid(src))); + (int)procid_to_pid(&src))); break; case 3: /* reset profile values */ memset((char *)profile_p, 0, sizeof(*profile_p)); DEBUG(1,("INFO: Profiling values cleared from pid %d\n", - (int)procid_to_pid(src))); + (int)procid_to_pid(&src))); break; } #else /* WITH_PROFILE */ -- cgit From 2c1fd700842021abf0628291132cbb6f908ac7be Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Dec 2005 10:27:45 +0000 Subject: r12476: Apply some const --- source/libsmb/clispnego.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libsmb/clispnego.c b/source/libsmb/clispnego.c index 6340a9bdcd4..cc481a066ab 100644 --- a/source/libsmb/clispnego.c +++ b/source/libsmb/clispnego.c @@ -260,7 +260,7 @@ BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se /* generate a krb5 GSS-API wrapper packet given a ticket */ -DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8 tok_id[2]) +DATA_BLOB spnego_gen_krb5_wrap(const DATA_BLOB ticket, const uint8 tok_id[2]) { ASN1_DATA data; DATA_BLOB ret; -- cgit From 54d2a7cdf3ec46f9ceb550b258e59281073f4379 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 25 Dec 2005 10:41:34 +0000 Subject: r12477: Remove a gcc -O6 warning --- source/smbd/quotas.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/smbd/quotas.c b/source/smbd/quotas.c index de31376d6c6..d6ba7bc2d55 100644 --- a/source/smbd/quotas.c +++ b/source/smbd/quotas.c @@ -206,6 +206,8 @@ BOOL disk_quotas(const char *path, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB uid_t euser_id; gid_t egrp_id; + ZERO_STRUCT(D); + euser_id = geteuid(); egrp_id = getegid(); -- cgit From f02dc9caf21627b9060a9a3156fb12ecee2280e1 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 25 Dec 2005 21:46:58 +0000 Subject: r12485: r12044@cabra: derrell | 2005-12-25 16:46:47 -0500 When enumerating what could be a server name or a workgroup name, first check for an existing server structure. If none exists, then go through the previous determination of whether it's a serrver or a workgroup. This should avoid doing a NetBIOS name query each time, if we've already connected to the specified server. (While we're at it, clean up indenting and line length in this area of code.) --- source/libsmb/libsmbclient.c | 160 +++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 73 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index d2d45a72284..b81dd88424c 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -2509,10 +2509,10 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) * Server not an empty string ... Check the rest and see what * gives */ - if (share[0] == (char)0) { - - if (path[0] != (char)0) { /* Should not have empty share with path */ + if (*share == '\0') { + if (*path != '\0') { + /* Should not have empty share with path */ errno = EINVAL + 8197; if (dir) { SAFE_FREE(dir->fname); @@ -2522,12 +2522,28 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) } - /* Check to see if <1D>, <1B>, or <20> translates */ - /* However, we check to see if is an IP address first */ + /* + * We don't know if is really a server name + * or is a workgroup/domain name. If we already have + * a server structure for it, we'll use it. + * Otherwise, check to see if <1D>, + * <1B>, or <20> translates. We check + * to see if is an IP address first. + */ + + /* See if we have an existing server */ + srv = smbc_server(context, server, "IPC$", + workgroup, user, password); + + /* + * If no existing server and not an IP addr, look for + * LMB or DMB + */ + if (!srv && + !is_ipaddress(server) && + (resolve_name(server, &rem_ip, 0x1d) || /* LMB */ + resolve_name(server, &rem_ip, 0x1b) )) { /* DMB */ - if (!is_ipaddress(server) && /* Not an IP addr so check next */ - (resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */ - resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */ fstring buserver; dir->dir_type = SMBC_SERVER; @@ -2535,22 +2551,23 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) /* * Get the backup list ... */ + if (!name_status_find(server, 0, 0, + rem_ip, buserver)) { - - if (!name_status_find(server, 0, 0, rem_ip, buserver)) { - - DEBUG(0, ("Could not get name of local/domain master browser for server %s\n", server)); - errno = EPERM; /* FIXME, is this correct */ + DEBUG(0, ("Could not get name of " + "local/domain master browser " + "for server %s\n", server)); + errno = EPERM; return NULL; } /* - * Get a connection to IPC$ on the server if we do not already have one - */ - - srv = smbc_server(context, buserver, "IPC$", workgroup, user, password); - + * Get a connection to IPC$ on the server if + * we do not already have one + */ + srv = smbc_server(context, buserver, "IPC$", + workgroup, user, password); if (!srv) { DEBUG(0, ("got no contact to IPC$\n")); if (dir) { @@ -2564,8 +2581,8 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) dir->srv = srv; /* Now, list the servers ... */ - - if (!cli_NetServerEnum(&srv->cli, server, 0x0000FFFE, list_fn, + if (!cli_NetServerEnum(&srv->cli, server, + 0x0000FFFE, list_fn, (void *)dir)) { if (dir) { @@ -2573,75 +2590,72 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) SAFE_FREE(dir); } return NULL; - } - } - else { - - if (resolve_name(server, &rem_ip, 0x20)) { - - /* Now, list the shares ... */ - - dir->dir_type = SMBC_FILE_SHARE; - - srv = smbc_server(context, server, "IPC$", workgroup, user, password); - - if (!srv) { + } else if (srv || + (resolve_name(server, &rem_ip, 0x20))) { + + /* If we hadn't found the server, get one now */ + if (!srv) { + srv = smbc_server(context, server, + "IPC$", workgroup, + user, password); + } - if (dir) { - SAFE_FREE(dir->fname); - SAFE_FREE(dir); - } - return NULL; + if (!srv) { + if (dir) { + SAFE_FREE(dir->fname); + SAFE_FREE(dir); + } + return NULL; - } + } - dir->srv = srv; + dir->dir_type = SMBC_FILE_SHARE; + dir->srv = srv; - /* Now, list the servers ... */ + /* List the shares ... */ - if (net_share_enum_rpc( - &srv->cli, - list_fn, - (void *) dir) < 0 && - cli_RNetShareEnum( - &srv->cli, - list_fn, - (void *)dir) < 0) { + if (net_share_enum_rpc( + &srv->cli, + list_fn, + (void *) dir) < 0 && + cli_RNetShareEnum( + &srv->cli, + list_fn, + (void *)dir) < 0) { - errno = cli_errno(&srv->cli); - if (dir) { - SAFE_FREE(dir->fname); - SAFE_FREE(dir); - } - return NULL; - - } - - } - else { - - errno = ECONNREFUSED; /* Neither the workgroup nor server exists */ - if (dir) { - SAFE_FREE(dir->fname); - SAFE_FREE(dir); - } - return NULL; - - } + errno = cli_errno(&srv->cli); + if (dir) { + SAFE_FREE(dir->fname); + SAFE_FREE(dir); + } + return NULL; + } + } else { + /* Neither the workgroup nor server exists */ + errno = ECONNREFUSED; + if (dir) { + SAFE_FREE(dir->fname); + SAFE_FREE(dir); + } + return NULL; } } - else { /* The server and share are specified ... work from there ... */ + else { + /* + * The server and share are specified ... work from + * there ... + */ pstring targetpath; struct cli_state *targetcli; - /* Well, we connect to the server and list the directory */ - + /* We connect to the server and list the directory */ dir->dir_type = SMBC_FILE_SHARE; - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, server, share, + workgroup, user, password); if (!srv) { -- cgit From cc9839a2295df106d5c83bc27894090df3fe0bd6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 26 Dec 2005 11:44:15 +0000 Subject: r12491: End profile fixes from SATOH Fumiyasu . Jeremy. --- source/smbd/nttrans.c | 1 - source/smbd/reply.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/source/smbd/nttrans.c b/source/smbd/nttrans.c index 91dcc933227..72288e2c244 100644 --- a/source/smbd/nttrans.c +++ b/source/smbd/nttrans.c @@ -1288,7 +1288,6 @@ static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *o if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) || NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) { restore_case_semantics(conn, file_attributes); - END_PROFILE(SMBntcreateX); return ERROR_NT(status); } } diff --git a/source/smbd/reply.c b/source/smbd/reply.c index 063cdf2974e..d56e3c1f1ce 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -5465,7 +5465,7 @@ int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int size, outsize = set_message(outbuf,0,0,True); if(!fsp || (fsp->conn != conn)) { - END_PROFILE(SMBgetattrE); + END_PROFILE(SMBsetattrE); return ERROR_DOS(ERRDOS,ERRbadfid); } -- cgit From 5c331846e3d0d227da0cf021f0c3462086d0c7eb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 26 Dec 2005 17:22:46 +0000 Subject: r12495: Crackcheck utility enhancement based on patch sent by Tom Geissler --- examples/auth/crackcheck/crackcheck.c | 73 ++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/examples/auth/crackcheck/crackcheck.c b/examples/auth/crackcheck/crackcheck.c index 338433779b0..0636114a17c 100644 --- a/examples/auth/crackcheck/crackcheck.c +++ b/examples/auth/crackcheck/crackcheck.c @@ -19,20 +19,81 @@ void usage(char *command) { exit(-1); } +int complexity(char* passwd) +{ + /* TG 26.10.2005 + * check password for complexity like MS Windows NT + */ + + int c_upper = 0; + int c_lower = 0; + int c_digit = 0; + int c_punct = 0; + int c_tot = 0; + int i, len; + + if (!passwd) goto fail; + len = strlen(passwd); + + for (i = 0; i < len; i++) { + + if (c_tot >= 3) break; + + if (isupper(passwd[i])) { + if (!c_upper) { + c_upper = 1; + c_tot += 1; + } + continue; + } + if (islower(passwd[i])) { + if (!c_lower) { + c_lower = 1; + c_tot += 1; + } + continue; + } + if (isdigit(passwd[i])) { + if (!c_digit) { + c_digit = 1; + c_tot += 1; + } + continue; + } + if (ispunct(passwd[i])) { + if (!c_punct) { + c_punct = 1; + c_tot += 1; + } + continue; + } + } + + if ((c_tot) < 3) goto fail; + return 0; + +fail: + fprintf(stderr, "ERR Complexity check failed\n\n"); + return -4; +} + int main(int argc, char **argv) { extern char *optarg; - int c; + int c, ret, complex_check = 0; char f[256]; char *dictionary = NULL; char *password; char *reply; - while ( (c = getopt(argc, argv, "d:")) != EOF){ + while ( (c = getopt(argc, argv, "d:c")) != EOF){ switch(c) { case 'd': dictionary = strdup(optarg); break; + case 'c': + complex_check = 1; + break; default: usage(argv[0]); } @@ -43,6 +104,7 @@ int main(int argc, char **argv) { usage(argv[0]); } + fflush(stdin); password = fgets(f, sizeof(f), stdin); if (password == NULL) { @@ -50,6 +112,13 @@ int main(int argc, char **argv) { exit(-2); } + if (complex_check) { + ret = complexity(password); + if (ret) { + exit(ret); + } + } + reply = FascistCheck(password, dictionary); if (reply != NULL) { fprintf(stderr, "ERR - %s\n\n", reply); -- cgit From c38ad8b70e0cb4f193240f198221e2f7b05c8227 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 26 Dec 2005 17:36:33 +0000 Subject: r12497: add a simplex option better usage message --- examples/auth/crackcheck/crackcheck.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/examples/auth/crackcheck/crackcheck.c b/examples/auth/crackcheck/crackcheck.c index 0636114a17c..ac29b22592e 100644 --- a/examples/auth/crackcheck/crackcheck.c +++ b/examples/auth/crackcheck/crackcheck.c @@ -13,9 +13,11 @@ void usage(char *command) { comm = c + 1; } - fprintf(stderr, "Usage: %s -d dictionary\n\n", comm); - fprintf(stderr, " -d dictionary file for cracklib\n\n"); - fprintf(stderr, " The password is expected to be given via stdin.\n\n"); + fprintf(stderr, "Usage: %s [-c] [-s] [-d ]\n\n", comm); + fprintf(stderr, " -c enables NT like complexity checks\n"); + fprintf(stderr, " -d for cracklib\n"); + fprintf(stderr, " -s simple check use NT like checks ONLY\n\n"); + fprintf(stderr, "The password is read via stdin.\n\n"); exit(-1); } @@ -79,14 +81,14 @@ fail: int main(int argc, char **argv) { extern char *optarg; - int c, ret, complex_check = 0; + int c, ret, complex_check = 0, simplex_check = 0; char f[256]; char *dictionary = NULL; char *password; char *reply; - while ( (c = getopt(argc, argv, "d:c")) != EOF){ + while ( (c = getopt(argc, argv, "d:cs")) != EOF){ switch(c) { case 'd': dictionary = strdup(optarg); @@ -94,13 +96,17 @@ int main(int argc, char **argv) { case 'c': complex_check = 1; break; + case 's': + complex_check = 1; + simplex_check = 1; + break; default: usage(argv[0]); } } - if (dictionary == NULL) { - fprintf(stderr, "ERR - Wrong Command Line\n\n"); + if (!simplex_check && dictionary == NULL) { + fprintf(stderr, "ERR - Missing cracklib dictionary\n\n"); usage(argv[0]); } @@ -119,6 +125,10 @@ int main(int argc, char **argv) { } } + if (simplex_check) { + exit(0); + } + reply = FascistCheck(password, dictionary); if (reply != NULL) { fprintf(stderr, "ERR - %s\n\n", reply); @@ -126,6 +136,5 @@ int main(int argc, char **argv) { } exit(0); - } -- cgit From c4f6089fb3a71e642ba3ab988758dacf6c07bc86 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 27 Dec 2005 20:52:36 +0000 Subject: r12522: Try and fix bug #2926 by removing setlocale(LC_ALL, "C") and replace calls to isupper/islower/toupper/tolower with ASCII equivalents (mapping into _w variants). Jeremy. --- source/auth/pass_check.c | 4 ++-- source/client/clitar.c | 2 +- source/include/smb.h | 3 +++ source/lib/charcnv.c | 11 +-------- source/lib/replace.c | 2 +- source/lib/username.c | 4 ++-- source/lib/util_str.c | 16 ++++++------- source/lib/util_unistr.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ source/passdb/passdb.c | 8 +++---- source/passdb/pdb_pgsql.c | 2 +- source/smbd/mangle_hash.c | 6 ++--- source/smbd/mangle_hash2.c | 12 +++++----- source/web/swat.c | 2 +- 13 files changed, 89 insertions(+), 39 deletions(-) diff --git a/source/auth/pass_check.c b/source/auth/pass_check.c index 0425e01cdcb..507e8a3836e 100644 --- a/source/auth/pass_check.c +++ b/source/auth/pass_check.c @@ -452,9 +452,9 @@ static NTSTATUS string_combinations2(char *s, int offset, NTSTATUS (*fn) (const for (i = offset; i < (len - (N - 1)); i++) { char c = s[i]; - if (!islower(c)) + if (!islower_ascii(c)) continue; - s[i] = toupper(c); + s[i] = toupper_ascii(c); if (!NT_STATUS_EQUAL(nt_status = string_combinations2(s, i + 1, fn, N - 1),NT_STATUS_WRONG_PASSWORD)) { return (nt_status); } diff --git a/source/client/clitar.c b/source/client/clitar.c index 5afe154cbbe..c15d24d619a 100644 --- a/source/client/clitar.c +++ b/source/client/clitar.c @@ -482,7 +482,7 @@ static int strslashcmp(char *s1, char *s2) { char *s1_0=s1; - while(*s1 && *s2 && (*s1 == *s2 || tolower(*s1) == tolower(*s2) || + while(*s1 && *s2 && (*s1 == *s2 || tolower_ascii(*s1) == tolower_ascii(*s2) || (*s1 == '\\' && *s2=='/') || (*s1 == '/' && *s2=='\\'))) { s1++; s2++; } diff --git a/source/include/smb.h b/source/include/smb.h index fc256c6f698..4f378f822e2 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -172,6 +172,9 @@ typedef smb_ucs2_t wfstring[FSTRING_LEN]; /* turn a 7 bit character into a ucs2 character */ #define UCS2_CHAR(c) ((c) << UCS2_SHIFT) +/* return an ascii version of a ucs2 character */ +#define UCS2_TO_CHAR(c) ((c) & 0xff) + /* Copy into a smb_ucs2_t from a possibly unaligned buffer. Return the copied smb_ucs2_t */ #define COPY_UCS2_CHAR(dest,src) (((unsigned char *)(dest))[0] = ((unsigned char *)(src))[0],\ ((unsigned char *)(dest))[1] = ((unsigned char *)(src))[1], (dest)) diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c index 0c806167f41..c4eeab135e9 100644 --- a/source/lib/charcnv.c +++ b/source/lib/charcnv.c @@ -84,15 +84,6 @@ static const char *charset_name(charset_t ch) } ret = ln; } -#ifdef HAVE_SETLOCALE - /* We set back the locale to C to get ASCII-compatible toupper/lower functions. - For now we do not need any other POSIX localisations anyway. When we should - really need localized string functions one day we need to write our own - ascii_tolower etc. - */ - setlocale(LC_ALL, "C"); - #endif - #endif if (!ret || !*ret) ret = "ASCII"; @@ -747,7 +738,7 @@ char *strdup_upper(const char *s) while (1) { if (*p & 0x80) break; - *q++ = toupper(*p); + *q++ = toupper_ascii(*p); if (!*p) break; p++; diff --git a/source/lib/replace.c b/source/lib/replace.c index 57ee6ea11e6..120fd3a4688 100644 --- a/source/lib/replace.c +++ b/source/lib/replace.c @@ -390,7 +390,7 @@ char *rep_inet_ntoa(struct in_addr ip) if (isdigit(c)) c -= '0'; else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + c -= isupper_ascii(c) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) diff --git a/source/lib/username.c b/source/lib/username.c index ecfd5fef9ef..7d66b320adf 100644 --- a/source/lib/username.c +++ b/source/lib/username.c @@ -716,9 +716,9 @@ static struct passwd *uname_string_combinations2(char *s,int offset,struct passw for (i=offset;i<(len-(N-1));i++) { char c = s[i]; - if (!islower((int)c)) + if (!islower_ascii((int)c)) continue; - s[i] = toupper(c); + s[i] = toupper_ascii(c); ret = uname_string_combinations2(s,i+1,fn,N-1); if(ret) return(ret); diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 80bb2ff2ad7..0b02487f774 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -201,8 +201,8 @@ int StrCaseCmp(const char *s, const char *t) /* not ascii anymore, do it the hard way from here on in */ break; - us = toupper(*ps); - ut = toupper(*pt); + us = toupper_ascii(*ps); + ut = toupper_ascii(*pt); if (us == ut) continue; else if (us < ut) @@ -309,7 +309,7 @@ int strwicmp(const char *psz1, const char *psz2) psz1++; while (isspace((int)*psz2)) psz2++; - if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0' + if (toupper_ascii(*psz1) != toupper_ascii(*psz2) || *psz1 == '\0' || *psz2 == '\0') break; psz1++; @@ -680,7 +680,7 @@ char *alpha_strcpy_fn(const char *fn, int line, char *dest, const char *src, con for(i = 0; i < len; i++) { int val = (src[i] & 0xff); - if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val)) + if (isupper_ascii(val) || islower_ascii(val) || isdigit(val) || strchr_m(other_safe_chars, val)) dest[i] = src[i]; else dest[i] = '_'; @@ -774,12 +774,12 @@ size_t strhex_to_str(char *p, size_t len, const char *strhex) continue; } - if (!(p1 = strchr_m(hexchars, toupper(strhex[i])))) + if (!(p1 = strchr_m(hexchars, toupper_ascii(strhex[i])))) break; i++; /* next hex digit */ - if (!(p2 = strchr_m(hexchars, toupper(strhex[i])))) + if (!(p2 = strchr_m(hexchars, toupper_ascii(strhex[i])))) break; /* get the two nybbles */ @@ -1510,7 +1510,7 @@ void strlower_m(char *s) (ie. they match for the first 128 chars) */ while (*s && !(((unsigned char)s[0]) & 0x80)) { - *s = tolower((unsigned char)*s); + *s = tolower_ascii((unsigned char)*s); s++; } @@ -1544,7 +1544,7 @@ void strupper_m(char *s) (ie. they match for the first 128 chars) */ while (*s && !(((unsigned char)s[0]) & 0x80)) { - *s = toupper((unsigned char)*s); + *s = toupper_ascii((unsigned char)*s); s++; } diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index b979745d366..880416a5491 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -51,6 +51,7 @@ static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */ void load_case_tables(void) { static int initialised; + char *old_locale = NULL, *saved_locale = NULL; int i; if (initialised) { @@ -61,6 +62,17 @@ void load_case_tables(void) upcase_table = map_file(lib_path("upcase.dat"), 0x20000); lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000); +#ifdef HAVE_SETLOCALE + /* Get the name of the current locale. */ + old_locale = setlocale(LC_ALL, NULL); + + /* Save it as it is in static storage. */ + saved_locale = SMB_STRDUP(old_locale); + + /* We set back the locale to C to get ASCII-compatible toupper/lower functions. */ + setlocale(LC_ALL, "C"); +#endif + /* we would like Samba to limp along even if these tables are not available */ if (!upcase_table) { @@ -92,6 +104,12 @@ void load_case_tables(void) lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i); } } + +#ifdef HAVE_SETLOCALE + /* Restore the old locale. */ + setlocale (LC_ALL, saved_locale); + SAFE_FREE(saved_locale); +#endif } /* @@ -997,3 +1015,41 @@ UNISTR2* ucs2_to_unistr2(TALLOC_CTX *ctx, UNISTR2* dst, smb_ucs2_t* src) return dst; } + +/************************************************************* + ascii only toupper - saves the need for smbd to be in C locale. +*************************************************************/ + +int toupper_ascii(int c) +{ + smb_ucs2_t uc = toupper_w(UCS2_CHAR(c)); + return UCS2_TO_CHAR(uc); +} + +/************************************************************* + ascii only tolower - saves the need for smbd to be in C locale. +*************************************************************/ + +int tolower_ascii(int c) +{ + smb_ucs2_t uc = tolower_w(UCS2_CHAR(c)); + return UCS2_TO_CHAR(uc); +} + +/************************************************************* + ascii only isupper - saves the need for smbd to be in C locale. +*************************************************************/ + +int isupper_ascii(int c) +{ + return isupper_w(UCS2_CHAR(c)); +} + +/************************************************************* + ascii only islower - saves the need for smbd to be in C locale. +*************************************************************/ + +int islower_ascii(int c) +{ + return islower_w(UCS2_CHAR(c)); +} diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index 006161b6639..ac4d2555978 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -566,8 +566,8 @@ BOOL pdb_gethexpwd(const char *p, unsigned char *pwd) return (False); for (i = 0; i < 32; i += 2) { - hinybble = toupper(p[i]); - lonybble = toupper(p[i + 1]); + hinybble = toupper_ascii(p[i]); + lonybble = toupper_ascii(p[i + 1]); p1 = strchr(hexchars, hinybble); p2 = strchr(hexchars, lonybble); @@ -616,8 +616,8 @@ BOOL pdb_gethexhours(const char *p, unsigned char *hours) } for (i = 0; i < 42; i += 2) { - hinybble = toupper(p[i]); - lonybble = toupper(p[i + 1]); + hinybble = toupper_ascii(p[i]); + lonybble = toupper_ascii(p[i + 1]); p1 = strchr(hexchars, hinybble); p2 = strchr(hexchars, lonybble); diff --git a/source/passdb/pdb_pgsql.c b/source/passdb/pdb_pgsql.c index 632903c1ac3..196fe8f855d 100644 --- a/source/passdb/pdb_pgsql.c +++ b/source/passdb/pdb_pgsql.c @@ -368,7 +368,7 @@ static NTSTATUS pgsqlsam_getsampwnam ( struct pdb_methods *methods, SAM_ACCOUNT lowercasename = smb_xstrdup(sname); l = strlen(lowercasename); for(i = 0; i < l; i++) { - lowercasename[i] = tolower(lowercasename[i]); + lowercasename[i] = tolower_ascii(lowercasename[i]); } result = pgsqlsam_select_by_field( methods, user, SQL_SEARCH_USER_NAME, lowercasename ) ; diff --git a/source/smbd/mangle_hash.c b/source/smbd/mangle_hash.c index 30befd2c849..2092f430c07 100644 --- a/source/smbd/mangle_hash.c +++ b/source/smbd/mangle_hash.c @@ -372,8 +372,8 @@ static BOOL is_mangled(const char *s, int snum) magic = strchr_m( s, magic_char ); while( magic && magic[1] && magic[2] ) { /* 3 chars, 1st is magic. */ if( ('.' == magic[3] || '/' == magic[3] || !(magic[3])) /* Ends with '.' or nul or '/' ? */ - && isbasechar( toupper(magic[1]) ) /* is 2nd char basechar? */ - && isbasechar( toupper(magic[2]) ) ) /* is 3rd char basechar? */ + && isbasechar( toupper_ascii(magic[1]) ) /* is 2nd char basechar? */ + && isbasechar( toupper_ascii(magic[2]) ) ) /* is 3rd char basechar? */ return( True ); /* If all above, then true, */ magic = strchr_m( magic+1, magic_char ); /* else seek next magic. */ } @@ -426,7 +426,7 @@ static void cache_mangled_name( const char mangled_name[13], char *raw_name ) s1 = strrchr( mangled_name_key, '.' ); if( s1 && (s2 = strrchr( raw_name, '.' )) ) { size_t i = 1; - while( s1[i] && (tolower( s1[i] ) == s2[i]) ) + while( s1[i] && (tolower_ascii( s1[i] ) == s2[i]) ) i++; if( !s1[i] && !s2[i] ) { /* Truncate at the '.' */ diff --git a/source/smbd/mangle_hash2.c b/source/smbd/mangle_hash2.c index 335ba8e2ef9..0a161c9e769 100644 --- a/source/smbd/mangle_hash2.c +++ b/source/smbd/mangle_hash2.c @@ -560,7 +560,7 @@ static void name_map(fstring name, BOOL need83, BOOL cache83, int default_case, if (! FLAG_CHECK(lead_chars[i], FLAG_ASCII)) { lead_chars[i] = '_'; } - lead_chars[i] = toupper(lead_chars[i]); + lead_chars[i] = toupper_ascii(lead_chars[i]); } for (;i Date: Wed, 28 Dec 2005 14:19:03 +0000 Subject: r12541: patch from Oliver Schulze L. to check for rpm v4.3 (CentOS) --- packaging/RedHat/makerpms.sh.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/RedHat/makerpms.sh.tmpl b/packaging/RedHat/makerpms.sh.tmpl index a37e03a1447..8da4a5d520e 100644 --- a/packaging/RedHat/makerpms.sh.tmpl +++ b/packaging/RedHat/makerpms.sh.tmpl @@ -46,7 +46,7 @@ esac ## now catch the right command to build an RPM (defaults ro 'rpm' ## case $RPMVER in - 4.[12]*) + 4.[123]*) RPM="rpmbuild" ;; esac -- cgit From f637cdccb6341a5b2188cb613a60484a2e22544d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 28 Dec 2005 21:10:11 +0000 Subject: r12544: Fix segfaults in winbind, smbpasswd and net --- source/nsswitch/winbindd.c | 2 ++ source/utils/net.c | 2 ++ source/utils/smbpasswd.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c index 60a4e2f6c01..e9b9ed42c4f 100644 --- a/source/nsswitch/winbindd.c +++ b/source/nsswitch/winbindd.c @@ -932,6 +932,8 @@ int main(int argc, char **argv) fault_setup((void (*)(void *))fault_quit ); + load_case_tables(); + /* Initialise for running in non-root mode */ sec_init(); diff --git a/source/utils/net.c b/source/utils/net.c index 4d9dec4b85b..839f6f1b019 100644 --- a/source/utils/net.c +++ b/source/utils/net.c @@ -781,6 +781,8 @@ static struct functable net_func[] = { zero_ip(&opt_dest_ip); + load_case_tables(); + /* set default debug level to 0 regardless of what smb.conf sets */ DEBUGLEVEL_CLASS[DBGC_ALL] = 0; dbf = x_stderr; diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c index 708d44df9f0..5aba1623890 100644 --- a/source/utils/smbpasswd.c +++ b/source/utils/smbpasswd.c @@ -569,6 +569,8 @@ int main(int argc, char **argv) local_flags = LOCAL_AM_ROOT; } + load_case_tables(); + local_flags = process_options(argc, argv, local_flags); setup_logging("smbpasswd", True); -- cgit From 19edc6b0e7eb79079d09be59521168ee2459ada6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Dec 2005 22:48:54 +0000 Subject: r12555: Fix more load_case_table swegfaults. Arggg. What I'd give for a global constructor... Jeremy. --- source/client/client.c | 1 + source/nsswitch/wbinfo.c | 1 + source/utils/eventlogadm.c | 2 ++ source/utils/ntlm_auth.c | 1 + source/utils/pdbedit.c | 2 ++ source/utils/smbcacls.c | 2 ++ source/utils/smbcquotas.c | 2 ++ source/utils/smbget.c | 2 ++ source/utils/smbtree.c | 1 + source/utils/status.c | 2 ++ source/utils/testparm.c | 2 ++ 11 files changed, 18 insertions(+) diff --git a/source/client/client.c b/source/client/client.c index f95bbea6718..7ac64970f81 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -3326,6 +3326,7 @@ static int do_message_op(void) POPT_TABLEEND }; + load_case_tables(); #ifdef KANJI pstrcpy(term_code, KANJI); diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c index c55f4bb4319..f3819b6f519 100644 --- a/source/nsswitch/wbinfo.c +++ b/source/nsswitch/wbinfo.c @@ -1022,6 +1022,7 @@ int main(int argc, char **argv) }; /* Samba client initialisation */ + load_case_tables(); if (!lp_load(dyn_CONFIGFILE, True, False, False)) { d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n", diff --git a/source/utils/eventlogadm.c b/source/utils/eventlogadm.c index a0fc4bcf9d4..eef7cde3771 100644 --- a/source/utils/eventlogadm.c +++ b/source/utils/eventlogadm.c @@ -166,6 +166,8 @@ int main( int argc, char *argv[] ) fstring opname; + load_case_tables(); + opt_debug = 0; /* todo set this from getopts */ lp_load( dyn_CONFIGFILE, True, False, False ); diff --git a/source/utils/ntlm_auth.c b/source/utils/ntlm_auth.c index 433ba069824..65dbfb71650 100644 --- a/source/utils/ntlm_auth.c +++ b/source/utils/ntlm_auth.c @@ -1752,6 +1752,7 @@ enum { }; /* Samba client initialisation */ + load_case_tables(); dbf = x_stderr; diff --git a/source/utils/pdbedit.c b/source/utils/pdbedit.c index 9c292bd212a..ddf0eea169b 100644 --- a/source/utils/pdbedit.c +++ b/source/utils/pdbedit.c @@ -775,6 +775,8 @@ int main (int argc, char **argv) POPT_TABLEEND }; + load_case_tables(); + setup_logging("pdbedit", True); pc = poptGetContext(NULL, argc, (const char **) argv, long_options, diff --git a/source/utils/smbcacls.c b/source/utils/smbcacls.c index fd1d3cbf89c..cbbd7adaab3 100644 --- a/source/utils/smbcacls.c +++ b/source/utils/smbcacls.c @@ -818,6 +818,8 @@ static struct cli_state *connect_one(const char *share) struct cli_state *cli; + load_case_tables(); + ctx=talloc_init("main"); /* set default debug level to 1 regardless of what smb.conf sets */ diff --git a/source/utils/smbcquotas.c b/source/utils/smbcquotas.c index be7c2c64e6a..f8e33131555 100644 --- a/source/utils/smbcquotas.c +++ b/source/utils/smbcquotas.c @@ -421,6 +421,8 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" }, { NULL } }; + load_case_tables(); + ZERO_STRUCT(qt); /* set default debug level to 1 regardless of what smb.conf sets */ diff --git a/source/utils/smbget.c b/source/utils/smbget.c index 9d44017bd35..4a2670e0c16 100644 --- a/source/utils/smbget.c +++ b/source/utils/smbget.c @@ -544,6 +544,8 @@ int main(int argc, const char **argv) }; poptContext pc; + load_case_tables(); + /* only read rcfile if it exists */ asprintf(&rcfile, "%s/.smbgetrc", getenv("HOME")); if(access(rcfile, F_OK) == 0) diff --git a/source/utils/smbtree.c b/source/utils/smbtree.c index 00f6a74f2f2..3755b7f8e55 100644 --- a/source/utils/smbtree.c +++ b/source/utils/smbtree.c @@ -203,6 +203,7 @@ static BOOL print_tree(struct user_auth_info *user_info) poptContext pc; /* Initialise samba stuff */ + load_case_tables(); setlinebuf(stdout); diff --git a/source/utils/status.c b/source/utils/status.c index 2c5756106a2..f19a217aa65 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -613,6 +613,8 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo POPT_TABLEEND }; + load_case_tables(); + setup_logging(argv[0],True); dbf = x_stderr; diff --git a/source/utils/testparm.c b/source/utils/testparm.c index e097ea34d61..f5c835725a4 100644 --- a/source/utils/testparm.c +++ b/source/utils/testparm.c @@ -230,6 +230,8 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ POPT_TABLEEND }; + load_case_tables(); + pc = poptGetContext(NULL, argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "[OPTION...] [host-name] [host-ip]"); -- cgit From 8d114b832a0848113697dc9087fbf6282fb412d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Dec 2005 13:10:33 +0000 Subject: r12564: Ensure load_case_tables is always done first. Jeremy. --- source/nmbd/nmbd.c | 2 ++ source/smbd/server.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c index 78411d34176..68004bad599 100644 --- a/source/nmbd/nmbd.c +++ b/source/nmbd/nmbd.c @@ -669,6 +669,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) { NULL } }; + load_case_tables(); + global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); diff --git a/source/smbd/server.c b/source/smbd/server.c index 304f1b588e2..ff894e2460c 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -718,6 +718,8 @@ void build_options(BOOL screen); { NULL } }; + load_case_tables(); + #ifdef HAVE_SET_AUTH_PARAMETERS set_auth_parameters(argc,argv); #endif @@ -742,8 +744,6 @@ void build_options(BOOL screen); sec_init(); - load_case_tables(); - set_remote_machine_name("smbd", False); if (interactive) { -- cgit From ac620610e5b93355c34c4d9b37b06d9330d3e35b Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 15:06:53 +0000 Subject: r12569: r12083@cabra: derrell | 2005-12-29 09:39:45 -0500 fix line length and make formatting/indentation more consistent --- source/libsmb/libsmbclient.c | 781 +++++++++++++++++++++++++++++-------------- 1 file changed, 526 insertions(+), 255 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index b81dd88424c..c4e36012f92 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -82,11 +82,15 @@ static int DLIST_CONTAINS(SMBCFILE * list, SMBCFILE *p) { /* * Find an lsa pipe handle associated with a cli struct. */ -static struct rpc_pipe_client *find_lsa_pipe_hnd(struct cli_state *ipc_cli) +static struct rpc_pipe_client * +find_lsa_pipe_hnd(struct cli_state *ipc_cli) { struct rpc_pipe_client *pipe_hnd; - for (pipe_hnd = ipc_cli->pipe_list; pipe_hnd; pipe_hnd = pipe_hnd->next) { + for (pipe_hnd = ipc_cli->pipe_list; + pipe_hnd; + pipe_hnd = pipe_hnd->next) { + if (pipe_hnd->pipe_idx == PI_LSARPC) { return pipe_hnd; } @@ -95,8 +99,14 @@ static struct rpc_pipe_client *find_lsa_pipe_hnd(struct cli_state *ipc_cli) return NULL; } -static int smbc_close_ctx(SMBCCTX *context, SMBCFILE *file); -static off_t smbc_lseek_ctx(SMBCCTX *context, SMBCFILE *file, off_t offset, int whence); +static int +smbc_close_ctx(SMBCCTX *context, + SMBCFILE *file); +static off_t +smbc_lseek_ctx(SMBCCTX *context, + SMBCFILE *file, + off_t offset, + int whence); extern BOOL in_client; @@ -315,7 +325,9 @@ smbc_parse_path(SMBCCTX *context, if (*p == '/') { strncpy(server, context->workgroup, - (strlen(context->workgroup) < 16)?strlen(context->workgroup):16); + ((strlen(context->workgroup) < 16) + ? strlen(context->workgroup) + : 16)); return 0; } @@ -396,9 +408,15 @@ smbc_parse_path(SMBCCTX *context, /* * Verify that the options specified in a URL are valid */ -static int smbc_check_options(char *server, char *share, char *path, char *options) +static int +smbc_check_options(char *server, + char *share, + char *path, + char *options) { - DEBUG(4, ("smbc_check_options(): server='%s' share='%s' path='%s' options='%s'\n", server, share, path, options)); + DEBUG(4, ("smbc_check_options(): server='%s' share='%s' " + "path='%s' options='%s'\n", + server, share, path, options)); /* No options at all is always ok */ if (! *options) return 0; @@ -410,7 +428,9 @@ static int smbc_check_options(char *server, char *share, char *path, char *optio /* * Convert an SMB error into a UNIX error ... */ -static int smbc_errno(SMBCCTX *context, struct cli_state *c) +static int +smbc_errno(SMBCCTX *context, + struct cli_state *c) { int ret = cli_errno(c); @@ -441,7 +461,9 @@ static int smbc_errno(SMBCCTX *context, struct cli_state *c) * Also useable outside libsmbclient to enable external cache * to do some checks too. */ -int smbc_check_server(SMBCCTX * context, SMBCSRV * server) +static int +smbc_check_server(SMBCCTX * context, + SMBCSRV * server) { if ( send_keepalive(server->cli.fd) == False ) return 1; @@ -456,7 +478,9 @@ int smbc_check_server(SMBCCTX * context, SMBCSRV * server) * * Also useable outside libsmbclient */ -int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv) +int +smbc_remove_unused_server(SMBCCTX * context, + SMBCSRV * srv) { SMBCFILE * file; @@ -469,7 +493,8 @@ int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv) for (file = context->internal->_files; file; file=file->next) { if (file->srv == srv) { /* Still used */ - DEBUG(3, ("smbc_remove_usused_server: %p still used by %p.\n", + DEBUG(3, ("smbc_remove_usused_server: " + "%p still used by %p.\n", srv, file)); return 1; } @@ -488,12 +513,13 @@ int smbc_remove_unused_server(SMBCCTX * context, SMBCSRV * srv) return 0; } -SMBCSRV *find_server(SMBCCTX *context, - const char *server, - const char *share, - fstring workgroup, - fstring username, - fstring password) +static SMBCSRV * +find_server(SMBCCTX *context, + const char *server, + const char *share, + fstring workgroup, + fstring username, + fstring password) { SMBCSRV *srv; int auth_called = 0; @@ -561,10 +587,13 @@ SMBCSRV *find_server(SMBCCTX *context, * info we need, unless the username and password were passed in. */ -SMBCSRV *smbc_server(SMBCCTX *context, - const char *server, const char *share, - fstring workgroup, fstring username, - fstring password) +static SMBCSRV * +smbc_server(SMBCCTX *context, + const char *server, + const char *share, + fstring workgroup, + fstring username, + fstring password) { SMBCSRV *srv=NULL; struct cli_state c; @@ -811,11 +840,14 @@ SMBCSRV *smbc_server(SMBCCTX *context, * Connect to a server for getting/setting attributes, possibly on an existing * connection. This works similarly to smbc_server(). */ -SMBCSRV *smbc_attr_server(SMBCCTX *context, - const char *server, const char *share, - fstring workgroup, - fstring username, fstring password, - POLICY_HND *pol) +static SMBCSRV * +smbc_attr_server(SMBCCTX *context, + const char *server, + const char *share, + fstring workgroup, + fstring username, + fstring password, + POLICY_HND *pol) { struct in_addr ip; struct cli_state *ipc_cli; @@ -927,11 +959,15 @@ SMBCSRV *smbc_attr_server(SMBCCTX *context, * Routine to open() a file ... */ -static SMBCFILE *smbc_open_ctx(SMBCCTX *context, const char *fname, int flags, mode_t mode) +static SMBCFILE * +smbc_open_ctx(SMBCCTX *context, + const char *fname, + int flags, + mode_t mode) { fstring server, share, user, password, workgroup; pstring path; - pstring targetpath; + pstring targetpath; struct cli_state *targetcli; SMBCSRV *srv = NULL; SMBCFILE *file = NULL; @@ -1088,7 +1124,10 @@ static SMBCFILE *smbc_open_ctx(SMBCCTX *context, const char *fname, int flags, m static int creat_bits = O_WRONLY | O_CREAT | O_TRUNC; /* FIXME: Do we need this */ -static SMBCFILE *smbc_creat_ctx(SMBCCTX *context, const char *path, mode_t mode) +static SMBCFILE * +smbc_creat_ctx(SMBCCTX *context, + const char *path, + mode_t mode) { if (!context || !context->internal || @@ -1106,7 +1145,11 @@ static SMBCFILE *smbc_creat_ctx(SMBCCTX *context, const char *path, mode_t mode) * Routine to read() a file ... */ -static ssize_t smbc_read_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_t count) +static ssize_t +smbc_read_ctx(SMBCCTX *context, + SMBCFILE *file, + void *buf, + size_t count) { int ret; fstring server, share, user, password; @@ -1163,7 +1206,8 @@ static ssize_t smbc_read_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_t } /*d_printf(">>>read: resolving %s\n", path);*/ - if (!cli_resolve_path( "", &file->srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &file->srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return -1; @@ -1191,14 +1235,20 @@ static ssize_t smbc_read_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_t * Routine to write() a file ... */ -static ssize_t smbc_write_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_t count) +static ssize_t +smbc_write_ctx(SMBCCTX *context, + SMBCFILE *file, + void *buf, + size_t count) { int ret; - off_t offset = file->offset; /* See "offset" comment in smbc_read_ctx() */ + off_t offset; fstring server, share, user, password; pstring path, targetpath; struct cli_state *targetcli; + offset = file->offset; /* See "offset" comment in smbc_read_ctx() */ + if (!context || !context->internal || !context->internal->_initialized) { @@ -1236,7 +1286,8 @@ static ssize_t smbc_write_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_ } /*d_printf(">>>write: resolving %s\n", path);*/ - if (!cli_resolve_path( "", &file->srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &file->srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return -1; @@ -1262,7 +1313,9 @@ static ssize_t smbc_write_ctx(SMBCCTX *context, SMBCFILE *file, void *buf, size_ * Routine to close() a file ... */ -static int smbc_close_ctx(SMBCCTX *context, SMBCFILE *file) +static int +smbc_close_ctx(SMBCCTX *context, + SMBCFILE *file) { SMBCSRV *srv; fstring server, share, user, password; @@ -1304,7 +1357,8 @@ static int smbc_close_ctx(SMBCCTX *context, SMBCFILE *file) } /*d_printf(">>>close: resolving %s\n", path);*/ - if (!cli_resolve_path( "", &file->srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &file->srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return -1; @@ -1339,14 +1393,21 @@ static int smbc_close_ctx(SMBCCTX *context, SMBCFILE *file) * Get info from an SMB server on a file. Use a qpathinfo call first * and if that fails, use getatr, as Win95 sometimes refuses qpathinfo */ -static BOOL smbc_getatr(SMBCCTX * context, SMBCSRV *srv, char *path, - uint16 *mode, SMB_OFF_T *size, - time_t *c_time, time_t *a_time, time_t *m_time, - SMB_INO_T *ino) +static BOOL +smbc_getatr(SMBCCTX * context, + SMBCSRV *srv, + char *path, + uint16 *mode, + SMB_OFF_T *size, + time_t *c_time, + time_t *a_time, + time_t *m_time, + SMB_INO_T *ino) { pstring fixedpath; pstring targetpath; struct cli_state *targetcli; + if (!context || !context->internal || !context->internal->_initialized) { @@ -1376,7 +1437,8 @@ static BOOL smbc_getatr(SMBCCTX * context, SMBCSRV *srv, char *path, { pstring temppath; pstrcpy(temppath, targetpath); - cli_dfs_make_full_path( targetpath, targetcli->desthost, targetcli->share, temppath); + cli_dfs_make_full_path(targetpath, targetcli->desthost, + targetcli->share, temppath); } if (!srv->no_pathinfo2 && @@ -1415,9 +1477,10 @@ static BOOL smbc_getatr(SMBCCTX * context, SMBCSRV *srv, char *path, * * "mode" (attributes) parameter may be set to -1 if it is not to be set. */ -static BOOL smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, - time_t c_time, time_t a_time, time_t m_time, - uint16 mode) +static BOOL +smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, + time_t c_time, time_t a_time, time_t m_time, + uint16 mode) { int fd; int ret; @@ -1544,7 +1607,9 @@ static BOOL smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, * Routine to unlink() a file */ - static int smbc_unlink_ctx(SMBCCTX *context, const char *fname) +static int +smbc_unlink_ctx(SMBCCTX *context, + const char *fname) { fstring server, share, user, password, workgroup; pstring path, targetpath; @@ -1640,12 +1705,27 @@ static BOOL smbc_setatr(SMBCCTX * context, SMBCSRV *srv, char *path, * Routine to rename() a file */ -static int smbc_rename_ctx(SMBCCTX *ocontext, const char *oname, - SMBCCTX *ncontext, const char *nname) +static int +smbc_rename_ctx(SMBCCTX *ocontext, + const char *oname, + SMBCCTX *ncontext, + const char *nname) { - fstring server1, share1, server2, share2, user1, user2, password1, password2, workgroup; - pstring path1, path2, targetpath1, targetpath2; - struct cli_state *targetcli1, *targetcli2; + fstring server1; + fstring share1; + fstring server2; + fstring share2; + fstring user1; + fstring user2; + fstring password1; + fstring password2; + fstring workgroup; + pstring path1; + pstring path2; + pstring targetpath1; + pstring targetpath2; + struct cli_state *targetcli1; + struct cli_state *targetcli2; SMBCSRV *srv = NULL; if (!ocontext || !ncontext || @@ -1698,8 +1778,9 @@ static int smbc_rename_ctx(SMBCCTX *ocontext, const char *oname, } fstrcpy(workgroup, ocontext->workgroup); - /* HELP !!! Which workgroup should I use ? Or are they always the same -- Tom */ - srv = smbc_server(ocontext, server1, share1, workgroup, user1, password1); + + srv = smbc_server(ocontext, server1, share1, workgroup, + user1, password1); if (!srv) { return -1; @@ -1721,7 +1802,8 @@ static int smbc_rename_ctx(SMBCCTX *ocontext, const char *oname, } /*d_printf(">>>rename: resolved path as %s\n", targetpath2);*/ - if (strcmp(targetcli1->desthost, targetcli2->desthost) || strcmp(targetcli1->share, targetcli2->share)) + if (strcmp(targetcli1->desthost, targetcli2->desthost) || + strcmp(targetcli1->share, targetcli2->share)) { /* can't rename across file systems */ @@ -1750,7 +1832,11 @@ static int smbc_rename_ctx(SMBCCTX *ocontext, const char *oname, * A routine to lseek() a file */ -static off_t smbc_lseek_ctx(SMBCCTX *context, SMBCFILE *file, off_t offset, int whence) +static off_t +smbc_lseek_ctx(SMBCCTX *context, + SMBCFILE *file, + off_t offset, + int whence) { SMB_OFF_T size; fstring server, share, user, password; @@ -1791,30 +1877,32 @@ static off_t smbc_lseek_ctx(SMBCCTX *context, SMBCFILE *file, off_t offset, int case SEEK_END: /*d_printf(">>>lseek: parsing %s\n", file->fname);*/ if (smbc_parse_path(context, file->fname, - server, sizeof(server), - share, sizeof(share), - path, sizeof(path), - user, sizeof(user), - password, sizeof(password), - NULL, 0)) { + server, sizeof(server), + share, sizeof(share), + path, sizeof(path), + user, sizeof(user), + password, sizeof(password), + NULL, 0)) { + errno = EINVAL; return -1; } /*d_printf(">>>lseek: resolving %s\n", path);*/ - if (!cli_resolve_path( "", &file->srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &file->srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return -1; } /*d_printf(">>>lseek: resolved path as %s\n", targetpath);*/ - if (!cli_qfileinfo(targetcli, file->cli_fd, NULL, &size, NULL, NULL, - NULL, NULL, NULL)) + if (!cli_qfileinfo(targetcli, file->cli_fd, NULL, + &size, NULL, NULL, NULL, NULL, NULL)) { SMB_OFF_T b_size = size; - if (!cli_getattrE(targetcli, file->cli_fd, NULL, &b_size, NULL, NULL, - NULL)) + if (!cli_getattrE(targetcli, file->cli_fd, + NULL, &b_size, NULL, NULL, NULL)) { errno = EINVAL; return -1; @@ -1838,8 +1926,9 @@ static off_t smbc_lseek_ctx(SMBCCTX *context, SMBCFILE *file, off_t offset, int * Generate an inode number from file name for those things that need it */ -static -ino_t smbc_inode(SMBCCTX *context, const char *name) +static ino_t +smbc_inode(SMBCCTX *context, + const char *name) { if (!context || !context->internal || @@ -1860,9 +1949,12 @@ ino_t smbc_inode(SMBCCTX *context, const char *name) * fstat below. */ -static -int smbc_setup_stat(SMBCCTX *context, struct stat *st, char *fname, - SMB_OFF_T size, int mode) +static int +smbc_setup_stat(SMBCCTX *context, + struct stat *st, + char *fname, + SMB_OFF_T size, + int mode) { st->st_mode = 0; @@ -1906,12 +1998,21 @@ int smbc_setup_stat(SMBCCTX *context, struct stat *st, char *fname, * Routine to stat a file given a name */ -static int smbc_stat_ctx(SMBCCTX *context, const char *fname, struct stat *st) +static int +smbc_stat_ctx(SMBCCTX *context, + const char *fname, + struct stat *st) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; - time_t m_time = 0, a_time = 0, c_time = 0; + time_t m_time = 0; + time_t a_time = 0; + time_t c_time = 0; SMB_OFF_T size = 0; uint16 mode = 0; SMB_INO_T ino = 0; @@ -1979,13 +2080,22 @@ static int smbc_stat_ctx(SMBCCTX *context, const char *fname, struct stat *st) * Routine to stat a file given an fd */ -static int smbc_fstat_ctx(SMBCCTX *context, SMBCFILE *file, struct stat *st) +static int +smbc_fstat_ctx(SMBCCTX *context, + SMBCFILE *file, + struct stat *st) { - time_t c_time, a_time, m_time; + time_t c_time; + time_t a_time; + time_t m_time; SMB_OFF_T size; uint16 mode; - fstring server, share, user, password; - pstring path, targetpath; + fstring server; + fstring share; + fstring user; + fstring password; + pstring path; + pstring targetpath; struct cli_state *targetcli; SMB_INO_T ino = 0; @@ -2023,17 +2133,18 @@ static int smbc_fstat_ctx(SMBCCTX *context, SMBCFILE *file, struct stat *st) } /*d_printf(">>>fstat: resolving %s\n", path);*/ - if (!cli_resolve_path( "", &file->srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &file->srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return -1; } /*d_printf(">>>fstat: resolved path as %s\n", targetpath);*/ - if (!cli_qfileinfo(targetcli, file->cli_fd, - &mode, &size, &c_time, &a_time, &m_time, NULL, &ino)) { - if (!cli_getattrE(targetcli, file->cli_fd, - &mode, &size, &c_time, &a_time, &m_time)) { + if (!cli_qfileinfo(targetcli, file->cli_fd, &mode, &size, + &c_time, &a_time, &m_time, NULL, &ino)) { + if (!cli_getattrE(targetcli, file->cli_fd, &mode, &size, + &c_time, &a_time, &m_time)) { errno = EINVAL; return -1; @@ -2058,7 +2169,8 @@ static int smbc_fstat_ctx(SMBCCTX *context, SMBCFILE *file, struct stat *st) * We accept the URL syntax explained in smbc_parse_path(), above. */ -static void smbc_remove_dir(SMBCFILE *dir) +static void +smbc_remove_dir(SMBCFILE *dir) { struct smbc_dir_list *d,*f; @@ -2076,7 +2188,11 @@ static void smbc_remove_dir(SMBCFILE *dir) } -static int add_dirent(SMBCFILE *dir, const char *name, const char *comment, uint32 type) +static int +add_dirent(SMBCFILE *dir, + const char *name, + const char *comment, + uint32 type) { struct smbc_dirent *dirent; int size; @@ -2149,7 +2265,10 @@ static int add_dirent(SMBCFILE *dir, const char *name, const char *comment, uint } static void -list_unique_wg_fn(const char *name, uint32 type, const char *comment, void *state) +list_unique_wg_fn(const char *name, + uint32 type, + const char *comment, + void *state) { SMBCFILE *dir = (SMBCFILE *)state; struct smbc_dir_list *dir_list; @@ -2190,7 +2309,10 @@ list_unique_wg_fn(const char *name, uint32 type, const char *comment, void *stat } static void -list_fn(const char *name, uint32 type, const char *comment, void *state) +list_fn(const char *name, + uint32 type, + const char *comment, + void *state) { SMBCFILE *dir = (SMBCFILE *)state; int dirent_type; @@ -2246,7 +2368,10 @@ list_fn(const char *name, uint32 type, const char *comment, void *state) } static void -dir_list_fn(const char *mnt, file_info *finfo, const char *mask, void *state) +dir_list_fn(const char *mnt, + file_info *finfo, + const char *mask, + void *state) { if (add_dirent((SMBCFILE *)state, finfo->name, "", @@ -2342,7 +2467,9 @@ done: -static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) +static SMBCFILE * +smbc_opendir_ctx(SMBCCTX *context, + const char *fname) { fstring server, share, user, password, options; pstring workgroup; @@ -2379,7 +2506,9 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) return NULL; } - DEBUG(4, ("parsed path: fname='%s' server='%s' share='%s' path='%s' options='%s'\n", fname, server, share, path, options)); + DEBUG(4, ("parsed path: fname='%s' server='%s' share='%s' " + "path='%s' options='%s'\n", + fname, server, share, path, options)); /* Ensure the options are valid */ if (smbc_check_options(server, share, path, options)) { @@ -2463,9 +2592,12 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) } for (i = 0; i < count && i < max_lmb_count; i++) { - DEBUG(99, ("Found master browser %d of %d: %s\n", i+1, MAX(count, max_lmb_count), inet_ntoa(ip_list[i].ip))); + DEBUG(99, ("Found master browser %d of %d: %s\n", + i+1, MAX(count, max_lmb_count), + inet_ntoa(ip_list[i].ip))); - cli = get_ipc_connect_master_ip(&ip_list[i], workgroup, &u_info); + cli = get_ipc_connect_master_ip(&ip_list[i], + workgroup, &u_info); /* cli == NULL is the master browser refused to talk or could not be found */ if ( !cli ) @@ -2474,7 +2606,8 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) fstrcpy(server, cli->desthost); cli_shutdown(cli); - DEBUG(4, ("using workgroup %s %s\n", workgroup, server)); + DEBUG(4, ("using workgroup %s %s\n", + workgroup, server)); /* * For each returned master browser IP address, get a @@ -2674,14 +2807,16 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) p = path + strlen(path); pstrcat(path, "\\*"); - if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath)) + if (!cli_resolve_path("", &srv->cli, path, + &targetcli, targetpath)) { d_printf("Could not resolve %s\n", path); return NULL; } - if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN, dir_list_fn, - (void *)dir) < 0) { + if (cli_list(targetcli, targetpath, + aDIR | aSYSTEM | aHIDDEN, + dir_list_fn, (void *)dir) < 0) { if (dir) { SAFE_FREE(dir->fname); @@ -2725,7 +2860,9 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) * Routine to close a directory */ -static int smbc_closedir_ctx(SMBCCTX *context, SMBCFILE *dir) +static int +smbc_closedir_ctx(SMBCCTX *context, + SMBCFILE *dir) { if (!context || !context->internal || @@ -2757,10 +2894,11 @@ static int smbc_closedir_ctx(SMBCCTX *context, SMBCFILE *dir) } -static void smbc_readdir_internal(SMBCCTX * context, - struct smbc_dirent *dest, - struct smbc_dirent *src, - int max_namebuf_len) +static void +smbc_readdir_internal(SMBCCTX * context, + struct smbc_dirent *dest, + struct smbc_dirent *src, + int max_namebuf_len) { if (context->options.urlencode_readdir_entries) { @@ -2802,7 +2940,9 @@ static void smbc_readdir_internal(SMBCCTX * context, * Routine to get a directory entry */ -struct smbc_dirent *smbc_readdir_ctx(SMBCCTX *context, SMBCFILE *dir) +struct smbc_dirent * +smbc_readdir_ctx(SMBCCTX *context, + SMBCFILE *dir) { int maxlen; struct smbc_dirent *dirp, *dirent; @@ -2861,10 +3001,11 @@ struct smbc_dirent *smbc_readdir_ctx(SMBCCTX *context, SMBCFILE *dir) * Routine to get directory entries */ -static int smbc_getdents_ctx(SMBCCTX *context, - SMBCFILE *dir, - struct smbc_dirent *dirp, - int count) +static int +smbc_getdents_ctx(SMBCCTX *context, + SMBCFILE *dir, + struct smbc_dirent *dirp, + int count) { int rem = count; int reqd; @@ -2962,10 +3103,17 @@ static int smbc_getdents_ctx(SMBCCTX *context, * Routine to create a directory ... */ -static int smbc_mkdir_ctx(SMBCCTX *context, const char *fname, mode_t mode) +static int +smbc_mkdir_ctx(SMBCCTX *context, + const char *fname, + mode_t mode) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path, targetpath; struct cli_state *targetcli; @@ -3034,23 +3182,35 @@ static int smbc_mkdir_ctx(SMBCCTX *context, const char *fname, mode_t mode) static int smbc_rmdir_dirempty = True; -static void rmdir_list_fn(const char *mnt, file_info *finfo, const char *mask, void *state) +static void +rmdir_list_fn(const char *mnt, + file_info *finfo, + const char *mask, + void *state) { - - if (strncmp(finfo->name, ".", 1) != 0 && strncmp(finfo->name, "..", 2) != 0) + if (strncmp(finfo->name, ".", 1) != 0 && + strncmp(finfo->name, "..", 2) != 0) { + smbc_rmdir_dirempty = False; - + } } /* * Routine to remove a directory */ -static int smbc_rmdir_ctx(SMBCCTX *context, const char *fname) +static int +smbc_rmdir_ctx(SMBCCTX *context, + const char *fname) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; - pstring path, targetpath; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; + pstring path; + pstring targetpath; struct cli_state *targetcli; if (!context || !context->internal || @@ -3094,27 +3254,6 @@ static int smbc_rmdir_ctx(SMBCCTX *context, const char *fname) } - /* if (strncmp(srv->cli.dev, "IPC", 3) == 0) { - - mode = aDIR | aRONLY; - - } - else if (strncmp(srv->cli.dev, "LPT", 3) == 0) { - - if (strcmp(path, "\\") == 0) { - - mode = aDIR | aRONLY; - - } - else { - - mode = aRONLY; - smbc_stat_printjob(srv, path, &size, &m_time); - c_time = a_time = m_time; - - } - else { */ - /*d_printf(">>>rmdir: resolving %s\n", path);*/ if (!cli_resolve_path( "", &srv->cli, path, &targetcli, targetpath)) { @@ -3130,19 +3269,21 @@ static int smbc_rmdir_ctx(SMBCCTX *context, const char *fname) if (errno == EACCES) { /* Check if the dir empty or not */ - pstring lpath; /* Local storage to avoid buffer overflows */ + /* Local storage to avoid buffer overflows */ + pstring lpath; smbc_rmdir_dirempty = True; /* Make this so ... */ pstrcpy(lpath, targetpath); pstrcat(lpath, "\\*"); - if (cli_list(targetcli, lpath, aDIR | aSYSTEM | aHIDDEN, rmdir_list_fn, - NULL) < 0) { + if (cli_list(targetcli, lpath, + aDIR | aSYSTEM | aHIDDEN, + rmdir_list_fn, NULL) < 0) { /* Fix errno to ignore latest error ... */ - - DEBUG(5, ("smbc_rmdir: cli_list returned an error: %d\n", + DEBUG(5, ("smbc_rmdir: " + "cli_list returned an error: %d\n", smbc_errno(context, targetcli))); errno = EACCES; @@ -3167,7 +3308,9 @@ static int smbc_rmdir_ctx(SMBCCTX *context, const char *fname) * Routine to return the current directory position */ -static off_t smbc_telldir_ctx(SMBCCTX *context, SMBCFILE *dir) +static off_t +smbc_telldir_ctx(SMBCCTX *context, + SMBCFILE *dir) { off_t ret_val; /* Squash warnings about cast */ @@ -3205,8 +3348,9 @@ static off_t smbc_telldir_ctx(SMBCCTX *context, SMBCFILE *dir) * A routine to run down the list and see if the entry is OK */ -struct smbc_dir_list *smbc_check_dir_ent(struct smbc_dir_list *list, - struct smbc_dirent *dirent) +struct smbc_dir_list * +smbc_check_dir_ent(struct smbc_dir_list *list, + struct smbc_dirent *dirent) { /* Run down the list looking for what we want */ @@ -3235,7 +3379,10 @@ struct smbc_dir_list *smbc_check_dir_ent(struct smbc_dir_list *list, * Routine to seek on a directory */ -static int smbc_lseekdir_ctx(SMBCCTX *context, SMBCFILE *dir, off_t offset) +static int +smbc_lseekdir_ctx(SMBCCTX *context, + SMBCFILE *dir, + off_t offset) { long int l_offset = offset; /* Handle problems of size */ struct smbc_dirent *dirent = (struct smbc_dirent *)l_offset; @@ -3285,7 +3432,10 @@ static int smbc_lseekdir_ctx(SMBCCTX *context, SMBCFILE *dir, off_t offset) * Routine to fstat a dir */ -static int smbc_fstatdir_ctx(SMBCCTX *context, SMBCFILE *dir, struct stat *st) +static int +smbc_fstatdir_ctx(SMBCCTX *context, + SMBCFILE *dir, + struct stat *st) { if (!context || !context->internal || @@ -3302,10 +3452,17 @@ static int smbc_fstatdir_ctx(SMBCCTX *context, SMBCFILE *dir, struct stat *st) } -int smbc_chmod_ctx(SMBCCTX *context, const char *fname, mode_t newmode) +static int +smbc_chmod_ctx(SMBCCTX *context, + const char *fname, + mode_t newmode) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; uint16 mode; @@ -3362,10 +3519,17 @@ int smbc_chmod_ctx(SMBCCTX *context, const char *fname, mode_t newmode) return 0; } -int smbc_utimes_ctx(SMBCCTX *context, const char *fname, struct timeval *tbuf) +static int +smbc_utimes_ctx(SMBCCTX *context, + const char *fname, + struct timeval *tbuf) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; time_t a_time; time_t m_time; @@ -3448,7 +3612,9 @@ int smbc_utimes_ctx(SMBCCTX *context, const char *fname, struct timeval *tbuf) computer running Windows NT 5.0" if denied ACEs do not appear before allowed ACEs. */ -static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) +static int +ace_compare(SEC_ACE *ace1, + SEC_ACE *ace2) { if (sec_ace_equal(ace1, ace2)) return 0; @@ -3472,12 +3638,14 @@ static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2) } -static void sort_acl(SEC_ACL *the_acl) +static void +sort_acl(SEC_ACL *the_acl) { uint32 i; if (!the_acl) return; - qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), QSORT_CAST ace_compare); + qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), + QSORT_CAST ace_compare); for (i=1;inum_aces;) { if (sec_ace_equal(&the_acl->ace[i-1], &the_acl->ace[i])) { @@ -3493,11 +3661,12 @@ static void sort_acl(SEC_ACL *the_acl) } /* convert a SID to a string, either numeric or username/group */ -static void convert_sid_to_string(struct cli_state *ipc_cli, - POLICY_HND *pol, - fstring str, - BOOL numeric, - DOM_SID *sid) +static void +convert_sid_to_string(struct cli_state *ipc_cli, + POLICY_HND *pol, + fstring str, + BOOL numeric, + DOM_SID *sid) { char **domains = NULL; char **names = NULL; @@ -3530,11 +3699,12 @@ static void convert_sid_to_string(struct cli_state *ipc_cli, } /* convert a string to a SID, either numeric or username/group */ -static BOOL convert_string_to_sid(struct cli_state *ipc_cli, - POLICY_HND *pol, - BOOL numeric, - DOM_SID *sid, - const char *str) +static BOOL +convert_string_to_sid(struct cli_state *ipc_cli, + POLICY_HND *pol, + BOOL numeric, + DOM_SID *sid, + const char *str) { uint32 *types = NULL; DOM_SID *sids = NULL; @@ -3569,16 +3739,19 @@ static BOOL convert_string_to_sid(struct cli_state *ipc_cli, /* parse an ACE in the same format as print_ace() */ -static BOOL parse_ace(struct cli_state *ipc_cli, - POLICY_HND *pol, - SEC_ACE *ace, - BOOL numeric, - char *str) +static BOOL +parse_ace(struct cli_state *ipc_cli, + POLICY_HND *pol, + SEC_ACE *ace, + BOOL numeric, + char *str) { char *p; const char *cp; fstring tok; - unsigned atype, aflags, amask; + unsigned int atype; + unsigned int aflags; + unsigned int amask; DOM_SID sid; SEC_ACCESS mask; const struct perm_value *v; @@ -3689,10 +3862,14 @@ static BOOL parse_ace(struct cli_state *ipc_cli, } /* add an ACE to a list of ACEs in a SEC_ACL */ -static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace, TALLOC_CTX *ctx) +static BOOL +add_ace(SEC_ACL **the_acl, + SEC_ACE *ace, + TALLOC_CTX *ctx) { SEC_ACL *newacl; SEC_ACE *aces; + if (! *the_acl) { (*the_acl) = make_sec_acl(ctx, 3, 1, ace); return True; @@ -3701,7 +3878,8 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace, TALLOC_CTX *ctx) aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces); memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE)); memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE)); - newacl = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces); + newacl = make_sec_acl(ctx, (*the_acl)->revision, + 1+(*the_acl)->num_aces, aces); SAFE_FREE(aces); (*the_acl) = newacl; return True; @@ -3709,17 +3887,19 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace, TALLOC_CTX *ctx) /* parse a ascii version of a security descriptor */ -static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx, - struct cli_state *ipc_cli, - POLICY_HND *pol, - BOOL numeric, - char *str) +static SEC_DESC * +sec_desc_parse(TALLOC_CTX *ctx, + struct cli_state *ipc_cli, + POLICY_HND *pol, + BOOL numeric, + char *str) { const char *p = str; fstring tok; SEC_DESC *ret; size_t sd_size; - DOM_SID *grp_sid=NULL, *owner_sid=NULL; + DOM_SID *grp_sid=NULL; + DOM_SID *owner_sid=NULL; SEC_ACL *dacl=NULL; int revision=1; @@ -3819,10 +3999,11 @@ static SEC_DESC *sec_desc_parse(TALLOC_CTX *ctx, /* Obtain the current dos attributes */ -static DOS_ATTR_DESC *dos_attr_query(SMBCCTX *context, - TALLOC_CTX *ctx, - const char *filename, - SMBCSRV *srv) +static DOS_ATTR_DESC * +dos_attr_query(SMBCCTX *context, + TALLOC_CTX *ctx, + const char *filename, + SMBCSRV *srv) { time_t m_time = 0, a_time = 0, c_time = 0; SMB_OFF_T size = 0; @@ -3859,10 +4040,11 @@ static DOS_ATTR_DESC *dos_attr_query(SMBCCTX *context, /* parse a ascii version of a security descriptor */ -static void dos_attr_parse(SMBCCTX *context, - DOS_ATTR_DESC *dad, - SMBCSRV *srv, - char *str) +static void +dos_attr_parse(SMBCCTX *context, + DOS_ATTR_DESC *dad, + SMBCSRV *srv, + char *str) { const char *p = str; fstring tok; @@ -3905,9 +4087,16 @@ static void dos_attr_parse(SMBCCTX *context, Retrieve the acls for a file. *******************************************************/ -static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, - struct cli_state *ipc_cli, POLICY_HND *pol, - char *filename, char *attr_name, char *buf, int bufsize) +static int +cacl_get(SMBCCTX *context, + TALLOC_CTX *ctx, + SMBCSRV *srv, + struct cli_state *ipc_cli, + POLICY_HND *pol, + char *filename, + char *attr_name, + char *buf, + int bufsize) { uint32 i; int n = 0; @@ -3970,7 +4159,9 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, if (all || all_nt || all_dos) { /* Exclusions are delimited by '!' */ - for (; pExclude != NULL; pExclude = (p == NULL ? NULL : p + 1)) { + for (; + pExclude != NULL; + pExclude = (p == NULL ? NULL : p + 1)) { /* Find end of this exclusion name */ if ((p = strchr(pExclude, '!')) != NULL) @@ -4062,7 +4253,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, n = strlen(p); } else { n = snprintf(buf, bufsize, - "REVISION:%d", sd->revision); + "REVISION:%d", + sd->revision); } } else if (StrCaseCmp(name, "revision") == 0) { if (determine_size) { @@ -4166,7 +4358,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, } n = strlen(p); } else { - n = snprintf(buf, bufsize, "%s", sidstr); + n = snprintf(buf, bufsize, + "%s", sidstr); } } @@ -4213,9 +4406,9 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, ace->info.mask); } } else if ((StrnCaseCmp(name, "acl", 3) == 0 && - StrCaseCmp(name + 3, sidstr) == 0) || + StrCaseCmp(name+3, sidstr) == 0) || (StrnCaseCmp(name, "acl+", 4) == 0 && - StrCaseCmp(name + 4, sidstr) == 0)) { + StrCaseCmp(name+4, sidstr) == 0)) { if (determine_size) { p = talloc_asprintf( ctx, @@ -4320,7 +4513,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, } n = strlen(p); } else { - n = snprintf(buf, bufsize, "0x%x", mode); + n = snprintf(buf, bufsize, + "0x%x", mode); } } @@ -4401,7 +4595,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, } n = strlen(p); } else { - n = snprintf(buf, bufsize, "%lu", c_time); + n = snprintf(buf, bufsize, + "%lu", c_time); } } @@ -4438,7 +4633,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, } n = strlen(p); } else { - n = snprintf(buf, bufsize, "%lu", a_time); + n = snprintf(buf, bufsize, + "%lu", a_time); } } @@ -4475,7 +4671,8 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, } n = strlen(p); } else { - n = snprintf(buf, bufsize, "%lu", m_time); + n = snprintf(buf, bufsize, + "%lu", m_time); } } @@ -4548,10 +4745,15 @@ static int cacl_get(SMBCCTX *context, TALLOC_CTX *ctx, SMBCSRV *srv, /***************************************************** set the ACLs on a file given an ascii description *******************************************************/ -static int cacl_set(TALLOC_CTX *ctx, struct cli_state *cli, - struct cli_state *ipc_cli, POLICY_HND *pol, - const char *filename, const char *the_acl, - int mode, int flags) +static int +cacl_set(TALLOC_CTX *ctx, + struct cli_state *cli, + struct cli_state *ipc_cli, + POLICY_HND *pol, + const char *filename, + const char *the_acl, + int mode, + int flags) { int fnum; int err = 0; @@ -4626,7 +4828,8 @@ static int cacl_set(TALLOC_CTX *ctx, struct cli_state *cli, &old->dacl->ace[j])) { uint32 k; for (k=j; kdacl->num_aces-1;k++) { - old->dacl->ace[k] = old->dacl->ace[k+1]; + old->dacl->ace[k] = + old->dacl->ace[k+1]; } old->dacl->num_aces--; if (old->dacl->num_aces == 0) { @@ -4730,18 +4933,23 @@ static int cacl_set(TALLOC_CTX *ctx, struct cli_state *cli, } -int smbc_setxattr_ctx(SMBCCTX *context, - const char *fname, - const char *name, - const void *value, - size_t size, - int flags) +static int +smbc_setxattr_ctx(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size, + int flags) { int ret; int ret2; SMBCSRV *srv; SMBCSRV *ipc_srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; TALLOC_CTX *ctx; POLICY_HND pol; @@ -4762,7 +4970,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, } - DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n", fname, name, (int) size, (const char*)value)); + DEBUG(4, ("smbc_setxattr(%s, %s, %.*s)\n", + fname, name, (int) size, (const char*)value)); if (smbc_parse_path(context, fname, server, sizeof(server), @@ -4806,7 +5015,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, StrCaseCmp(name, "system.*+") == 0) { /* Yup. */ char *namevalue = - talloc_asprintf(ctx, "%s:%s", name+7, (const char *) value); + talloc_asprintf(ctx, "%s:%s", + name+7, (const char *) value); if (! namevalue) { errno = ENOMEM; ret = -1; @@ -4867,7 +5077,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, /* Yup. */ char *namevalue = - talloc_asprintf(ctx, "%s:%s", name+19, (const char *) value); + talloc_asprintf(ctx, "%s:%s", + name+19, (const char *) value); if (! ipc_srv) { ret = -1; /* errno set by smbc_server() */ @@ -4896,7 +5107,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, /* Yup. */ char *namevalue = - talloc_asprintf(ctx, "%s:%s", name+19, (const char *) value); + talloc_asprintf(ctx, "%s:%s", + name+19, (const char *) value); if (! ipc_srv) { @@ -4922,7 +5134,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, /* Yup. */ char *namevalue = - talloc_asprintf(ctx, "%s:%s", name+19, (const char *) value); + talloc_asprintf(ctx, "%s:%s", + name+19, (const char *) value); if (! ipc_srv) { /* errno set by smbc_server() */ @@ -4953,7 +5166,8 @@ int smbc_setxattr_ctx(SMBCCTX *context, dad = dos_attr_query(context, ctx, path, srv); if (dad) { char *namevalue = - talloc_asprintf(ctx, "%s:%s", name+16, (const char *) value); + talloc_asprintf(ctx, "%s:%s", + name+16, (const char *) value); if (! namevalue) { errno = ENOMEM; ret = -1; @@ -4989,16 +5203,21 @@ int smbc_setxattr_ctx(SMBCCTX *context, return -1; } -int smbc_getxattr_ctx(SMBCCTX *context, - const char *fname, - const char *name, - const void *value, - size_t size) +static int +smbc_getxattr_ctx(SMBCCTX *context, + const char *fname, + const char *name, + const void *value, + size_t size) { int ret; SMBCSRV *srv; SMBCSRV *ipc_srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; TALLOC_CTX *ctx; POLICY_HND pol; @@ -5103,14 +5322,19 @@ int smbc_getxattr_ctx(SMBCCTX *context, } -int smbc_removexattr_ctx(SMBCCTX *context, - const char *fname, - const char *name) +static int +smbc_removexattr_ctx(SMBCCTX *context, + const char *fname, + const char *name) { int ret; SMBCSRV *srv; SMBCSRV *ipc_srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; TALLOC_CTX *ctx; POLICY_HND pol; @@ -5209,10 +5433,11 @@ int smbc_removexattr_ctx(SMBCCTX *context, return -1; } -int smbc_listxattr_ctx(SMBCCTX *context, - const char *fname, - char *list, - size_t size) +static int +smbc_listxattr_ctx(SMBCCTX *context, + const char *fname, + char *list, + size_t size) { /* * This isn't quite what listxattr() is supposed to do. This returns @@ -5258,9 +5483,14 @@ int smbc_listxattr_ctx(SMBCCTX *context, * Open a print file to be written to by other calls */ -static SMBCFILE *smbc_open_print_job_ctx(SMBCCTX *context, const char *fname) +static SMBCFILE * +smbc_open_print_job_ctx(SMBCCTX *context, + const char *fname) { - fstring server, share, user, password; + fstring server; + fstring share; + fstring user; + fstring password; pstring path; if (!context || !context->internal || @@ -5304,10 +5534,17 @@ static SMBCFILE *smbc_open_print_job_ctx(SMBCCTX *context, const char *fname) * copy it to a print file on the share specified by printq. */ -static int smbc_print_file_ctx(SMBCCTX *c_file, const char *fname, SMBCCTX *c_print, const char *printq) +static int +smbc_print_file_ctx(SMBCCTX *c_file, + const char *fname, + SMBCCTX *c_print, + const char *printq) { - SMBCFILE *fid1, *fid2; - int bytes, saverr, tot_bytes = 0; + SMBCFILE *fid1; + SMBCFILE *fid2; + int bytes; + int saverr; + int tot_bytes = 0; char buf[4096]; if (!c_file || !c_file->internal->_initialized || !c_print || @@ -5380,10 +5617,17 @@ static int smbc_print_file_ctx(SMBCCTX *c_file, const char *fname, SMBCCTX *c_pr * Routine to list print jobs on a printer share ... */ -static int smbc_list_print_jobs_ctx(SMBCCTX *context, const char *fname, smbc_list_print_job_fn fn) +static int +smbc_list_print_jobs_ctx(SMBCCTX *context, + const char *fname, + smbc_list_print_job_fn fn) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; if (!context || !context->internal || @@ -5426,7 +5670,8 @@ static int smbc_list_print_jobs_ctx(SMBCCTX *context, const char *fname, smbc_li } - if (cli_print_queue(&srv->cli, (void (*)(struct print_job_info *))fn) < 0) { + if (cli_print_queue(&srv->cli, + (void (*)(struct print_job_info *))fn) < 0) { errno = smbc_errno(context, &srv->cli); return -1; @@ -5441,10 +5686,17 @@ static int smbc_list_print_jobs_ctx(SMBCCTX *context, const char *fname, smbc_li * Delete a print job from a remote printer share */ -static int smbc_unlink_print_job_ctx(SMBCCTX *context, const char *fname, int id) +static int +smbc_unlink_print_job_ctx(SMBCCTX *context, + const char *fname, + int id) { SMBCSRV *srv; - fstring server, share, user, password, workgroup; + fstring server; + fstring share; + fstring user; + fstring password; + fstring workgroup; pstring path; int err; @@ -5505,9 +5757,10 @@ static int smbc_unlink_print_job_ctx(SMBCCTX *context, const char *fname, int id /* * Get a new empty handle to fill in with your own info */ -SMBCCTX * smbc_new_context(void) +SMBCCTX * +smbc_new_context(void) { - SMBCCTX * context; + SMBCCTX *context; context = SMB_MALLOC_P(SMBCCTX); if (!context) { @@ -5579,7 +5832,9 @@ SMBCCTX * smbc_new_context(void) * and thus you'll be leaking memory if not handled properly. * */ -int smbc_free_context(SMBCCTX * context, int shutdown_ctx) +int +smbc_free_context(SMBCCTX *context, + int shutdown_ctx) { if (!context) { errno = EBADF; @@ -5601,12 +5856,15 @@ int smbc_free_context(SMBCCTX * context, int shutdown_ctx) if (context->callbacks.purge_cached_fn(context)) { SMBCSRV * s; SMBCSRV * next; - DEBUG(1, ("Could not purge all servers, Nice way shutdown failed.\n")); + DEBUG(1, ("Could not purge all servers, " + "Nice way shutdown failed.\n")); s = context->internal->_servers; while (s) { - DEBUG(1, ("Forced shutdown: %p (fd=%d)\n", s, s->cli.fd)); + DEBUG(1, ("Forced shutdown: %p (fd=%d)\n", + s, s->cli.fd)); cli_shutdown(&s->cli); - context->callbacks.remove_cached_srv_fn(context, s); + context->callbacks.remove_cached_srv_fn(context, + s); next = s->next; DLIST_REMOVE(context->internal->_servers, s); SAFE_FREE(s); @@ -5618,17 +5876,20 @@ int smbc_free_context(SMBCCTX * context, int shutdown_ctx) else { /* This is the polite way */ if (context->callbacks.purge_cached_fn(context)) { - DEBUG(1, ("Could not purge all servers, free_context failed.\n")); + DEBUG(1, ("Could not purge all servers, " + "free_context failed.\n")); errno = EBUSY; return 1; } if (context->internal->_servers) { - DEBUG(1, ("Active servers in context, free_context failed.\n")); + DEBUG(1, ("Active servers in context, " + "free_context failed.\n")); errno = EBUSY; return 1; } if (context->internal->_files) { - DEBUG(1, ("Active files in context, free_context failed.\n")); + DEBUG(1, ("Active files in context, " + "free_context failed.\n")); errno = EBUSY; return 1; } @@ -5653,11 +5914,13 @@ int smbc_free_context(SMBCCTX * context, int shutdown_ctx) * valid values for info->debug from 0 to 100, * and insist that info->fn must be non-null. */ -SMBCCTX * smbc_init_context(SMBCCTX * context) +SMBCCTX * +smbc_init_context(SMBCCTX *context) { pstring conf; int pid; - char *user = NULL, *home = NULL; + char *user = NULL; + char *home = NULL; if (!context || !context->internal) { errno = EBADF; @@ -5669,7 +5932,9 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) return 0; } - if (!context->callbacks.auth_fn || context->debug < 0 || context->debug > 100) { + if (!context->callbacks.auth_fn || + context->debug < 0 || + context->debug > 100) { errno = EINVAL; return NULL; @@ -5677,7 +5942,10 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) } if (!smbc_initialized) { - /* Do some library wide intialisations the first time we get called */ + /* + * Do some library-wide intializations the first time we get + * called + */ BOOL conf_loaded = False; /* Set this to what the user wants */ @@ -5755,15 +6023,17 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) if (!context->netbios_name) { /* - * We try to get our netbios name from the config. If that fails we fall - * back on constructing our netbios name from our hostname etc + * We try to get our netbios name from the config. If that + * fails we fall back on constructing our netbios name from + * our hostname etc */ if (global_myname()) { context->netbios_name = SMB_STRDUP(global_myname()); } else { /* - * Hmmm, I want to get hostname as well, but I am too lazy for the moment + * Hmmm, I want to get hostname as well, but I am too + * lazy for the moment */ pid = sys_getpid(); context->netbios_name = SMB_MALLOC(17); @@ -5771,7 +6041,8 @@ SMBCCTX * smbc_init_context(SMBCCTX * context) errno = ENOMEM; return NULL; } - slprintf(context->netbios_name, 16, "smbc%s%d", context->user, pid); + slprintf(context->netbios_name, 16, + "smbc%s%d", context->user, pid); } } -- cgit From d2d7950291be08ef5dc3b6fee77f65f4c647c06d Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 15:06:59 +0000 Subject: r12570: r12084@cabra: derrell | 2005-12-29 10:05:16 -0500 do not open connection when only looking for cached connection; also, fix crash caused by missing initialization following recent locale changes --- source/libsmb/libsmbclient.c | 81 ++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index c4e36012f92..8cfef769e57 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -589,6 +589,7 @@ find_server(SMBCCTX *context, static SMBCSRV * smbc_server(SMBCCTX *context, + BOOL connect_if_not_found, const char *server, const char *share, fstring workgroup, @@ -644,13 +645,18 @@ smbc_server(SMBCCTX *context, errno = smbc_errno(context, &srv->cli); cli_shutdown(&srv->cli); - context->callbacks.remove_cached_srv_fn(context, srv); + context->callbacks.remove_cached_srv_fn(context, + srv); srv = NULL; } - /* Regenerate the dev value since it's based on both server and share */ + /* + * Regenerate the dev value since it's based on both + * server and share + */ if (srv) { - srv->dev = (dev_t)(str_checksum(server) ^ str_checksum(share)); + srv->dev = (dev_t)(str_checksum(server) ^ + str_checksum(share)); } } } @@ -662,6 +668,12 @@ smbc_server(SMBCCTX *context, return srv; } + /* If we're not asked to connect when a connection doesn't exist... */ + if (! connect_if_not_found) { + /* ... then we're done here. */ + return NULL; + } + make_nmb_name(&calling, context->netbios_name, 0x0); make_nmb_name(&called , server, 0x20); @@ -1003,7 +1015,8 @@ smbc_open_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -1646,7 +1659,8 @@ smbc_unlink_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -1779,8 +1793,8 @@ smbc_rename_ctx(SMBCCTX *ocontext, fstrcpy(workgroup, ocontext->workgroup); - srv = smbc_server(ocontext, server1, share1, workgroup, - user1, password1); + srv = smbc_server(ocontext, True, + server1, share1, workgroup, user1, password1); if (!srv) { return -1; @@ -2049,7 +2063,8 @@ smbc_stat_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ @@ -2616,8 +2631,8 @@ smbc_opendir_ctx(SMBCCTX *context, * workgroups/domains that it knows about. */ - srv = smbc_server(context, server, - "IPC$", workgroup, user, password); + srv = smbc_server(context, True, server, "IPC$", + workgroup, user, password); if (!srv) { continue; } @@ -2664,8 +2679,12 @@ smbc_opendir_ctx(SMBCCTX *context, * to see if is an IP address first. */ - /* See if we have an existing server */ - srv = smbc_server(context, server, "IPC$", + /* + * See if we have an existing server. Do not + * establish a connection if one does not already + * exist. + */ + srv = smbc_server(context, False, server, "IPC$", workgroup, user, password); /* @@ -2699,7 +2718,8 @@ smbc_opendir_ctx(SMBCCTX *context, * Get a connection to IPC$ on the server if * we do not already have one */ - srv = smbc_server(context, buserver, "IPC$", + srv = smbc_server(context, True, + buserver, "IPC$", workgroup, user, password); if (!srv) { DEBUG(0, ("got no contact to IPC$\n")); @@ -2729,8 +2749,9 @@ smbc_opendir_ctx(SMBCCTX *context, /* If we hadn't found the server, get one now */ if (!srv) { - srv = smbc_server(context, server, - "IPC$", workgroup, + srv = smbc_server(context, True, + server, "IPC$", + workgroup, user, password); } @@ -2787,7 +2808,7 @@ smbc_opendir_ctx(SMBCCTX *context, /* We connect to the server and list the directory */ dir->dir_type = SMBC_FILE_SHARE; - srv = smbc_server(context, server, share, + srv = smbc_server(context, True, server, share, workgroup, user, password); if (!srv) { @@ -3149,7 +3170,8 @@ smbc_mkdir_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -3246,7 +3268,8 @@ smbc_rmdir_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -3498,7 +3521,8 @@ smbc_chmod_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ @@ -3593,7 +3617,8 @@ smbc_utimes_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ @@ -4988,7 +5013,8 @@ smbc_setxattr_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ } @@ -5255,7 +5281,8 @@ smbc_getxattr_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ } @@ -5371,7 +5398,8 @@ smbc_removexattr_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { return -1; /* errno set by smbc_server */ } @@ -5662,7 +5690,8 @@ smbc_list_print_jobs_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -5732,7 +5761,8 @@ smbc_unlink_print_job_ctx(SMBCCTX *context, fstrcpy(workgroup, context->workgroup); - srv = smbc_server(context, server, share, workgroup, user, password); + srv = smbc_server(context, True, + server, share, workgroup, user, password); if (!srv) { @@ -5951,6 +5981,7 @@ smbc_init_context(SMBCCTX *context) /* Set this to what the user wants */ DEBUGLEVEL = context->debug; + load_case_tables(); setup_logging( "libsmbclient", True); /* Here we would open the smb.conf file if needed ... */ -- cgit From 997a09dff8148d52ee522583e27ccfa01a06c8c3 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 16:26:06 +0000 Subject: r12576: r12115@cabra: derrell | 2005-12-29 11:16:03 -0500 bug (enhancement) #2651: add option to log debug messages to stderr instead of stdout --- examples/libsmbclient/testbrowse.c | 46 ++++++++++++++++++++++++++++---------- source/include/libsmb_internal.h | 18 ++++++++++----- source/libsmb/libsmbclient.c | 30 +++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 19 deletions(-) diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 6fa70eab414..eba6fff4ebf 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -29,6 +29,7 @@ int main(int argc, char * argv[]) { int debug = 0; + int debug_stderr = 0; int scan = 0; int iterations = -1; int again; @@ -37,6 +38,7 @@ main(int argc, char * argv[]) char * q; char buf[1024]; poptContext pc; + SMBCCTX * context; struct poptOption long_options[] = { POPT_AUTOHELP @@ -44,6 +46,10 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "stderr", 'e', POPT_ARG_NONE, &debug_stderr, + 0, "Debug log to stderr instead of stdout", "integer" + }, { "scan", 's', POPT_ARG_NONE, &scan, 0, "Scan for servers and shares", "integer" @@ -69,14 +75,36 @@ main(int argc, char * argv[]) } } + /* Allocate a new context */ + context = smbc_new_context(); + if (!context) { + printf("Could not allocate new smbc context\n"); + return 1; + } + + /* Set mandatory options (is that a contradiction in terms?) */ + context->debug = debug; + context->callbacks.auth_fn = (scan ? no_auth_data_fn : get_auth_data_fn); + + /* If we've been asked to log to stderr instead of stdout... */ + if (debug_stderr) { + /* ... then set the option to do so */ + smbc_option_set(context, "debug_stderr", NULL); + } + + /* Initialize the context using the previously specified options */ + if (!smbc_init_context(context)) { + smbc_free_context(context, 0); + printf("Could not initialize smbc context\n"); + return 1; + } + + /* Tell the compatibility layer to use this context */ + smbc_set_context(context); + + if (scan) { - if (smbc_init(no_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) @@ -87,12 +115,6 @@ main(int argc, char * argv[]) } else { - if (smbc_init(get_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) diff --git a/source/include/libsmb_internal.h b/source/include/libsmb_internal.h index 081bb415e56..04264303288 100644 --- a/source/include/libsmb_internal.h +++ b/source/include/libsmb_internal.h @@ -47,11 +47,12 @@ struct _SMBCFILE { struct smbc_internal_data { - /** INTERNAL: is this handle initialized ? + /* + * Is this handle initialized ? */ - int _initialized; + BOOL _initialized; - /** INTERNAL: dirent pointer location + /* dirent pointer location * * Leave room for any urlencoded filename and the comment field. * @@ -64,13 +65,20 @@ struct smbc_internal_data { */ char _dirent[1024]; - /** INTERNAL: server connection list + /* + * server connection list */ SMBCSRV * _servers; - /** INTERNAL: open file/dir list + /* + * open file/dir list */ SMBCFILE * _files; + + /* + * Log to standard error instead of the more typical standard output + */ + BOOL _debug_stderr; }; diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 8cfef769e57..6eca3946d8f 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -5937,6 +5937,27 @@ smbc_free_context(SMBCCTX *context, } +/* + * Each time the context structure is changed, we have binary backward + * compatibility issues. Instead of modifying the public portions of the + * context structure to add new options, instead, we put them in the internal + * portion of the context structure and provide a set function for these new + * options. + */ +void +smbc_option_set(SMBCCTX *context, + char *option_name, + void *option_value) +{ + if (strcmp(option_name, "debug_stderr") == 0) { + /* + * Log to standard error instead of standard output. + */ + context->internal->_debug_stderr = True; + } +} + + /* * Initialise the library etc * @@ -5982,7 +6003,12 @@ smbc_init_context(SMBCCTX *context) DEBUGLEVEL = context->debug; load_case_tables(); - setup_logging( "libsmbclient", True); + + setup_logging("libsmbclient", True); + if (context->internal->_debug_stderr) { + dbf = x_stderr; + x_setbuf(x_stderr, NULL); + } /* Here we would open the smb.conf file if needed ... */ @@ -6099,7 +6125,7 @@ smbc_init_context(SMBCCTX *context) * FIXME: Should we check the function pointers here? */ - context->internal->_initialized = 1; + context->internal->_initialized = True; return context; } -- cgit From 3e7b17c5c71df1ebd250b0296cf80ca461469822 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 17:03:39 +0000 Subject: r12579: r12122@cabra: derrell | 2005-12-29 12:03:00 -0500 allow for arbitrary option value types --- examples/libsmbclient/testbrowse.c | 2 +- source/libsmb/libsmbclient.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index eba6fff4ebf..b5337ae983a 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -89,7 +89,7 @@ main(int argc, char * argv[]) /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { /* ... then set the option to do so */ - smbc_option_set(context, "debug_stderr", NULL); + smbc_option_set(context, "debug_stderr"); } /* Initialize the context using the previously specified options */ diff --git a/source/libsmb/libsmbclient.c b/source/libsmb/libsmbclient.c index 6eca3946d8f..51f94e42e37 100644 --- a/source/libsmb/libsmbclient.c +++ b/source/libsmb/libsmbclient.c @@ -5947,14 +5947,22 @@ smbc_free_context(SMBCCTX *context, void smbc_option_set(SMBCCTX *context, char *option_name, - void *option_value) + ...) { + va_list args; + + va_start(args, option_name); + if (strcmp(option_name, "debug_stderr") == 0) { /* * Log to standard error instead of standard output. + * + * optional parameters: none (it can't be turned off once on) */ context->internal->_debug_stderr = True; } + + va_end(args); } -- cgit From 01b09bf17211cfb932da7f3553618fee79bf1bd1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 29 Dec 2005 19:30:06 +0000 Subject: r12581: And another one :-) --- source/rpcclient/rpcclient.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/rpcclient/rpcclient.c b/source/rpcclient/rpcclient.c index 46f2df29d33..5bca67d7a63 100644 --- a/source/rpcclient/rpcclient.c +++ b/source/rpcclient/rpcclient.c @@ -704,6 +704,8 @@ out_free: POPT_TABLEEND }; + load_case_tables(); + ZERO_STRUCT(server_ip); setlinebuf(stdout); -- cgit From b4cd57a67e7754a2e730eb5f8902c93cdc8e9289 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 29 Dec 2005 23:47:58 +0000 Subject: r12593: packaging fixes missed from the 3.0.21 build --- packaging/Fedora/samba.spec.tmpl | 4 ++-- packaging/RedHat/samba.spec.tmpl | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packaging/Fedora/samba.spec.tmpl b/packaging/Fedora/samba.spec.tmpl index bac333699ff..4f4299470b1 100644 --- a/packaging/Fedora/samba.spec.tmpl +++ b/packaging/Fedora/samba.spec.tmpl @@ -299,9 +299,9 @@ fi %{_mandir}/man8/nmbd.8* %{_mandir}/man8/pdbedit.8* %{_mandir}/man8/smbd.8* -%{_mandir}/man8/pam_winbind.8* +%{_mandir}/man7/pam_winbind.7* %{_mandir}/man8/tdbbackup.8* -%{_mandir}/man8/libsmbclient.8* +%{_mandir}/man7/libsmbclient.7* %{_libdir}/samba/vfs diff --git a/packaging/RedHat/samba.spec.tmpl b/packaging/RedHat/samba.spec.tmpl index 004f57cf522..b19a8874983 100644 --- a/packaging/RedHat/samba.spec.tmpl +++ b/packaging/RedHat/samba.spec.tmpl @@ -95,7 +95,6 @@ CFLAGS="$RPM_OPT_FLAGS $EXTRA" ./configure \ --with-pam_smbpass \ --with-syslog \ --with-utmp \ - --with-sambabook=%{prefix}/share/swat/using_samba \ --with-swatdir=%{prefix}/share/swat \ --with-shared-modules=idmap_rid \ --with-libsmbclient @@ -116,7 +115,7 @@ mkdir -p $RPM_BUILD_ROOT/etc/{logrotate.d,pam.d,samba} mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d mkdir -p $RPM_BUILD_ROOT%{prefix}/{bin,sbin} mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/{help,include,using_samba} -mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/using_samba/{figs,gifs} +mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/help/using_samba/{figs,gifs} mkdir -p $RPM_BUILD_ROOTMANDIR_MACRO mkdir -p $RPM_BUILD_ROOT/var/lib/samba mkdir -p $RPM_BUILD_ROOT/var/{log,run}/samba @@ -126,7 +125,7 @@ mkdir -p $RPM_BUILD_ROOT%{prefix}/lib/samba/vfs mkdir -p $RPM_BUILD_ROOT%{prefix}/{lib,include} # Install standard binary files -for i in nmblookup smbclient smbpasswd smbstatus testparm \ +for i in nmblookup smbget smbclient smbpasswd smbstatus testparm \ rpcclient smbspool smbcacls smbcontrol wbinfo smbmnt net \ smbcacls pdbedit eventlogadm tdbbackup smbtree ntlm_auth smbcquotas do @@ -215,7 +214,6 @@ find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; rm -f $RPM_BUILD_ROOT/%{_mandir}/man1/editreg.1* rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbget.1* rm -f $RPM_BUILD_ROOT/%{_mandir}/man8/mount.cifs.8* @@ -416,6 +414,7 @@ fi /sbin/mount.smb %{prefix}/bin/mksmbpasswd.sh %{prefix}/bin/smbclient +%{prefix}/bin/smbget %{prefix}/bin/smbspool %{prefix}/bin/rpcclient %{prefix}/bin/testparm @@ -450,9 +449,10 @@ fi %{prefix}/lib/libmsrpc.a %{prefix}/lib/libmsrpc.so %{prefix}/share/swat/help/* +%{prefix}/share/swat/images/*.gif %{prefix}/share/swat/include/*.html %{prefix}/share/swat/lang/*/help/* -%{prefix}/share/swat/using_samba/* +%{prefix}/share/swat/lang/*/images/*.gif %config(noreplace) /etc/samba/lmhosts %config(noreplace) /etc/samba/smb.conf %config(noreplace) /etc/samba/smbusers -- cgit From 59b4b10edc3276aa40daa49653660b7bd6a15259 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 30 Dec 2005 11:01:29 +0000 Subject: r12603: NO, I'm not claiming maintainership of this. Fix bug 3351. Volker --- source/passdb/pdb_sql.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/source/passdb/pdb_sql.c b/source/passdb/pdb_sql.c index f52888bfa91..f4f6e0112ae 100644 --- a/source/passdb/pdb_sql.c +++ b/source/passdb/pdb_sql.c @@ -536,13 +536,12 @@ char *sql_account_query_update(TALLOC_CTX *mem_ctx, const char *location, const if (query->update) { query->part1[strlen(query->part1) - 1] = '\0'; - query->part1 = - talloc_asprintf_append(query->part1, - " WHERE %s = '%s'", - config_value_read(location, - "user sid column", - CONFIG_USER_SID_DEFAULT), - sid_to_string(sid_str, pdb_get_user_sid (newpwd))); + query->part1 = talloc_asprintf( + mem_ctx, "%s WHERE %s = '%s'", query->part1, + config_value_read(location, + "user sid column", + CONFIG_USER_SID_DEFAULT), + sid_to_string(sid_str, pdb_get_user_sid (newpwd))); } else { query->part2[strlen(query->part2) - 1] = ')'; query->part1[strlen(query->part1) - 1] = ')'; -- cgit From f8385c2cb55e6b8aee73161b557506eb664bea72 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 31 Dec 2005 10:57:43 +0000 Subject: r12645: Fix some memleaks. This will also be in the trunk checkin that comes next. Volker --- source/passdb/pdb_ldap.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 74ed907a870..0bf051eecda 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -4070,6 +4070,9 @@ static BOOL ldapgroup2displayentry(struct ldap_search_state *state, vals = ldap_get_values(ld, entry, "sambaGroupType"); if ((vals == NULL) || (vals[0] == NULL)) { DEBUG(5, ("\"sambaGroupType\" not found\n")); + if (vals != NULL) { + ldap_value_free(vals); + } return False; } @@ -4077,9 +4080,12 @@ static BOOL ldapgroup2displayentry(struct ldap_search_state *state, if ((state->group_type != 0) && ((state->group_type != group_type))) { + ldap_value_free(vals); return False; } + ldap_value_free(vals); + /* display name is the NT group name */ vals = ldap_get_values(ld, entry, "displayName"); @@ -4119,6 +4125,9 @@ static BOOL ldapgroup2displayentry(struct ldap_search_state *state, vals = ldap_get_values(ld, entry, "sambaSid"); if ((vals == NULL) || (vals[0] == NULL)) { DEBUG(0, ("\"objectSid\" not found\n")); + if (vals != NULL) { + ldap_value_free(vals); + } return False; } -- cgit From 71980ec2c7ecd3594cfeeb266803d2736a0b4d79 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 1 Jan 2006 15:59:22 +0000 Subject: r12653: Patch from SATOH Fumiyasu for bug #3348. Don't assume owning sticky bit directory means write access allowed. Jeremy. --- source/smbd/posix_acls.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/smbd/posix_acls.c b/source/smbd/posix_acls.c index 1b8e1d62143..f49f80f006f 100644 --- a/source/smbd/posix_acls.c +++ b/source/smbd/posix_acls.c @@ -4149,8 +4149,13 @@ BOOL can_delete_file_in_directory(connection_struct *conn, const char *fname) if(SMB_VFS_STAT(conn, fname, &sbuf_file) != 0) { return False; } - if (current_user.uid == sbuf_file.st_uid) { - return True; + /* + * Patch from SATOH Fumiyasu + * for bug #3348. Don't assume owning sticky bit + * directory means write access allowed. + */ + if (current_user.uid != sbuf_file.st_uid) { + return False; } return False; } -- cgit From ba31d461a4998ebf3f2481cfb088ceb16ed159c7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 1 Jan 2006 18:02:50 +0000 Subject: r12660: Happy New Year! metze --- source/include/smb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/smb.h b/source/include/smb.h index 4f378f822e2..d2eb5644e0d 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -28,7 +28,7 @@ #define _SMB_H /* logged when starting the various Samba daemons */ -#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2005" +#define COPYRIGHT_STARTUP_MESSAGE "Copyright Andrew Tridgell and the Samba Team 1992-2006" #if defined(LARGE_SMB_OFF_T) -- cgit From ae869f7d20e0bb411a637778714597223e27b952 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 1 Jan 2006 18:30:44 +0000 Subject: r12663: Fix a memleak --- source/passdb/pdb_ldap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index 0bf051eecda..b35ce18eee5 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -3638,6 +3638,10 @@ static NTSTATUS ldapsam_lookup_rids(struct pdb_methods *methods, goto done; } + if (msg != NULL) { + ldap_msgfree(msg); + } + /* Same game for groups */ { -- cgit From a564f2e25ff852d3253cfd01058678a694d969e0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 2 Jan 2006 18:23:49 +0000 Subject: r12678: One more --- source/utils/nmblookup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/utils/nmblookup.c b/source/utils/nmblookup.c index 09148ad37c3..e88d7862901 100644 --- a/source/utils/nmblookup.c +++ b/source/utils/nmblookup.c @@ -214,6 +214,8 @@ int main(int argc,char *argv[]) *lookup = 0; + load_case_tables(); + setup_logging(argv[0],True); pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, -- cgit From d9bb9e8228b1e88892f96462cc06d9d44e924a4f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Jan 2006 12:48:54 +0000 Subject: r12713: Remove use of uint8_t -> uint8. Jeremy. --- source/libsmb/smbencrypt.c | 2 +- source/nsswitch/winbindd_ldap.c | 12 ++++++------ source/smbd/oplock.c | 2 +- source/tdb/tdbutil.c | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/libsmb/smbencrypt.c b/source/libsmb/smbencrypt.c index f99e48a0b9c..99f99f23f8c 100644 --- a/source/libsmb/smbencrypt.c +++ b/source/libsmb/smbencrypt.c @@ -542,7 +542,7 @@ void sess_crypt_blob(DATA_BLOB *out, const DATA_BLOB *in, const DATA_BLOB *sessi for (i=0,k=0; ilength; i += 8, k += 7) { - uint8_t bin[8], bout[8], key[7]; + uint8 bin[8], bout[8], key[7]; memset(bin, 0, 8); memcpy(bin, &in->data[i], MIN(8, in->length-i)); diff --git a/source/nsswitch/winbindd_ldap.c b/source/nsswitch/winbindd_ldap.c index 4eedf0ce9f3..736d852a74e 100644 --- a/source/nsswitch/winbindd_ldap.c +++ b/source/nsswitch/winbindd_ldap.c @@ -34,7 +34,7 @@ struct ldap_message_queue { }; struct rw_buffer { - uint8_t *data; + uint8 *data; size_t ofs, length; }; @@ -67,7 +67,7 @@ struct pending_ldap_message { struct pending_ldap_message *pending_messages; -static BOOL append_to_buf(struct rw_buffer *buf, uint8_t *data, size_t length) +static BOOL append_to_buf(struct rw_buffer *buf, uint8 *data, size_t length) { buf->data = SMB_REALLOC(buf->data, buf->length+length); @@ -92,7 +92,7 @@ static BOOL read_into_buf(int fd, struct rw_buffer *buf) return append_to_buf(buf, tmp_buf, len); } -static void peek_into_buf(struct rw_buffer *buf, uint8_t **out, +static void peek_into_buf(struct rw_buffer *buf, uint8 **out, size_t *out_length) { *out = buf->data; @@ -101,7 +101,7 @@ static void peek_into_buf(struct rw_buffer *buf, uint8_t **out, static void consumed_from_buf(struct rw_buffer *buf, size_t length) { - uint8_t *new = memdup(buf->data+length, buf->length-length); + uint8 *new = memdup(buf->data+length, buf->length-length); free(buf->data); buf->data = new; buf->length -= length; @@ -109,7 +109,7 @@ static void consumed_from_buf(struct rw_buffer *buf, size_t length) static BOOL write_out_of_buf(int fd, struct rw_buffer *buf) { - uint8_t *tmp; + uint8 *tmp; size_t tmp_length, written; peek_into_buf(buf, &tmp, &tmp_length); @@ -176,7 +176,7 @@ static void new_ldap_client(int listen_sock) static struct ldap_message *get_msg_from_buf(struct rw_buffer *buffer, BOOL *error) { - uint8_t *buf; + uint8 *buf; int buf_length, msg_length; DATA_BLOB blob; ASN1_DATA data; diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c index 54e7da11afe..f788fc9e2e0 100644 --- a/source/smbd/oplock.c +++ b/source/smbd/oplock.c @@ -252,7 +252,7 @@ int setup_oplock_select_set( fd_set *fds) ****************************************************************************/ static char *new_break_smb_message(TALLOC_CTX *mem_ctx, - files_struct *fsp, uint8_t cmd) + files_struct *fsp, uint8 cmd) { char *result = TALLOC_ARRAY(mem_ctx, char, smb_size + 8*2 + 0); diff --git a/source/tdb/tdbutil.c b/source/tdb/tdbutil.c index ac9280cf8bd..53011006327 100644 --- a/source/tdb/tdbutil.c +++ b/source/tdb/tdbutil.c @@ -485,7 +485,7 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...) return result; } -BOOL tdb_pack_append(TALLOC_CTX *mem_ctx, uint8_t **buf, size_t *len, +BOOL tdb_pack_append(TALLOC_CTX *mem_ctx, uint8 **buf, size_t *len, const char *fmt, ...) { va_list ap; @@ -496,10 +496,10 @@ BOOL tdb_pack_append(TALLOC_CTX *mem_ctx, uint8_t **buf, size_t *len, va_end(ap); if (mem_ctx != NULL) - *buf = TALLOC_REALLOC_ARRAY(mem_ctx, *buf, uint8_t, + *buf = TALLOC_REALLOC_ARRAY(mem_ctx, *buf, uint8, (*len) + len1); else - *buf = SMB_REALLOC_ARRAY(*buf, uint8_t, (*len) + len1); + *buf = SMB_REALLOC_ARRAY(*buf, uint8, (*len) + len1); if (*buf == NULL) return False; -- cgit From 9d74e1799fffa7a50cabca03683c48ae817afdef Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 4 Jan 2006 13:04:43 +0000 Subject: r12714: Fix segfault in pdb_nds.c. Guenther --- source/lib/smbldap.c | 8 ++++---- source/passdb/pdb_nds.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/lib/smbldap.c b/source/lib/smbldap.c index a3ebe72df21..609816b8774 100644 --- a/source/lib/smbldap.c +++ b/source/lib/smbldap.c @@ -664,21 +664,21 @@ int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) open a connection to the ldap server (just until the bind) ******************************************************************/ -int smb_ldap_setup_full_conn(LDAP *ldap_struct, const char *uri) +int smb_ldap_setup_full_conn(LDAP **ldap_struct, const char *uri) { int rc, version; - rc = smb_ldap_setup_conn(&ldap_struct, uri); + rc = smb_ldap_setup_conn(ldap_struct, uri); if (rc) { return rc; } - rc = smb_ldap_upgrade_conn(ldap_struct, &version); + rc = smb_ldap_upgrade_conn(*ldap_struct, &version); if (rc) { return rc; } - rc = smb_ldap_start_tls(ldap_struct, version); + rc = smb_ldap_start_tls(*ldap_struct, version); if (rc) { return rc; } diff --git a/source/passdb/pdb_nds.c b/source/passdb/pdb_nds.c index 1ec96932231..cf2d1d7c8a8 100644 --- a/source/passdb/pdb_nds.c +++ b/source/passdb/pdb_nds.c @@ -807,7 +807,7 @@ static NTSTATUS pdb_nds_update_login_attempts(struct pdb_methods *methods, if((success != True) || (got_clear_text_pw == True)) { - rc = smb_ldap_setup_full_conn(ld, ldap_state->location); + rc = smb_ldap_setup_full_conn(&ld, ldap_state->location); if (rc) { return NT_STATUS_INVALID_CONNECTION; } -- cgit From 2d492971650fbb936291f34715a0b7fe6f95d0a9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jan 2006 11:35:29 +0000 Subject: r12721: GPFS 2.4 on Linux will contain some windows semantics, ie share modes and oplocks across the cluster. Adapt Samba to it. The gpfs API is called via libgpfs.so. This code is written with dlopen(), so that you can compile on a system with gpfs installed and later on run on systems without gpfs available. So to actually make Samba call gpfs share mode calls you need to compile with gpfs.h and libgpfs.so around and set 'gpfs share = yes' on the shares you export from GPFS. Volker --- source/Makefile.in | 2 +- source/configure.in | 13 ++++ source/param/loadparm.c | 4 ++ source/smbd/gpfs.c | 159 +++++++++++++++++++++++++++++++++++++++++++++ source/smbd/open.c | 14 ++++ source/smbd/oplock_linux.c | 22 +++++-- source/smbd/server.c | 2 + 7 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 source/smbd/gpfs.c diff --git a/source/Makefile.in b/source/Makefile.in index 9d00cb72a1d..54dbecb764e 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -403,7 +403,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \ lib/sysquotas_xfs.o lib/sysquotas_4A.o \ smbd/change_trust_pw.o smbd/fake_file.o \ smbd/quotas.o smbd/ntquotas.o $(AFS_OBJ) smbd/msdfs.o \ - $(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/statvfs.o \ + $(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/gpfs.o smbd/statvfs.o \ $(MANGLE_OBJ) @VFS_STATIC@ SMBD_OBJ_BASE = $(PARAM_OBJ) $(SMBD_OBJ_SRV) $(LIBSMB_OBJ) \ diff --git a/source/configure.in b/source/configure.in index ec1bdacad84..2b1f4d691f9 100644 --- a/source/configure.in +++ b/source/configure.in @@ -1159,6 +1159,19 @@ AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols) AC_CHECK_HEADERS(libexc.h) AC_CHECK_LIB(exc, trace_back_stack) +echo -n "checking for GPFS 2.4 libs... " +save_LIBS="$LIBS" +LIBS="$LIBS -lgpfs" +AC_TRY_LINK([#include ], + [gpfs_set_share(0,GPFS_SHARE_READ,GPFS_DENY_NONE)], + samba_cv_HAVE_GPFS_SET_SHARE=yes, + samba_cv_HAVE_GPFS_SET_SHARE=no) +echo $samba_cv_HAVE_GPFS_SET_SHARE +if test x"$samba_cv_HAVE_GPFS_SET_SHARE" = x"yes"; then + AC_DEFINE(HAVE_GPFS_SET_SHARE,1,[Whether GPFS 2.4 libs are available]) +fi +LIBS="$save_LIBS" + # syscall() is needed for smbwrapper. AC_CHECK_FUNCS(syscall) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 526bce9b60e..3fa6dee5a24 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -433,6 +433,7 @@ typedef struct BOOL bProfileAcls; BOOL bMap_acl_inherit; BOOL bAfs_Share; + BOOL bGpfs_Share; BOOL bEASupport; BOOL bAclCheckPermissions; BOOL bAclMapFullControl; @@ -569,6 +570,7 @@ static service sDefault = { False, /* bProfileAcls */ False, /* bMap_acl_inherit */ False, /* bAfs_Share */ + False, /* bGpfs_Share */ False, /* bEASupport */ True, /* bAclCheckPermissions */ True, /* bAclMapFullControl */ @@ -967,6 +969,7 @@ static struct parm_struct parm_table[] = { {"announce as", P_ENUM, P_GLOBAL, &Globals.announce_as, NULL, enum_announce_as, FLAG_ADVANCED}, {"map acl inherit", P_BOOL, P_LOCAL, &sDefault.bMap_acl_inherit, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, {"afs share", P_BOOL, P_LOCAL, &sDefault.bAfs_Share, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, + {"gpfs share", P_BOOL, P_LOCAL, &sDefault.bGpfs_Share, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, {"max mux", P_INTEGER, P_GLOBAL, &Globals.max_mux, NULL, NULL, FLAG_ADVANCED}, {"max xmit", P_INTEGER, P_GLOBAL, &Globals.max_xmit, NULL, NULL, FLAG_ADVANCED}, @@ -2001,6 +2004,7 @@ FN_LOCAL_BOOL(_lp_use_sendfile, bUseSendfile) FN_LOCAL_BOOL(lp_profile_acls, bProfileAcls) FN_LOCAL_BOOL(lp_map_acl_inherit, bMap_acl_inherit) FN_LOCAL_BOOL(lp_afs_share, bAfs_Share) +FN_LOCAL_BOOL(lp_gpfs_share, bGpfs_Share) FN_LOCAL_BOOL(lp_acl_check_permissions, bAclCheckPermissions) FN_LOCAL_BOOL(lp_acl_group_control, bAclGroupControl) FN_LOCAL_BOOL(lp_acl_map_full_control, bAclMapFullControl) diff --git a/source/smbd/gpfs.c b/source/smbd/gpfs.c new file mode 100644 index 00000000000..4a8b9eea6c5 --- /dev/null +++ b/source/smbd/gpfs.c @@ -0,0 +1,159 @@ +/* + * Unix SMB/CIFS implementation. + * Provide a connection to GPFS specific features + * Copyright (C) Volker Lendecke 2005 + * + * 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. + */ + +#include "includes.h" + +#ifdef HAVE_GPFS_SET_SHARE + +#include "gpfs.h" + +static void *libgpfs_handle = NULL; + +static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny); +static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType); + +BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, + uint32 share_access) +{ + unsigned int allow = GPFS_SHARE_NONE; + unsigned int deny = GPFS_DENY_NONE; + int result; + + if (gpfs_set_share_fn == NULL) { + return False; + } + + if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) { + /* No real file, don't disturb */ + return True; + } + + allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA| + DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0; + allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ? + GPFS_SHARE_READ : 0; + deny |= (share_access & (FILE_SHARE_WRITE|FILE_SHARE_DELETE)) ? + 0 : GPFS_DENY_WRITE; + deny |= (share_access & (FILE_SHARE_READ)) ? + 0 : GPFS_DENY_READ; + + DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n", + access_mask, allow, share_access, deny)); + + result = gpfs_set_share_fn(fsp->fh->fd, allow, deny); + if (result != 0) { + if (errno == ENOSYS) { + DEBUG(5, ("'gpfs share = yes' set, but no gpfs " + "available. Allowing access\n")); + return True; + } else { + DEBUG(10, ("gpfs_set_share failed: %s\n", + strerror(errno))); + } + } + + return (result == 0); +} + +int set_gpfs_lease(int fd, int leasetype) +{ + int gpfs_type = GPFS_LEASE_NONE; + + if (gpfs_set_lease_fn == NULL) { + errno = EINVAL; + return -1; + } + + if (leasetype == F_RDLCK) { + gpfs_type = GPFS_LEASE_READ; + } + if (leasetype == F_WRLCK) { + gpfs_type = GPFS_LEASE_WRITE; + } + return gpfs_set_lease_fn(fd, gpfs_type); +} + +void init_gpfs(void) +{ + if (libgpfs_handle != NULL) { + return; + } + + libgpfs_handle = sys_dlopen("libgpfs.so", RTLD_LAZY); + + if (libgpfs_handle == NULL) { + DEBUG(10, ("sys_dlopen for libgpfs.so failed: %s\n", + strerror(errno))); + return; + } + + DEBUG(10, ("libgpfs.so loaded\n")); + + gpfs_set_share_fn = sys_dlsym(libgpfs_handle, "gpfs_set_share"); + if (gpfs_set_share_fn == NULL) { + DEBUG(3, ("libgpfs.so does not contain the symbol " + "'gpfs_set_share'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_lease_fn = NULL; + return; + } + + gpfs_set_lease_fn = sys_dlsym(libgpfs_handle, "gpfs_set_lease"); + if (gpfs_set_lease_fn == NULL) { + DEBUG(3, ("libgpfs.so does not contain the symbol " + "'gpfs_set_lease'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_share_fn = NULL; + return; + } +} + +#else + +int set_gpfs_lease(int snum, int leasetype) +{ + DEBUG(0, ("'gpfs share = yes' set without gpfs support compiled\n")); + + /* We need to indicate that no GPFS is around by returning ENOSYS, so + * that the normal linux kernel oplock code is called. */ + errno = ENOSYS; + return -1; +} + +BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, + uint32 share_access) +{ + DEBUG(0, ("'gpfs share = yes' set without gpfs support compiled\n")); + /* Don't disturb but complain */ + return True; +} + +void init_gpfs(void) +{ + return; +} + +#endif diff --git a/source/smbd/open.c b/source/smbd/open.c index e6c749fab9c..2f82f04b639 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -1599,6 +1599,20 @@ files_struct *open_file_ntcreate(connection_struct *conn, * deny mode is compatible with all current opens. */ + if (lp_gpfs_share(SNUM(fsp->conn)) && + !set_gpfs_sharemode(fsp, access_mask, share_access)) { + + /* GPFS does have share mode support, so the comment above wrt + * NFS being wrong is not correct here. */ + + set_saved_error_triple(ERRDOS, ERRbadshare, + NT_STATUS_SHARING_VIOLATION); + talloc_free(lck); + fd_close(conn, fsp); + file_free(fsp); + return NULL; + } + /* * If requested, truncate the file. */ diff --git a/source/smbd/oplock_linux.c b/source/smbd/oplock_linux.c index ab0c08f7fcc..0285bfce97a 100644 --- a/source/smbd/oplock_linux.c +++ b/source/smbd/oplock_linux.c @@ -101,11 +101,11 @@ static void set_capability(unsigned capability) } /**************************************************************************** - Call SETLEASE. If we get EACCES then we try setting up the right capability and - try again + Call SETLEASE. If we get EACCES then we try setting up the right capability + and try again ****************************************************************************/ -static int linux_setlease(int fd, int leasetype) +static int linux_setlease(int snum, int fd, int leasetype) { int ret; @@ -114,7 +114,17 @@ static int linux_setlease(int fd, int leasetype) return -1; } - ret = fcntl(fd, F_SETLEASE, leasetype); + if (lp_gpfs_share(snum)) { + ret = set_gpfs_lease(fd, leasetype); + } else { + ret = fcntl(fd, F_SETLEASE, leasetype); + } + + if ((ret < 0) && (errno == ENOSYS)) { + /* This must have come from GPFS not being available */ + ret = fcntl(fd, F_SETLEASE, leasetype); + } + if (ret == -1 && errno == EACCES) { set_capability(CAP_LEASE); ret = fcntl(fd, F_SETLEASE, leasetype); @@ -154,7 +164,7 @@ static files_struct *linux_oplock_receive_message(fd_set *fds) static BOOL linux_set_kernel_oplock(files_struct *fsp, int oplock_type) { - if (linux_setlease(fsp->fh->fd, F_WRLCK) == -1) { + if (linux_setlease(SNUM(fsp->conn), fsp->fh->fd, F_WRLCK) == -1) { DEBUG(3,("linux_set_kernel_oplock: Refused oplock on file %s, fd = %d, dev = %x, \ inode = %.0f. (%s)\n", fsp->fsp_name, fsp->fh->fd, @@ -188,7 +198,7 @@ oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev, /* * Remove the kernel oplock on this file. */ - if (linux_setlease(fsp->fh->fd, F_UNLCK) == -1) { + if (linux_setlease(SNUM(fsp->conn), fsp->fh->fd, F_UNLCK) == -1) { if (DEBUGLVL(0)) { dbgtext("linux_release_kernel_oplock: Error when removing kernel oplock on file " ); dbgtext("%s, dev = %x, inode = %.0f, file_id = %lu. Error was %s\n", diff --git a/source/smbd/server.c b/source/smbd/server.c index ff894e2460c..56c9c721276 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -899,6 +899,8 @@ void build_options(BOOL screen); if (!print_backend_init()) exit(1); + init_gpfs(); + /* Setup the main smbd so that we can get messages. */ /* don't worry about general printing messages here */ -- cgit From 25afb826b30fbebcddbed669f0e6ac58565b298a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 6 Jan 2006 10:27:12 +0000 Subject: r12735: After talking to Tridge and Jeremy... This needs to be made more generic before it goes in. Volker --- source/Makefile.in | 2 +- source/configure.in | 13 ---- source/param/loadparm.c | 4 -- source/smbd/gpfs.c | 159 --------------------------------------------- source/smbd/open.c | 14 ---- source/smbd/oplock_linux.c | 22 ++----- source/smbd/server.c | 2 - 7 files changed, 7 insertions(+), 209 deletions(-) delete mode 100644 source/smbd/gpfs.c diff --git a/source/Makefile.in b/source/Makefile.in index 54dbecb764e..9d00cb72a1d 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -403,7 +403,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \ lib/sysquotas_xfs.o lib/sysquotas_4A.o \ smbd/change_trust_pw.o smbd/fake_file.o \ smbd/quotas.o smbd/ntquotas.o $(AFS_OBJ) smbd/msdfs.o \ - $(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/gpfs.o smbd/statvfs.o \ + $(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/statvfs.o \ $(MANGLE_OBJ) @VFS_STATIC@ SMBD_OBJ_BASE = $(PARAM_OBJ) $(SMBD_OBJ_SRV) $(LIBSMB_OBJ) \ diff --git a/source/configure.in b/source/configure.in index 2b1f4d691f9..ec1bdacad84 100644 --- a/source/configure.in +++ b/source/configure.in @@ -1159,19 +1159,6 @@ AC_CHECK_FUNCS(setbuffer shmget shm_open backtrace_symbols) AC_CHECK_HEADERS(libexc.h) AC_CHECK_LIB(exc, trace_back_stack) -echo -n "checking for GPFS 2.4 libs... " -save_LIBS="$LIBS" -LIBS="$LIBS -lgpfs" -AC_TRY_LINK([#include ], - [gpfs_set_share(0,GPFS_SHARE_READ,GPFS_DENY_NONE)], - samba_cv_HAVE_GPFS_SET_SHARE=yes, - samba_cv_HAVE_GPFS_SET_SHARE=no) -echo $samba_cv_HAVE_GPFS_SET_SHARE -if test x"$samba_cv_HAVE_GPFS_SET_SHARE" = x"yes"; then - AC_DEFINE(HAVE_GPFS_SET_SHARE,1,[Whether GPFS 2.4 libs are available]) -fi -LIBS="$save_LIBS" - # syscall() is needed for smbwrapper. AC_CHECK_FUNCS(syscall) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 3fa6dee5a24..526bce9b60e 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -433,7 +433,6 @@ typedef struct BOOL bProfileAcls; BOOL bMap_acl_inherit; BOOL bAfs_Share; - BOOL bGpfs_Share; BOOL bEASupport; BOOL bAclCheckPermissions; BOOL bAclMapFullControl; @@ -570,7 +569,6 @@ static service sDefault = { False, /* bProfileAcls */ False, /* bMap_acl_inherit */ False, /* bAfs_Share */ - False, /* bGpfs_Share */ False, /* bEASupport */ True, /* bAclCheckPermissions */ True, /* bAclMapFullControl */ @@ -969,7 +967,6 @@ static struct parm_struct parm_table[] = { {"announce as", P_ENUM, P_GLOBAL, &Globals.announce_as, NULL, enum_announce_as, FLAG_ADVANCED}, {"map acl inherit", P_BOOL, P_LOCAL, &sDefault.bMap_acl_inherit, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, {"afs share", P_BOOL, P_LOCAL, &sDefault.bAfs_Share, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, - {"gpfs share", P_BOOL, P_LOCAL, &sDefault.bGpfs_Share, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, {"max mux", P_INTEGER, P_GLOBAL, &Globals.max_mux, NULL, NULL, FLAG_ADVANCED}, {"max xmit", P_INTEGER, P_GLOBAL, &Globals.max_xmit, NULL, NULL, FLAG_ADVANCED}, @@ -2004,7 +2001,6 @@ FN_LOCAL_BOOL(_lp_use_sendfile, bUseSendfile) FN_LOCAL_BOOL(lp_profile_acls, bProfileAcls) FN_LOCAL_BOOL(lp_map_acl_inherit, bMap_acl_inherit) FN_LOCAL_BOOL(lp_afs_share, bAfs_Share) -FN_LOCAL_BOOL(lp_gpfs_share, bGpfs_Share) FN_LOCAL_BOOL(lp_acl_check_permissions, bAclCheckPermissions) FN_LOCAL_BOOL(lp_acl_group_control, bAclGroupControl) FN_LOCAL_BOOL(lp_acl_map_full_control, bAclMapFullControl) diff --git a/source/smbd/gpfs.c b/source/smbd/gpfs.c deleted file mode 100644 index 4a8b9eea6c5..00000000000 --- a/source/smbd/gpfs.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Provide a connection to GPFS specific features - * Copyright (C) Volker Lendecke 2005 - * - * 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. - */ - -#include "includes.h" - -#ifdef HAVE_GPFS_SET_SHARE - -#include "gpfs.h" - -static void *libgpfs_handle = NULL; - -static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny); -static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType); - -BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, - uint32 share_access) -{ - unsigned int allow = GPFS_SHARE_NONE; - unsigned int deny = GPFS_DENY_NONE; - int result; - - if (gpfs_set_share_fn == NULL) { - return False; - } - - if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) { - /* No real file, don't disturb */ - return True; - } - - allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA| - DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0; - allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ? - GPFS_SHARE_READ : 0; - deny |= (share_access & (FILE_SHARE_WRITE|FILE_SHARE_DELETE)) ? - 0 : GPFS_DENY_WRITE; - deny |= (share_access & (FILE_SHARE_READ)) ? - 0 : GPFS_DENY_READ; - - DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n", - access_mask, allow, share_access, deny)); - - result = gpfs_set_share_fn(fsp->fh->fd, allow, deny); - if (result != 0) { - if (errno == ENOSYS) { - DEBUG(5, ("'gpfs share = yes' set, but no gpfs " - "available. Allowing access\n")); - return True; - } else { - DEBUG(10, ("gpfs_set_share failed: %s\n", - strerror(errno))); - } - } - - return (result == 0); -} - -int set_gpfs_lease(int fd, int leasetype) -{ - int gpfs_type = GPFS_LEASE_NONE; - - if (gpfs_set_lease_fn == NULL) { - errno = EINVAL; - return -1; - } - - if (leasetype == F_RDLCK) { - gpfs_type = GPFS_LEASE_READ; - } - if (leasetype == F_WRLCK) { - gpfs_type = GPFS_LEASE_WRITE; - } - return gpfs_set_lease_fn(fd, gpfs_type); -} - -void init_gpfs(void) -{ - if (libgpfs_handle != NULL) { - return; - } - - libgpfs_handle = sys_dlopen("libgpfs.so", RTLD_LAZY); - - if (libgpfs_handle == NULL) { - DEBUG(10, ("sys_dlopen for libgpfs.so failed: %s\n", - strerror(errno))); - return; - } - - DEBUG(10, ("libgpfs.so loaded\n")); - - gpfs_set_share_fn = sys_dlsym(libgpfs_handle, "gpfs_set_share"); - if (gpfs_set_share_fn == NULL) { - DEBUG(3, ("libgpfs.so does not contain the symbol " - "'gpfs_set_share'\n")); - sys_dlclose(libgpfs_handle); - - /* leave libgpfs_handle != NULL around, no point - in trying twice */ - gpfs_set_lease_fn = NULL; - return; - } - - gpfs_set_lease_fn = sys_dlsym(libgpfs_handle, "gpfs_set_lease"); - if (gpfs_set_lease_fn == NULL) { - DEBUG(3, ("libgpfs.so does not contain the symbol " - "'gpfs_set_lease'\n")); - sys_dlclose(libgpfs_handle); - - /* leave libgpfs_handle != NULL around, no point - in trying twice */ - gpfs_set_share_fn = NULL; - return; - } -} - -#else - -int set_gpfs_lease(int snum, int leasetype) -{ - DEBUG(0, ("'gpfs share = yes' set without gpfs support compiled\n")); - - /* We need to indicate that no GPFS is around by returning ENOSYS, so - * that the normal linux kernel oplock code is called. */ - errno = ENOSYS; - return -1; -} - -BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, - uint32 share_access) -{ - DEBUG(0, ("'gpfs share = yes' set without gpfs support compiled\n")); - /* Don't disturb but complain */ - return True; -} - -void init_gpfs(void) -{ - return; -} - -#endif diff --git a/source/smbd/open.c b/source/smbd/open.c index 2f82f04b639..e6c749fab9c 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -1599,20 +1599,6 @@ files_struct *open_file_ntcreate(connection_struct *conn, * deny mode is compatible with all current opens. */ - if (lp_gpfs_share(SNUM(fsp->conn)) && - !set_gpfs_sharemode(fsp, access_mask, share_access)) { - - /* GPFS does have share mode support, so the comment above wrt - * NFS being wrong is not correct here. */ - - set_saved_error_triple(ERRDOS, ERRbadshare, - NT_STATUS_SHARING_VIOLATION); - talloc_free(lck); - fd_close(conn, fsp); - file_free(fsp); - return NULL; - } - /* * If requested, truncate the file. */ diff --git a/source/smbd/oplock_linux.c b/source/smbd/oplock_linux.c index 0285bfce97a..ab0c08f7fcc 100644 --- a/source/smbd/oplock_linux.c +++ b/source/smbd/oplock_linux.c @@ -101,11 +101,11 @@ static void set_capability(unsigned capability) } /**************************************************************************** - Call SETLEASE. If we get EACCES then we try setting up the right capability - and try again + Call SETLEASE. If we get EACCES then we try setting up the right capability and + try again ****************************************************************************/ -static int linux_setlease(int snum, int fd, int leasetype) +static int linux_setlease(int fd, int leasetype) { int ret; @@ -114,17 +114,7 @@ static int linux_setlease(int snum, int fd, int leasetype) return -1; } - if (lp_gpfs_share(snum)) { - ret = set_gpfs_lease(fd, leasetype); - } else { - ret = fcntl(fd, F_SETLEASE, leasetype); - } - - if ((ret < 0) && (errno == ENOSYS)) { - /* This must have come from GPFS not being available */ - ret = fcntl(fd, F_SETLEASE, leasetype); - } - + ret = fcntl(fd, F_SETLEASE, leasetype); if (ret == -1 && errno == EACCES) { set_capability(CAP_LEASE); ret = fcntl(fd, F_SETLEASE, leasetype); @@ -164,7 +154,7 @@ static files_struct *linux_oplock_receive_message(fd_set *fds) static BOOL linux_set_kernel_oplock(files_struct *fsp, int oplock_type) { - if (linux_setlease(SNUM(fsp->conn), fsp->fh->fd, F_WRLCK) == -1) { + if (linux_setlease(fsp->fh->fd, F_WRLCK) == -1) { DEBUG(3,("linux_set_kernel_oplock: Refused oplock on file %s, fd = %d, dev = %x, \ inode = %.0f. (%s)\n", fsp->fsp_name, fsp->fh->fd, @@ -198,7 +188,7 @@ oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev, /* * Remove the kernel oplock on this file. */ - if (linux_setlease(SNUM(fsp->conn), fsp->fh->fd, F_UNLCK) == -1) { + if (linux_setlease(fsp->fh->fd, F_UNLCK) == -1) { if (DEBUGLVL(0)) { dbgtext("linux_release_kernel_oplock: Error when removing kernel oplock on file " ); dbgtext("%s, dev = %x, inode = %.0f, file_id = %lu. Error was %s\n", diff --git a/source/smbd/server.c b/source/smbd/server.c index 56c9c721276..ff894e2460c 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -899,8 +899,6 @@ void build_options(BOOL screen); if (!print_backend_init()) exit(1); - init_gpfs(); - /* Setup the main smbd so that we can get messages. */ /* don't worry about general printing messages here */ -- cgit From 4ee0b368a90d4cf71f9ae61da353e665c859653a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 6 Jan 2006 14:55:26 +0000 Subject: r12742: Don't write null sid mappings into the winbindd_cache.tdb. Guenther --- source/nsswitch/winbindd_cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 81dd85e588b..eea0d16ca83 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -989,7 +989,9 @@ do_query: status = domain->backend->name_to_sid(domain, mem_ctx, domain_name, name, sid, type); /* and save it */ - wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type); + if (NT_STATUS_IS_OK(status)) { + wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type); + } /* We can't save the sid to name mapping as we don't know the correct case of the name without looking it up */ -- cgit From fcb173fdc537604a91c2e8d9950dc3960cbdc010 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:28 +0000 Subject: r12757: r12126@cabra: derrell | 2006-01-03 15:21:36 -0500 added flag to not request authentication information --- examples/libsmbclient/testbrowse.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index b5337ae983a..ca126c9510f 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -30,6 +30,7 @@ main(int argc, char * argv[]) { int debug = 0; int debug_stderr = 0; + int no_auth = 0; int scan = 0; int iterations = -1; int again; @@ -58,6 +59,10 @@ main(int argc, char * argv[]) "iterations", 'i', POPT_ARG_INT, &iterations, 0, "Iterations", "integer" }, + { + "noauth", 'A', POPT_ARG_NONE, &no_auth, + 0, "Do not request authentication data", "integer" + }, { NULL } @@ -82,9 +87,14 @@ main(int argc, char * argv[]) return 1; } + /* If we're scanning, do no requests for authentication data */ + if (scan) { + no_auth = 1; + } + /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; - context->callbacks.auth_fn = (scan ? no_auth_data_fn : get_auth_data_fn); + context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { @@ -102,7 +112,6 @@ main(int argc, char * argv[]) /* Tell the compatibility layer to use this context */ smbc_set_context(context); - if (scan) { for (; -- cgit From 19170cafbc4235781d6a3212d559447ad6d9c64a Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:31 +0000 Subject: r12758: r12127@cabra: derrell | 2006-01-03 15:22:18 -0500 remove old superfluous comment and ifdef --- source/libsmb/clilist.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/source/libsmb/clilist.c b/source/libsmb/clilist.c index 252dafcfa8b..48780e28dfa 100644 --- a/source/libsmb/clilist.c +++ b/source/libsmb/clilist.c @@ -169,11 +169,7 @@ static size_t interpret_long_filename(struct cli_state *cli, int level,char *p,f int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, void (*fn)(const char *, file_info *, const char *, void *), void *state) { -#if 1 - int max_matches = 1366; /* Match W2k - was 512. */ -#else - int max_matches = 512; -#endif + int max_matches = 1366; int info_level; char *p, *p2; pstring mask; -- cgit From 6e300b2096dfaa1a4ecaf0d62ff641aaa95d39cd Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:36 +0000 Subject: r12759: r12128@cabra: derrell | 2006-01-07 15:34:01 -0500 Incorporate a number of changes suggested by David Collier-Brown Thanks, David! --- examples/libsmbclient/smbwrapper/Makefile | 7 +- examples/libsmbclient/smbwrapper/bsd-strlcat.c | 71 ++++ examples/libsmbclient/smbwrapper/bsd-strlcpy.c | 67 +++ examples/libsmbclient/smbwrapper/bsd-strlfunc.h | 7 + examples/libsmbclient/smbwrapper/smbsh.c | 25 +- examples/libsmbclient/smbwrapper/smbw.c | 37 +- examples/libsmbclient/smbwrapper/smbw.h | 4 + examples/libsmbclient/smbwrapper/smbw_dir.c | 29 +- examples/libsmbclient/smbwrapper/wrapper.c | 515 ++++++++++++------------ examples/libsmbclient/smbwrapper/wrapper.h | 4 + 10 files changed, 479 insertions(+), 287 deletions(-) create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlcat.c create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlcpy.c create mode 100644 examples/libsmbclient/smbwrapper/bsd-strlfunc.h diff --git a/examples/libsmbclient/smbwrapper/Makefile b/examples/libsmbclient/smbwrapper/Makefile index 8e7070cb597..c94ef8fa6af 100644 --- a/examples/libsmbclient/smbwrapper/Makefile +++ b/examples/libsmbclient/smbwrapper/Makefile @@ -10,8 +10,11 @@ CFLAGS= -fpic -g -O0 $(DEFS) $(SMBINCLUDE) BIN = . -SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o -SMBSH_OBJS = smbsh.o +STRFUNC = bsd-strlcat.o bsd-strlcpy.o + + +SMBWRAPPER_OBJS = smbw.o smbw_dir.o smbw_stat.o wrapper.o select.o $(STRFUNC) +SMBSH_OBJS = smbsh.o $(STRFUNC) all: $(BIN)/smbwrapper.so $(BIN)/smbsh diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcat.c b/examples/libsmbclient/smbwrapper/bsd-strlcat.c new file mode 100644 index 00000000000..d82ced3e8a3 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcat.c @@ -0,0 +1,71 @@ +/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +smbw_strlcat(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlcpy.c b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c new file mode 100644 index 00000000000..9f7e55da8e0 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlcpy.c @@ -0,0 +1,67 @@ +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This version has been modified for inclusion in Samba. + * It has been converted to ANSI C from old-style K&R C. + */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +smbw_strlcpy(char *dst, const char *src, size_t siz) +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/examples/libsmbclient/smbwrapper/bsd-strlfunc.h b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h new file mode 100644 index 00000000000..fb3a045ac6c --- /dev/null +++ b/examples/libsmbclient/smbwrapper/bsd-strlfunc.h @@ -0,0 +1,7 @@ +#ifndef __BSD_STRLFUNC_H__ + +extern size_t strlcpy(char *dst, const char *src, size_t siz); +extern size_t strlcat(char *dst, const char *src, size_t siz); + +#define __BSD_STRLFUNC_H__ +#endif diff --git a/examples/libsmbclient/smbwrapper/smbsh.c b/examples/libsmbclient/smbwrapper/smbsh.c index 7b33de766fd..23b1ac26c79 100644 --- a/examples/libsmbclient/smbwrapper/smbsh.c +++ b/examples/libsmbclient/smbwrapper/smbsh.c @@ -28,6 +28,7 @@ #include #include #include +#include "bsd-strlfunc.h" #ifndef FALSE # define FALSE (0) @@ -67,13 +68,13 @@ int main(int argc, char *argv[]) switch (opt) { case 'p': /* prepend library before smbwrapper.so */ if (*pre != '\0') - strncat(pre, " ", PATH_MAX - strlen(pre)); - strncat(pre, optarg, PATH_MAX - strlen(pre)); + smbw_strlcat(pre, " ", sizeof(pre)); + smbw_strlcat(pre, optarg, sizeof(pre)); break; case 'a': /* append library after smbwrapper.so */ - strncat(post, " ", PATH_MAX - strlen(post)); - strncat(post, optarg, PATH_MAX - strlen(post)); + smbw_strlcat(post, " ", sizeof(post)); + smbw_strlcat(post, optarg, sizeof(post)); break; case 'd': @@ -121,20 +122,22 @@ int main(int argc, char *argv[]) } } - strncpy(line, pre, PATH_MAX - strlen(line)); - strncat(line, " ", PATH_MAX - strlen(line)); - strncat(line, libd, PATH_MAX - strlen(line)); - strncat(line, "/smbwrapper.so", PATH_MAX - strlen(line)); - strncat(line, post, PATH_MAX - strlen(line)); + smbw_strlcpy(line, pre, PATH_MAX - strlen(line)); + smbw_strlcat(line, " ", sizeof(line)); + smbw_strlcat(line, libd, sizeof(line)); + smbw_strlcat(line, "/smbwrapper.so", sizeof(line)); + smbw_strlcat(line, post, sizeof(line)); setenv("LD_PRELOAD", line, TRUE); setenv("LD_BIND_NOW", "true", TRUE); snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); if (stat(line, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) { - snprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.32.so:DEFAULT", libd); setenv("_RLD_LIST", line, TRUE); - snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); + snprintf(line, sizeof(line)-1, + "%s/smbwrapper.so:DEFAULT", libd); setenv("_RLDN32_LIST", line, TRUE); } else { snprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); diff --git a/examples/libsmbclient/smbwrapper/smbw.c b/examples/libsmbclient/smbwrapper/smbw.c index d2f1c18695d..a44f2f4046a 100644 --- a/examples/libsmbclient/smbwrapper/smbw.c +++ b/examples/libsmbclient/smbwrapper/smbw.c @@ -26,6 +26,13 @@ #include #include #include "smbw.h" +#include "bsd-strlfunc.h" + +typedef enum StartupType +{ + StartupType_Fake, + StartupType_Real +} StartupType; int smbw_fd_map[__FD_SETSIZE]; int smbw_ref_count[__FD_SETSIZE]; @@ -44,6 +51,9 @@ static SMBCCTX *smbw_ctx; extern int smbw_debug; +/***************************************************** +smbw_ref -- manipulate reference counts +******************************************************/ int smbw_ref(int client_fd, Ref_Count_Type type, ...) { va_list ap; @@ -100,9 +110,9 @@ static void get_envvar_auth_data(const char *srv, p = getenv("PASSWORD"); if (p == NULL) p = ""; - strncpy(wg, w, wglen); - strncpy(un, u, unlen); - strncpy(pw, p, pwlen); + smbw_strlcpy(wg, w, wglen); + smbw_strlcpy(un, u, unlen); + smbw_strlcpy(pw, p, pwlen); } static smbc_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data; @@ -130,7 +140,7 @@ static void do_shutdown(void) /***************************************************** initialise structures *******************************************************/ -static void do_init(int is_real_startup) +static void do_init(StartupType startupType) { int i; char *p; @@ -147,7 +157,7 @@ static void do_init(int is_real_startup) /* See if we've been told to start in a particular directory */ if ((p=getenv("SMBW_DIR")) != NULL) { - strncpy(smbw_cwd, p, PATH_MAX); + smbw_strlcpy(smbw_cwd, p, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -161,6 +171,7 @@ static void do_init(int is_real_startup) } if ((smbw_ctx = smbc_new_context()) == NULL) { + fprintf(stderr, "Could not create a context.\n"); exit(1); } @@ -169,16 +180,16 @@ static void do_init(int is_real_startup) smbw_ctx->options.browse_max_lmb_count = 0; smbw_ctx->options.urlencode_readdir_entries = 1; smbw_ctx->options.one_share_per_server = 1; -// smbw_cache_functions(smbw_ctx); if (smbc_init_context(smbw_ctx) == NULL) { + fprintf(stderr, "Could not initialize context.\n"); exit(1); } smbc_set_context(smbw_ctx); /* if not real startup, exit handler has already been established */ - if (is_real_startup) { + if (startupType == StartupType_Real) { atexit(do_shutdown); } } @@ -188,7 +199,7 @@ initialise structures, real start up vs a fork() *******************************************************/ void smbw_init(void) { - do_init(1); + do_init(StartupType_Real); } @@ -407,6 +418,10 @@ ssize_t smbw_pread(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) int saved_errno; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -460,6 +475,10 @@ ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs) ssize_t ret; SMBW_OFF_T old_ofs; + if (count == 0) { + return 0; + } + client_fd = smbw_fd_map[smbw_fd]; if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 || @@ -731,7 +750,7 @@ int smbw_fork(void) } /* Re-initialize this library for the child */ - do_init(0); + do_init(StartupType_Fake); /* and continue in the child */ return 0; diff --git a/examples/libsmbclient/smbwrapper/smbw.h b/examples/libsmbclient/smbwrapper/smbw.h index 717b5c2f1c7..161d57ebbb1 100644 --- a/examples/libsmbclient/smbwrapper/smbw.h +++ b/examples/libsmbclient/smbwrapper/smbw.h @@ -34,6 +34,10 @@ #include "libsmbclient.h" #include "wrapper.h" +#ifndef __restrict +# define __restrict +#endif + #undef DEBUG #define DEBUG(level, s) do { if (level <= debug_level) printf s; } while (0) diff --git a/examples/libsmbclient/smbwrapper/smbw_dir.c b/examples/libsmbclient/smbwrapper/smbw_dir.c index f3ec03e5a85..986b7f82204 100644 --- a/examples/libsmbclient/smbwrapper/smbw_dir.c +++ b/examples/libsmbclient/smbwrapper/smbw_dir.c @@ -21,6 +21,7 @@ */ #include "smbw.h" +#include "bsd-strlfunc.h" /***************************************************** determine if a directory handle is a smb one @@ -70,12 +71,12 @@ int smbw_getdents(unsigned int fd_smbw, dirent_external->d_reclen = sizeof(struct SMBW_dirent); dirent_external->d_type = dirent_internal->smbc_type; - strncpy(dirent_external->d_name, - dirent_internal->name, - sizeof(dirent_external->d_name) - 1); - strncpy(dirent_external->d_comment, - dirent_internal->comment, - sizeof(dirent_external->d_comment) - 1); + smbw_strlcpy(dirent_external->d_name, + dirent_internal->name, + sizeof(dirent_external->d_name) - 1); + smbw_strlcpy(dirent_external->d_comment, + dirent_internal->comment, + sizeof(dirent_external->d_comment) - 1); } return(count - remaining); @@ -128,7 +129,7 @@ int smbw_chdir(const char *name) } } - strncpy(smbw_cwd, path, PATH_MAX); + smbw_strlcpy(smbw_cwd, path, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); @@ -196,7 +197,7 @@ char *smbw_getcwd(char *buf, size_t size) } } - strncpy(buf, smbw_cwd, size); + smbw_strlcpy(buf, smbw_cwd, size); buf[size-1] = '\0'; return buf; } @@ -278,12 +279,12 @@ struct SMBW_dirent *smbw_readdir(DIR *dirp) dirent_external.d_off = smbc_telldir(fd_client); dirent_external.d_reclen = sizeof(struct SMBW_dirent); dirent_external.d_type = dirent_internal->smbc_type; - strncpy(dirent_external.d_name, - dirent_internal->name, - sizeof(dirent_external.d_name) - 1); - strncpy(dirent_external.d_comment, - dirent_internal->comment, - sizeof(dirent_external.d_comment) - 1); + smbw_strlcpy(dirent_external.d_name, + dirent_internal->name, + sizeof(dirent_external.d_name) - 1); + smbw_strlcpy(dirent_external.d_comment, + dirent_internal->comment, + sizeof(dirent_external.d_comment) - 1); return &dirent_external; } diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 71d6f203ada..12904c30737 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -65,6 +65,7 @@ #include #include #include "libsmbclient.h" +#include "bsd-strlfunc.h" #include "wrapper.h" /* @@ -106,12 +107,12 @@ static int debugFd = 2; if (! initialized) initialize(); \ (* smbw_libc.write)(debugFd, "["buf"]", sizeof(buf)+1); \ errno = saved_errno; \ - } while (0); + } while (0) #else # define check_init(buf) \ do { \ if (! initialized) smbw_initialize(); \ - } while (0); + } while (0) #endif static void initialize(void); @@ -135,17 +136,20 @@ static void initialize(void) #if SMBW_DEBUG & 0x1 char *error; #endif - + saved_errno = errno; if (initialized) { - errno = saved_errno; return; } initialized = 1; if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { +#ifdef RTLD_NEXT + lib = RTLD_NEXT; +#else exit(1); +#endif } #if SMBW_DEBUG & 0x1 @@ -171,117 +175,122 @@ static void initialize(void) * C library doesn't support them, then the wrapper function will * never be called, and the null pointer will never be dereferenced. */ - do { - GETSYM(write, "write"); /* first, to allow debugging */ - GETSYM(open, "open"); - GETSYM(_open, "_open"); - GETSYM(__open, "__open"); - GETSYM(open64, "open64"); - GETSYM(_open64, "_open64"); - GETSYM(__open64, "__open64"); - GETSYM(pread, "pread"); - GETSYM(pread64, "pread64"); - GETSYM(pwrite, "pwrite"); - GETSYM(pwrite64, "pwrite64"); - GETSYM(close, "close"); - GETSYM(__close, "__close"); - GETSYM(_close, "_close"); - GETSYM(fcntl, "fcntl"); - GETSYM(__fcntl, "__fcntl"); - GETSYM(_fcntl, "_fcntl"); - GETSYM(getdents, "getdents"); - GETSYM(__getdents, "__getdents"); - GETSYM(_getdents, "_getdents"); - GETSYM(getdents64, "getdents64"); - GETSYM(lseek, "lseek"); - GETSYM(__lseek, "__lseek"); - GETSYM(_lseek, "_lseek"); - GETSYM(lseek64, "lseek64"); - GETSYM(__lseek64, "__lseek64"); - GETSYM(_lseek64, "_lseek64"); - GETSYM(read, "read"); - GETSYM(__read, "__read"); - GETSYM(_read, "_read"); - GETSYM(__write, "__write"); - GETSYM(_write, "_write"); - GETSYM(access, "access"); - GETSYM(chmod, "chmod"); - GETSYM(fchmod, "fchmod"); - GETSYM(chown, "chown"); - GETSYM(fchown, "fchown"); - GETSYM(__xstat, "__xstat"); - GETSYM(getcwd, "getcwd"); - GETSYM(mkdir, "mkdir"); - GETSYM(__fxstat, "__fxstat"); - GETSYM(__lxstat, "__lxstat"); - GETSYM(stat, "stat"); - GETSYM(lstat, "lstat"); - GETSYM(fstat, "fstat"); - GETSYM(unlink, "unlink"); - GETSYM(utime, "utime"); - GETSYM(utimes, "utimes"); - GETSYM(readlink, "readlink"); - GETSYM(rename, "rename"); - GETSYM(rmdir, "rmdir"); - GETSYM(symlink, "symlink"); - GETSYM(dup, "dup"); - GETSYM(dup2, "dup2"); - GETSYM(opendir, "opendir"); - GETSYM(readdir, "readdir"); - GETSYM(closedir, "closedir"); - GETSYM(telldir, "telldir"); - GETSYM(seekdir, "seekdir"); - GETSYM(creat, "creat"); - GETSYM(creat64, "creat64"); - GETSYM(__xstat64, "__xstat64"); - GETSYM(stat64, "stat64"); - GETSYM(__fxstat64, "__fxstat64"); - GETSYM(fstat64, "fstat64"); - GETSYM(__lxstat64, "__lxstat64"); - GETSYM(lstat64, "lstat64"); - GETSYM(_llseek, "_llseek"); - GETSYM(readdir64, "readdir64"); - GETSYM(readdir_r, "readdir_r"); - GETSYM(readdir64_r, "readdir64_r"); - GETSYM(setxattr, "setxattr"); - GETSYM(lsetxattr, "lsetxattr"); - GETSYM(fsetxattr, "fsetxattr"); - GETSYM(getxattr, "getxattr"); - GETSYM(lgetxattr, "lgetxattr"); - GETSYM(fgetxattr, "fgetxattr"); - GETSYM(removexattr, "removexattr"); - GETSYM(lremovexattr, "lremovexattr"); - GETSYM(fremovexattr, "fremovexattr"); - GETSYM(listxattr, "listxattr"); - GETSYM(llistxattr, "llistxattr"); - GETSYM(flistxattr, "flistxattr"); - GETSYM(chdir, "chdir"); - GETSYM(fchdir, "fchdir"); - GETSYM(fork, "fork"); - GETSYM(select, "select"); - GETSYM(_select, "_select"); - GETSYM(__select, "__select"); - } while (0); + GETSYM(write, "write"); /* first, to allow debugging */ + GETSYM(open, "open"); + GETSYM(_open, "_open"); + GETSYM(__open, "__open"); + GETSYM(open64, "open64"); + GETSYM(_open64, "_open64"); + GETSYM(__open64, "__open64"); + GETSYM(pread, "pread"); + GETSYM(pread64, "pread64"); + GETSYM(pwrite, "pwrite"); + GETSYM(pwrite64, "pwrite64"); + GETSYM(close, "close"); + GETSYM(__close, "__close"); + GETSYM(_close, "_close"); + GETSYM(fcntl, "fcntl"); + GETSYM(__fcntl, "__fcntl"); + GETSYM(_fcntl, "_fcntl"); + GETSYM(getdents, "getdents"); + GETSYM(__getdents, "__getdents"); + GETSYM(_getdents, "_getdents"); + GETSYM(getdents64, "getdents64"); + GETSYM(lseek, "lseek"); + GETSYM(__lseek, "__lseek"); + GETSYM(_lseek, "_lseek"); + GETSYM(lseek64, "lseek64"); + GETSYM(__lseek64, "__lseek64"); + GETSYM(_lseek64, "_lseek64"); + GETSYM(read, "read"); + GETSYM(__read, "__read"); + GETSYM(_read, "_read"); + GETSYM(__write, "__write"); + GETSYM(_write, "_write"); + GETSYM(access, "access"); + GETSYM(chmod, "chmod"); + GETSYM(fchmod, "fchmod"); + GETSYM(chown, "chown"); + GETSYM(fchown, "fchown"); + GETSYM(__xstat, "__xstat"); + GETSYM(getcwd, "getcwd"); + GETSYM(mkdir, "mkdir"); + GETSYM(__fxstat, "__fxstat"); + GETSYM(__lxstat, "__lxstat"); + GETSYM(stat, "stat"); + GETSYM(lstat, "lstat"); + GETSYM(fstat, "fstat"); + GETSYM(unlink, "unlink"); + GETSYM(utime, "utime"); + GETSYM(utimes, "utimes"); + GETSYM(readlink, "readlink"); + GETSYM(rename, "rename"); + GETSYM(rmdir, "rmdir"); + GETSYM(symlink, "symlink"); + GETSYM(dup, "dup"); + GETSYM(dup2, "dup2"); + GETSYM(opendir, "opendir"); + GETSYM(readdir, "readdir"); + GETSYM(closedir, "closedir"); + GETSYM(telldir, "telldir"); + GETSYM(seekdir, "seekdir"); + GETSYM(creat, "creat"); + GETSYM(creat64, "creat64"); + GETSYM(__xstat64, "__xstat64"); + GETSYM(stat64, "stat64"); + GETSYM(__fxstat64, "__fxstat64"); + GETSYM(fstat64, "fstat64"); + GETSYM(__lxstat64, "__lxstat64"); + GETSYM(lstat64, "lstat64"); + GETSYM(_llseek, "_llseek"); + GETSYM(readdir64, "readdir64"); + GETSYM(readdir_r, "readdir_r"); + GETSYM(readdir64_r, "readdir64_r"); + GETSYM(setxattr, "setxattr"); + GETSYM(lsetxattr, "lsetxattr"); + GETSYM(fsetxattr, "fsetxattr"); + GETSYM(getxattr, "getxattr"); + GETSYM(lgetxattr, "lgetxattr"); + GETSYM(fgetxattr, "fgetxattr"); + GETSYM(removexattr, "removexattr"); + GETSYM(lremovexattr, "lremovexattr"); + GETSYM(fremovexattr, "fremovexattr"); + GETSYM(listxattr, "listxattr"); + GETSYM(llistxattr, "llistxattr"); + GETSYM(flistxattr, "flistxattr"); + GETSYM(chdir, "chdir"); + GETSYM(fchdir, "fchdir"); + GETSYM(fork, "fork"); + GETSYM(select, "select"); + GETSYM(_select, "_select"); + GETSYM(__select, "__select"); +#ifdef RTLD_NEXT + if (lib != RTLD_NEXT) { + dlclose(lib); + } +#else dlclose(lib); - +#endif + + /* Ensure that the C library is immediately available */ if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { exit(1); } #if SMBW_DEBUG & 4 { - if ((debugFd = - open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) - { + if ((debugFd = + open(SMBW_DEBUG_FILE, O_WRONLY | O_CREAT | O_APPEND)) < 0) + { # define SMBW_MESSAGE "Could not create " SMBW_DEBUG_FILE "\n" - (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); + (* smbw_libc.write)(1, SMBW_MESSAGE, sizeof(SMBW_MESSAGE)); # undef SMBW_MESSAGE - exit(1); - } + exit(1); + } } #endif - + errno = saved_errno; } @@ -328,11 +337,11 @@ static void stat64_convert(struct SMBW_stat *src, struct stat64 *dest) static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -362,21 +371,23 @@ static void dirent_convert(struct SMBW_dirent *src, struct dirent *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) { char *p; - + memset(dest, '\0', sizeof(*dest)); dest->d_ino = src->d_ino; dest->d_off = src->d_off; - + switch(src->d_type) { case SMBC_WORKGROUP: @@ -406,11 +417,13 @@ static void dirent64_convert(struct SMBW_dirent *src, struct dirent64 *dest) dest->d_type = DT_LNK; break; } - + dest->d_reclen = src->d_reclen; - strncpy(dest->d_name, src->d_name, sizeof(dest->d_name)); + smbw_strlcpy(dest->d_name, src->d_name, sizeof(dest->d_name)); p = dest->d_name + strlen(dest->d_name) + 1; - strncpy(p, src->d_comment, sizeof(dest->d_name) - (p - dest->d_name)); + smbw_strlcpy(p, + src->d_comment, + sizeof(dest->d_name) - (p - dest->d_name)); } static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode_t)) @@ -418,7 +431,7 @@ static int openx(char *name, int flags, mode_t mode, int (* f)(char *, int, mode if (smbw_path(name)) { return smbw_open(name, flags, mode); } - + return (* f)(name, flags, mode); } @@ -427,7 +440,7 @@ static int closex(int fd, int (* f)(int fd)) if (smbw_fd(fd)) { return smbw_close(fd); } - + return (* f)(fd); } @@ -436,7 +449,7 @@ static int fcntlx(int fd, int cmd, long arg, int (* f)(int, int, long)) if (smbw_fd(fd)) { return smbw_fcntl(fd, cmd, arg); } - + return (* f)(fd, cmd, arg); } @@ -448,14 +461,14 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent)); - + internal_count = sizeof(struct SMBW_dirent) * n; internal = malloc(internal_count); if (internal == NULL) { @@ -465,15 +478,15 @@ static int getdentsx(int fd, struct dirent *external, unsigned int count, int (* ret = smbw_getdents(fd, internal, internal_count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * n; for (i = 0; i < n; i++) dirent_convert(&internal[i], &external[i]); - + return ret; } - + return (* f)(fd, external, count); } @@ -483,7 +496,7 @@ static off_t lseekx(int fd, off_t (* f)(int, off_t, int)) { off_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -491,11 +504,11 @@ static off_t lseekx(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) { return (off_t) smbw_lseek(fd, offset, whence); } - + ret = (* f)(fd, offset, whence); if (smbw_debug) { @@ -513,7 +526,7 @@ static off64_t lseek64x(int fd, off64_t (* f)(int, off64_t, int)) { off64_t ret; - + /* * We have left the definitions of the smbw_ functions undefined, * because types such as off_t can differ in meaning betweent his @@ -521,7 +534,7 @@ static off64_t lseek64x(int fd, * integer value, however, MUST have their return value defined. */ off64_t smbw_lseek(); - + if (smbw_fd(fd)) ret = smbw_lseek(fd, offset, whence); else @@ -541,7 +554,7 @@ static ssize_t readx(int fd, void *buf, size_t count, ssize_t (* f)(int, void *, if (smbw_fd(fd)) { return smbw_read(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -550,7 +563,7 @@ static ssize_t writex(int fd, void *buf, size_t count, ssize_t (* f)(int, void * if (smbw_fd(fd)) { return smbw_write(fd, buf, count); } - + return (* f)(fd, buf, count); } @@ -563,27 +576,27 @@ int open(__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open"); - + return openx((char *) name, flags, mode, smbw_libc.open); } int _open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc._open); } int __open(char *name, int flags, mode_t mode) { check_init("open"); - + return openx(name, flags, mode, smbw_libc.__open); } @@ -591,11 +604,11 @@ int open64 (__const char *name, int flags, ...) { va_list ap; mode_t mode; - + va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); - + check_init("open64"); return openx((char *) name, flags, mode, smbw_libc.open64); } @@ -615,44 +628,44 @@ int __open64(char *name, int flags, mode_t mode) ssize_t pread(int fd, void *buf, size_t size, off_t ofs) { check_init("pread"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, ofs); } - + return (* smbw_libc.pread)(fd, buf, size, ofs); } ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs) { check_init("pread64"); - + if (smbw_fd(fd)) { return smbw_pread(fd, buf, size, (off_t) ofs); } - + return (* smbw_libc.pread64)(fd, buf, size, ofs); } ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) { check_init("pwrite"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, ofs); } - + return (* smbw_libc.pwrite)(fd, (void *) buf, size, ofs); } ssize_t pwrite64(int fd, const void *buf, size_t size, off64_t ofs) { check_init("pwrite64"); - + if (smbw_fd(fd)) { return smbw_pwrite(fd, (void *) buf, size, (off_t) ofs); } - + return (* smbw_libc.pwrite64)(fd, (void *) buf, size, ofs); } @@ -714,11 +727,11 @@ int fcntl (int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.fcntl); } @@ -727,11 +740,11 @@ int __fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("__fcntl"); return fcntlx(fd, cmd, arg, smbw_libc.__fcntl); } @@ -740,11 +753,11 @@ int _fcntl(int fd, int cmd, ...) { va_list ap; long arg; - + va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); - + check_init("_fcntl"); return fcntlx(fd, cmd, arg, smbw_libc._fcntl); } @@ -775,14 +788,14 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) struct SMBW_dirent *internal; int ret; int n; - + /* * LIMITATION: If they pass a count which is not a multiple of * the size of struct dirent, they will not get a partial * structure; we ignore the excess count. */ n = (count / sizeof(struct dirent64)); - + internal = malloc(sizeof(struct SMBW_dirent) * n); if (internal == NULL) { errno = ENOMEM; @@ -791,15 +804,15 @@ int getdents64(int fd, struct dirent64 *external, unsigned int count) ret = smbw_getdents(fd, internal, count); if (ret <= 0) return ret; - + ret = sizeof(struct dirent) * count; for (i = 0; count; i++, count--) dirent64_convert(&internal[i], &external[i]); - + return ret; } - + return (* smbw_libc.getdents64)(fd, external, count); } @@ -923,57 +936,57 @@ ssize_t _write(int fd, const void *buf, size_t count) int access(const char *name, int mode) { check_init("access"); - + if (smbw_path((char *) name)) { return smbw_access((char *) name, mode); } - + return (* smbw_libc.access)((char *) name, mode); } int chmod(const char *name, mode_t mode) { check_init("chmod"); - + if (smbw_path((char *) name)) { return smbw_chmod((char *) name, mode); } - + return (* smbw_libc.chmod)((char *) name, mode); } int fchmod(int fd, mode_t mode) { check_init("fchmod"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchmod)(fd, mode); } int chown(const char *name, uid_t owner, gid_t group) { check_init("chown"); - + if (smbw_path((char *) name)) { return smbw_chown((char *) name, owner, group); } - + return (* smbw_libc.chown)((char *) name, owner, group); } int fchown(int fd, uid_t owner, gid_t group) { check_init("fchown"); - + if (smbw_fd(fd)) { /* Not yet implemented in libsmbclient */ return ENOTSUP; } - + return (* smbw_libc.fchown)(fd, owner, group); } @@ -986,148 +999,148 @@ char *getcwd(char *buf, size_t size) int mkdir(const char *name, mode_t mode) { check_init("mkdir"); - + if (smbw_path((char *) name)) { return smbw_mkdir((char *) name, mode); } - + return (* smbw_libc.mkdir)((char *) name, mode); } int __fxstat(int vers, int fd, struct stat *st) { check_init("__fxstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__fxstat)(vers, fd, st); } int __xstat(int vers, const char *name, struct stat *st) { check_init("__xstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__xstat)(vers, (char *) name, st); } int __lxstat(int vers, const char *name, struct stat *st) { check_init("__lxstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.__lxstat)(vers, (char *) name, st); } int stat(const char *name, struct stat *st) { check_init("stat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.stat)((char *) name, st); } int lstat(const char *name, struct stat *st) { check_init("lstat"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.lstat)((char *) name, st); } int fstat(int fd, struct stat *st) { check_init("fstat"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat_convert(&statbuf, st); return ret; } - + return (* smbw_libc.fstat)(fd, st); } int unlink(const char *name) { check_init("unlink"); - + if (smbw_path((char *) name)) { return smbw_unlink((char *) name); } - + return (* smbw_libc.unlink)((char *) name); } int utime(const char *name, const struct utimbuf *tvp) { check_init("utime"); - + if (smbw_path(name)) { return smbw_utime(name, (struct utimbuf *) tvp); } - + return (* smbw_libc.utime)((char *) name, (struct utimbuf *) tvp); } int utimes(const char *name, const struct timeval *tvp) { check_init("utimes"); - + if (smbw_path(name)) { return smbw_utimes(name, (struct timeval *) tvp); } - + return (* smbw_libc.utimes)((char *) name, (struct timeval *) tvp); } int readlink(const char *path, char *buf, size_t bufsize) { check_init("readlink"); - + if (smbw_path((char *) path)) { return smbw_readlink(path, (char *) buf, bufsize); } - + return (* smbw_libc.readlink)((char *) path, buf, bufsize); } int rename(const char *oldname, const char *newname) { int p1, p2; - + check_init("rename"); - + p1 = smbw_path((char *) oldname); p2 = smbw_path((char *) newname); if (p1 ^ p2) { @@ -1138,27 +1151,27 @@ int rename(const char *oldname, const char *newname) if (p1 && p2) { return smbw_rename((char *) oldname, (char *) newname); } - + return (* smbw_libc.rename)((char *) oldname, (char *) newname); } int rmdir(const char *name) { check_init("rmdir"); - + if (smbw_path((char *) name)) { return smbw_rmdir((char *) name); } - + return (* smbw_libc.rmdir)((char *) name); } int symlink(const char *topath, const char *frompath) { int p1, p2; - + check_init("symlink"); - + p1 = smbw_path((char *) topath); p2 = smbw_path((char *) frompath); if (p1 || p2) { @@ -1166,25 +1179,25 @@ int symlink(const char *topath, const char *frompath) errno = EPERM; return -1; } - + return (* smbw_libc.symlink)((char *) topath, (char *) frompath); } int dup(int fd) { check_init("dup"); - + if (smbw_fd(fd)) { return smbw_dup(fd); } - + return (* smbw_libc.dup)(fd); } int dup2(int oldfd, int newfd) { check_init("dup2"); - + if (smbw_fd(newfd)) { (* smbw_libc.close)(newfd); } @@ -1192,7 +1205,7 @@ int dup2(int oldfd, int newfd) if (smbw_fd(oldfd)) { return smbw_dup2(oldfd, newfd); } - + return (* smbw_libc.dup2)(oldfd, newfd); } @@ -1200,18 +1213,18 @@ int dup2(int oldfd, int newfd) DIR *opendir(const char *name) { check_init("opendir"); - + if (smbw_path((char *) name)) { return (void *)smbw_opendir((char *) name); } - + return (* smbw_libc.opendir)((char *) name); } struct dirent *readdir(DIR *dir) { check_init("readdir"); - + if (smbw_dirp(dir)) { static struct dirent external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1227,41 +1240,41 @@ struct dirent *readdir(DIR *dir) int closedir(DIR *dir) { check_init("closedir"); - + if (smbw_dirp(dir)) { return smbw_closedir(dir); } - + return (* smbw_libc.closedir)(dir); } long telldir(DIR *dir) { check_init("telldir"); - + if (smbw_dirp(dir)) { return (long) smbw_telldir(dir); } - + return (* smbw_libc.telldir)(dir); } void seekdir(DIR *dir, long offset) { check_init("seekdir"); - + if (smbw_dirp(dir)) { smbw_seekdir(dir, (long long) offset); return; } - + (* smbw_libc.seekdir)(dir, offset); } int creat(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat"); return openx((char *) path, creat_bits, mode, smbw_libc.open); } @@ -1269,7 +1282,7 @@ int creat(const char *path, mode_t mode) int creat64(const char *path, mode_t mode) { extern int creat_bits; - + check_init("creat64"); return openx((char *) path, creat_bits, mode, smbw_libc.open64); } @@ -1277,103 +1290,103 @@ int creat64(const char *path, mode_t mode) int __xstat64 (int ver, const char *name, struct stat64 *st64) { check_init("__xstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__xstat64)(ver, (char *) name, st64); } int stat64(const char *name, struct stat64 *st64) { check_init("stat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.stat64)((char *) name, st64); } int __fxstat64(int ver, int fd, struct stat64 *st64) { check_init("__fxstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__fxstat64)(ver, fd, st64); } int fstat64(int fd, struct stat64 *st64) { check_init("fstat64"); - + if (smbw_fd(fd)) { struct SMBW_stat statbuf; int ret = smbw_fstat(fd, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.fstat64)(fd, st64); } int __lxstat64(int ver, const char *name, struct stat64 *st64) { check_init("__lxstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat(name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.__lxstat64)(ver, (char *) name, st64); } int lstat64(const char *name, struct stat64 *st64) { check_init("lstat64"); - + if (smbw_path((char *) name)) { struct SMBW_stat statbuf; int ret = smbw_stat((char *) name, &statbuf); stat64_convert(&statbuf, st64); return ret; } - + return (* smbw_libc.lstat64)((char *) name, st64); } int _llseek(unsigned int fd, unsigned long offset_high, unsigned long offset_low, loff_t *result, unsigned int whence) { check_init("_llseek"); - + if (smbw_fd(fd)) { *result = lseek(fd, offset_low, whence); return (*result < 0 ? -1 : 0); } - + return (* smbw_libc._llseek)(fd, offset_high, offset_low, result, whence); } struct dirent64 *readdir64(DIR *dir) { check_init("readdir64"); - + if (smbw_dirp(dir)) { static struct dirent64 external; struct SMBW_dirent * internal = (void *)smbw_readdir(dir); @@ -1383,14 +1396,14 @@ struct dirent64 *readdir64(DIR *dir) } return NULL; } - + return (* smbw_libc.readdir64)(dir); } int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) { check_init("readdir_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1400,14 +1413,14 @@ int readdir_r(DIR *dir, struct dirent *external, struct dirent **result) } return ret; } - + return (* smbw_libc.readdir_r)(dir, external, result); } int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) { check_init("readdir64_r"); - + if (smbw_dirp(dir)) { struct SMBW_dirent internal; int ret = smbw_readdir_r(dir, &internal, NULL); @@ -1417,7 +1430,7 @@ int readdir64_r(DIR *dir, struct dirent64 *external, struct dirent64 **result) } return ret; } - + return (* smbw_libc.readdir64_r)(dir, external, result); } @@ -1436,7 +1449,7 @@ int setxattr(const char *fname, if (smbw_path(fname)) { return smbw_setxattr(fname, name, value, size, flags); } - + return (* smbw_libc.setxattr)(fname, name, value, size, flags); } @@ -1449,7 +1462,7 @@ int lsetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lsetxattr(fname, name, value, size, flags); } - + return (* smbw_libc.lsetxattr)(fname, name, value, size, flags); } @@ -1462,7 +1475,7 @@ int fsetxattr(int fd, if (smbw_fd(fd)) { return smbw_fsetxattr(fd, name, value, size, flags); } - + return (* smbw_libc.fsetxattr)(fd, name, value, size, flags); } @@ -1474,7 +1487,7 @@ int getxattr(const char *fname, if (smbw_path(fname)) { return smbw_getxattr(fname, name, value, size); } - + return (* smbw_libc.getxattr)(fname, name, value, size); } @@ -1486,7 +1499,7 @@ int lgetxattr(const char *fname, if (smbw_path(fname)) { return smbw_lgetxattr(fname, name, value, size); } - + return (* smbw_libc.lgetxattr)(fname, name, value, size); } @@ -1498,7 +1511,7 @@ int fgetxattr(int fd, if (smbw_fd(fd)) { return smbw_fgetxattr(fd, name, value, size); } - + return (* smbw_libc.fgetxattr)(fd, name, value, size); } @@ -1508,7 +1521,7 @@ int removexattr(const char *fname, if (smbw_path(fname)) { return smbw_removexattr(fname, name); } - + return (* smbw_libc.removexattr)(fname, name); } @@ -1518,7 +1531,7 @@ int lremovexattr(const char *fname, if (smbw_path(fname)) { return smbw_lremovexattr(fname, name); } - + return (* smbw_libc.lremovexattr)(fname, name); } @@ -1528,7 +1541,7 @@ int fremovexattr(int fd, if (smbw_fd(fd)) { return smbw_fremovexattr(fd, name); } - + return (* smbw_libc.fremovexattr)(fd, name); } @@ -1539,7 +1552,7 @@ int listxattr(const char *fname, if (smbw_path(fname)) { return smbw_listxattr(fname, list, size); } - + return (* smbw_libc.listxattr)(fname, list, size); } @@ -1550,7 +1563,7 @@ int llistxattr(const char *fname, if (smbw_path(fname)) { return smbw_llistxattr(fname, list, size); } - + return (* smbw_libc.llistxattr)(fname, list, size); } @@ -1561,7 +1574,7 @@ int flistxattr(int fd, if (smbw_fd(fd)) { return smbw_flistxattr(fd, list, size); } - + return (* smbw_libc.flistxattr)(fd, list, size); } @@ -1609,7 +1622,7 @@ void free(void *ptr) { static int in_progress = 0; void __libc_free(void *ptr); - + if (in_progress) return; in_progress = 1; __libc_free(ptr); @@ -1628,7 +1641,7 @@ smbw_sigaction_handler(int signum, { /* Our entire purpose for trapping signals is to call this! */ sys_select_signal(); - + /* Call the user's handler */ if (user_action[signum].sa_handler != SIG_IGN && user_action[signum].sa_handler != SIG_DFL && @@ -1660,14 +1673,14 @@ do_select(int n, int saved_errno; sigset_t sigset; struct sigaction new_action; - + saved_errno = errno; for (i=1; i<_NSIG; i++) { sigemptyset(&sigset); new_action.sa_mask = sigset; new_action.sa_flags = SA_SIGINFO; new_action.sa_sigaction = smbw_sigaction_handler; - + if (sigaction(i, &new_action, &user_action[i]) < 0) { if (errno != EINVAL) { return -1; @@ -1675,14 +1688,14 @@ do_select(int n, } } errno = saved_errno; - + ret = (* select_fn)(n, readfds, writefds, exceptfds, timeout); saved_errno = errno; - + for (i=0; i<_NSIG; i++) { (void) sigaction(i, &user_action[i], NULL); } - + errno = saved_errno; return ret; } @@ -1695,7 +1708,7 @@ select(int n, struct timeval *timeout) { check_init("select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.select); } @@ -1708,7 +1721,7 @@ _select(int n, struct timeval *timeout) { check_init("_select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc._select); } @@ -1721,7 +1734,7 @@ __select(int n, struct timeval *timeout) { check_init("__select"); - + return do_select(n, readfds, writefds, exceptfds, timeout, smbw_libc.__select); } diff --git a/examples/libsmbclient/smbwrapper/wrapper.h b/examples/libsmbclient/smbwrapper/wrapper.h index 6d0d9f527a3..5a18b9d76cf 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.h +++ b/examples/libsmbclient/smbwrapper/wrapper.h @@ -32,6 +32,10 @@ #include #include +#ifndef __FD_SETSIZE +# define __FD_SETSIZE 256 +#endif + extern int smbw_fd_map[__FD_SETSIZE]; extern int smbw_ref_count[__FD_SETSIZE]; extern char smbw_cwd[PATH_MAX]; -- cgit From 5c44ab33ab4a2ba0ff0e1cb43b0888fc4e65e982 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 7 Jan 2006 22:11:30 +0000 Subject: r12760: Fix bug 3384 --- source/tdb/tdbtool.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/tdb/tdbtool.c b/source/tdb/tdbtool.c index ce8490ea065..bcfb96adc09 100644 --- a/source/tdb/tdbtool.c +++ b/source/tdb/tdbtool.c @@ -232,6 +232,11 @@ static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen) { TDB_DATA key, dbuf; + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); + return; + } + key.dptr = keyname; key.dsize = keylen; dbuf.dptr = data; @@ -246,6 +251,16 @@ static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen) { TDB_DATA key, dbuf; + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); + return; + } + + if ((data == NULL) || (datalen == 0)) { + terror("need data"); + return; + } + key.dptr = keyname; key.dsize = keylen; dbuf.dptr = data; @@ -263,6 +278,11 @@ static void show_tdb(char *keyname, size_t keylen) { TDB_DATA key, dbuf; + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); + return; + } + key.dptr = keyname; key.dsize = keylen; @@ -283,6 +303,11 @@ static void delete_tdb(char *keyname, size_t keylen) { TDB_DATA key; + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); + return; + } + key.dptr = keyname; key.dsize = keylen; @@ -296,6 +321,11 @@ static void move_rec(char *keyname, size_t keylen, char* tdbname) TDB_DATA key, dbuf; TDB_CONTEXT *dst_tdb; + if ((keyname == NULL) || (keylen == 0)) { + terror("need key"); + return; + } + if ( !tdbname ) { terror("need destination tdb name"); return; -- cgit From 575b913e7417fc78440a1b7e1f9301795e822749 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 8 Jan 2006 15:31:25 +0000 Subject: r12771: Apply patch from bug 3374, attempt to fix build on tru64. Thanks to "The Written Word" -- whoever that is :-) Volker --- source/include/includes.h | 1 + source/nsswitch/winbind_nss_config.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/source/include/includes.h b/source/include/includes.h index 80fc3feed98..f704fcb6874 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -565,6 +565,7 @@ typedef int VOLATILE SIG_ATOMIC_T; #endif #ifndef HAVE_SOCKLEN_T_TYPE +#define HAVE_SOCKLEN_T_TYPE typedef int socklen_t; #endif diff --git a/source/nsswitch/winbind_nss_config.h b/source/nsswitch/winbind_nss_config.h index 77d1dbe26e0..a3243b99e30 100644 --- a/source/nsswitch/winbind_nss_config.h +++ b/source/nsswitch/winbind_nss_config.h @@ -139,4 +139,8 @@ typedef int BOOL; #define S_ISSOCK(mode) ((mode & S_IFSOCK) == S_IFSOCK) #endif +#ifndef HAVE_SOCKLEN_T_TYPE +typedef int socklen_t; +#endif + #endif -- cgit From f7f59112c6233e9094cd70d782c9c5f7820724f7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 8 Jan 2006 22:00:01 +0000 Subject: r12781: Support the level parameter for lsa_lookupsids. Simplify the interfaces to domain trusts a bit: Nothing outside secrets.c needs to know we're storing stuff in ucs2. Volker --- source/utils/smbcontrol.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/utils/smbcontrol.c b/source/utils/smbcontrol.c index 25b42a58c1e..b8f7c2f2b55 100644 --- a/source/utils/smbcontrol.c +++ b/source/utils/smbcontrol.c @@ -786,6 +786,8 @@ int main(int argc, const char **argv) POPT_TABLEEND }; + load_case_tables(); + setup_logging(argv[0],True); /* Parse command line arguments using popt */ -- cgit From 5df72be2be518c3078d382006438fad0ba8b6b32 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 9 Jan 2006 12:51:57 +0000 Subject: r12787: Revert last commit that removed our logic of memorizing negative name_to_sid lookups in the cache. Guenther --- source/nsswitch/winbindd_cache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index eea0d16ca83..81dd85e588b 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -989,9 +989,7 @@ do_query: status = domain->backend->name_to_sid(domain, mem_ctx, domain_name, name, sid, type); /* and save it */ - if (NT_STATUS_IS_OK(status)) { - wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type); - } + wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type); /* We can't save the sid to name mapping as we don't know the correct case of the name without looking it up */ -- cgit From 6efc15556c8d4ff0269ee8fb3e1a90e0ee57b517 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 9 Jan 2006 12:59:41 +0000 Subject: r12788: Since we have agreed on the case of winbindd names, we can store a sid_to_name lookup result already after doing a sucessfull name_to_sid lookup. Guenther --- source/nsswitch/winbindd_cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/nsswitch/winbindd_cache.c b/source/nsswitch/winbindd_cache.c index 81dd85e588b..1d047b8356f 100644 --- a/source/nsswitch/winbindd_cache.c +++ b/source/nsswitch/winbindd_cache.c @@ -991,8 +991,11 @@ do_query: /* and save it */ wcache_save_name_to_sid(domain, status, domain_name, name, sid, *type); - /* We can't save the sid to name mapping as we don't know the - correct case of the name without looking it up */ + if (NT_STATUS_IS_OK(status)) { + strupper_m(CONST_DISCARD(char *,domain_name)); + strlower_m(CONST_DISCARD(char *,name)); + wcache_save_sid_to_name(domain, status, sid, domain_name, name, *type); + } return status; } -- cgit From 07778a9384813b95b796b775510a04ddef8d28d2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 9 Jan 2006 15:54:16 +0000 Subject: r12794: BUG 3340: patch from William JoJo to fix automatic inclusion of aio support on AIX --- source/include/includes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/includes.h b/source/include/includes.h index f704fcb6874..44b5ea1bd79 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -514,7 +514,7 @@ #include #endif -#ifdef HAVE_AIO_H +#if defined(HAVE_AIO_H) && defined(WITH_AIO) #include #endif -- cgit From cceced1bf4a972fccde9eea99f078949eaf30acb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Jan 2006 21:58:40 +0000 Subject: r12802: Fix for bugzilla #3389 from William Jojo. This fixes failures on AIX in linking smbd when the symbol table for ld exceeds 65536 bytes. --- source/configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/configure.in b/source/configure.in index ec1bdacad84..40cb4208253 100644 --- a/source/configure.in +++ b/source/configure.in @@ -1460,7 +1460,7 @@ if test "$enable_shared" = "yes"; then *aix*) AC_DEFINE(AIX,1,[Whether the host os is aix]) BLDSHARED="true" LDSHFLAGS="-Wl,-bexpall,-bM:SRE,-bnoentry,-berok" - DYNEXP="-Wl,-brtl,-bexpall" + DYNEXP="-Wl,-brtl,-bexpall,-bbigtoc" PICFLAGS="-O2" if test "${GCC}" != "yes"; then ## for funky AIX compiler using strncpy() -- cgit From 51102b2c7036726472abf031fe313a6c9248eb80 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 11 Jan 2006 10:21:23 +0000 Subject: r12837: - configure check for Tru64 EA functions (not yet implemented) - find Tru64 AIO lib in configure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Björn Jacke Volker --- source/configure.in | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/source/configure.in b/source/configure.in index 40cb4208253..89891cf4129 100644 --- a/source/configure.in +++ b/source/configure.in @@ -795,7 +795,7 @@ AC_CHECK_HEADERS(shadow.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h) AC_CHECK_HEADERS(nss.h nss_common.h nsswitch.h ns_api.h sys/security.h security/pam_appl.h) AC_CHECK_HEADERS(stropts.h poll.h) AC_CHECK_HEADERS(sys/capability.h syscall.h sys/syscall.h) -AC_CHECK_HEADERS(sys/acl.h sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h) +AC_CHECK_HEADERS(sys/acl.h sys/attributes.h attr/xattr.h sys/xattr.h sys/extattr.h sys/uio.h sys/proplist.h) AC_CHECK_HEADERS(sys/cdefs.h glob.h) AC_CHECK_HEADERS(netinet/ip.h,,,[[ @@ -1345,12 +1345,23 @@ AC_LIBTESTFUNC(sec, getprpwnam) ############################################ # Check if we have libattr -AC_SEARCH_LIBS(getxattr, [attr]) -AC_CHECK_FUNCS(getxattr lgetxattr fgetxattr listxattr llistxattr) -AC_CHECK_FUNCS(flistxattr removexattr lremovexattr fremovexattr) -AC_CHECK_FUNCS(setxattr lsetxattr fsetxattr) -AC_CHECK_FUNCS(attr_get attr_list attr_set attr_remove) -AC_CHECK_FUNCS(attr_getf attr_listf attr_setf attr_removef) +case "$host_os" in + *osf*) + AC_SEARCH_LIBS(getproplist, [proplist]) + AC_CHECK_FUNCS(getproplist fgetproplist setproplist fsetproplist) + AC_CHECK_FUNCS(delproplist fdelproplist add_proplist_entry get_proplist_entry) + AC_CHECK_FUNCS(sizeof_proplist_entry) + ;; + *) + AC_SEARCH_LIBS(getxattr, [attr]) + AC_CHECK_FUNCS(getxattr lgetxattr fgetxattr listxattr llistxattr) + AC_CHECK_FUNCS(flistxattr removexattr lremovexattr fremovexattr) + AC_CHECK_FUNCS(setxattr lsetxattr fsetxattr) + AC_CHECK_FUNCS(attr_get attr_list attr_set attr_remove) + AC_CHECK_FUNCS(attr_getf attr_listf attr_setf attr_removef) + ;; +esac + # Check if we have extattr case "$host_os" in *freebsd4* | *dragonfly* ) @@ -4478,9 +4489,10 @@ AC_ARG_WITH(aio-support, case "$host_os" in *) AC_CHECK_LIB(rt,aio_read,[AIO_LIBS="$ACL_LIBS -lrt"]) + AC_CHECK_LIB(aio,aio_read,[AIO_LIBS="$ACL_LIBS -laio"]) AC_CACHE_CHECK([for asynchronous io support],samba_cv_HAVE_AIO,[ aio_LIBS=$LIBS - LIBS="$LIBS -lrt" + LIBS=$AIO_LIBS AC_TRY_LINK([#include #include ], [ struct aiocb a; return aio_read(&a);], @@ -4488,7 +4500,7 @@ samba_cv_HAVE_AIO=yes,samba_cv_HAVE_AIO=no) LIBS=$aio_LIBS]) AC_CACHE_CHECK([for 64-bit asynchronous io support],samba_cv_HAVE_AIO64,[ aio_LIBS=$LIBS - LIBS="$LIBS -lrt" + LIBS=$AIO_LIBS AC_TRY_LINK([#include #include ], [ struct aiocb64 a; return aio_read64(&a);], @@ -4497,10 +4509,10 @@ samba_cv_HAVE_AIO64=yes,samba_cv_HAVE_AIO64=no) if test x"$samba_cv_HAVE_AIO64" = x"yes"; then AC_DEFINE(HAVE_AIOCB64,1,[Whether 64 bit aio is available]) AC_DEFINE(WITH_AIO, 1, [Using asynchronous io]) - LIBS="$LIBS -lrt" + LIBS=$AIO_LIBS elif test x"$samba_cv_HAVE_AIO" = x"yes"; then AC_DEFINE(WITH_AIO, 1, [Using asynchronous io]) - LIBS="$LIBS -lrt" + LIBS=$AIO_LIBS fi if test x"$samba_cv_HAVE_AIO" = x"yes"; then -- cgit From 6061e25c2404f4450a582132d913ef2501a05ddf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 11 Jan 2006 12:00:59 +0000 Subject: r12839: - apply changes from svn r4963 also for VFS configure - KRB5_CONFIG should not be used - rename it to KRB5CONFIG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Björn Jacke Volker --- examples/VFS/configure.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/VFS/configure.in b/examples/VFS/configure.in index fda4cf3a316..515d43f0096 100644 --- a/examples/VFS/configure.in +++ b/examples/VFS/configure.in @@ -84,11 +84,11 @@ fi ################################################# # check for krb5-config from recent MIT and Heimdal kerberos 5 - AC_PATH_PROG(KRB5_CONFIG, krb5-config) + AC_PATH_PROG(KRB5CONFIG, krb5-config) AC_MSG_CHECKING(for working krb5-config) - if test -x "$KRB5_CONFIG"; then - CFLAGS="$CFLAGS `$KRB5_CONFIG --cflags | sed s/@INCLUDE_des@//`" - CPPFLAGS="$CPPFLAGS `$KRB5_CONFIG --cflags | sed s/@INCLUDE_des@//`" + if test -x "$KRB5CONFIG"; then + CFLAGS="$CFLAGS `$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`" + CPPFLAGS="$CPPFLAGS `$KRB5CONFIG --cflags | sed s/@INCLUDE_des@//`" FOUND_KRB5=yes AC_MSG_RESULT(yes) else -- cgit From 635dec91d854715353b8074813d5a3113f66db8e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 11 Jan 2006 12:09:30 +0000 Subject: r12840: Add -W to smbpasswd. Thanks to William Jojo . Volker --- source/utils/smbpasswd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/utils/smbpasswd.c b/source/utils/smbpasswd.c index 5aba1623890..7659bb2997a 100644 --- a/source/utils/smbpasswd.c +++ b/source/utils/smbpasswd.c @@ -92,7 +92,7 @@ static int process_options(int argc, char **argv, int local_flags) user_name[0] = '\0'; - while ((ch = getopt(argc, argv, "c:axdehminjr:sw:R:D:U:L")) != EOF) { + while ((ch = getopt(argc, argv, "c:axdehminjr:sw:R:D:U:LW")) != EOF) { switch(ch) { case 'L': local_flags |= LOCAL_AM_ROOT; @@ -153,6 +153,10 @@ static int process_options(int argc, char **argv, int local_flags) got_username = True; fstrcpy(user_name, optarg); break; + case 'W': + local_flags |= LOCAL_SET_LDAP_ADMIN_PW; + *ldap_secret = '\0'; + break; } case 'h': default: @@ -325,6 +329,10 @@ static int process_root(int local_flags) if (local_flags & LOCAL_SET_LDAP_ADMIN_PW) { printf("Setting stored password for \"%s\" in secrets.tdb\n", lp_ldap_admin_dn()); + if ( ! *ldap_secret ) { + new_passwd = prompt_for_new_password(stdin_passwd_get); + fstrcpy(ldap_secret, new_passwd); + } if (!store_ldap_admin_pw(ldap_secret)) DEBUG(0,("ERROR: Failed to store the ldap admin password!\n")); goto done; -- cgit From 3dfdf7ef598f4bcb5f877979c9dcba0c1eca4b53 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 11 Jan 2006 18:22:06 +0000 Subject: r12852: r12150@cabra: derrell | 2006-01-11 13:21:14 -0500 Although RTLD_NEXT was not working properly a number of years ago, it seems to be now. Replace dlopen(/lib/libc...) with direct use of RTLD_NEXT --- examples/libsmbclient/smbwrapper/wrapper.c | 45 ++++++++++-------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/examples/libsmbclient/smbwrapper/wrapper.c b/examples/libsmbclient/smbwrapper/wrapper.c index 12904c30737..e6f764c16d8 100644 --- a/examples/libsmbclient/smbwrapper/wrapper.c +++ b/examples/libsmbclient/smbwrapper/wrapper.c @@ -62,7 +62,14 @@ #include #include #include +#ifdef __USE_GNU +# define SMBW_USE_GNU +#endif +#define __USE_GNU /* need this to have RTLD_NEXT defined */ #include +#ifndef SMBW_USE_GNU +# undef __USE_GNU +#endif #include #include "libsmbclient.h" #include "bsd-strlfunc.h" @@ -131,7 +138,6 @@ void smbw_initialize(void) static void initialize(void) { - void *lib = NULL; int saved_errno; #if SMBW_DEBUG & 0x1 char *error; @@ -144,26 +150,18 @@ static void initialize(void) } initialized = 1; - if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { -#ifdef RTLD_NEXT - lib = RTLD_NEXT; -#else - exit(1); -#endif - } - #if SMBW_DEBUG & 0x1 -# define GETSYM(symname, symstring) \ - if ((smbw_libc.symname = dlsym(lib, symstring)) == NULL) { \ - if (smbw_libc.write != NULL && \ - (error = dlerror()) != NULL) { \ - (* smbw_libc.write)(1, error, strlen(error)); \ - (* smbw_libc.write)(1, "\n", 1); \ - } \ +# define GETSYM(symname, symstring) \ + if ((smbw_libc.symname = dlsym(RTLD_NEXT, symstring)) == NULL) { \ + if (smbw_libc.write != NULL && \ + (error = dlerror()) != NULL) { \ + (* smbw_libc.write)(1, error, strlen(error)); \ + (* smbw_libc.write)(1, "\n", 1); \ + } \ } #else # define GETSYM(symname, symstring) \ - smbw_libc.symname = dlsym(lib, symstring); + smbw_libc.symname = dlsym(RTLD_NEXT, symstring); #endif /* @@ -265,19 +263,6 @@ static void initialize(void) GETSYM(_select, "_select"); GETSYM(__select, "__select"); -#ifdef RTLD_NEXT - if (lib != RTLD_NEXT) { - dlclose(lib); - } -#else - dlclose(lib); -#endif - - /* Ensure that the C library is immediately available */ - if ((lib = dlopen("/lib/libc.so.6", RTLD_NOW | RTLD_GLOBAL)) == NULL) { - exit(1); - } - #if SMBW_DEBUG & 4 { if ((debugFd = -- cgit From e439626aa1d2f610596d2cc2be7d9c8833372ddb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 11 Jan 2006 19:18:40 +0000 Subject: r12853: Fix segfault in "net rpc vampire|samdump" (Bugzilla #3390). The session key, after beeing set, was zeroed later on by the prs_init in the CLI_DO_RPC macro. Guenther --- source/include/rpc_client.h | 21 +++++++++++++++++++-- source/rpc_client/cli_netlogon.c | 5 +---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/include/rpc_client.h b/source/include/rpc_client.h index 8a83c0f8ae8..0524f037e2c 100644 --- a/source/include/rpc_client.h +++ b/source/include/rpc_client.h @@ -23,8 +23,8 @@ /* macro to expand cookie-cutter code in cli_xxx() using rpc_api_pipe_req() */ -#define CLI_DO_RPC( pcli, ctx, p_idx, opnum, q_in, r_out, \ - q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \ +#define CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \ + q_ps, r_ps, q_io_fn, r_io_fn, default_error, copy_sess_key ) \ {\ SMB_ASSERT(pcli->pipe_idx == p_idx); \ if (!prs_init( &q_ps, RPC_MAX_PDU_FRAG_LEN, ctx, MARSHALL )) { \ @@ -34,6 +34,7 @@ prs_mem_free( &q_ps );\ return NT_STATUS_NO_MEMORY;\ }\ + if ( copy_sess_key) prs_set_session_key(&q_ps, (const char *)pcli->dc->sess_key);\ if ( q_io_fn("", &q_in, &q_ps, 0) ) {\ NTSTATUS _smb_pipe_stat_ = rpc_api_pipe_req(pcli, opnum, &q_ps, &r_ps); \ if (!NT_STATUS_IS_OK(_smb_pipe_stat_)) {\ @@ -41,6 +42,7 @@ prs_mem_free( &r_ps );\ return _smb_pipe_stat_;\ }\ + if ( copy_sess_key ) prs_set_session_key(&r_ps, (const char *)pcli->dc->sess_key);\ if (!r_io_fn("", &r_out, &r_ps, 0)) {\ prs_mem_free( &q_ps );\ prs_mem_free( &r_ps );\ @@ -55,6 +57,21 @@ prs_mem_free( &r_ps );\ } +#define CLI_DO_RPC_COPY_SESS_KEY( pcli, ctx, p_idx, opnum, q_in, r_out, \ + q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \ +{\ + CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \ + q_ps, r_ps, q_io_fn, r_io_fn, default_error, True ); \ +} + +#define CLI_DO_RPC( pcli, ctx, p_idx, opnum, q_in, r_out, \ + q_ps, r_ps, q_io_fn, r_io_fn, default_error ) \ +{\ + CLI_DO_RPC_INTERNAL( pcli, ctx, p_idx, opnum, q_in, r_out, \ + q_ps, r_ps, q_io_fn, r_io_fn, default_error, False ); \ +} + + /* Arrrgg. Same but with WERRORS. Needed for registry code. */ #define CLI_DO_RPC_WERR( pcli, ctx, p_idx, opnum, q_in, r_out, \ diff --git a/source/rpc_client/cli_netlogon.c b/source/rpc_client/cli_netlogon.c index e3cc97cdc6b..b5addf33751 100644 --- a/source/rpc_client/cli_netlogon.c +++ b/source/rpc_client/cli_netlogon.c @@ -604,15 +604,12 @@ NTSTATUS rpccli_netlogon_sam_sync(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c creds_client_step(cli->dc, &clnt_creds); - prs_set_session_key(&qbuf, (const char *)cli->dc->sess_key); - prs_set_session_key(&rbuf, (const char *)cli->dc->sess_key); - init_net_q_sam_sync(&q, cli->dc->remote_machine, global_myname(), &clnt_creds, &ret_creds, database_id, next_rid); /* Marshall data and send request */ - CLI_DO_RPC(cli, mem_ctx, PI_NETLOGON, NET_SAM_SYNC, + CLI_DO_RPC_COPY_SESS_KEY(cli, mem_ctx, PI_NETLOGON, NET_SAM_SYNC, q, r, qbuf, rbuf, net_io_q_sam_sync, -- cgit From f482bb9c61fca406a32289c499ff0b7a04de3bd3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Jan 2006 20:23:02 +0000 Subject: r12855: Remove erroneous commenting out of valgrind fix. Jeremy. --- source/lib/clobber.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/clobber.c b/source/lib/clobber.c index 54b24ffed39..fb3a0dc2815 100644 --- a/source/lib/clobber.c +++ b/source/lib/clobber.c @@ -54,7 +54,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running * under valgrind.) */ -// VALGRIND_MAKE_WRITABLE(dest, len); + VALGRIND_MAKE_WRITABLE(dest, len); #endif /* VALGRIND */ #endif /* DEVELOPER */ } -- cgit From 69ff52397ad7e9a2346a649a4b210947150d47c5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 12 Jan 2006 17:37:25 +0000 Subject: r12870: fixing net rpc registry enumerate from overwritnig the open subkey handle --- source/utils/net_rpc_registry.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/utils/net_rpc_registry.c b/source/utils/net_rpc_registry.c index 289fb59fea3..4ce0b44e4cd 100644 --- a/source/utils/net_rpc_registry.c +++ b/source/utils/net_rpc_registry.c @@ -124,7 +124,6 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, return werror_to_ntstatus(result); } } - memcpy( &pol_key, &pol_hive, sizeof(POLICY_HND) ); /* get the subkeys */ -- cgit From 0ff3a1ecb2abec6a73252a476a0aa250dcdada02 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Thu, 12 Jan 2006 18:06:05 +0000 Subject: r12871: Merge Volkers rev 12667 from trunk as his analysis hit the nail on the head. Volker: Thanks for poking me last week. --- source/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Makefile.in b/source/Makefile.in index 9d00cb72a1d..1876045df01 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -815,7 +815,7 @@ MAKEDIR = || exec false; \ # of gcc-3.4 and run 'make pch' before you do the main build. pch: rm -f $(srcdir)/include/includes.h.gch - $(CC) -I. -I$(srcdir) $(FLAGS) -c $(srcdir)/include/includes.h -o $(srcdir)/include/includes.h.gch + $(CC) -I. -I$(srcdir) $(FLAGS) @PIE_CFLAGS@ -c $(srcdir)/include/includes.h -o $(srcdir)/include/includes.h.gch ## ## Targets for 'make test' -- cgit From 43543f32b912b4a393ad7c292d2eae3935b5cbcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 12 Jan 2006 22:17:54 +0000 Subject: r12877: Stop passing structs around in smb messages, instead always linearize into little-endian. Should fix all Solaris issues with this, plus provide a cleaner base moving forward for cluster-aware Samba where smbd's can communicate across different compilers/architectures (eventually these message will have to go cross-machine). Jeremy. --- source/configure.in | 19 ++++- source/include/includes.h | 20 ++++- source/include/smb.h | 44 ++++++++++- source/locking/locking.c | 17 +++-- source/smbd/close.c | 6 +- source/smbd/open.c | 22 ++++-- source/smbd/oplock.c | 188 ++++++++++++++++++++++++++++++++-------------- source/smbd/trans2.c | 4 +- 8 files changed, 245 insertions(+), 75 deletions(-) diff --git a/source/configure.in b/source/configure.in index 89891cf4129..22dfa671542 100644 --- a/source/configure.in +++ b/source/configure.in @@ -1639,7 +1639,11 @@ if test x"$samba_cv_HAVE_OFF64_T" = x"yes"; then fi AC_CACHE_CHECK([for 64 bit ino_t],samba_cv_SIZEOF_INO_T,[ -AC_TRY_RUN([#include +AC_TRY_RUN([ +#if defined(HAVE_UNISTD_H) +#include +#endif +#include #include main() { exit((sizeof(ino_t) == 8) ? 0 : 1); }], samba_cv_SIZEOF_INO_T=yes,samba_cv_SIZEOF_INO_T=no,samba_cv_SIZEOF_INO_T=cross)]) @@ -1660,6 +1664,19 @@ if test x"$samba_cv_HAVE_INO64_T" = x"yes"; then AC_DEFINE(HAVE_INO64_T,1,[Whether the 'ino64_t' type is available]) fi +AC_CACHE_CHECK([for 64 bit dev_t],samba_cv_SIZEOF_DEV_T,[ +AC_TRY_RUN([ +#if defined(HAVE_UNISTD_H) +#include +#endif +#include +#include +main() { exit((sizeof(dev_t) == 8) ? 0 : 1); }], +samba_cv_SIZEOF_DEV_T=yes,samba_cv_SIZEOF_DEV_T=no,samba_cv_SIZEOF_DEV_T=cross)]) +if test x"$samba_cv_SIZEOF_DEV_T" = x"yes"; then + AC_DEFINE(SIZEOF_DEV_T,8,[The size of the 'dev_t' type]) +fi + AC_CACHE_CHECK([for dev64_t],samba_cv_HAVE_DEV64_T,[ AC_TRY_RUN([ #if defined(HAVE_UNISTD_H) diff --git a/source/include/includes.h b/source/include/includes.h index 44b5ea1bd79..a9b792d5f67 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -657,6 +657,20 @@ typedef int socklen_t; # endif #endif +#ifndef LARGE_SMB_DEV_T +# if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8)) +# define LARGE_SMB_DEV_T 1 +# endif +#endif + +#ifdef LARGE_SMB_DEV_T +#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32)) +#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((SMB_BIG_UINT)(IVAL((p),(ofs))))| (((SMB_BIG_UINT)(IVAL((p),(ofs)+4))) << 32))) +#else +#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0)) +#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs)))) +#endif + /* * Setup the correctly sized inode type. */ @@ -676,9 +690,11 @@ typedef int socklen_t; #endif #ifdef LARGE_SMB_INO_T -#define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32)) +#define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32)) +#define INO_T_VAL(p, ofs) ((SMB_INO_T)(((SMB_BIG_UINT)(IVAL(p,ofs)))| (((SMB_BIG_UINT)(IVAL(p,(ofs)+4))) << 32))) #else -#define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0)) +#define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0)) +#define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs)))) #endif #ifndef SMB_OFF_T diff --git a/source/include/smb.h b/source/include/smb.h index d2eb5644e0d..6ceb4ec1cdd 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -631,6 +631,25 @@ struct share_mode_entry { unsigned long share_file_id; }; +/* oplock break message definition - linearization of share_mode_entry. + +Offset Data length. +0 struct process_id pid 4 +4 uint16 op_mid 2 +6 uint16 op_type 2 +8 uint32 access_mask 4 +12 uint32 share_access 4 +16 uint32 private_options 4 +20 uint32 time sec 4 +24 uint32 time usec 4 +28 SMB_DEV_T dev 8 bytes. +36 SMB_INO_T inode 8 bytes +44 unsigned long file_id 4 bytes +48 + +*/ +#define MSG_SMB_SHARE_MODE_ENTRY_SIZE 48 + struct share_mode_lock { const char *servicepath; /* canonicalized. */ const char *filename; @@ -1456,18 +1475,41 @@ struct inform_level2_message { unsigned long source_file_id; }; +/* kernel_oplock_message definition. + struct kernel_oplock_message { SMB_DEV_T dev; SMB_INO_T inode; unsigned long file_id; }; +Offset Data length. +0 SMB_DEV_T dev 8 bytes. +8 SMB_INO_T inode 8 bytes +16 unsigned long file_id 4 bytes +20 + +*/ +#define MSG_SMB_KERNEL_BREAK_SIZE 20 + +/* file_renamed_message definition. + struct file_renamed_message { SMB_DEV_T dev; SMB_INO_T inode; - char names[1]; /* A variable area containing sharepath and filename. */ + char names[1]; A variable area containing sharepath and filename. }; +Offset Data length. +0 SMB_DEV_T dev 8 bytes. +8 SMB_INO_T inode 8 bytes +16 char [] name zero terminated namelen bytes +minimum length == 18. + +*/ + +#define MSG_FILE_RENAMED_MIN_SIZE 16 + /* * On the wire return values for oplock types. */ diff --git a/source/locking/locking.c b/source/locking/locking.c index 07377831b4a..d9737895ba1 100644 --- a/source/locking/locking.c +++ b/source/locking/locking.c @@ -662,10 +662,10 @@ BOOL rename_share_filename(struct share_mode_lock *lck, const char *servicepath, const char *newname) { - struct file_renamed_message *frm = NULL; size_t sp_len; size_t fn_len; size_t msg_len; + char *frm = NULL; int i; if (!lck) { @@ -694,20 +694,21 @@ BOOL rename_share_filename(struct share_mode_lock *lck, sp_len = strlen(lck->servicepath); fn_len = strlen(lck->filename); - msg_len = sizeof(*frm) + sp_len + 1 + fn_len + 1; + msg_len = MSG_FILE_RENAMED_MIN_SIZE + sp_len + 1 + fn_len + 1; /* Set up the name changed message. */ frm = TALLOC(lck, msg_len); if (!frm) { return False; } - frm->dev = lck->dev; - frm->inode = lck->ino; + + SDEV_T_VAL(frm,0,lck->dev); + SINO_T_VAL(frm,8,lck->ino); DEBUG(10,("rename_share_filename: msg_len = %d\n", msg_len )); - safe_strcpy(&frm->names[0], lck->servicepath, sp_len); - safe_strcpy(&frm->names[sp_len + 1], lck->filename, fn_len); + safe_strcpy(&frm[16], lck->servicepath, sp_len); + safe_strcpy(&frm[16 + sp_len + 1], lck->filename, fn_len); /* Send the messages. */ for (i=0; inum_share_modes; i++) { @@ -723,11 +724,13 @@ BOOL rename_share_filename(struct share_mode_lock *lck, DEBUG(10,("rename_share_filename: sending rename message to pid %u " "dev %x, inode %.0f sharepath %s newname %s\n", (unsigned int)procid_to_pid(&se->pid), - (unsigned int)frm->dev, (double)frm->inode, + (unsigned int)lck->dev, (double)lck->ino, lck->servicepath, lck->filename )); + become_root(); message_send_pid(se->pid, MSG_SMB_FILE_RENAME, frm, msg_len, True); + unbecome_root(); } return True; diff --git a/source/smbd/close.c b/source/smbd/close.c index f8348699359..c0d87b1b212 100644 --- a/source/smbd/close.c +++ b/source/smbd/close.c @@ -130,9 +130,13 @@ static void notify_deferred_opens(struct share_mode_lock *lck) */ schedule_deferred_open_smb_message(e->op_mid); } else { + char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE]; + + share_mode_entry_to_message(msg, e); + become_root(); message_send_pid(e->pid, MSG_SMB_OPEN_RETRY, - e, sizeof(*e), True); + msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); unbecome_root(); } } diff --git a/source/smbd/open.c b/source/smbd/open.c index e6c749fab9c..0ccac592d61 100644 --- a/source/smbd/open.c +++ b/source/smbd/open.c @@ -683,12 +683,17 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck, files_struct *fsp) if (delay_it) { BOOL ret; + char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE]; + DEBUG(10, ("Sending break request to PID %s\n", procid_str_static(&exclusive->pid))); exclusive->op_mid = get_current_mid(); + + share_mode_entry_to_message(msg, exclusive); + become_root(); ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST, - exclusive, sizeof(*exclusive), True); + msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); unbecome_root(); if (!ret) { DEBUG(3, ("Could not send oplock break message\n")); @@ -2055,25 +2060,30 @@ files_struct *open_file_stat(connection_struct *conn, char *fname, void msg_file_was_renamed(int msg_type, struct process_id src, void *buf, size_t len) { files_struct *fsp; - struct file_renamed_message *frm = (struct file_renamed_message *)buf; + char *frm = (char *)buf; + SMB_DEV_T dev; + SMB_INO_T inode; const char *sharepath; const char *newname; size_t sp_len; - if (buf == NULL || len < sizeof(*frm)) { + if (buf == NULL || len < MSG_FILE_RENAMED_MIN_SIZE + 2) { DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n", (int)len)); return; } - sharepath = &frm->names[0]; + /* Unpack the message. */ + dev = DEV_T_VAL(frm,0); + inode = INO_T_VAL(frm,8); + sharepath = &frm[16]; newname = sharepath + strlen(sharepath) + 1; sp_len = strlen(sharepath); DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, " "dev %x, inode %.0f\n", - sharepath, newname, (unsigned int)frm->dev, (double)frm->inode )); + sharepath, newname, (unsigned int)dev, (double)inode )); - for(fsp = file_find_di_first(frm->dev, frm->inode); fsp; fsp = file_find_di_next(fsp)) { + for(fsp = file_find_di_first(dev, inode); fsp; fsp = file_find_di_next(fsp)) { if (memcmp(fsp->conn->connectpath, sharepath, sp_len) == 0) { DEBUG(10,("msg_file_was_renamed: renaming file fnum %d from %s -> %s\n", fsp->fnum, fsp->fsp_name, newname )); diff --git a/source/smbd/oplock.c b/source/smbd/oplock.c index f788fc9e2e0..6739d29470b 100644 --- a/source/smbd/oplock.c +++ b/source/smbd/oplock.c @@ -48,8 +48,9 @@ int32 get_number_of_exclusive_open_oplocks(void) BOOL oplock_message_waiting(fd_set *fds) { - if (koplocks && koplocks->msg_waiting(fds)) + if (koplocks && koplocks->msg_waiting(fds)) { return True; + } return False; } @@ -84,7 +85,7 @@ void process_kernel_oplocks(void) while (koplocks->msg_waiting(&fds)) { files_struct *fsp; - struct kernel_oplock_message msg; + char msg[MSG_SMB_KERNEL_BREAK_SIZE]; fsp = koplocks->receive_message(&fds); @@ -94,12 +95,17 @@ void process_kernel_oplocks(void) return; } - msg.dev = fsp->dev; - msg.inode = fsp->inode; - msg.file_id = fsp->file_id; + /* Put the kernel break info into the message. */ + SDEV_T_VAL(msg,0,fsp->dev); + SINO_T_VAL(msg,8,fsp->inode); + SIVAL(msg,16,fsp->file_id); + + /* Don't need to be root here as we're only ever + sending to ourselves. */ + message_send_pid(pid_to_procid(sys_getpid()), MSG_SMB_KERNEL_BREAK, - &msg, sizeof(msg), True); + &msg, MSG_SMB_KERNEL_BREAK_SIZE, True); } } @@ -110,15 +116,17 @@ void process_kernel_oplocks(void) BOOL set_file_oplock(files_struct *fsp, int oplock_type) { - if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) + if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) { return False; + } fsp->oplock_type = oplock_type; fsp->sent_oplock_break = NO_BREAK_SENT; - if (oplock_type == LEVEL_II_OPLOCK) + if (oplock_type == LEVEL_II_OPLOCK) { level_II_oplocks_open++; - else + } else { exclusive_oplocks_open++; + } DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \ tv_sec = %x, tv_usec = %x\n", @@ -140,10 +148,11 @@ void release_file_oplock(files_struct *fsp) koplocks->release_oplock(fsp); } - if (fsp->oplock_type == LEVEL_II_OPLOCK) + if (fsp->oplock_type == LEVEL_II_OPLOCK) { level_II_oplocks_open--; - else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) + } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) { exclusive_oplocks_open--; + } SMB_ASSERT(exclusive_oplocks_open>=0); SMB_ASSERT(level_II_oplocks_open>=0); @@ -160,8 +169,9 @@ void release_file_oplock(files_struct *fsp) static void downgrade_file_oplock(files_struct *fsp) { - if (koplocks) + if (koplocks) { koplocks->release_oplock(fsp); + } fsp->oplock_type = LEVEL_II_OPLOCK; exclusive_oplocks_open--; level_II_oplocks_open++; @@ -223,7 +233,7 @@ BOOL downgrade_oplock(files_struct *fsp) fsp->fsp_name, fsp->fnum, (unsigned int)dev, (double)inode)); } - + downgrade_file_oplock(fsp); talloc_free(lck); return ret; @@ -284,8 +294,9 @@ static void wait_before_sending_break(void) struct timeval cur_tv; long wait_left = (long)lp_oplock_break_wait_time(); - if (wait_left == 0) + if (wait_left == 0) { return; + } GetTimeOfDay(&cur_tv); @@ -307,7 +318,7 @@ static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, un files_struct *fsp = NULL; if( DEBUGLVL( 3 ) ) { - dbgtext( "initial_break_processing: called for dev = %x, inode = %.0f file_id = %lu\n", + dbgtext( "initial_break_processing: called for dev = 0x%x, inode = %.0f file_id = %lu\n", (unsigned int)dev, (double)inode, file_id); dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n", exclusive_oplocks_open, level_II_oplocks_open ); @@ -325,7 +336,7 @@ static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, un /* The file could have been closed in the meantime - return success. */ if( DEBUGLVL( 3 ) ) { dbgtext( "initial_break_processing: cannot find open file with " ); - dbgtext( "dev = %x, inode = %.0f file_id = %lu", (unsigned int)dev, + dbgtext( "dev = 0x%x, inode = %.0f file_id = %lu", (unsigned int)dev, (double)inode, file_id); dbgtext( "allowing break to succeed.\n" ); } @@ -370,7 +381,7 @@ static void oplock_timeout_handler(struct timed_event *te, static void process_oplock_break_message(int msg_type, struct process_id src, void *buf, size_t len) { - struct share_mode_entry *msg = buf; + struct share_mode_entry msg; files_struct *fsp; char *break_msg; BOOL break_to_level2 = False; @@ -381,17 +392,20 @@ static void process_oplock_break_message(int msg_type, struct process_id src, return; } - if (len != sizeof(*msg)) { + if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) { DEBUG(0, ("Got invalid msg len %d\n", (int)len)); return; } - DEBUG(10, ("Got oplock break message from pid %d: %d/%d/%d\n", - (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode, - (int)msg->share_file_id)); + /* De-linearize incoming message. */ + message_to_share_mode_entry(&msg, buf); + + DEBUG(10, ("Got oplock break message from pid %d: 0x%x/%.0f/%d\n", + (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode, + (int)msg.share_file_id)); - fsp = initial_break_processing(msg->dev, msg->inode, - msg->share_file_id); + fsp = initial_break_processing(msg.dev, msg.inode, + msg.share_file_id); if (fsp == NULL) { /* We hit race here. Break messages are sent, and before we @@ -399,8 +413,11 @@ static void process_oplock_break_message(int msg_type, struct process_id src, * with 'ok, oplock broken' */ DEBUG(3, ("Did not find fsp\n")); become_root(); + + /* We just send the same message back. */ message_send_pid(src, MSG_SMB_BREAK_RESPONSE, - msg, sizeof(*msg), True); + buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); + unbecome_root(); return; } @@ -408,21 +425,24 @@ static void process_oplock_break_message(int msg_type, struct process_id src, if (fsp->sent_oplock_break != NO_BREAK_SENT) { /* Remember we have to inform the requesting PID when the * client replies */ - msg->pid = src; - ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg, + msg.pid = src; + ADD_TO_ARRAY(NULL, struct share_mode_entry, msg, &fsp->pending_break_messages, &fsp->num_pending_break_messages); return; } - if (EXCLUSIVE_OPLOCK_TYPE(msg->op_type) && + if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) && !EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) { - DEBUG(3, ("Already downgraded oplock on %.0f/%.0f: %s\n", - (double)fsp->dev, (double)fsp->inode, + DEBUG(3, ("Already downgraded oplock on 0x%x/%.0f: %s\n", + (unsigned int)fsp->dev, (double)fsp->inode, fsp->fsp_name)); become_root(); + + /* We just send the same message back. */ message_send_pid(src, MSG_SMB_BREAK_RESPONSE, - msg, sizeof(*msg), True); + buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); + unbecome_root(); return; } @@ -466,8 +486,8 @@ static void process_oplock_break_message(int msg_type, struct process_id src, /* Async level2 request, don't send a reply */ fsp->sent_oplock_break = ASYNC_LEVEL_II_BREAK_SENT; } - msg->pid = src; - ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg, + msg.pid = src; + ADD_TO_ARRAY(NULL, struct share_mode_entry, msg, &fsp->pending_break_messages, &fsp->num_pending_break_messages); @@ -490,7 +510,9 @@ static void process_oplock_break_message(int msg_type, struct process_id src, static void process_kernel_oplock_break(int msg_type, struct process_id src, void *buf, size_t len) { - struct kernel_oplock_message *msg = buf; + SMB_DEV_T dev; + SMB_INO_T inode; + unsigned long file_id; files_struct *fsp; char *break_msg; BOOL sign_state; @@ -500,16 +522,21 @@ static void process_kernel_oplock_break(int msg_type, struct process_id src, return; } - if (len != sizeof(*msg)) { + if (len != MSG_SMB_KERNEL_BREAK_SIZE) { DEBUG(0, ("Got invalid msg len %d\n", (int)len)); return; } - DEBUG(10, ("Got kernel oplock break message from pid %d: %d/%d/%d\n", - (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode, - (int)msg->file_id)); + /* Pull the data from the message. */ + dev = DEV_T_VAL(buf, 0); + inode = INO_T_VAL(buf, 8); + file_id = (unsigned long)IVAL(buf, 16); - fsp = initial_break_processing(msg->dev, msg->inode, msg->file_id); + DEBUG(10, ("Got kernel oplock break message from pid %d: 0x%x/%.0f/%u\n", + (int)procid_to_pid(&src), (unsigned int)dev, (double)inode, + (unsigned int)file_id)); + + fsp = initial_break_processing(dev, inode, file_id); if (fsp == NULL) { DEBUG(3, ("Got a kernel oplock break message for a file " @@ -551,9 +578,13 @@ void reply_to_oplock_break_requests(files_struct *fsp) become_root(); for (i=0; inum_pending_break_messages; i++) { - struct share_mode_entry *msg = &fsp->pending_break_messages[i]; - message_send_pid(msg->pid, MSG_SMB_BREAK_RESPONSE, - msg, sizeof(*msg), True); + struct share_mode_entry *e = &fsp->pending_break_messages[i]; + char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE]; + + share_mode_entry_to_message(msg, e); + + message_send_pid(e->pid, MSG_SMB_BREAK_RESPONSE, + msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); } unbecome_root(); @@ -569,46 +600,52 @@ void reply_to_oplock_break_requests(files_struct *fsp) static void process_oplock_break_response(int msg_type, struct process_id src, void *buf, size_t len) { - struct share_mode_entry *msg = buf; + struct share_mode_entry msg; if (buf == NULL) { DEBUG(0, ("Got NULL buffer\n")); return; } - if (len != sizeof(*msg)) { - DEBUG(0, ("Got invalid msg len %d\n", (int)len)); + if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) { + DEBUG(0, ("Got invalid msg len %u\n", (unsigned int)len)); return; } - DEBUG(10, ("Got oplock break response from pid %d: %d/%d/%d mid %d\n", - (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode, - (int)msg->share_file_id, (int)msg->op_mid)); + /* De-linearize incoming message. */ + message_to_share_mode_entry(&msg, buf); + + DEBUG(10, ("Got oplock break response from pid %d: 0x%x/%.0f/%u mid %u\n", + (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode, + (unsigned int)msg.share_file_id, (unsigned int)msg.op_mid)); /* Here's the hack from open.c, store the mid in the 'port' field */ - schedule_deferred_open_smb_message(msg->op_mid); + schedule_deferred_open_smb_message(msg.op_mid); } static void process_open_retry_message(int msg_type, struct process_id src, void *buf, size_t len) { - struct share_mode_entry *msg = buf; + struct share_mode_entry msg; if (buf == NULL) { DEBUG(0, ("Got NULL buffer\n")); return; } - if (len != sizeof(*msg)) { + if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) { DEBUG(0, ("Got invalid msg len %d\n", (int)len)); return; } - DEBUG(10, ("Got open retry msg from pid %d: %d/%d mid %d\n", - (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode, - (int)msg->op_mid)); + /* De-linearize incoming message. */ + message_to_share_mode_entry(&msg, buf); - schedule_deferred_open_smb_message(msg->op_mid); + DEBUG(10, ("Got open retry msg from pid %d: 0x%x/%.0f mid %u\n", + (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode, + (unsigned int)msg.op_mid)); + + schedule_deferred_open_smb_message(msg.op_mid); } /**************************************************************************** @@ -662,6 +699,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp) for(i = 0; i < lck->num_share_modes; i++) { struct share_mode_entry *share_entry = &lck->share_modes[i]; + char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE]; /* * As there could have been multiple writes waiting at the @@ -692,9 +730,11 @@ void release_level_2_oplocks_on_change(files_struct *fsp) abort(); } + share_mode_entry_to_message(msg, share_entry); + become_root(); message_send_pid(share_entry->pid, MSG_SMB_ASYNC_LEVEL2_BREAK, - share_entry, sizeof(*share_entry), True); + msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True); unbecome_root(); } @@ -702,6 +742,44 @@ void release_level_2_oplocks_on_change(files_struct *fsp) talloc_free(lck); } +/**************************************************************************** + Linearize a share mode entry struct to an internal oplock break message. +****************************************************************************/ + +void share_mode_entry_to_message(char *msg, struct share_mode_entry *e) +{ + SIVAL(msg,0,(uint32)e->pid.pid); + SSVAL(msg,4,e->op_mid); + SSVAL(msg,6,e->op_type); + SIVAL(msg,8,e->access_mask); + SIVAL(msg,12,e->share_access); + SIVAL(msg,16,e->private_options); + SIVAL(msg,20,(uint32)e->time.tv_sec); + SIVAL(msg,24,(uint32)e->time.tv_usec); + SDEV_T_VAL(msg,28,e->dev); + SINO_T_VAL(msg,36,e->inode); + SIVAL(msg,44,e->share_file_id); +} + +/**************************************************************************** + De-linearize an internal oplock break message to a share mode entry struct. +****************************************************************************/ + +void message_to_share_mode_entry(struct share_mode_entry *e, char *msg) +{ + e->pid.pid = (pid_t)IVAL(msg,0); + e->op_mid = SVAL(msg,4); + e->op_type = SVAL(msg,6); + e->access_mask = IVAL(msg,8); + e->share_access = IVAL(msg,12); + e->private_options = IVAL(msg,16); + e->time.tv_sec = (time_t)IVAL(msg,20); + e->time.tv_usec = (int)IVAL(msg,24); + e->dev = DEV_T_VAL(msg,28); + e->inode = INO_T_VAL(msg,36); + e->share_file_id = (unsigned long)IVAL(msg,44); +} + /**************************************************************************** Setup oplocks for this process. ****************************************************************************/ diff --git a/source/smbd/trans2.c b/source/smbd/trans2.c index 191ccdcf8bd..8ff219b468c 100644 --- a/source/smbd/trans2.c +++ b/source/smbd/trans2.c @@ -1536,7 +1536,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn, SIVAL(p,4,0); p+= 8; - SINO_T(p,0,(SMB_INO_T)sbuf.st_ino); /* inode number */ + SINO_T_VAL(p,0,(SMB_INO_T)sbuf.st_ino); /* inode number */ p+= 8; SIVAL(p,0, unix_perms_to_wire(sbuf.st_mode)); /* Standard UNIX file permissions */ @@ -3353,7 +3353,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd SIVAL(pdata,4,0); pdata += 8; - SINO_T(pdata,0,(SMB_INO_T)sbuf.st_ino); /* inode number */ + SINO_T_VAL(pdata,0,(SMB_INO_T)sbuf.st_ino); /* inode number */ pdata += 8; SIVAL(pdata,0, unix_perms_to_wire(sbuf.st_mode)); /* Standard UNIX file permissions */ -- cgit From 0fa509b7e0e96abc353218f21c53039cf42b8eb9 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 13 Jan 2006 00:07:54 +0000 Subject: r12878: Don't use non-static array initialisers. --- source/libads/ldap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libads/ldap.c b/source/libads/ldap.c index 8c8401dff9c..dc93bd556c7 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -1800,8 +1800,9 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname) char *hostnameDN, *host; int rc; LDAPControl ldap_control; - LDAPControl * pldap_control[] = {&ldap_control, 0}; + LDAPControl * pldap_control[2] = {NULL, NULL}; + pldap_control[0] = &ldap_control; memset(&ldap_control, 0, sizeof(LDAPControl)); ldap_control.ldctl_oid = (char *)LDAP_SERVER_TREE_DELETE_OID; -- cgit From ff4230e94ba8406c63269b7630d9baae6c2faa56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Jan 2006 02:54:46 +0000 Subject: r12885: Oops. Missed last part of correct patch for #3348. Caught by Samba4 oplock torture tester. Jeremy. --- source/smbd/posix_acls.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/smbd/posix_acls.c b/source/smbd/posix_acls.c index f49f80f006f..e485dc1eb12 100644 --- a/source/smbd/posix_acls.c +++ b/source/smbd/posix_acls.c @@ -4157,7 +4157,6 @@ BOOL can_delete_file_in_directory(connection_struct *conn, const char *fname) if (current_user.uid != sbuf_file.st_uid) { return False; } - return False; } #endif -- cgit From 3e0a66a87f9e42c3dc823f1f367ab2b5679000bb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 03:10:50 +0000 Subject: r12889: BUG 3380: fix crash when changing printer drivers caused by accessing a previously freed pointer --- source/printing/nt_printing.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/printing/nt_printing.c b/source/printing/nt_printing.c index 09775e60c8c..3649da1ac05 100644 --- a/source/printing/nt_printing.c +++ b/source/printing/nt_printing.c @@ -3279,6 +3279,8 @@ WERROR delete_all_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key ) TALLOC_FREE( data ); + p2->data = NULL; + DEBUG(8,("delete_all_printer_data: Removed all Printer Data from printer [%s]\n", p2->printername )); -- cgit From 0656951b3798910ea4c9ae026173dfd595676a9b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 13 Jan 2006 11:11:23 +0000 Subject: r12900: Merge from trunk: Correctly handle the case where users logon with an expired password. In that case pam_sm_authenticate has to return PAM_SUCESS instead of PAM_NEW_AUTHTOK_REQD or PAM_AUTHTOK_EXPIRED and pam_sm_acct_mgmt has to take care of requesting an immediate password change. (see the Linux PAM documentation). Fixes Bugzilla #1524, #3205. Tested with login, sshd, kdm and gdm on Linux. Thanks to Scott Barker . Guenther --- source/nsswitch/pam_winbind.c | 44 ++++++++++++++++++++++++++++++++++++++++++- source/nsswitch/pam_winbind.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/pam_winbind.c b/source/nsswitch/pam_winbind.c index a87ccb4972e..61c01daa165 100644 --- a/source/nsswitch/pam_winbind.c +++ b/source/nsswitch/pam_winbind.c @@ -57,6 +57,11 @@ static int _pam_parse(int argc, const char **argv) return ctrl; } +static void _pam_winbind_cleanup_func(pam_handle_t *pamh, void *data, int error_status) +{ + SAFE_FREE(data); +} + /* --- authentication management functions --- */ /* Attempt a conversation */ @@ -508,7 +513,22 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags, } /* Now use the username to look up password */ - return winbind_auth_request(username, password, member, ctrl); + retval = winbind_auth_request(username, password, member, ctrl); + if (retval == PAM_NEW_AUTHTOK_REQD || + retval == PAM_AUTHTOK_EXPIRED) { + + char *buf; + + if (!asprintf(&buf, "%d", retval)) { + return PAM_BUF_ERR; + } + + pam_set_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (void *)buf, _pam_winbind_cleanup_func); + + return PAM_SUCCESS; + } + + return retval; } PAM_EXTERN @@ -527,6 +547,8 @@ int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) { const char *username; + void *tmp = NULL; + int retval = PAM_USER_UNKNOWN; /* parse arguments */ @@ -555,6 +577,26 @@ int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, return PAM_IGNORE; return PAM_USER_UNKNOWN; case 0: + pam_get_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (const void **)&tmp); + + if (tmp != NULL) { + retval = atoi(tmp); + switch (retval) { + case PAM_AUTHTOK_EXPIRED: + /* fall through, since new token is required in this case */ + case PAM_NEW_AUTHTOK_REQD: + _pam_log(LOG_WARNING, "pam_sm_acct_mgmt success but %s is set", + PAM_WINBIND_NEW_AUTHTOK_REQD); + _pam_log(LOG_NOTICE, "user '%s' needs new password", username); + /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */ + return PAM_NEW_AUTHTOK_REQD; + default: + _pam_log(LOG_WARNING, "pam_sm_acct_mgmt success"); + _pam_log(LOG_NOTICE, "user '%s' granted access", username); + return PAM_SUCCESS; + } + } + /* Otherwise, the authentication looked good */ _pam_log(LOG_NOTICE, "user '%s' granted access", username); return PAM_SUCCESS; diff --git a/source/nsswitch/pam_winbind.h b/source/nsswitch/pam_winbind.h index 7cae477714b..86ba9772879 100644 --- a/source/nsswitch/pam_winbind.h +++ b/source/nsswitch/pam_winbind.h @@ -84,6 +84,8 @@ do { \ #define WINBIND__OLD_PASSWORD (1<<5) #define WINBIND_REQUIRED_MEMBERSHIP (1<<6) +#define PAM_WINBIND_NEW_AUTHTOK_REQD "PAM_WINBIND_NEW_AUTHTOK_REQD" + /* * here is the string to inform the user that the new passwords they * typed were not the same. -- cgit From 44f07a8ff5a5dd64d7badef839cb8b532b4b75b3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 13 Jan 2006 11:19:59 +0000 Subject: r12901: Fix netfileenum returning WERR_BUF_TOO_SMALL. Guenther --- source/rpcclient/cmd_srvsvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rpcclient/cmd_srvsvc.c b/source/rpcclient/cmd_srvsvc.c index da81a82c8d5..53ee7300da3 100644 --- a/source/rpcclient/cmd_srvsvc.c +++ b/source/rpcclient/cmd_srvsvc.c @@ -433,7 +433,7 @@ static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli, SRV_FILE_INFO_CTR ctr; WERROR result; ENUM_HND hnd; - uint32 preferred_len = 0; + uint32 preferred_len = 0xffff; if (argc > 2) { printf("Usage: %s [infolevel]\n", argv[0]); -- cgit From 80a3b4e7178ce06592afe9853176b75b75a43fcf Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 13 Jan 2006 14:55:08 +0000 Subject: r12904: Fix #3264, allow to load idmap_ad with "idmap backend = ad". Finally cleanup the way idmap modules are build and loaded, idmap_rid now will have to be loaded without prefix, just "rid". Guenther --- source/Makefile.in | 4 ++-- source/configure.in | 8 ++++---- source/sam/idmap_rid.c | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index 1876045df01..58d0bb46a15 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -1239,12 +1239,12 @@ bin/smbpasswd.@SHLIBEXT@: passdb/pdb_smbpasswd.@PICSUFFIX@ @$(SHLD) $(LDSHFLAGS) -o $@ passdb/pdb_smbpasswd.@PICSUFFIX@ \ @SONAMEFLAG@`basename $@` -bin/idmap_rid.@SHLIBEXT@: sam/idmap_rid.@PICSUFFIX@ +bin/rid.@SHLIBEXT@: sam/idmap_rid.@PICSUFFIX@ @echo "Building plugin $@" @$(SHLD) $(LDSHFLAGS) -o $@ sam/idmap_rid.@PICSUFFIX@ \ @SONAMEFLAG@`basename $@` -bin/idmap_ad.@SHLIBEXT@: sam/idmap_ad.@PICSUFFIX@ +bin/ad.@SHLIBEXT@: sam/idmap_ad.@PICSUFFIX@ @echo "Building plugin $@" @$(SHLD) $(LDSHFLAGS) -o $@ sam/idmap_ad.@PICSUFFIX@ \ @SONAMEFLAG@`basename $@` diff --git a/source/configure.in b/source/configure.in index 22dfa671542..f3f3d44d0bf 100644 --- a/source/configure.in +++ b/source/configure.in @@ -5160,10 +5160,10 @@ SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$SHLIBEXT", RPC) SMB_MODULE(rpc_echo, \$(RPC_ECHO_OBJ), "bin/librpc_echo.$SHLIBEXT", RPC) SMB_SUBSYSTEM(RPC,smbd/server.o) -SMB_MODULE(idmap_ldap, sam/idmap_ldap.o, "bin/idmap_ldap.$SHLIBEXT", IDMAP) -SMB_MODULE(idmap_tdb, sam/idmap_tdb.o, "bin/idmap_tdb.$SHLIBEXT", IDMAP) -SMB_MODULE(idmap_rid, sam/idmap_rid.o, "bin/idmap_rid.$SHLIBEXT", IDMAP) -SMB_MODULE(idmap_ad, sam/idmap_ad.o, "bin/idmap_ad.$SHLIBEXT", IDMAP) +SMB_MODULE(idmap_ldap, sam/idmap_ldap.o, "bin/ldap.$SHLIBEXT", IDMAP) +SMB_MODULE(idmap_tdb, sam/idmap_tdb.o, "bin/tdb.$SHLIBEXT", IDMAP) +SMB_MODULE(idmap_rid, sam/idmap_rid.o, "bin/rid.$SHLIBEXT", IDMAP) +SMB_MODULE(idmap_ad, sam/idmap_ad.o, "bin/ad.$SHLIBEXT", IDMAP) SMB_SUBSYSTEM(IDMAP,sam/idmap.o) SMB_MODULE(charset_weird, modules/weird.o, "bin/weird.$SHLIBEXT", CHARSET) diff --git a/source/sam/idmap_rid.c b/source/sam/idmap_rid.c index 4a1ae141b10..eced549a557 100644 --- a/source/sam/idmap_rid.c +++ b/source/sam/idmap_rid.c @@ -555,7 +555,6 @@ static struct idmap_methods rid_methods = { NTSTATUS init_module(void) { - return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "idmap_rid", &rid_methods); return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "rid", &rid_methods); } -- cgit From 22644d8797a962ade0064f6b46e7963ac5954ec2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 18:45:30 +0000 Subject: r12912: patch from Tony Mountifield for BUG 3327 (fix bad access to gencache.tdb after fork() in smbmount --- source/client/smbmount.c | 3 +++ source/lib/gencache.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/source/client/smbmount.c b/source/client/smbmount.c index 4438964b838..d8254ef23a7 100644 --- a/source/client/smbmount.c +++ b/source/client/smbmount.c @@ -386,6 +386,9 @@ static void send_fs_socket(char *the_service, char *mount_point, struct cli_stat c = NULL; if (!closed) { + /* close the name cache so that close_our_files() doesn't steal its FD */ + namecache_shutdown(); + /* redirect stdout & stderr since we can't know that the library functions we use are using DEBUG. */ if ( (fd = open("/dev/null", O_WRONLY)) < 0) diff --git a/source/lib/gencache.c b/source/lib/gencache.c index 85599c92d33..fd44616270c 100644 --- a/source/lib/gencache.c +++ b/source/lib/gencache.c @@ -83,10 +83,13 @@ BOOL gencache_init(void) BOOL gencache_shutdown(void) { + int ret; /* tdb_close routine returns -1 on error */ if (!cache) return False; DEBUG(5, ("Closing cache file\n")); - return tdb_close(cache) != -1; + ret = tdb_close(cache); + cache = NULL; + return ret != -1; } -- cgit From 32a0807701f4c2b2d09ae08fabd25f1a06c8cb19 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 19:38:09 +0000 Subject: r12913: missed merge to fix BUG 3391; ensure we can lookup account policies --- source/passdb/passdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/passdb/passdb.c b/source/passdb/passdb.c index ac4d2555978..f9f6021d81b 100644 --- a/source/passdb/passdb.c +++ b/source/passdb/passdb.c @@ -2400,13 +2400,16 @@ BOOL pdb_increment_bad_password_count(SAM_ACCOUNT *sampass) { uint32 account_policy_lockout; BOOL autolock_updated = False, badpw_updated = False; + BOOL ret; if (!sampass) return False; /* Retrieve the account lockout policy */ - if (!pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT, - &account_policy_lockout)) { + become_root(); + ret = pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT, &account_policy_lockout); + unbecome_root(); + if ( !ret ) { DEBUG(0, ("pdb_increment_bad_password_count: pdb_get_account_policy failed.\n")); return False; } -- cgit From 742407e9290105a602fbfbcd790f189317392e6e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 20:24:50 +0000 Subject: r12914: adding query/set ops for security descriptors on services. --- source/include/rpc_svcctl.h | 33 +++++++++++- source/rpc_parse/parse_svcctl.c | 103 ++++++++++++++++++++++++++++++++++++++ source/rpc_server/srv_svcctl.c | 52 ++++++++++++++++++- source/rpc_server/srv_svcctl_nt.c | 92 ++++++++++++++++++++++++++++++++++ source/services/services_db.c | 47 +++++++++++++++++ 5 files changed, 324 insertions(+), 3 deletions(-) diff --git a/source/include/rpc_svcctl.h b/source/include/rpc_svcctl.h index 4a058999a38..8ca5e1772b8 100644 --- a/source/include/rpc_svcctl.h +++ b/source/include/rpc_svcctl.h @@ -27,8 +27,8 @@ #define SVCCTL_CLOSE_SERVICE 0x00 #define SVCCTL_CONTROL_SERVICE 0x01 #define SVCCTL_LOCK_SERVICE_DB 0x03 -#define SVCCTL_QUERY_SERVICE_SEC 0x04 /* not impmenented */ -#define SVCCTL_SET_SEVICE_SEC 0x05 /* not implemented */ +#define SVCCTL_QUERY_SERVICE_SEC 0x04 +#define SVCCTL_SET_SERVICE_SEC 0x05 #define SVCCTL_QUERY_STATUS 0x06 #define SVCCTL_UNLOCK_SERVICE_DB 0x08 #define SVCCTL_ENUM_DEPENDENT_SERVICES_W 0x0d @@ -385,5 +385,34 @@ typedef struct { WERROR status; } SVCCTL_R_UNLOCK_SERVICE_DB; + +/**************************/ + +typedef struct { + POLICY_HND handle; + uint32 security_flags; + uint32 buffer_size; +} SVCCTL_Q_QUERY_SERVICE_SEC; + +typedef struct { + RPC_BUFFER buffer; + uint32 needed; + WERROR status; +} SVCCTL_R_QUERY_SERVICE_SEC; + +/**************************/ + +typedef struct { + POLICY_HND handle; + uint32 security_flags; + RPC_BUFFER buffer; + uint32 buffer_size; +} SVCCTL_Q_SET_SERVICE_SEC; + +typedef struct { + WERROR status; +} SVCCTL_R_SET_SERVICE_SEC; + + #endif /* _RPC_SVCCTL_H */ diff --git a/source/rpc_parse/parse_svcctl.c b/source/rpc_parse/parse_svcctl.c index dd0c68bd797..2cb44c63195 100644 --- a/source/rpc_parse/parse_svcctl.c +++ b/source/rpc_parse/parse_svcctl.c @@ -1029,6 +1029,109 @@ BOOL svcctl_io_r_unlock_service_db(const char *desc, SVCCTL_R_UNLOCK_SERVICE_DB return True; } +/******************************************************************* +********************************************************************/ + +BOOL svcctl_io_q_query_service_sec(const char *desc, SVCCTL_Q_QUERY_SERVICE_SEC *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_query_service_sec"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("security_flags", ps, depth, &q_u->security_flags)) + return False; + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + return True; + +} + +/******************************************************************* +********************************************************************/ + +BOOL svcctl_io_r_query_service_sec(const char *desc, SVCCTL_R_QUERY_SERVICE_SEC *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_query_service_sec"); + depth++; + + if(!prs_align(ps)) + return False; + + if (!prs_rpcbuffer("buffer", ps, depth, &r_u->buffer)) + return False; + + if(!prs_uint32("needed", ps, depth, &r_u->needed)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + +/******************************************************************* +********************************************************************/ + +BOOL svcctl_io_q_set_service_sec(const char *desc, SVCCTL_Q_SET_SERVICE_SEC *q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_q_set_service_sec"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!smb_io_pol_hnd("handle", &q_u->handle, ps, depth)) + return False; + if(!prs_uint32("security_flags", ps, depth, &q_u->security_flags)) + return False; + + if (!prs_rpcbuffer("buffer", ps, depth, &q_u->buffer)) + return False; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size)) + return False; + + return True; + +} + +/******************************************************************* +********************************************************************/ + +BOOL svcctl_io_r_set_service_sec(const char *desc, SVCCTL_R_SET_SERVICE_SEC *r_u, prs_struct *ps, int depth) +{ + if ( !r_u ) + return False; + + prs_debug(ps, depth, desc, "svcctl_io_r_set_service_sec"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_werror("status", ps, depth, &r_u->status)) + return False; + + return True; +} + diff --git a/source/rpc_server/srv_svcctl.c b/source/rpc_server/srv_svcctl.c index 31d8bbe9b3d..74ae3aaa16f 100644 --- a/source/rpc_server/srv_svcctl.c +++ b/source/rpc_server/srv_svcctl.c @@ -358,6 +358,54 @@ static BOOL api_svcctl_unlock_service_db(pipes_struct *p) return True; } +/******************************************************************* + ********************************************************************/ + +static BOOL api_svcctl_query_security_sec(pipes_struct *p) +{ + SVCCTL_Q_QUERY_SERVICE_SEC q_u; + SVCCTL_R_QUERY_SERVICE_SEC r_u; + prs_struct *data = &p->in_data.data; + prs_struct *rdata = &p->out_data.rdata; + + ZERO_STRUCT(q_u); + ZERO_STRUCT(r_u); + + if(!svcctl_io_q_query_service_sec("", &q_u, data, 0)) + return False; + + r_u.status = _svcctl_query_service_sec(p, &q_u, &r_u); + + if(!svcctl_io_r_query_service_sec("", &r_u, rdata, 0)) + return False; + + return True; +} + +/******************************************************************* + ********************************************************************/ + +static BOOL api_svcctl_set_security_sec(pipes_struct *p) +{ + SVCCTL_Q_SET_SERVICE_SEC q_u; + SVCCTL_R_SET_SERVICE_SEC r_u; + prs_struct *data = &p->in_data.data; + prs_struct *rdata = &p->out_data.rdata; + + ZERO_STRUCT(q_u); + ZERO_STRUCT(r_u); + + if(!svcctl_io_q_set_service_sec("", &q_u, data, 0)) + return False; + + r_u.status = _svcctl_set_service_sec(p, &q_u, &r_u); + + if(!svcctl_io_r_set_service_sec("", &r_u, rdata, 0)) + return False; + + return True; +} + /******************************************************************* \PIPE\svcctl commands @@ -378,7 +426,9 @@ static struct api_struct api_svcctl_cmds[] = { "SVCCTL_CONTROL_SERVICE" , SVCCTL_CONTROL_SERVICE , api_svcctl_control_service }, { "SVCCTL_QUERY_SERVICE_STATUSEX_W" , SVCCTL_QUERY_SERVICE_STATUSEX_W , api_svcctl_query_service_status_ex }, { "SVCCTL_LOCK_SERVICE_DB" , SVCCTL_LOCK_SERVICE_DB , api_svcctl_lock_service_db }, - { "SVCCTL_UNLOCK_SERVICE_DB" , SVCCTL_UNLOCK_SERVICE_DB , api_svcctl_unlock_service_db } + { "SVCCTL_UNLOCK_SERVICE_DB" , SVCCTL_UNLOCK_SERVICE_DB , api_svcctl_unlock_service_db }, + { "SVCCTL_QUERY_SERVICE_SEC" , SVCCTL_QUERY_SERVICE_SEC , api_svcctl_query_security_sec }, + { "SVCCTL_SET_SERVICE_SEC" , SVCCTL_SET_SERVICE_SEC , api_svcctl_set_security_sec } }; diff --git a/source/rpc_server/srv_svcctl_nt.c b/source/rpc_server/srv_svcctl_nt.c index 97c38753c33..4db8f7ed3f7 100644 --- a/source/rpc_server/srv_svcctl_nt.c +++ b/source/rpc_server/srv_svcctl_nt.c @@ -771,3 +771,95 @@ WERROR _svcctl_unlock_service_db( pipes_struct *p, SVCCTL_Q_UNLOCK_SERVICE_DB *q return close_policy_hnd( p, &q_u->h_lock) ? WERR_OK : WERR_BADFID; } + +/******************************************************************** +********************************************************************/ + +WERROR _svcctl_query_service_sec( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_SEC *q_u, SVCCTL_R_QUERY_SERVICE_SEC *r_u ) +{ + SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle ); + SEC_DESC *sec_desc; + + + /* only support the SCM and individual services */ + + if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) ) + return WERR_BADFID; + + /* check access reights (according to MSDN) */ + + if ( !(info->access_granted & STD_RIGHT_READ_CONTROL_ACCESS) ) + return WERR_ACCESS_DENIED; + + /* TODO: handle something besides DACL_SECURITY_INFORMATION */ + + if ( (q_u->security_flags & DACL_SECURITY_INFORMATION) != DACL_SECURITY_INFORMATION ) + return WERR_INVALID_PARAM; + + /* lookup the security descriptor and marshall it up for a reply */ + + if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, info->name, get_root_nt_token() )) ) + return WERR_NOMEM; + + r_u->needed = sec_desc_size( sec_desc ); + + if ( r_u->needed > q_u->buffer_size ) { + ZERO_STRUCTP( &r_u->buffer ); + return WERR_INSUFFICIENT_BUFFER; + } + + rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx ); + + if ( !sec_io_desc("", &sec_desc, &r_u->buffer.prs, 0 ) ) + return WERR_NOMEM; + + return WERR_OK; +} + +/******************************************************************** +********************************************************************/ + +WERROR _svcctl_set_service_sec( pipes_struct *p, SVCCTL_Q_SET_SERVICE_SEC *q_u, SVCCTL_R_SET_SERVICE_SEC *r_u ) +{ + SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle ); + SEC_DESC *sec_desc = NULL; + uint32 required_access; + + if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) ) + return WERR_BADFID; + + /* check the access on the open handle */ + + switch ( q_u->security_flags ) { + case DACL_SECURITY_INFORMATION: + required_access = STD_RIGHT_WRITE_DAC_ACCESS; + break; + + case OWNER_SECURITY_INFORMATION: + case GROUP_SECURITY_INFORMATION: + required_access = STD_RIGHT_WRITE_OWNER_ACCESS; + break; + + case SACL_SECURITY_INFORMATION: + return WERR_INVALID_PARAM; + default: + return WERR_INVALID_PARAM; + } + + if ( !(info->access_granted & required_access) ) + return WERR_ACCESS_DENIED; + + /* read the security descfriptor */ + + if ( !sec_io_desc("", &sec_desc, &q_u->buffer.prs, 0 ) ) + return WERR_NOMEM; + + /* store the new SD */ + + if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc, p->pipe_user.nt_user_token ) ) + return WERR_ACCESS_DENIED; + + return WERR_OK; +} + + diff --git a/source/services/services_db.c b/source/services/services_db.c index b3ba7fcc966..a16657c0edc 100644 --- a/source/services/services_db.c +++ b/source/services/services_db.c @@ -519,6 +519,53 @@ SEC_DESC* svcctl_get_secdesc( TALLOC_CTX *ctx, const char *name, NT_USER_TOKEN * return ret_sd; } +/******************************************************************** + Wrapper to make storing a Service sd easier +********************************************************************/ + +BOOL svcctl_set_secdesc( TALLOC_CTX *ctx, const char *name, SEC_DESC *sec_desc, NT_USER_TOKEN *token ) +{ + REGISTRY_KEY *key; + WERROR wresult; + pstring path; + REGVAL_CTR *values; + prs_struct ps; + BOOL ret = False; + + /* now add the security descriptor */ + + pstr_sprintf( path, "%s\\%s\\%s", KEY_SERVICES, name, "Security" ); + wresult = regkey_open_internal( &key, path, token, REG_KEY_ALL ); + if ( !W_ERROR_IS_OK(wresult) ) { + DEBUG(0,("svcctl_get_secdesc: key lookup failed! [%s] (%s)\n", + path, dos_errstr(wresult))); + return False; + } + + if ( !(values = TALLOC_ZERO_P( key, REGVAL_CTR )) ) { + DEBUG(0,("add_new_svc_name: talloc() failed!\n")); + regkey_close_internal( key ); + return False; + } + + /* stream the printer security descriptor */ + + prs_init( &ps, RPC_MAX_PDU_FRAG_LEN, key, MARSHALL); + + if ( sec_io_desc("sec_desc", &sec_desc, &ps, 0 ) ) { + uint32 offset = prs_offset( &ps ); + regval_ctr_addvalue( values, "Security", REG_BINARY, prs_data_p(&ps), offset ); + ret = store_reg_values( key, values ); + } + + /* cleanup */ + + prs_mem_free( &ps ); + regkey_close_internal( key); + + return ret; +} + /******************************************************************** ********************************************************************/ -- cgit From 489e6b464e5ee827409219d3d0c874170e0126ab Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 20:26:59 +0000 Subject: r12915: protect against changing the SCM security descriptor --- source/rpc_server/srv_svcctl_nt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/rpc_server/srv_svcctl_nt.c b/source/rpc_server/srv_svcctl_nt.c index 4db8f7ed3f7..049bdf60756 100644 --- a/source/rpc_server/srv_svcctl_nt.c +++ b/source/rpc_server/srv_svcctl_nt.c @@ -828,6 +828,11 @@ WERROR _svcctl_set_service_sec( pipes_struct *p, SVCCTL_Q_SET_SERVICE_SEC *q_u, if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) ) return WERR_BADFID; + /* can't set the security de4scriptor on the ServiceControlManager */ + + if ( info->type == SVC_HANDLE_IS_SCM ) + return WERR_ACCESS_DENIED; + /* check the access on the open handle */ switch ( q_u->security_flags ) { -- cgit From 57d94d3d83b0f7e8775fe630346c66cd9a4abb75 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 13 Jan 2006 21:22:25 +0000 Subject: r12916: use rpcstr_pull() instead of unistr_to_ascii() when validating share names --- source/rpc_server/srv_srvsvc_nt.c | 10 +++------- source/smbd/uid.c | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index 090aa4c9ff2..230f0626628 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -1,5 +1,5 @@ - /* - * Unix SMB/CIFS implementation. +/* + * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1997, * Copyright (C) Jeremy Allison 2001. @@ -2312,11 +2312,7 @@ WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV switch ( q_u->type ) { case 0x9: - /* Run the name through alpha_strcpy() to remove any unsafe - shell characters. Compare the copied string with the original - and fail if the strings don't match */ - - unistr2_to_ascii(sharename, &q_u->uni_name, sizeof(sharename)); + rpcstr_pull(sharename, q_u->uni_name.buffer, sizeof(sharename), q_u->uni_name.uni_str_len*2, 0); if ( !validate_net_name( sharename, INVALID_SHARENAME_CHARS, sizeof(sharename) ) ) { DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", sharename)); return WERR_INVALID_NAME; diff --git a/source/smbd/uid.c b/source/smbd/uid.c index 458eb3a2c86..9db3d97ab2d 100644 --- a/source/smbd/uid.c +++ b/source/smbd/uid.c @@ -190,7 +190,7 @@ static BOOL check_user_ok(connection_struct *conn, user_struct *vuser,int snum) /**************************************************************************** Become the user of a connection number without changing the security context - stack, but modify the currnet_user entries. + stack, but modify the current_user entries. ****************************************************************************/ BOOL change_to_user(connection_struct *conn, uint16 vuid) -- cgit From 60ecfbb046b77c1be9656b6e69affc06668e134c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Jan 2006 23:23:09 +0000 Subject: r12920: Fix for #3401 from Andrew Bartlett. Original fix from Yau Lam Yiu . Jeremy. --- source/libsmb/ntlmssp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libsmb/ntlmssp.c b/source/libsmb/ntlmssp.c index 0becc7fdee3..6dd623047a0 100644 --- a/source/libsmb/ntlmssp.c +++ b/source/libsmb/ntlmssp.c @@ -384,6 +384,11 @@ static void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state, void ntlmssp_weaken_keys(NTLMSSP_STATE *ntlmssp_state) { + /* Nothing to weaken. We certainly don't want to 'extend' the length... */ + if (!ntlmssp_state->session_key.length < 8) { + return; + } + /* Key weakening not performed on the master key for NTLM2 and does not occour for NTLM1. Therefore we only need to do this for the LM_KEY. -- cgit From cd1f0b09a54bb3bd11646615804f6bc8f20a1d91 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Jan 2006 23:54:12 +0000 Subject: r12922: Fix typo. Jeremy. --- source/libsmb/ntlmssp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libsmb/ntlmssp.c b/source/libsmb/ntlmssp.c index 6dd623047a0..c891ede9bb7 100644 --- a/source/libsmb/ntlmssp.c +++ b/source/libsmb/ntlmssp.c @@ -385,7 +385,7 @@ static void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state, void ntlmssp_weaken_keys(NTLMSSP_STATE *ntlmssp_state) { /* Nothing to weaken. We certainly don't want to 'extend' the length... */ - if (!ntlmssp_state->session_key.length < 8) { + if (ntlmssp_state->session_key.length < 8) { return; } -- cgit From 3511c376402da620f4203658ca0d6f6b7b64c8a1 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Sat, 14 Jan 2006 12:37:25 +0000 Subject: r12935: After discussion with Volker fix bug #3397 using a variant of the patch by Alex Deiter (tiamat@komi.mts.ru). Introduces level 9 of getuserinfo and allows to successfully install MS SMS2003 on a member of a Samba domain. Also added support for this level in rpcclient. The code for infolevel 9 is modelled upon Samba-TNG by Alex Deiter. Jerry, we need this in 3.0.21b. --- source/include/rpc_samr.h | 9 +++++++ source/rpc_parse/parse_samr.c | 42 ++++++++++++++++++++++++++++++++ source/rpc_server/srv_samr_nt.c | 53 +++++++++++++++++++++++++++++++++++++++-- source/rpcclient/cmd_samr.c | 11 +++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) diff --git a/source/include/rpc_samr.h b/source/include/rpc_samr.h index 5555aaef0e4..342db37ea57 100644 --- a/source/include/rpc_samr.h +++ b/source/include/rpc_samr.h @@ -408,6 +408,7 @@ typedef struct sam_user_info_16 } SAM_USER_INFO_16; + /* SAM_USER_INFO_7 */ typedef struct sam_user_info_7 { @@ -417,6 +418,13 @@ typedef struct sam_user_info_7 } SAM_USER_INFO_7; +/* SAM_USER_INFO_9 */ +typedef struct sam_user_info_9 +{ + uint32 rid_group; /* Primary Group RID */ +} SAM_USER_INFO_9; + + /* SAMR_Q_CLOSE_HND - probably a policy handle close */ typedef struct q_samr_close_hnd_info { @@ -1255,6 +1263,7 @@ typedef struct sam_userinfo_ctr_info union { SAM_USER_INFO_7 *id7; + SAM_USER_INFO_9 *id9; SAM_USER_INFO_16 *id16; SAM_USER_INFO_17 *id17; SAM_USER_INFO_18 *id18; diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index 0a055ff826a..6c2b4f4ea71 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -5182,6 +5182,39 @@ static BOOL sam_io_user_info7(const char *desc, SAM_USER_INFO_7 * usr, return True; } +/******************************************************************* +inits a SAM_USER_INFO_9 structure. +********************************************************************/ + +void init_sam_user_info9(SAM_USER_INFO_9 * usr, uint32 rid_group) +{ + DEBUG(5, ("init_sam_user_info9\n")); + + usr->rid_group = rid_group; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ + +static BOOL sam_io_user_info9(const char *desc, SAM_USER_INFO_9 * usr, + prs_struct *ps, int depth) +{ + if (usr == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_user_info9"); + depth++; + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("rid_group", ps, depth, &usr->rid_group)) + return False; + + return True; +} + /******************************************************************* inits a SAM_USER_INFO_16 structure. ********************************************************************/ @@ -6354,6 +6387,15 @@ static BOOL samr_io_userinfo_ctr(const char *desc, SAM_USERINFO_CTR **ppctr, } ret = sam_io_user_info7("", ctr->info.id7, ps, depth); break; + case 9: + if (UNMARSHALLING(ps)) + ctr->info.id9 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_9,1); + if (ctr->info.id9 == NULL) { + DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n")); + return False; + } + ret = sam_io_user_info9("", ctr->info.id9, ps, depth); + break; case 16: if (UNMARSHALLING(ps)) ctr->info.id16 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_16,1); diff --git a/source/rpc_server/srv_samr_nt.c b/source/rpc_server/srv_samr_nt.c index c90b4d36600..8f8c035c9cd 100644 --- a/source/rpc_server/srv_samr_nt.c +++ b/source/rpc_server/srv_samr_nt.c @@ -1672,6 +1672,41 @@ static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx, SAM_USER_INFO_7 *id7, DOM_S return NT_STATUS_OK; } + +/************************************************************************* + get_user_info_9. Only gives out primary group SID. + *************************************************************************/ +static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx, SAM_USER_INFO_9 * id9, DOM_SID *user_sid) +{ + SAM_ACCOUNT *smbpass=NULL; + BOOL ret; + NTSTATUS nt_status; + + nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass); + + if (!NT_STATUS_IS_OK(nt_status)) { + return nt_status; + } + + become_root(); + ret = pdb_getsampwsid(smbpass, user_sid); + unbecome_root(); + + if (ret==False) { + DEBUG(4,("User %s not found\n", sid_string_static(user_sid))); + return NT_STATUS_NO_SUCH_USER; + } + + DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) )); + + ZERO_STRUCTP(id9); + init_sam_user_info9(id9, pdb_get_group_rid(smbpass) ); + + pdb_free_sam(&smbpass); + + return NT_STATUS_OK; +} + /************************************************************************* get_user_info_16. Safe. Only gives out acb bits. *************************************************************************/ @@ -1864,6 +1899,8 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ /* ok! user info levels (lots: see MSDEV help), off we go... */ ctr->switch_value = q_u->switch_value; + DEBUG(5,("_samr_query_userinfo: user info level: %d\n", q_u->switch_value)); + switch (q_u->switch_value) { case 7: ctr->info.id7 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_7); @@ -1873,6 +1910,14 @@ NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_ if (!NT_STATUS_IS_OK(r_u->status = get_user_info_7(p->mem_ctx, ctr->info.id7, &info->sid))) return r_u->status; break; + case 9: + ctr->info.id9 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_9); + if (ctr->info.id9 == NULL) + return NT_STATUS_NO_MEMORY; + + if (!NT_STATUS_IS_OK(r_u->status = get_user_info_9(p->mem_ctx, ctr->info.id9, &info->sid))) + return r_u->status; + break; case 16: ctr->info.id16 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_16); if (ctr->info.id16 == NULL) @@ -2677,8 +2722,12 @@ NTSTATUS _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_ ZERO_STRUCT(sid); - if (!secrets_fetch_domain_sid(domain_name, &sid)) { - r_u->status = NT_STATUS_NO_SUCH_DOMAIN; + if (strequal(domain_name, builtin_domain_name())) { + sid_copy(&sid, &global_sid_Builtin); + } else { + if (!secrets_fetch_domain_sid(domain_name, &sid)) { + r_u->status = NT_STATUS_NO_SUCH_DOMAIN; + } } DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name, sid_string_static(&sid))); diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index e711cc7d1c0..991b55a13c8 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -38,6 +38,14 @@ static void display_sam_user_info_7(SAM_USER_INFO_7 *usr) printf("\tUser Name :\t%s\n", temp); } +/**************************************************************************** + display sam_user_info_9 structure + ****************************************************************************/ +static void display_sam_user_info_9(SAM_USER_INFO_9 *usr) +{ + printf("\tPrimary group RID :\tox%x\n", usr->rid_group); +} + /**************************************************************************** display sam_user_info_21 structure ****************************************************************************/ @@ -398,6 +406,9 @@ static NTSTATUS cmd_samr_query_user(struct rpc_pipe_client *cli, case 7: display_sam_user_info_7(user_ctr->info.id7); break; + case 9: + display_sam_user_info_9(user_ctr->info.id9); + break; default: printf("Unsupported infolevel: %d\n", info_level); break; -- cgit From 899deef9831b090aba832dd511a2f805d28c0f3c Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Sat, 14 Jan 2006 15:25:33 +0000 Subject: r12936: Fix bug #3264. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we detect a leading 'idmap_' for the idmap backend setting we strip this and inform about the deprecated config with DEBUG 0. I'm not sure if we should set a TTL of one year or five additional releases from now for this code. This is required for the changes Günther made as the first step to solve bug #3264. With this fix we can even run with an old config. This is very important as we else will break existing configurations with an update. --- source/sam/idmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/sam/idmap.c b/source/sam/idmap.c index ec3ccb29859..900f25f9c11 100644 --- a/source/sam/idmap.c +++ b/source/sam/idmap.c @@ -128,6 +128,12 @@ BOOL idmap_init(const char **remote_backend) pparams++; fstrcpy( params, pparams ); } + + /* strip any leading idmap_ prefix of */ + if ( strncmp( rem_backend, "idmap_", 6) == 0 ) { + rem_backend += 6; + DEBUG(0, ("idmap_init: idmap backend uses deprecated 'idmap_' prefix. Please replace 'idmap_%s' by '%s' in %s\n", rem_backend, rem_backend, dyn_CONFIGFILE)); + } DEBUG(3, ("idmap_init: using '%s' as remote backend\n", rem_backend)); -- cgit From dc8eeb96a03c1f02ebccec5670ef86fa7130d386 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 14 Jan 2006 20:25:51 +0000 Subject: r12938: Fix for #3408 (change password fails) from William Jojo . Jeremy. --- source/smbd/chgpasswd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/smbd/chgpasswd.c b/source/smbd/chgpasswd.c index fed73db043f..5a179dbf478 100644 --- a/source/smbd/chgpasswd.c +++ b/source/smbd/chgpasswd.c @@ -153,9 +153,13 @@ static int dochild(int master, const char *slavedev, const struct passwd *pass, DEBUG(3, ("More weirdness, could not open %s\n", slavedev)); return (False); } -#ifdef I_PUSH - ioctl(slave, I_PUSH, "ptem"); - ioctl(slave, I_PUSH, "ldterm"); +#if defined(I_PUSH) && defined(I_FIND) + if (ioctl(slave, I_FIND, "ptem") == 0) { + ioctl(slave, I_PUSH, "ptem"); + } + if (ioctl(slave, I_FIND, "ldterm") == 0) { + ioctl(slave, I_PUSH, "ldterm"); + } #elif defined(TIOCSCTTY) if (ioctl(slave, TIOCSCTTY, 0) < 0) { -- cgit From 44e77e78cacd24fe69f9e49330f9a150b3d6f394 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 15 Jan 2006 12:30:36 +0000 Subject: r12946: fix a segfault in nmbd when 'wins support = yes' caused by double free --- source/nmbd/nmbd_namelistdb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/nmbd/nmbd_namelistdb.c b/source/nmbd/nmbd_namelistdb.c index 894b8776134..baaf5dbd548 100644 --- a/source/nmbd/nmbd_namelistdb.c +++ b/source/nmbd/nmbd_namelistdb.c @@ -82,9 +82,11 @@ void remove_name_from_namelist(struct subnet_record *subrec, { if (subrec == wins_server_subnet) { remove_name_from_wins_namelist(namerec); - } else { - subrec->namelist_changed = True; - } + return; + } + + subrec->namelist_changed = True; + DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); -- cgit From 02d1df5e1d5343831542567027ccaf3f288655d5 Mon Sep 17 00:00:00 2001 From: James Peach Date: Sun, 15 Jan 2006 23:09:17 +0000 Subject: r12951: Tell the MIPSPro compiler to push DEBUG calls out of line. --- source/include/debug.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/include/debug.h b/source/include/debug.h index 99c96e6bb18..b6fb50a9acb 100644 --- a/source/include/debug.h +++ b/source/include/debug.h @@ -43,6 +43,12 @@ int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2); BOOL dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2); BOOL dbghdr( int level, const char *file, const char *func, int line ); +#if defined(sgi) && (_COMPILER_VERSION >= 730) +#pragma mips_frequency_hint NEVER Debug1 +#pragma mips_frequency_hint NEVER dbgtext +#pragma mips_frequency_hint NEVER dbghdr +#endif + extern XFILE *dbf; extern pstring debugf; -- cgit From 977d31d860607fa7d2e3dcde0aeea9d0f1696e18 Mon Sep 17 00:00:00 2001 From: James Peach Date: Sun, 15 Jan 2006 23:13:47 +0000 Subject: r12953: Support the TCP_FASTACK socket option if it is available. Note that this will not acutally help, but it is good to be complete. --- source/lib/util_sock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c index 6562dae952b..91c3305996e 100644 --- a/source/lib/util_sock.c +++ b/source/lib/util_sock.c @@ -180,6 +180,9 @@ static const smb_socket_option socket_options[] = { #endif #ifdef SO_RCVTIMEO {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, +#endif +#ifdef TCP_FASTACK + {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT}, #endif {NULL,0,0,0,0}}; -- cgit From e2ddad2651da35690918be254fd94ee65d63a39d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 16 Jan 2006 05:47:39 +0000 Subject: r12956: Fix for bug #3035 from SATOH Fumiyasu On a Windows share, a file with read-only dosmode can be opened with DELETE_ACCESS. But on a Samba share (delete readonly = no), it fails with NT_STATUS_CANNOT_DELETE error. This semantic causes a problem that a user can not rename a file with read-only dosmode on a Samba share from a Windows command prompt (i.e. cmd.exe, but can rename from Windows Explorer). Jeremy. --- source/smbd/reply.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/smbd/reply.c b/source/smbd/reply.c index d56e3c1f1ce..69c71c74b59 100644 --- a/source/smbd/reply.c +++ b/source/smbd/reply.c @@ -1888,7 +1888,19 @@ NTSTATUS can_delete(connection_struct *conn, char *fname, uint32 dirtype, BOOL b return NT_STATUS_OBJECT_NAME_INVALID; #endif /* JRATEST */ - if (!lp_delete_readonly(SNUM(conn))) { + /* Fix for bug #3035 from SATOH Fumiyasu + + On a Windows share, a file with read-only dosmode can be opened with + DELETE_ACCESS. But on a Samba share (delete readonly = no), it + fails with NT_STATUS_CANNOT_DELETE error. + + This semantic causes a problem that a user can not + rename a file with read-only dosmode on a Samba share + from a Windows command prompt (i.e. cmd.exe, but can rename + from Windows Explorer). + */ + + if (!check_is_at_open && !lp_delete_readonly(SNUM(conn))) { if (fattr & aRONLY) { return NT_STATUS_CANNOT_DELETE; } -- cgit From 855a6a33b3cea614cd167e59e6e2fb47d32b33b1 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Mon, 16 Jan 2006 17:21:47 +0000 Subject: r12964: Rewind rem_backend in the case we have to workaround the idmap_ prefix. Else SAFE_FREE seg faults. Thanks to Günther for pointing me at this. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've implemented in in this was as we should announce to remove the idmap_ strip stuff after some time at all. --- source/sam/idmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/sam/idmap.c b/source/sam/idmap.c index 900f25f9c11..9fc1a573a92 100644 --- a/source/sam/idmap.c +++ b/source/sam/idmap.c @@ -120,6 +120,7 @@ BOOL idmap_init(const char **remote_backend) char *rem_backend = smb_xstrdup(*remote_backend); fstring params = ""; char *pparams; + BOOL idmap_prefix_workaround = False; /* get any mode parameters passed in */ @@ -132,6 +133,7 @@ BOOL idmap_init(const char **remote_backend) /* strip any leading idmap_ prefix of */ if ( strncmp( rem_backend, "idmap_", 6) == 0 ) { rem_backend += 6; + idmap_prefix_workaround = True; DEBUG(0, ("idmap_init: idmap backend uses deprecated 'idmap_' prefix. Please replace 'idmap_%s' by '%s' in %s\n", rem_backend, rem_backend, dyn_CONFIGFILE)); } @@ -146,9 +148,13 @@ BOOL idmap_init(const char **remote_backend) } } else { DEBUG(0, ("idmap_init: could not load remote backend '%s'\n", rem_backend)); + if (idmap_prefix_workaround) + rem_backend -= 6; SAFE_FREE(rem_backend); return False; } + if (idmap_prefix_workaround) + rem_backend -= 6; SAFE_FREE(rem_backend); } -- cgit From da0ac8790f8bfd03ef63c1da691514bf8a72cc33 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 16 Jan 2006 18:03:56 +0000 Subject: r12967: BUG 1061: don't corrupt the file name when reading an lmhosts file (-H) in nmbd. Patch from Andrew Esh --- source/nmbd/nmbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c index 68004bad599..ea7e9a5288f 100644 --- a/source/nmbd/nmbd.c +++ b/source/nmbd/nmbd.c @@ -657,13 +657,14 @@ static BOOL open_sockets(BOOL isdaemon, int port) pstring logfile; static BOOL opt_interactive; poptContext pc; + static char *p_lmhosts = dyn_LMHOSTSFILE; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, - {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, + {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, POPT_COMMON_SAMBA { NULL } @@ -803,8 +804,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) } /* Load in any static local names. */ - load_lmhosts_file(dyn_LMHOSTSFILE); - DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE)); + load_lmhosts_file(p_lmhosts); + DEBUG(3,("Loaded hosts file %s\n", p_lmhosts)); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) { -- cgit From 15c858d6b73367c8dd99834a8afd8daf3853c3bd Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Tue, 17 Jan 2006 21:22:00 +0000 Subject: r12986: Use d_fprintf(stderr, ...) for any error message in net. All 'usage' messages are still printed to stdout. Fix some compiler warnings for system() calls where we didn't used the return code. Add appropriate error messages and return with the error code we got from system() or NT_STATUS_UNSUCCESSFUL. --- source/utils/net.c | 38 +++++++------- source/utils/net_ads.c | 88 ++++++++++++++++---------------- source/utils/net_ads_cldap.c | 12 ++--- source/utils/net_cache.c | 14 ++--- source/utils/net_groupmap.c | 78 ++++++++++++++-------------- source/utils/net_idmap.c | 28 +++++----- source/utils/net_rap.c | 2 +- source/utils/net_rpc.c | 110 ++++++++++++++++++++-------------------- source/utils/net_rpc_join.c | 8 +-- source/utils/net_rpc_printer.c | 24 ++++----- source/utils/net_rpc_registry.c | 30 ++++++----- source/utils/net_rpc_rights.c | 10 ++-- source/utils/net_rpc_samsync.c | 33 ++++++++---- source/utils/net_rpc_service.c | 32 ++++++------ source/utils/net_status.c | 16 +++--- source/utils/net_time.c | 10 ++-- 16 files changed, 278 insertions(+), 255 deletions(-) diff --git a/source/utils/net.c b/source/utils/net.c index 839f6f1b019..a2a9ac6a391 100644 --- a/source/utils/net.c +++ b/source/utils/net.c @@ -128,7 +128,7 @@ int net_run_function(int argc, const char **argv, struct functable *table, if (StrCaseCmp(argv[0], table[i].funcname) == 0) return table[i].fn(argc-1, argv+1); } - d_printf("No command: %s\n", argv[0]); + d_fprintf(stderr, "No command: %s\n", argv[0]); return usage_fn(argc, argv); } @@ -158,21 +158,21 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { - d_printf("Could not connect to server %s\n", server_name); + d_fprintf(stderr, "Could not connect to server %s\n", server_name); /* Display a nicer message depending on the result */ if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_LOGON_FAILURE)) - d_printf("The username or password was not correct.\n"); + d_fprintf(stderr, "The username or password was not correct.\n"); if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT)) - d_printf("The account was locked out.\n"); + d_fprintf(stderr, "The account was locked out.\n"); if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED)) - d_printf("The account was disabled.\n"); + d_fprintf(stderr, "The account was disabled.\n"); return nt_status; } @@ -257,7 +257,7 @@ int net_use_machine_password(void) char *user_name = NULL; if (!secrets_init()) { - d_printf("ERROR: Unable to open secrets database\n"); + d_fprintf(stderr, "ERROR: Unable to open secrets database\n"); exit(1); } @@ -362,7 +362,7 @@ struct cli_state *net_make_ipc_connection(unsigned flags) NTSTATUS nt_status; if (!net_find_server(flags, &server_ip, &server_name)) { - d_printf("\nUnable to find a suitable server\n"); + d_fprintf(stderr, "\nUnable to find a suitable server\n"); return NULL; } @@ -409,7 +409,7 @@ static int net_join(int argc, const char **argv) if (net_ads_join(argc, argv) == 0) return 0; else - d_printf("ADS join did not work, falling back to RPC...\n"); + d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n"); } return net_rpc_join(argc, argv); } @@ -431,7 +431,7 @@ static int net_changesecretpw(int argc, const char **argv) trust_pw = getpass("Enter machine password: "); if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) { - d_printf("Unable to write the machine account password in the secrets database"); + d_fprintf(stderr, "Unable to write the machine account password in the secrets database"); return 1; } else { @@ -486,7 +486,7 @@ static int net_getlocalsid(int argc, const char **argv) panic when we can't. */ if (!secrets_init()) { - d_printf("Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name); + d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name); return 1; } @@ -536,14 +536,14 @@ static int net_getdomainsid(int argc, const char **argv) get_global_sam_sid(); if (!secrets_fetch_domain_sid(global_myname(), &domain_sid)) { - d_printf("Could not fetch local SID\n"); + d_fprintf(stderr, "Could not fetch local SID\n"); return 1; } sid_to_string(sid_str, &domain_sid); d_printf("SID for domain %s is: %s\n", global_myname(), sid_str); if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) { - d_printf("Could not fetch domain SID\n"); + d_fprintf(stderr, "Could not fetch domain SID\n"); return 1; } @@ -575,22 +575,22 @@ static int net_afs_key(int argc, const char **argv) } if (!secrets_init()) { - d_printf("Could not open secrets.tdb\n"); + d_fprintf(stderr, "Could not open secrets.tdb\n"); return -1; } if ((fd = open(argv[0], O_RDONLY, 0)) < 0) { - d_printf("Could not open %s\n", argv[0]); + d_fprintf(stderr, "Could not open %s\n", argv[0]); return -1; } if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) { - d_printf("Could not read keyfile\n"); + d_fprintf(stderr, "Could not read keyfile\n"); return -1; } if (!secrets_store_afs_keyfile(argv[1], &keyfile)) { - d_printf("Could not write keyfile to secrets.tdb\n"); + d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n"); return -1; } @@ -642,7 +642,7 @@ static BOOL search_maxrid(struct pdb_search *search, const char *type, uint32 i, num_entries; if (search == NULL) { - d_printf("get_maxrid: Could not search %s\n", type); + d_fprintf(stderr, "get_maxrid: Could not search %s\n", type); return False; } @@ -799,7 +799,7 @@ static struct functable net_func[] = { case 'I': opt_dest_ip = *interpret_addr2(poptGetOptArg(pc)); if (is_zero_ip(opt_dest_ip)) - d_printf("\nInvalid ip address specified\n"); + d_fprintf(stderr, "\nInvalid ip address specified\n"); else opt_have_ip = True; break; @@ -813,7 +813,7 @@ static struct functable net_func[] = { } break; default: - d_printf("\nInvalid option %s: %s\n", + d_fprintf(stderr, "\nInvalid option %s: %s\n", poptBadOption(pc, 0), poptStrerror(opt)); net_help(argc, argv); exit(1); diff --git a/source/utils/net_ads.c b/source/utils/net_ads.c index 49a7f1cc2dd..f54896b3a82 100644 --- a/source/utils/net_ads.c +++ b/source/utils/net_ads.c @@ -78,7 +78,7 @@ static int net_ads_lookup(int argc, const char **argv) ads_connect(ads); if (!ads) { - d_printf("Didn't find the cldap server!\n"); + d_fprintf(stderr, "Didn't find the cldap server!\n"); return -1; } if (!ads->config.realm) { ads->config.realm = CONST_DISCARD(char *, opt_target_workgroup); @@ -108,7 +108,7 @@ static int net_ads_info(int argc, const char **argv) ads_connect(ads); if (!ads || !ads->config.realm) { - d_printf("Didn't find the ldap server!\n"); + d_fprintf(stderr, "Didn't find the ldap server!\n"); return -1; } @@ -229,7 +229,7 @@ static int net_ads_workgroup(int argc, const char **argv) } if (!ADS_ERR_OK(ads_workgroup_name(ads, ctx, &workgroup))) { - d_printf("Failed to find workgroup for realm '%s'\n", + d_fprintf(stderr, "Failed to find workgroup for realm '%s'\n", ads->config.realm); talloc_destroy(ctx); ads_destroy(&ads); @@ -295,12 +295,12 @@ static int ads_user_add(int argc, const char **argv) status = ads_find_user_acct(ads, &res, argv[0]); if (!ADS_ERR_OK(status)) { - d_printf("ads_user_add: %s\n", ads_errstr(status)); + d_fprintf(stderr, "ads_user_add: %s\n", ads_errstr(status)); goto done; } if (ads_count_replies(ads, res)) { - d_printf("ads_user_add: User %s already exists\n", argv[0]); + d_fprintf(stderr, "ads_user_add: User %s already exists\n", argv[0]); goto done; } @@ -311,7 +311,7 @@ static int ads_user_add(int argc, const char **argv) status = ads_add_user_acct(ads, argv[0], opt_container, opt_comment); if (!ADS_ERR_OK(status)) { - d_printf("Could not add user %s: %s\n", argv[0], + d_fprintf(stderr, "Could not add user %s: %s\n", argv[0], ads_errstr(status)); goto done; } @@ -335,7 +335,7 @@ static int ads_user_add(int argc, const char **argv) } /* password didn't set, delete account */ - d_printf("Could not add user %s. Error setting password %s\n", + d_fprintf(stderr, "Could not add user %s. Error setting password %s\n", argv[0], ads_errstr(status)); ads_msgfree(ads, res); status=ads_find_user_acct(ads, &res, argv[0]); @@ -373,7 +373,7 @@ static int ads_user_info(int argc, const char **argv) } if (!escaped_user) { - d_printf("ads_user_info: failed to escape user %s\n", argv[0]); + d_fprintf(stderr, "ads_user_info: failed to escape user %s\n", argv[0]); ads_destroy(&ads); return -1; } @@ -383,7 +383,7 @@ static int ads_user_info(int argc, const char **argv) safe_free(searchstring); if (!ADS_ERR_OK(rc)) { - d_printf("ads_search: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_search: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -436,7 +436,7 @@ static int ads_user_delete(int argc, const char **argv) ads_destroy(&ads); return 0; } - d_printf("Error deleting user %s: %s\n", argv[0], + d_fprintf(stderr, "Error deleting user %s: %s\n", argv[0], ads_errstr(rc)); ads_destroy(&ads); return -1; @@ -501,12 +501,12 @@ static int ads_group_add(int argc, const char **argv) status = ads_find_user_acct(ads, &res, argv[0]); if (!ADS_ERR_OK(status)) { - d_printf("ads_group_add: %s\n", ads_errstr(status)); + d_fprintf(stderr, "ads_group_add: %s\n", ads_errstr(status)); goto done; } if (ads_count_replies(ads, res)) { - d_printf("ads_group_add: Group %s already exists\n", argv[0]); + d_fprintf(stderr, "ads_group_add: Group %s already exists\n", argv[0]); ads_msgfree(ads, res); goto done; } @@ -521,7 +521,7 @@ static int ads_group_add(int argc, const char **argv) d_printf("Group %s added\n", argv[0]); rc = 0; } else { - d_printf("Could not add group %s: %s\n", argv[0], + d_fprintf(stderr, "Could not add group %s: %s\n", argv[0], ads_errstr(status)); } @@ -562,7 +562,7 @@ static int ads_group_delete(int argc, const char **argv) ads_destroy(&ads); return 0; } - d_printf("Error deleting group %s: %s\n", argv[0], + d_fprintf(stderr, "Error deleting group %s: %s\n", argv[0], ads_errstr(rc)); ads_destroy(&ads); return -1; @@ -614,13 +614,13 @@ static int net_ads_status(int argc, const char **argv) rc = ads_find_machine_acct(ads, &res, global_myname()); if (!ADS_ERR_OK(rc)) { - d_printf("ads_find_machine_acct: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_find_machine_acct: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } if (ads_count_replies(ads, res) == 0) { - d_printf("No machine account for '%s' found\n", global_myname()); + d_fprintf(stderr, "No machine account for '%s' found\n", global_myname()); ads_destroy(&ads); return -1; } @@ -650,7 +650,7 @@ static int net_ads_leave(int argc, const char **argv) rc = ads_leave_realm(ads, global_myname()); if (!ADS_ERR_OK(rc)) { - d_printf("Failed to delete host '%s' from the '%s' realm.\n", + d_fprintf(stderr, "Failed to delete host '%s' from the '%s' realm.\n", global_myname(), ads->config.realm); ads_destroy(&ads); return -1; @@ -734,13 +734,13 @@ int net_ads_join(int argc, const char **argv) } if (!*lp_realm()) { - d_printf("realm must be set in in smb.conf for ADS join to succeed.\n"); + d_fprintf(stderr, "realm must be set in in smb.conf for ADS join to succeed.\n"); ads_destroy(&ads); return -1; } if (strcmp(ads->config.realm, lp_realm()) != 0) { - d_printf("realm of remote server (%s) and realm in smb.conf (%s) DO NOT match. Aborting join\n", ads->config.realm, lp_realm()); + d_fprintf(stderr, "realm of remote server (%s) and realm in smb.conf (%s) DO NOT match. Aborting join\n", ads->config.realm, lp_realm()); ads_destroy(&ads); return -1; } @@ -753,7 +753,7 @@ int net_ads_join(int argc, const char **argv) ads_msgfree(ads, res); if (rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_NO_SUCH_OBJECT) { - d_printf("ads_join_realm: organizational unit %s does not exist (dn:%s)\n", + d_fprintf(stderr, "ads_join_realm: organizational unit %s does not exist (dn:%s)\n", org_unit, dn); ads_destroy(&ads); return -1; @@ -761,34 +761,34 @@ int net_ads_join(int argc, const char **argv) free(dn); if (!ADS_ERR_OK(rc)) { - d_printf("ads_join_realm: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_join_realm: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } rc = ads_join_realm(ads, global_myname(), account_type, org_unit); if (!ADS_ERR_OK(rc)) { - d_printf("ads_join_realm: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_join_realm: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } rc = ads_domain_sid(ads, &dom_sid); if (!ADS_ERR_OK(rc)) { - d_printf("ads_domain_sid: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_domain_sid: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } if (asprintf(&machine_account, "%s$", global_myname()) == -1) { - d_printf("asprintf failed\n"); + d_fprintf(stderr, "asprintf failed\n"); ads_destroy(&ads); return -1; } rc = ads_set_machine_password(ads, machine_account, password); if (!ADS_ERR_OK(rc)) { - d_printf("ads_set_machine_password: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_set_machine_password: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -796,7 +796,7 @@ int net_ads_join(int argc, const char **argv) /* make sure we get the right workgroup */ if ( !(ctx = talloc_init("net ads join")) ) { - d_printf("talloc_init() failed!\n"); + d_fprintf(stderr, "talloc_init() failed!\n"); ads_destroy(&ads); return -1; } @@ -904,14 +904,14 @@ static int net_ads_printer_search(int argc, const char **argv) rc = ads_find_printers(ads, &res); if (!ADS_ERR_OK(rc)) { - d_printf("ads_find_printer: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_find_printer: %s\n", ads_errstr(rc)); ads_msgfree(ads, res); ads_destroy(&ads); return -1; } if (ads_count_replies(ads, res) == 0) { - d_printf("No results found\n"); + d_fprintf(stderr, "No results found\n"); ads_msgfree(ads, res); ads_destroy(&ads); return -1; @@ -949,14 +949,14 @@ static int net_ads_printer_info(int argc, const char **argv) rc = ads_find_printer_on_server(ads, &res, printername, servername); if (!ADS_ERR_OK(rc)) { - d_printf("ads_find_printer_on_server: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_find_printer_on_server: %s\n", ads_errstr(rc)); ads_msgfree(ads, res); ads_destroy(&ads); return -1; } if (ads_count_replies(ads, res) == 0) { - d_printf("Printer '%s' not found\n", printername); + d_fprintf(stderr, "Printer '%s' not found\n", printername); ads_msgfree(ads, res); ads_destroy(&ads); return -1; @@ -1018,7 +1018,7 @@ static int net_ads_printer_publish(int argc, const char **argv) Undefined, NULL); if (NT_STATUS_IS_ERR(nt_status)) { - d_printf("Unable to open a connnection to %s to obtain data " + d_fprintf(stderr, "Unable to open a connnection to %s to obtain data " "for %s\n", servername, printername); ads_destroy(&ads); return -1; @@ -1029,7 +1029,7 @@ static int net_ads_printer_publish(int argc, const char **argv) ads_find_machine_acct(ads, &res, servername); if (ads_count_replies(ads, res) == 0) { - d_printf("Could not find machine account for server %s\n", + d_fprintf(stderr, "Could not find machine account for server %s\n", servername); ads_destroy(&ads); return -1; @@ -1046,7 +1046,7 @@ static int net_ads_printer_publish(int argc, const char **argv) rc = ads_add_printer_entry(ads, prt_dn, mem_ctx, &mods); if (!ADS_ERR_OK(rc)) { - d_printf("ads_publish_printer: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_publish_printer: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -1082,14 +1082,14 @@ static int net_ads_printer_remove(int argc, const char **argv) rc = ads_find_printer_on_server(ads, &res, argv[0], servername); if (!ADS_ERR_OK(rc)) { - d_printf("ads_find_printer_on_server: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_find_printer_on_server: %s\n", ads_errstr(rc)); ads_msgfree(ads, res); ads_destroy(&ads); return -1; } if (ads_count_replies(ads, res) == 0) { - d_printf("Printer '%s' not found\n", argv[1]); + d_fprintf(stderr, "Printer '%s' not found\n", argv[1]); ads_msgfree(ads, res); ads_destroy(&ads); return -1; @@ -1101,7 +1101,7 @@ static int net_ads_printer_remove(int argc, const char **argv) ads_memfree(ads, prt_dn); if (!ADS_ERR_OK(rc)) { - d_printf("ads_del_dn: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -1136,12 +1136,12 @@ static int net_ads_password(int argc, const char **argv) ADS_STATUS ret; if (opt_user_name == NULL || opt_password == NULL) { - d_printf("You must supply an administrator username/password\n"); + d_fprintf(stderr, "You must supply an administrator username/password\n"); return -1; } if (argc < 1) { - d_printf("ERROR: You must say which username to change password for\n"); + d_fprintf(stderr, "ERROR: You must say which username to change password for\n"); return -1; } @@ -1170,7 +1170,7 @@ static int net_ads_password(int argc, const char **argv) ads_connect(ads); if (!ads || !ads->config.realm) { - d_printf("Didn't find the kerberos server!\n"); + d_fprintf(stderr, "Didn't find the kerberos server!\n"); return -1; } @@ -1185,7 +1185,7 @@ static int net_ads_password(int argc, const char **argv) ret = kerberos_set_password(ads->auth.kdc_server, auth_principal, auth_password, user, new_password, ads->auth.time_offset); if (!ADS_ERR_OK(ret)) { - d_printf("Password change failed :-( ...\n"); + d_fprintf(stderr, "Password change failed :-( ...\n"); ads_destroy(&ads); return -1; } @@ -1224,7 +1224,7 @@ int net_ads_changetrustpw(int argc, const char **argv) ret = ads_change_trust_account_password(ads, host_principal); if (!ADS_ERR_OK(ret)) { - d_printf("Password change failed :-( ...\n"); + d_fprintf(stderr, "Password change failed :-( ...\n"); ads_destroy(&ads); SAFE_FREE(host_principal); return -1; @@ -1288,7 +1288,7 @@ static int net_ads_search(int argc, const char **argv) LDAP_SCOPE_SUBTREE, ldap_exp, attrs, &res); if (!ADS_ERR_OK(rc)) { - d_printf("search failed: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "search failed: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -1348,7 +1348,7 @@ static int net_ads_dn(int argc, const char **argv) LDAP_SCOPE_BASE, "(objectclass=*)", attrs, &res); if (!ADS_ERR_OK(rc)) { - d_printf("search failed: %s\n", ads_errstr(rc)); + d_fprintf(stderr, "search failed: %s\n", ads_errstr(rc)); ads_destroy(&ads); return -1; } @@ -1495,7 +1495,7 @@ int net_ads(int argc, const char **argv) static int net_ads_noads(void) { - d_printf("ADS support not compiled in\n"); + d_fprintf(stderr, "ADS support not compiled in\n"); return -1; } diff --git a/source/utils/net_ads_cldap.c b/source/utils/net_ads_cldap.c index 9f70a5b7257..2e7a28b3222 100644 --- a/source/utils/net_ads_cldap.c +++ b/source/utils/net_ads_cldap.c @@ -93,7 +93,7 @@ static unsigned pull_netlogon_string(char *ret, const char *ptr, uint8 len = (uint8)*(ptr++); if ((pret - ret + len + 1) >= MAX_DNS_LABEL) { - d_printf("DC returning too long DNS name\n"); + d_fprintf(stderr, "DC returning too long DNS name\n"); return 0; } @@ -178,13 +178,13 @@ static int send_cldap_netlogon(int sock, const char *domain, asn1_pop_tag(&data); if (data.has_error) { - d_printf("Failed to build cldap netlogon at offset %d\n", (int)data.ofs); + d_fprintf(stderr, "Failed to build cldap netlogon at offset %d\n", (int)data.ofs); asn1_free(&data); return -1; } if (write(sock, data.data, data.length) != (ssize_t)data.length) { - d_printf("failed to send cldap query (%s)\n", strerror(errno)); + d_fprintf(stderr, "failed to send cldap query (%s)\n", strerror(errno)); } asn1_free(&data); @@ -210,7 +210,7 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply) ret = read(sock, blob.data, blob.length); if (ret <= 0) { - d_printf("no reply received to cldap netlogon\n"); + d_fprintf(stderr, "no reply received to cldap netlogon\n"); return -1; } blob.length = ret; @@ -232,7 +232,7 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply) asn1_end_tag(&data); if (data.has_error) { - d_printf("Failed to parse cldap reply\n"); + d_fprintf(stderr, "Failed to parse cldap reply\n"); return -1; } @@ -284,7 +284,7 @@ int ads_cldap_netlogon(ADS_STRUCT *ads) sock = open_udp_socket(target, ads->ldap_port); if (sock == -1) { - d_printf("Failed to open udp socket to %s:%u\n", + d_fprintf(stderr, "Failed to open udp socket to %s:%u\n", inet_ntoa(ads->ldap_ip), ads->ldap_port); return -1; diff --git a/source/utils/net_cache.c b/source/utils/net_cache.c index 6bbab1c8177..0c107a5f01d 100644 --- a/source/utils/net_cache.c +++ b/source/utils/net_cache.c @@ -64,7 +64,7 @@ static void delete_cache_entry(const char* keystr, const char* datastr, const time_t timeout, void* dptr) { if (!gencache_del(keystr)) - d_printf("Couldn't delete entry! key = %s\n", keystr); + d_fprintf(stderr, "Couldn't delete entry! key = %s\n", keystr); } @@ -147,7 +147,7 @@ static int net_cache_add(int argc, const char **argv) /* parse timeout given in command line */ timeout = parse_timeout(timeout_str); if (!timeout) { - d_printf("Invalid timeout argument.\n"); + d_fprintf(stderr, "Invalid timeout argument.\n"); return -1; } @@ -157,7 +157,7 @@ static int net_cache_add(int argc, const char **argv) return 0; } - d_printf("Entry couldn't be added. Perhaps there's already such a key.\n"); + d_fprintf(stderr, "Entry couldn't be added. Perhaps there's already such a key.\n"); gencache_shutdown(); return -1; } @@ -187,7 +187,7 @@ static int net_cache_set(int argc, const char **argv) /* parse timeout given in command line */ timeout = parse_timeout(timeout_str); if (!timeout) { - d_printf("Invalid timeout argument.\n"); + d_fprintf(stderr, "Invalid timeout argument.\n"); return -1; } @@ -197,7 +197,7 @@ static int net_cache_set(int argc, const char **argv) return 0; } - d_printf("Entry couldn't be set. Perhaps there's no such a key.\n"); + d_fprintf(stderr, "Entry couldn't be set. Perhaps there's no such a key.\n"); gencache_shutdown(); return -1; } @@ -223,7 +223,7 @@ static int net_cache_del(int argc, const char **argv) return 0; } - d_printf("Couldn't delete specified entry\n"); + d_fprintf(stderr, "Couldn't delete specified entry\n"); return -1; } @@ -250,7 +250,7 @@ static int net_cache_get(int argc, const char **argv) return 0; } - d_printf("Failed to find entry\n"); + d_fprintf(stderr, "Failed to find entry\n"); return -1; } diff --git a/source/utils/net_groupmap.c b/source/utils/net_groupmap.c index 89bad6ea519..1cff120c393 100644 --- a/source/utils/net_groupmap.c +++ b/source/utils/net_groupmap.c @@ -122,19 +122,19 @@ static int net_groupmap_list(int argc, const char **argv) else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) { fstrcpy( ntgroup, get_string_param( argv[i] ) ); if ( !ntgroup[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) { fstrcpy( sid_string, get_string_param( argv[i] ) ); if ( !sid_string[0] ) { - d_printf("must supply a SID\n"); + d_fprintf(stderr, "must supply a SID\n"); return -1; } } else { - d_printf("Bad option: %s\n", argv[i]); + d_fprintf(stderr, "Bad option: %s\n", argv[i]); return -1; } } @@ -153,7 +153,7 @@ static int net_groupmap_list(int argc, const char **argv) /* Get the current mapping from the database */ if(!pdb_getgrsid(&map, sid)) { - d_printf("Failure to local group SID in the database\n"); + d_fprintf(stderr, "Failure to local group SID in the database\n"); return -1; } @@ -197,35 +197,35 @@ static int net_groupmap_add(int argc, const char **argv) if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) { rid = get_int_param(argv[i]); if ( rid < DOMAIN_GROUP_RID_ADMINS ) { - d_printf("RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1); + d_fprintf(stderr, "RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1); return -1; } } else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) { fstrcpy( unixgrp, get_string_param( argv[i] ) ); if ( !unixgrp[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) { fstrcpy( ntgroup, get_string_param( argv[i] ) ); if ( !ntgroup[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) { fstrcpy( string_sid, get_string_param( argv[i] ) ); if ( !string_sid[0] ) { - d_printf("must supply a SID\n"); + d_fprintf(stderr, "must supply a SID\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) { fstrcpy( ntcomment, get_string_param( argv[i] ) ); if ( !ntcomment[0] ) { - d_printf("must supply a comment string\n"); + d_fprintf(stderr, "must supply a comment string\n"); return -1; } } @@ -247,7 +247,7 @@ static int net_groupmap_add(int argc, const char **argv) } } else { - d_printf("Bad option: %s\n", argv[i]); + d_fprintf(stderr, "Bad option: %s\n", argv[i]); return -1; } } @@ -258,7 +258,7 @@ static int net_groupmap_add(int argc, const char **argv) } if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) { - d_printf("Can't lookup UNIX group %s\n", unixgrp); + d_fprintf(stderr, "Can't lookup UNIX group %s\n", unixgrp); return -1; } @@ -296,7 +296,7 @@ static int net_groupmap_add(int argc, const char **argv) if (!add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment)) { - d_printf("adding entry for group %s failed!\n", ntgroup); + d_fprintf(stderr, "adding entry for group %s failed!\n", ntgroup); return -1; } @@ -322,28 +322,28 @@ static int net_groupmap_modify(int argc, const char **argv) if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) { fstrcpy( ntgroup, get_string_param( argv[i] ) ); if ( !ntgroup[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) { fstrcpy( sid_string, get_string_param( argv[i] ) ); if ( !sid_string[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) { fstrcpy( ntcomment, get_string_param( argv[i] ) ); if ( !ntcomment[0] ) { - d_printf("must supply a comment string\n"); + d_fprintf(stderr, "must supply a comment string\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) { fstrcpy( unixgrp, get_string_param( argv[i] ) ); if ( !unixgrp[0] ) { - d_printf("must supply a group name\n"); + d_fprintf(stderr, "must supply a group name\n"); return -1; } } @@ -361,7 +361,7 @@ static int net_groupmap_modify(int argc, const char **argv) } } else { - d_printf("Bad option: %s\n", argv[i]); + d_fprintf(stderr, "Bad option: %s\n", argv[i]); return -1; } } @@ -388,7 +388,7 @@ static int net_groupmap_modify(int argc, const char **argv) /* Get the current mapping from the database */ if(!pdb_getgrsid(&map, sid)) { - d_printf("Failure to local group SID in the database\n"); + d_fprintf(stderr, "Failure to local group SID in the database\n"); return -1; } @@ -398,7 +398,7 @@ static int net_groupmap_modify(int argc, const char **argv) */ if (sid_type != SID_NAME_UNKNOWN) { if (map.sid_name_use == SID_NAME_WKN_GRP) { - d_printf("You can only change between domain and local groups.\n"); + d_fprintf(stderr, "You can only change between domain and local groups.\n"); return -1; } @@ -415,7 +415,7 @@ static int net_groupmap_modify(int argc, const char **argv) if ( unixgrp[0] ) { gid = nametogid( unixgrp ); if ( gid == -1 ) { - d_printf("Unable to lookup UNIX group %s. Make sure the group exists.\n", + d_fprintf(stderr, "Unable to lookup UNIX group %s. Make sure the group exists.\n", unixgrp); return -1; } @@ -424,7 +424,7 @@ static int net_groupmap_modify(int argc, const char **argv) } if ( !pdb_update_group_mapping_entry(&map) ) { - d_printf("Could not update group database\n"); + d_fprintf(stderr, "Could not update group database\n"); return -1; } @@ -445,19 +445,19 @@ static int net_groupmap_delete(int argc, const char **argv) if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) { fstrcpy( ntgroup, get_string_param( argv[i] ) ); if ( !ntgroup[0] ) { - d_printf("must supply a name\n"); + d_fprintf(stderr, "must supply a name\n"); return -1; } } else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) { fstrcpy( sid_string, get_string_param( argv[i] ) ); if ( !sid_string[0] ) { - d_printf("must supply a SID\n"); + d_fprintf(stderr, "must supply a SID\n"); return -1; } } else { - d_printf("Bad option: %s\n", argv[i]); + d_fprintf(stderr, "Bad option: %s\n", argv[i]); return -1; } } @@ -473,12 +473,12 @@ static int net_groupmap_delete(int argc, const char **argv) fstrcpy( ntgroup, sid_string ); if ( !get_sid_from_input(&sid, ntgroup) ) { - d_printf("Unable to resolve group %s to a SID\n", ntgroup); + d_fprintf(stderr, "Unable to resolve group %s to a SID\n", ntgroup); return -1; } if ( !pdb_delete_group_mapping_entry(sid) ) { - printf("Failed to removing group %s from the mapping db!\n", ntgroup); + d_fprintf(stderr, "Failed to removing group %s from the mapping db!\n", ntgroup); return -1; } @@ -511,7 +511,7 @@ static int net_groupmap_set(int argc, const char **argv) grp = getgrnam(argv[1]); if (grp == NULL) { - d_printf("Could not find unix group %s\n", argv[1]); + d_fprintf(stderr, "Could not find unix group %s\n", argv[1]); return -1; } } @@ -530,7 +530,7 @@ static int net_groupmap_set(int argc, const char **argv) /* Ok, add it */ if (grp == NULL) { - d_printf("Could not find group mapping for %s\n", + d_fprintf(stderr, "Could not find group mapping for %s\n", ntgroup); return -1; } @@ -549,7 +549,7 @@ static int net_groupmap_set(int argc, const char **argv) fstrcpy(map.comment, ""); if (!pdb_add_group_mapping_entry(&map)) { - d_printf("Could not add mapping entry for %s\n", + d_fprintf(stderr, "Could not add mapping entry for %s\n", ntgroup); return -1; } @@ -559,7 +559,7 @@ static int net_groupmap_set(int argc, const char **argv) if ( opt_localgroup || opt_domaingroup ) { if (map.sid_name_use == SID_NAME_WKN_GRP) { - d_printf("Can't change type of the BUILTIN group %s\n", + d_fprintf(stderr, "Can't change type of the BUILTIN group %s\n", map.nt_name); return -1; } @@ -583,7 +583,7 @@ static int net_groupmap_set(int argc, const char **argv) map.gid = grp->gr_gid; if (!pdb_update_group_mapping_entry(&map)) { - d_printf("Could not update group mapping for %s\n", ntgroup); + d_fprintf(stderr, "Could not update group mapping for %s\n", ntgroup); return -1; } @@ -597,7 +597,7 @@ static int net_groupmap_cleanup(int argc, const char **argv) if (!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &entries, ENUM_ALL_MAPPED)) { - d_printf("Could not list group mappings\n"); + d_fprintf(stderr, "Could not list group mappings\n"); return -1; } @@ -634,7 +634,7 @@ static int net_groupmap_addmem(int argc, const char **argv) } if (!pdb_add_aliasmem(&alias, &member)) { - d_printf("Could not add sid %s to alias %s\n", + d_fprintf(stderr, "Could not add sid %s to alias %s\n", argv[1], argv[0]); return -1; } @@ -654,7 +654,7 @@ static int net_groupmap_delmem(int argc, const char **argv) } if (!pdb_del_aliasmem(&alias, &member)) { - d_printf("Could not delete sid %s from alias %s\n", + d_fprintf(stderr, "Could not delete sid %s from alias %s\n", argv[1], argv[0]); return -1; } @@ -678,7 +678,7 @@ static int net_groupmap_listmem(int argc, const char **argv) num = 0; if (!pdb_enum_aliasmem(&alias, &members, &num)) { - d_printf("Could not list members for sid %s\n", argv[0]); + d_fprintf(stderr, "Could not list members for sid %s\n", argv[0]); return -1; } @@ -703,7 +703,7 @@ static BOOL print_alias_memberships(TALLOC_CTX *mem_ctx, if (!pdb_enum_alias_memberships(mem_ctx, domain_sid, member, 1, &alias_rids, &num_alias_rids)) { - d_printf("Could not list memberships for sid %s\n", + d_fprintf(stderr, "Could not list memberships for sid %s\n", sid_string_static(member)); return False; } @@ -731,14 +731,14 @@ static int net_groupmap_memberships(int argc, const char **argv) mem_ctx = talloc_init("net_groupmap_memberships"); if (mem_ctx == NULL) { - d_printf("talloc_init failed\n"); + d_fprintf(stderr, "talloc_init failed\n"); return -1; } domain_sid = get_global_sam_sid(); builtin_sid = string_sid_talloc(mem_ctx, "S-1-5-32"); if ((domain_sid == NULL) || (builtin_sid == NULL)) { - d_printf("Could not get domain sid\n"); + d_fprintf(stderr, "Could not get domain sid\n"); return -1; } @@ -800,7 +800,7 @@ int net_groupmap(int argc, const char **argv) /* we shouldn't have silly checks like this */ if (getuid() != 0) { - d_printf("You must be root to edit group mappings.\nExiting...\n"); + d_fprintf(stderr, "You must be root to edit group mappings.\nExiting...\n"); return -1; } diff --git a/source/utils/net_idmap.c b/source/utils/net_idmap.c index 8109bef5225..0b5f68101ed 100644 --- a/source/utils/net_idmap.c +++ b/source/utils/net_idmap.c @@ -59,7 +59,7 @@ static int net_idmap_dump(int argc, const char **argv) idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", argv[0]); + d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); return -1; } @@ -102,7 +102,7 @@ static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, } if (idptr == NULL) { - d_printf("Illegal idmap entry: [%s]->[%s]\n", + d_fprintf(stderr, "Illegal idmap entry: [%s]->[%s]\n", key.dptr, data.dptr); hwms->ok = False; return -1; @@ -132,7 +132,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) || !lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) { - d_printf("idmap range missing\n"); + d_fprintf(stderr, "idmap range missing\n"); return NT_STATUS_UNSUCCESSFUL; } @@ -145,7 +145,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", tdbfile); + d_fprintf(stderr, "Could not open idmap: %s\n", tdbfile); return NT_STATUS_NO_SUCH_FILE; } @@ -161,18 +161,18 @@ static NTSTATUS net_idmap_fixup_hwm(void) hwms.user_hwm, hwms.group_hwm); if (hwms.user_hwm >= highest.user_hwm) { - d_printf("Highest UID out of uid range\n"); + d_fprintf(stderr, "Highest UID out of uid range\n"); goto done; } if (hwms.group_hwm >= highest.group_hwm) { - d_printf("Highest GID out of gid range\n"); + d_fprintf(stderr, "Highest GID out of gid range\n"); goto done; } if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) || (tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) { - d_printf("Could not store HWMs\n"); + d_fprintf(stderr, "Could not store HWMs\n"); goto done; } @@ -188,7 +188,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) static int net_idmap_restore(int argc, const char **argv) { if (!idmap_init(lp_idmap_backend())) { - d_printf("Could not init idmap\n"); + d_fprintf(stderr, "Could not init idmap\n"); return -1; } @@ -230,7 +230,7 @@ static int net_idmap_restore(int argc, const char **argv) } if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) { - d_printf("Could not set mapping of %s %lu to sid %s\n", + d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n", (type == ID_GROUPID) ? "GID" : "UID", (type == ID_GROUPID) ? (unsigned long)id.gid: (unsigned long)id.uid, @@ -260,14 +260,14 @@ static int net_idmap_delete(int argc, const char **argv) idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", argv[0]); + d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); return -1; } fstrcpy(sid, argv[1]); if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) { - d_printf("Can only delete SIDs, %s is does not start with " + d_fprintf(stderr, "Can only delete SIDs, %s is does not start with " "S-1-5-\n", sid); return -1; } @@ -278,17 +278,17 @@ static int net_idmap_delete(int argc, const char **argv) data = tdb_fetch(idmap_tdb, key); if (data.dptr == NULL) { - d_printf("Could not find sid %s\n", argv[1]); + d_fprintf(stderr, "Could not find sid %s\n", argv[1]); return -1; } if (tdb_delete(idmap_tdb, key) != 0) { - d_printf("Could not delete key %s\n", argv[1]); + d_fprintf(stderr, "Could not delete key %s\n", argv[1]); return -1; } if (tdb_delete(idmap_tdb, data) != 0) { - d_printf("Could not delete key %s\n", data.dptr); + d_fprintf(stderr, "Could not delete key %s\n", data.dptr); return -1; } diff --git a/source/utils/net_rap.c b/source/utils/net_rap.c index 8205fe3fda9..e80beb36456 100644 --- a/source/utils/net_rap.c +++ b/source/utils/net_rap.c @@ -112,7 +112,7 @@ static int rap_file_user(int argc, const char **argv) if (argc == 0) return net_rap_file_usage(argc, argv); - d_printf("net rap file user not implemented yet\n"); + d_fprintf(stderr, "net rap file user not implemented yet\n"); return -1; } diff --git a/source/utils/net_rpc.c b/source/utils/net_rpc.c index d2cecd24350..0495a7b92c2 100644 --- a/source/utils/net_rpc.c +++ b/source/utils/net_rpc.c @@ -347,7 +347,7 @@ static int net_rpc_oldjoin(int argc, const char **argv) int rc = net_rpc_perform_oldjoin(argc, argv); if (rc) { - d_printf("Failed to join domain\n"); + d_fprintf(stderr, "Failed to join domain\n"); } return rc; @@ -607,7 +607,7 @@ static NTSTATUS rpc_user_add_internals(const DOM_SID *domain_sid, done: if (!NT_STATUS_IS_OK(result)) { - d_printf("Failed to add user %s - %s\n", acct_name, + d_fprintf(stderr, "Failed to add user %s - %s\n", acct_name, nt_errstr(result)); } else { d_printf("Added user %s\n", acct_name); @@ -714,7 +714,7 @@ static NTSTATUS rpc_user_del_internals(const DOM_SID *domain_sid, /* Display results */ if (!NT_STATUS_IS_OK(result)) { - d_printf("Failed to delete user account - %s\n", nt_errstr(result)); + d_fprintf(stderr, "Failed to delete user account - %s\n", nt_errstr(result)); } else { d_printf("Deleted user account\n"); } @@ -829,7 +829,7 @@ static NTSTATUS rpc_user_rename_internals(const DOM_SID *domain_sid, done: if (!NT_STATUS_IS_OK(result)) { - d_printf("Failed to rename user from %s to %s - %s\n", old_name, new_name, + d_fprintf(stderr, "Failed to rename user from %s to %s - %s\n", old_name, new_name, nt_errstr(result)); } else { d_printf("Renamed user from %s to %s\n", old_name, new_name); @@ -1280,7 +1280,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, &connect_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Request samr_connect failed\n"); + d_fprintf(stderr, "Request samr_connect failed\n"); goto done; } @@ -1289,7 +1289,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, domain_sid, &domain_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Request open_domain failed\n"); + d_fprintf(stderr, "Request open_domain failed\n"); goto done; } @@ -1299,7 +1299,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, &name_types); if (!NT_STATUS_IS_OK(result)) { - d_printf("Lookup of '%s' failed\n",argv[0]); + d_fprintf(stderr, "Lookup of '%s' failed\n",argv[0]); goto done; } @@ -1310,7 +1310,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, MAXIMUM_ALLOWED_ACCESS, group_rids[0], &group_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Request open_group failed"); + d_fprintf(stderr, "Request open_group failed"); goto done; } @@ -1321,7 +1321,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, &group_attrs); if (!NT_STATUS_IS_OK(result)) { - d_printf("Unable to query group members of %s",argv[0]); + d_fprintf(stderr, "Unable to query group members of %s",argv[0]); goto done; } @@ -1338,7 +1338,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, group_rids[i], &user_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Unable to open group member %d\n",group_rids[i]); + d_fprintf(stderr, "Unable to open group member %d\n",group_rids[i]); goto done; } @@ -1348,7 +1348,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, 21, &user_ctr); if (!NT_STATUS_IS_OK(result)) { - d_printf("Unable to lookup userinfo for group member %d\n",group_rids[i]); + d_fprintf(stderr, "Unable to lookup userinfo for group member %d\n",group_rids[i]); goto done; } @@ -1364,8 +1364,8 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, } if (group_is_primary) { - d_printf("Unable to delete group because some of it's " - "members have it as primary group\n"); + d_fprintf(stderr, "Unable to delete group because some " + "of it's members have it as primary group\n"); result = NT_STATUS_MEMBERS_PRIMARY_GROUP; goto done; } @@ -1397,14 +1397,14 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, group_rids[0], &group_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Request open_alias failed\n"); + d_fprintf(stderr, "Request open_alias failed\n"); goto done; } result = rpccli_samr_delete_dom_alias(pipe_hnd, mem_ctx, &group_pol); break; default: - d_printf("%s is of type %s. This command is only for deleting local or global groups\n", + d_fprintf(stderr, "%s is of type %s. This command is only for deleting local or global groups\n", argv[0],sid_type_lookup(name_types[0])); result = NT_STATUS_UNSUCCESSFUL; goto done; @@ -1415,7 +1415,7 @@ static NTSTATUS rpc_group_delete_internals(const DOM_SID *domain_sid, if (opt_verbose) d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types[0]),argv[0]); } else { - d_printf("Deleting of %s failed: %s\n",argv[0], + d_fprintf(stderr, "Deleting of %s failed: %s\n",argv[0], get_friendly_nt_error_msg(result)); } @@ -1482,7 +1482,7 @@ static NTSTATUS rpc_group_add_internals(const DOM_SID *domain_sid, if (NT_STATUS_IS_OK(result)) DEBUG(5, ("add group succeeded\n")); else - d_printf("add group failed: %s\n", nt_errstr(result)); + d_fprintf(stderr, "add group failed: %s\n", nt_errstr(result)); return result; } @@ -1538,7 +1538,7 @@ static NTSTATUS rpc_alias_add_internals(const DOM_SID *domain_sid, if (NT_STATUS_IS_OK(result)) DEBUG(5, ("add alias succeeded\n")); else - d_printf("add alias failed: %s\n", nt_errstr(result)); + d_fprintf(stderr, "add alias failed: %s\n", nt_errstr(result)); return result; } @@ -1652,7 +1652,7 @@ static NTSTATUS rpc_add_groupmem(struct rpc_pipe_client *pipe_hnd, &num_rids, &rids, &rid_types); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not lookup up group member %s\n", member); + d_fprintf(stderr, "Could not lookup up group member %s\n", member); goto done; } @@ -1696,7 +1696,7 @@ static NTSTATUS rpc_add_aliasmem(struct rpc_pipe_client *pipe_hnd, &member_sid, &member_type); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not lookup up group member %s\n", member); + d_fprintf(stderr, "Could not lookup up group member %s\n", member); return result; } @@ -1752,7 +1752,7 @@ static NTSTATUS rpc_group_addmem_internals(const DOM_SID *domain_sid, if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0], &group_sid, &group_type))) { - d_printf("Could not lookup group name %s\n", argv[0]); + d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]); return NT_STATUS_UNSUCCESSFUL; } @@ -1761,7 +1761,7 @@ static NTSTATUS rpc_group_addmem_internals(const DOM_SID *domain_sid, &group_sid, argv[1]); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not add %s to %s: %s\n", + d_fprintf(stderr, "Could not add %s to %s: %s\n", argv[1], argv[0], nt_errstr(result)); } return result; @@ -1772,14 +1772,14 @@ static NTSTATUS rpc_group_addmem_internals(const DOM_SID *domain_sid, &group_sid, argv[1]); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not add %s to %s: %s\n", + d_fprintf(stderr, "Could not add %s to %s: %s\n", argv[1], argv[0], nt_errstr(result)); } return result; } - d_printf("Can only add members to global or local groups which " - "%s is not\n", argv[0]); + d_fprintf(stderr, "Can only add members to global or local groups " + "which %s is not\n", argv[0]); return NT_STATUS_UNSUCCESSFUL; } @@ -1830,7 +1830,7 @@ static NTSTATUS rpc_del_groupmem(struct rpc_pipe_client *pipe_hnd, &num_rids, &rids, &rid_types); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not lookup up group member %s\n", member); + d_fprintf(stderr, "Could not lookup up group member %s\n", member); goto done; } @@ -1872,7 +1872,7 @@ static NTSTATUS rpc_del_aliasmem(struct rpc_pipe_client *pipe_hnd, &member_sid, &member_type); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not lookup up group member %s\n", member); + d_fprintf(stderr, "Could not lookup up group member %s\n", member); return result; } @@ -1926,7 +1926,7 @@ static NTSTATUS rpc_group_delmem_internals(const DOM_SID *domain_sid, if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0], &group_sid, &group_type))) { - d_printf("Could not lookup group name %s\n", argv[0]); + d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]); return NT_STATUS_UNSUCCESSFUL; } @@ -1935,7 +1935,7 @@ static NTSTATUS rpc_group_delmem_internals(const DOM_SID *domain_sid, &group_sid, argv[1]); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not del %s from %s: %s\n", + d_fprintf(stderr, "Could not del %s from %s: %s\n", argv[1], argv[0], nt_errstr(result)); } return result; @@ -1946,14 +1946,14 @@ static NTSTATUS rpc_group_delmem_internals(const DOM_SID *domain_sid, &group_sid, argv[1]); if (!NT_STATUS_IS_OK(result)) { - d_printf("Could not del %s from %s: %s\n", + d_fprintf(stderr, "Could not del %s from %s: %s\n", argv[1], argv[0], nt_errstr(result)); } return result; } - d_printf("Can only delete members from global or local groups which " - "%s is not\n", argv[0]); + d_fprintf(stderr, "Can only delete members from global or local groups " + "which %s is not\n", argv[0]); return NT_STATUS_UNSUCCESSFUL; } @@ -2281,7 +2281,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd, &num_members, &alias_sids); if (!NT_STATUS_IS_OK(result)) { - d_printf("Couldn't list alias members\n"); + d_fprintf(stderr, "Couldn't list alias members\n"); return result; } @@ -2291,7 +2291,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd, lsa_pipe = cli_rpc_pipe_open_noauth(pipe_hnd->cli, PI_LSARPC, &result); if (!lsa_pipe) { - d_printf("Couldn't open LSA pipe. Error was %s\n", + d_fprintf(stderr, "Couldn't open LSA pipe. Error was %s\n", nt_errstr(result) ); return result; } @@ -2300,7 +2300,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd, SEC_RIGHTS_MAXIMUM_ALLOWED, &lsa_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Couldn't open LSA policy handle\n"); + d_fprintf(stderr, "Couldn't open LSA policy handle\n"); cli_rpc_pipe_close(lsa_pipe); return result; } @@ -2311,7 +2311,7 @@ static NTSTATUS rpc_list_alias_members(struct rpc_pipe_client *pipe_hnd, if (!NT_STATUS_IS_OK(result) && !NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) { - d_printf("Couldn't lookup SIDs\n"); + d_fprintf(stderr, "Couldn't lookup SIDs\n"); cli_rpc_pipe_close(lsa_pipe); return result; } @@ -2383,7 +2383,7 @@ static NTSTATUS rpc_group_members_internals(const DOM_SID *domain_sid, &sid_Builtin, &domain_pol); if (!NT_STATUS_IS_OK(result)) { - d_printf("Couldn't find group %s\n", argv[0]); + d_fprintf(stderr, "Couldn't find group %s\n", argv[0]); return result; } @@ -2392,13 +2392,13 @@ static NTSTATUS rpc_group_members_internals(const DOM_SID *domain_sid, &rids, &rid_types); if (!NT_STATUS_IS_OK(result)) { - d_printf("Couldn't find group %s\n", argv[0]); + d_fprintf(stderr, "Couldn't find group %s\n", argv[0]); return result; } } if (num_rids != 1) { - d_printf("Couldn't find group %s\n", argv[0]); + d_fprintf(stderr, "Couldn't find group %s\n", argv[0]); return result; } @@ -2466,12 +2466,12 @@ static NTSTATUS rpc_group_rename_internals(const DOM_SID *domain_sid, 1, argv, &num_rids, &rids, &rid_types); if (num_rids != 1) { - d_printf("Couldn't find group %s\n", argv[0]); + d_fprintf(stderr, "Couldn't find group %s\n", argv[0]); return result; } if (rid_types[0] != SID_NAME_DOM_GRP) { - d_printf("Can only rename domain groups\n"); + d_fprintf(stderr, "Can only rename domain groups\n"); return NT_STATUS_UNSUCCESSFUL; } @@ -3057,7 +3057,7 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state False); break; default: - d_printf("Unsupported mode %d\n", net_mode_share); + d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share); return; } @@ -3099,7 +3099,7 @@ static void copy_fn(const char *mnt, file_info *f, const char *mask, void *state True); break; default: - d_printf("Unsupported file mode %d\n", net_mode_share); + d_fprintf(stderr, "Unsupported file mode %d\n", net_mode_share); return; } @@ -3124,7 +3124,7 @@ BOOL sync_files(struct copy_clistate *cp_clistate, pstring mask) DEBUG(3,("calling cli_list with mask: %s\n", mask)); if (cli_list(cp_clistate->cli_share_src, mask, cp_clistate->attribute, copy_fn, cp_clistate) == -1) { - d_printf("listing %s failed with error: %s\n", + d_fprintf(stderr, "listing %s failed with error: %s\n", mask, cli_errstr(cp_clistate->cli_share_src)); return False; } @@ -3156,7 +3156,7 @@ BOOL copy_top_level_perms(struct copy_clistate *cp_clistate, False); break; default: - d_printf("Unsupported mode %d\n", net_mode_share); + d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share); break; } @@ -3233,7 +3233,7 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid, printf("syncing"); break; default: - d_printf("Unsupported mode %d\n", net_mode_share); + d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share); break; } printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n", @@ -3268,13 +3268,13 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid, } if (!copy_top_level_perms(&cp_clistate, netname)) { - d_printf("Could not handle the top level directory permissions for the share: %s\n", netname); + d_fprintf(stderr, "Could not handle the top level directory permissions for the share: %s\n", netname); nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (!sync_files(&cp_clistate, mask)) { - d_printf("could not handle files for share: %s\n", netname); + d_fprintf(stderr, "could not handle files for share: %s\n", netname); nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -3878,8 +3878,8 @@ static BOOL get_user_tokens(int *num_tokens, struct user_token **user_tokens) if (lp_winbind_use_default_domain() && (opt_target_workgroup == NULL)) { - d_printf("winbind use default domain = yes set, please " - "specify a workgroup\n"); + d_fprintf(stderr, "winbind use default domain = yes set, " + "please specify a workgroup\n"); return False; } @@ -4681,11 +4681,11 @@ static NTSTATUS rpc_reg_shutdown_internals(const DOM_SID *domain_sid, if (W_ERROR_IS_OK(result)) { d_printf("\nShutdown of remote machine succeeded\n"); } else { - d_printf("\nShutdown of remote machine failed\n"); + d_fprintf(stderr, "\nShutdown of remote machine failed\n"); if (W_ERROR_EQUAL(result,WERR_MACHINE_LOCKED)) - d_printf("\nMachine locked, use -f switch to force\n"); + d_fprintf(stderr, "\nMachine locked, use -f switch to force\n"); else - d_printf("\nresult was: %s\n", dos_errstr(result)); + d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(result)); } return werror_to_ntstatus(result); @@ -5634,12 +5634,12 @@ static int rpc_trustdom_list(int argc, const char **argv) if (remote_cli) { /* query for domain's sid */ if (run_rpc_command(remote_cli, PI_LSARPC, 0, rpc_query_domain_sid, argc, argv)) - d_printf("couldn't get domain's sid\n"); + d_fprintf(stderr, "couldn't get domain's sid\n"); cli_shutdown(remote_cli); } else { - d_printf("domain controller is not responding\n"); + d_fprintf(stderr, "domain controller is not responding\n"); }; }; diff --git a/source/utils/net_rpc_join.c b/source/utils/net_rpc_join.c index 12e51a85d17..6a5a7559c3a 100644 --- a/source/utils/net_rpc_join.c +++ b/source/utils/net_rpc_join.c @@ -202,14 +202,14 @@ int net_rpc_join_newstyle(int argc, const char **argv) if (!NT_STATUS_IS_OK(result) && !NT_STATUS_EQUAL(result, NT_STATUS_USER_EXISTS)) { - d_printf("Creation of workstation account failed\n"); + d_fprintf(stderr, "Creation of workstation account failed\n"); /* If NT_STATUS_ACCESS_DENIED then we have a valid username/password combo but the user does not have administrator access. */ if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) - d_printf("User specified does not have administrator privileges\n"); + d_fprintf(stderr, "User specified does not have administrator privileges\n"); goto done; } @@ -317,7 +317,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) && (sec_channel_type == SEC_CHAN_BDC) ) { - d_printf("Please make sure that no computer account\n" + d_fprintf(stderr, "Please make sure that no computer account\n" "named like this machine (%s) exists in the domain\n", global_myname()); } @@ -338,7 +338,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) && (sec_channel_type == SEC_CHAN_BDC) ) { - d_printf("Please make sure that no computer account\n" + d_fprintf(stderr, "Please make sure that no computer account\n" "named like this machine (%s) exists in the domain\n", global_myname()); } diff --git a/source/utils/net_rpc_printer.c b/source/utils/net_rpc_printer.c index d8f3099dec8..5e282403a24 100644 --- a/source/utils/net_rpc_printer.c +++ b/source/utils/net_rpc_printer.c @@ -403,14 +403,14 @@ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close %s on originating server: %s\n", + d_fprintf(stderr, "could not close %s on originating server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (!cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close %s on destination server: %s\n", + d_fprintf(stderr, "could not close %s on destination server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -504,7 +504,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* allocate memory */ if (!(data = (char *)SMB_MALLOC(read_size))) { - d_printf("malloc fail for size %d\n", read_size); + d_fprintf(stderr, "malloc fail for size %d\n", read_size); nt_status = NT_STATUS_NO_MEMORY; goto out; } @@ -538,7 +538,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, nread + start, n); if (n != ret) { - d_printf("Error writing file: %s\n", + d_fprintf(stderr, "Error writing file: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -561,7 +561,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } if (!cli_chkpath(cli_share_dst, dst_name)) { - d_printf("cannot check for directory %s: %s\n", + d_fprintf(stderr, "cannot check for directory %s: %s\n", dst_name, cli_errstr(cli_share_dst)); goto out; } @@ -570,14 +570,14 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close file on originating server: %s\n", + d_fprintf(stderr, "could not close file on originating server: %s\n", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (is_file && !cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close file on destination server: %s\n", + d_fprintf(stderr, "could not close file on destination server: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -704,7 +704,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar } if (!cli_chkpath(cli_share, dir)) { - d_printf("cannot check %s: %s\n", + d_fprintf(stderr, "cannot check %s: %s\n", dir, cli_errstr(cli_share)); goto out; } @@ -859,13 +859,13 @@ static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { - d_printf("no access to printer [%s] on [%s] for user [%s] granted\n", + d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", printername2, servername, username); return False; } if (!W_ERROR_IS_OK(result)) { - d_printf("cannot open printer %s on server %s: %s\n", + d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", printername2, servername, dos_errstr(result)); return False; } @@ -2134,9 +2134,9 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, if (W_ERROR_IS_OK(result)) d_printf ("printer [%s] successfully added.\n", printername); else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS)) - d_printf ("printer [%s] already exists.\n", printername); + d_fprintf (stderr, "printer [%s] already exists.\n", printername); else { - printf ("could not create printer\n"); + d_fprintf (stderr, "could not create printer [%s]\n", printername); goto done; } diff --git a/source/utils/net_rpc_registry.c b/source/utils/net_rpc_registry.c index 4ce0b44e4cd..9852fe4a94f 100644 --- a/source/utils/net_rpc_registry.c +++ b/source/utils/net_rpc_registry.c @@ -105,7 +105,7 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, } if ( !reg_split_hive( argv[0], &hive, subpath ) ) { - d_printf("invalid registry path\n"); + d_fprintf(stderr, "invalid registry path\n"); return NT_STATUS_OK; } @@ -113,14 +113,14 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to connect to remote registry\n"); + d_fprintf(stderr, "Unable to connect to remote registry\n"); return werror_to_ntstatus(result); } if ( strlen( subpath ) != 0 ) { result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to open [%s]\n", argv[0]); + d_fprintf(stderr, "Unable to open [%s]\n", argv[0]); return werror_to_ntstatus(result); } } @@ -223,7 +223,7 @@ static NTSTATUS rpc_registry_save_internal(const DOM_SID *domain_sid, } if ( !reg_split_hive( argv[0], &hive, subpath ) ) { - d_printf("invalid registry path\n"); + d_fprintf(stderr, "invalid registry path\n"); return NT_STATUS_OK; } @@ -231,19 +231,19 @@ static NTSTATUS rpc_registry_save_internal(const DOM_SID *domain_sid, result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to connect to remote registry\n"); + d_fprintf(stderr, "Unable to connect to remote registry\n"); return werror_to_ntstatus(result); } result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to open [%s]\n", argv[0]); + d_fprintf(stderr, "Unable to open [%s]\n", argv[0]); return werror_to_ntstatus(result); } result = rpccli_reg_save_key(pipe_hnd, mem_ctx, &pol_key, argv[1] ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]); + d_fprintf(stderr, "Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]); } @@ -329,7 +329,7 @@ static BOOL dump_registry_tree( REGF_FILE *file, REGF_NK_REC *nk, const char *pa d_printf("\n"); dump_registry_tree( file, key, regpath ); } - + return True; } @@ -401,7 +401,7 @@ static int rpc_registry_dump( int argc, const char **argv ) d_printf("Opening %s....", argv[0]); if ( !(registry = regfio_open( argv[0], O_RDONLY, 0)) ) { - d_printf("Failed to open %s for reading\n", argv[0]); + d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]); return 1; } d_printf("ok\n"); @@ -432,6 +432,7 @@ static int rpc_registry_copy( int argc, const char **argv ) { REGF_FILE *infile, *outfile; REGF_NK_REC *nk; + int result = 1; if (argc != 2 ) { d_printf("Usage: net rpc copy \n"); @@ -440,15 +441,15 @@ static int rpc_registry_copy( int argc, const char **argv ) d_printf("Opening %s....", argv[0]); if ( !(infile = regfio_open( argv[0], O_RDONLY, 0 )) ) { - d_printf("Failed to open %s for reading\n", argv[0]); + d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]); return 1; } d_printf("ok\n"); d_printf("Opening %s....", argv[1]); if ( !(outfile = regfio_open( argv[1], (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) { - d_printf("Failed to open %s for writing\n", argv[1]); - return 1; + d_fprintf(stderr, "Failed to open %s for writing\n", argv[1]); + goto out_close_infile; } d_printf("ok\n"); @@ -459,15 +460,18 @@ static int rpc_registry_copy( int argc, const char **argv ) write_registry_tree( infile, nk, NULL, outfile, "" ); + result = 0; + d_printf("Closing %s...", argv[1]); regfio_close( outfile ); d_printf("ok\n"); +out_close_infile: d_printf("Closing %s...", argv[0]); regfio_close( infile ); d_printf("ok\n"); - return 0; + return( result); } /******************************************************************** diff --git a/source/utils/net_rpc_rights.c b/source/utils/net_rpc_rights.c index a563475ee10..2c15fef5a09 100644 --- a/source/utils/net_rpc_rights.c +++ b/source/utils/net_rpc_rights.c @@ -335,15 +335,15 @@ static NTSTATUS rpc_rights_list_internal(const DOM_SID *domain_sid, if ( !NT_STATUS_IS_OK(result) ) { if ( NT_STATUS_EQUAL( result, NT_STATUS_NO_SUCH_PRIVILEGE ) ) - d_printf("No such privilege exists: %s.\n", privname); + d_fprintf(stderr, "No such privilege exists: %s.\n", privname); else - d_printf("Error resolving privilege display name [%s].\n", nt_errstr(result)); + d_fprintf(stderr, "Error resolving privilege display name [%s].\n", nt_errstr(result)); continue; } result = enum_accounts_for_privilege(pipe_hnd, mem_ctx, &pol, privname); if (!NT_STATUS_IS_OK(result)) { - d_printf("Error enumerating accounts for privilege %s [%s].\n", + d_fprintf(stderr, "Error enumerating accounts for privilege %s [%s].\n", privname, nt_errstr(result)); continue; } @@ -437,7 +437,7 @@ static NTSTATUS rpc_rights_grant_internal(const DOM_SID *domain_sid, done: if ( !NT_STATUS_IS_OK(result) ) { - d_printf("Failed to grant privileges for %s (%s)\n", + d_fprintf(stderr, "Failed to grant privileges for %s (%s)\n", argv[0], nt_errstr(result)); } @@ -488,7 +488,7 @@ static NTSTATUS rpc_rights_revoke_internal(const DOM_SID *domain_sid, done: if ( !NT_STATUS_IS_OK(result) ) { - d_printf("Failed to revoke privileges for %s (%s)", + d_fprintf(stderr, "Failed to revoke privileges for %s (%s)", argv[0], nt_errstr(result)); } diff --git a/source/utils/net_rpc_samsync.c b/source/utils/net_rpc_samsync.c index f4a0ab90e8f..09e62d9defa 100644 --- a/source/utils/net_rpc_samsync.c +++ b/source/utils/net_rpc_samsync.c @@ -536,7 +536,7 @@ static NTSTATUS fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta) /* try and find the possible unix account again */ if ( !(passwd = Get_Pwnam(account)) ) { - d_printf("Could not create posix account info for '%s'\n", account); + d_fprintf(stderr, "Could not create posix account info for '%s'\n", account); nt_ret = NT_STATUS_NO_SUCH_USER; goto done; } @@ -1847,7 +1847,7 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd, const char *add_ldif = "/tmp/add.ldif", *mod_ldif = "/tmp/mod.ldif"; FILE *add_fd, *mod_fd, *ldif_fd; char sys_cmd[1024]; - int num_alloced = 0, g_index = 0, a_index = 0; + int num_alloced = 0, g_index = 0, a_index = 0, sys_cmd_result; /* Set up array for mapping accounts to groups */ /* Array element is the group rid */ @@ -2068,7 +2068,12 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd, fflush(ldif_fd); } pstr_sprintf(sys_cmd, "cat %s >> %s", add_ldif, ldif_file); - system(sys_cmd); + sys_cmd_result = system(sys_cmd); + if (sys_cmd_result) { + d_fprintf(stderr, "%s failed. Error was (%s)\n", + sys_cmd, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } if (db_type == SAM_DATABASE_DOMAIN) { fprintf(ldif_fd, "# SAM_DATABASE_DOMAIN: MODIFY ENTITIES\n"); @@ -2083,11 +2088,21 @@ static NTSTATUS fetch_database_to_ldif(struct rpc_pipe_client *pipe_hnd, fflush(ldif_fd); } pstr_sprintf(sys_cmd, "cat %s >> %s", mod_ldif, ldif_file); - system(sys_cmd); + sys_cmd_result = system(sys_cmd); + if (sys_cmd_result) { + d_fprintf(stderr, "%s failed. Error was (%s)\n", + sys_cmd, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } /* Delete the temporary ldif files */ pstr_sprintf(sys_cmd, "rm -f %s %s", add_ldif, mod_ldif); - system(sys_cmd); + sys_cmd_result = system(sys_cmd); + if (sys_cmd_result) { + d_fprintf(stderr, "%s failed. Error was (%s)\n", + sys_cmd, strerror(errno)); + return NT_STATUS_UNSUCCESSFUL; + } /* Close the ldif file */ fclose(ldif_fd); @@ -2154,11 +2169,11 @@ NTSTATUS rpc_vampire_internals(const DOM_SID *domain_sid, } if (!NT_STATUS_IS_OK(result)) { - d_printf("Failed to fetch domain database: %s\n", + d_fprintf(stderr, "Failed to fetch domain database: %s\n", nt_errstr(result)); if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) - d_printf("Perhaps %s is a Windows 2000 native mode " - "domain?\n", domain_name); + d_fprintf(stderr, "Perhaps %s is a Windows 2000 native " + "mode domain?\n", domain_name); goto fail; } @@ -2170,7 +2185,7 @@ NTSTATUS rpc_vampire_internals(const DOM_SID *domain_sid, } if (!NT_STATUS_IS_OK(result)) { - d_printf("Failed to fetch builtin database: %s\n", + d_fprintf(stderr, "Failed to fetch builtin database: %s\n", nt_errstr(result)); goto fail; } diff --git a/source/utils/net_rpc_service.c b/source/utils/net_rpc_service.c index ed7d1dfab1f..27127a1c3f9 100644 --- a/source/utils/net_rpc_service.c +++ b/source/utils/net_rpc_service.c @@ -40,7 +40,7 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, service, SC_RIGHT_SVC_QUERY_STATUS ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); return result; } @@ -110,7 +110,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -120,7 +120,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, control, &service_status ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Control service request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Control service request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -162,7 +162,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -170,7 +170,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, SVCCTL_STATE_ALL, &num_services, &services ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to enumerate services. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to enumerate services. [%s]\n", dos_errstr(result)); goto done; } @@ -219,7 +219,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -229,7 +229,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -237,7 +237,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -247,7 +247,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_query_config(pipe_hnd, mem_ctx, &hService, &config ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query config request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query config request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -318,7 +318,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -356,7 +356,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -394,7 +394,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -433,7 +433,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -443,7 +443,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, servicename, SC_RIGHT_SVC_START ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -451,7 +451,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -460,7 +460,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) d_printf("Successfully started service: %s\n", servicename ); else - d_printf("Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); + d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); done: rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); diff --git a/source/utils/net_status.c b/source/utils/net_status.c index 31693affe73..d3b1bae276d 100644 --- a/source/utils/net_status.c +++ b/source/utils/net_status.c @@ -74,7 +74,7 @@ static int net_status_sessions(int argc, const char **argv) TDB_DEFAULT, O_RDONLY, 0); if (tdb == NULL) { - d_printf("%s not initialised\n", lock_path("sessionid.tdb")); + d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb")); return -1; } @@ -186,7 +186,7 @@ static int net_status_shares_parseable(int argc, const char **argv) TDB_DEFAULT, O_RDONLY, 0); if (tdb == NULL) { - d_printf("%s not initialised\n", lock_path("sessionid.tdb")); + d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb")); return -1; } @@ -197,9 +197,9 @@ static int net_status_shares_parseable(int argc, const char **argv) TDB_DEFAULT, O_RDONLY, 0); if (tdb == NULL) { - d_printf("%s not initialised\n", lock_path("connections.tdb")); - d_printf("This is normal if no SMB client has ever connected " - "to your server.\n"); + d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb")); + d_fprintf(stderr, "This is normal if no SMB client has ever " + "connected to your server.\n"); return -1; } @@ -226,10 +226,10 @@ static int net_status_shares(int argc, const char **argv) TDB_DEFAULT, O_RDONLY, 0); if (tdb == NULL) { - d_printf("%s not initialised\n", + d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb")); - d_printf("This is normal if no SMB client has ever " - "connected to your server.\n"); + d_fprintf(stderr, "This is normal if no SMB client has " + "ever connected to your server.\n"); return -1; } diff --git a/source/utils/net_time.c b/source/utils/net_time.c index 691adcea00e..1a7116d447d 100644 --- a/source/utils/net_time.c +++ b/source/utils/net_time.c @@ -99,6 +99,7 @@ static int net_time_set(int argc, const char **argv) { time_t t = nettime(NULL); char *cmd; + int result; if (t == 0) return -1; @@ -106,10 +107,13 @@ static int net_time_set(int argc, const char **argv) roll your own. I'm putting this in as it works on a large number of systems and the user has a choice in whether its used or not */ asprintf(&cmd, "/bin/date %s", systime(t)); - system(cmd); + result = system(cmd); + if (result) + d_fprintf(stderr, "%s failed. Error was (%s)\n", + cmd, strerror(errno)); free(cmd); - return 0; + return result; } /* display the time on a remote box in a format ready for /bin/date */ @@ -161,7 +165,7 @@ int net_time(int argc, const char **argv) if (!opt_host && !opt_have_ip && !find_master_ip(opt_target_workgroup, &opt_dest_ip)) { - d_printf("Could not locate a time server. Try "\ + d_fprintf(stderr, "Could not locate a time server. Try "\ "specifying a target host.\n"); net_time_usage(argc,argv); return -1; -- cgit From b3444d6c7591e3d10a0a7e5731de2efce58aa05f Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 18 Jan 2006 04:44:59 +0000 Subject: r12990: BUG 3329: patch from David May for Solaris shell script portability issues in 'make test' --- source/script/tests/functions | 4 ++-- source/script/tests/runtests.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/script/tests/functions b/source/script/tests/functions index 40e185e153f..8cb8f0b1550 100644 --- a/source/script/tests/functions +++ b/source/script/tests/functions @@ -34,7 +34,7 @@ stop_smbd() ## check to see if smbd is already running check_smbd_running - if test $? == 0; then + if test $? = 0; then echo "Unable to stop smbd!" exit 2 fi @@ -74,7 +74,7 @@ stop_nmbd() ## check to see if smbd is already running kill -0 $nmbd_pid 2> /dev/null - if test $? == 0; then + if test $? = 0; then echo "Unable to stop nmbd!" exit 2 fi diff --git a/source/script/tests/runtests.sh b/source/script/tests/runtests.sh index a5dc3ecfb4a..ddaf94e8ac5 100644 --- a/source/script/tests/runtests.sh +++ b/source/script/tests/runtests.sh @@ -1,11 +1,11 @@ #!/bin/sh -if [ "x$1" == "x" ]; then +if [ "x$1" = "x" ]; then echo "$0 " exit 1 fi -if [ $# == 2 ]; then +if [ $# = 2 ]; then testnum=$2 fi @@ -49,7 +49,7 @@ export USERNAME PASSWORD ## verify that we were built with --enable-socket-wrapper ## -if test "x`smbd -b | grep SOCKET_WRAPPER`" == "x"; then +if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then echo "***" echo "*** You must include --enable-socket-wrapper when compiling Samba" echo "*** in order to execute 'make test'. Exiting...." -- cgit From 074a618416f9aebd125b7c2ce7121a8a98c2530d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 18 Jan 2006 04:56:28 +0000 Subject: r12991: some fixes for BUG 3331 - solaris packaging --- packaging/Solaris/makepkg.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packaging/Solaris/makepkg.sh b/packaging/Solaris/makepkg.sh index 2d599fca9b7..18e9f00f84a 100644 --- a/packaging/Solaris/makepkg.sh +++ b/packaging/Solaris/makepkg.sh @@ -128,15 +128,16 @@ echo "Install directory: $INSTALL_BASE" cd $DISTR_BASE/source -if [ "x$1" != "xnobuild" ]; then +if test "x$1" = "xbuild" ]; then ./configure --prefix=$INSTALL_BASE \ - --with-acl-support \ - --with-included-popt \ --localstatedir=/var/lib/samba \ --with-piddir=/var/run \ --with-logfilebase=/var/log/samba \ --with-privatedir=/etc/samba/private \ --with-configdir=/etc/samba \ + --with-lockdir=/var/lib/samba \ + --with-pam --with-acl-support \ + --with-quotas --with-included-popt \ && make if [ $? -ne 0 ]; then -- cgit From 815225bb15ed6b40f84e9f228a3bdfc00d7918f1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 18 Jan 2006 10:05:55 +0000 Subject: r12993: Ouch... --- source/configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/configure.in b/source/configure.in index f3f3d44d0bf..ed3aac2c43f 100644 --- a/source/configure.in +++ b/source/configure.in @@ -5194,7 +5194,7 @@ SMB_MODULE(vfs_cap, \$(VFS_CAP_OBJ), "bin/cap.$SHLIBEXT", VFS) SMB_MODULE(vfs_expand_msdfs, \$(VFS_EXPAND_MSDFS_OBJ), "bin/expand_msdfs.$SHLIBEXT", VFS) SMB_MODULE(vfs_shadow_copy, \$(VFS_SHADOW_COPY_OBJ), "bin/shadow_copy.$SHLIBEXT", VFS) SMB_MODULE(vfs_afsacl, \$(VFS_AFSACL_OBJ), "bin/afsacl.$SHLIBEXT", VFS) -SMB_MODULE(vfs_catia, \$(VFS_AFSACL_OBJ), "bin/catia.$SHLIBEXT", VFS) +SMB_MODULE(vfs_catia, \$(VFS_CATIA_OBJ), "bin/catia.$SHLIBEXT", VFS) SMB_SUBSYSTEM(VFS,smbd/vfs.o) AC_DEFINE_UNQUOTED(STRING_STATIC_MODULES, "$string_static_modules", [String list of builtin modules]) -- cgit From 8a433fff000bf76c44afc5cac865f26c3ab03dfb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 18 Jan 2006 10:25:04 +0000 Subject: r12994: Fix cut&paste error, thanks to Björn Jachke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/configure.in b/source/configure.in index ed3aac2c43f..147038a9301 100644 --- a/source/configure.in +++ b/source/configure.in @@ -4505,8 +4505,8 @@ AC_ARG_WITH(aio-support, AC_MSG_RESULT(yes) case "$host_os" in *) - AC_CHECK_LIB(rt,aio_read,[AIO_LIBS="$ACL_LIBS -lrt"]) - AC_CHECK_LIB(aio,aio_read,[AIO_LIBS="$ACL_LIBS -laio"]) + AC_CHECK_LIB(rt,aio_read,[AIO_LIBS="$AIO_LIBS -lrt"]) + AC_CHECK_LIB(aio,aio_read,[AIO_LIBS="$AIO_LIBS -laio"]) AC_CACHE_CHECK([for asynchronous io support],samba_cv_HAVE_AIO,[ aio_LIBS=$LIBS LIBS=$AIO_LIBS -- cgit From ed7041d043625e6bf2772cb0587ceb2e6b59a52d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Jan 2006 19:25:18 +0000 Subject: r13012: Fix #3421 - it turns out krb5_kt_get_entry() on MIT does an implicit open/read/close and blows away an open keytab handle - so make sure we use a new handle. Wonderful analysis from Luke helped fix this. Jeremy. --- source/libsmb/clikrb5.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/source/libsmb/clikrb5.c b/source/libsmb/clikrb5.c index 67e9f539adf..6e87f73df14 100644 --- a/source/libsmb/clikrb5.c +++ b/source/libsmb/clikrb5.c @@ -767,7 +767,6 @@ static krb5_enctype get_enctype_from_ap_req(krb5_ap_req *ap_req) static krb5_error_code get_key_from_keytab(krb5_context context, - krb5_keytab keytab, krb5_const_principal server, krb5_enctype enctype, krb5_kvno kvno, @@ -775,13 +774,18 @@ get_key_from_keytab(krb5_context context, { krb5_keytab_entry entry; krb5_error_code ret; - krb5_keytab real_keytab; + krb5_keytab keytab; char *name = NULL; - if (keytab == NULL) { - krb5_kt_default(context, &real_keytab); - } else { - real_keytab = keytab; + /* We have to open a new keytab handle here, as MIT does + an implicit open/getnext/close on krb5_kt_get_entry. We + may be in the middle of a keytab enumeration when this is + called. JRA. */ + + ret = krb5_kt_default(context, &keytab); + if (ret) { + DEBUG(0,("get_key_from_keytab: failed to open keytab: %s\n", error_message(ret))); + return ret; } if ( DEBUGLEVEL >= 10 ) { @@ -792,7 +796,7 @@ get_key_from_keytab(krb5_context context, } ret = krb5_kt_get_entry(context, - real_keytab, + keytab, server, kvno, enctype, @@ -819,10 +823,7 @@ get_key_from_keytab(krb5_context context, smb_krb5_kt_free_entry(context, &entry); out: - if (keytab == NULL) { - krb5_kt_close(context, real_keytab); - } - + krb5_kt_close(context, keytab); return ret; } @@ -913,7 +914,6 @@ krb5_error_code decode_krb5_ap_req(const krb5_data *code, krb5_ap_req **rep); } ret = get_key_from_keytab(context, - keytab, server, enctype, kvno, -- cgit From 246dc43407a9cee65e5f64a7dbf19983e1dad491 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Jan 2006 20:45:44 +0000 Subject: r13015: Make logic much clearer. From jpeach. Jeremy. --- source/libsmb/ntlmssp_sign.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libsmb/ntlmssp_sign.c b/source/libsmb/ntlmssp_sign.c index e41cd6437c2..cc6323718b3 100644 --- a/source/libsmb/ntlmssp_sign.c +++ b/source/libsmb/ntlmssp_sign.c @@ -139,7 +139,7 @@ NTSTATUS ntlmssp_sign_packet(NTLMSSP_STATE *ntlmssp_state, { NTSTATUS nt_status; - if (!ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN) { + if (!(ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SIGN)) { DEBUG(3, ("NTLMSSP Signing not negotiated - cannot sign packet!\n")); return NT_STATUS_INVALID_PARAMETER; } @@ -238,7 +238,7 @@ NTSTATUS ntlmssp_seal_packet(NTLMSSP_STATE *ntlmssp_state, { NTSTATUS nt_status; - if (!ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL) { + if (!(ntlmssp_state->neg_flags & NTLMSSP_NEGOTIATE_SEAL)) { DEBUG(3, ("NTLMSSP Sealing not negotiated - cannot seal packet!\n")); return NT_STATUS_INVALID_PARAMETER; } -- cgit From 88ae99d5cdc0c6f3a736f19301f7b8c06de16a15 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 18 Jan 2006 22:40:00 +0000 Subject: r13020: Prevent cli_krb5_get_ticket of getting into an infite loop. This whole area of code needs to be reworked later on. Guenther --- source/libsmb/clikrb5.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libsmb/clikrb5.c b/source/libsmb/clikrb5.c index 6e87f73df14..e0dcefeb1d7 100644 --- a/source/libsmb/clikrb5.c +++ b/source/libsmb/clikrb5.c @@ -456,6 +456,7 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context, krb5_creds creds; krb5_data in_data; BOOL creds_ready = False; + int i = 0, maxtries = 3; retval = krb5_parse_name(context, principal, &server); if (retval) { @@ -479,7 +480,7 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context, goto cleanup_creds; } - while(!creds_ready) { + while (!creds_ready && (i < maxtries)) { if ((retval = krb5_get_credentials(context, 0, ccache, &creds, &credsp))) { DEBUG(1,("ads_krb5_mk_req: krb5_get_credentials failed for %s (%s)\n", @@ -497,6 +498,8 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context, if (!ads_cleanup_expired_creds(context, ccache, credsp)) creds_ready = True; + + i++; } DEBUG(10,("ads_krb5_mk_req: Ticket (%s) in ccache (%s) is valid until: (%s - %u)\n", -- cgit From 882d54bfdf329584b444d99cda6b02181199bd32 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 18 Jan 2006 23:42:29 +0000 Subject: r13023: Ensure we notice if we exit due to guest user setup fail. Jeremy. --- source/smbd/server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/smbd/server.c b/source/smbd/server.c index ff894e2460c..620bf3ebbdd 100644 --- a/source/smbd/server.c +++ b/source/smbd/server.c @@ -826,8 +826,10 @@ void build_options(BOOL screen); init_structs(); - if (!init_guest_info()) + if (!init_guest_info()) { + DEBUG(0,("ERROR: failed to setup guest info.\n")); return -1; + } #ifdef WITH_PROFILE if (!profile_setup(False)) { -- cgit From 63b743564c5aaa5f960eb806e5176e5b5d8c31c3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 19 Jan 2006 00:03:07 +0000 Subject: r13024: Add is_null_sid. GUenther --- source/lib/util_sid.c | 6 ++++++ source/nsswitch/winbindd_util.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/lib/util_sid.c b/source/lib/util_sid.c index f3fc5af9eaa..e2b2ebf28ca 100644 --- a/source/lib/util_sid.c +++ b/source/lib/util_sid.c @@ -619,3 +619,9 @@ void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, size_t *num) return; } + +BOOL is_null_sid(const DOM_SID *sid) +{ + static const DOM_SID null_sid = {0}; + return sid_equal(sid, &null_sid); +} diff --git a/source/nsswitch/winbindd_util.c b/source/nsswitch/winbindd_util.c index efae9568845..4c3306a8aca 100644 --- a/source/nsswitch/winbindd_util.c +++ b/source/nsswitch/winbindd_util.c @@ -106,7 +106,6 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const { struct winbindd_domain *domain; const char *alternative_name = NULL; - static const DOM_SID null_sid = {0}; /* ignore alt_name if we are not in an AD domain */ @@ -128,7 +127,7 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const } } if (sid) { - if (sid_equal(sid, &null_sid) ) { + if (is_null_sid(sid)) { } else if (sid_equal(sid, &domain->sid)) { return domain; -- cgit From 902f48ff642e0e189a6ea2db0814f6b39191fcbe Mon Sep 17 00:00:00 2001 From: James Peach Date: Thu, 19 Jan 2006 00:30:16 +0000 Subject: r13027: Support file change notifications from FAM. --- source/Makefile.in | 6 +- source/configure.in | 33 +++- source/param/loadparm.c | 4 + source/smbd/notify.c | 8 +- source/smbd/notify_fam.c | 446 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 491 insertions(+), 6 deletions(-) create mode 100644 source/smbd/notify_fam.c diff --git a/source/Makefile.in b/source/Makefile.in index 58d0bb46a15..15d22d8fa59 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -347,7 +347,7 @@ PROFILES_OBJ = utils/profiles.o \ OPLOCK_OBJ = smbd/oplock.o smbd/oplock_irix.o smbd/oplock_linux.o -NOTIFY_OBJ = smbd/notify.o smbd/notify_hash.o smbd/notify_kernel.o +NOTIFY_OBJ = smbd/notify.o smbd/notify_hash.o smbd/notify_kernel.o smbd/notify_fam.o VFS_AUDIT_OBJ = modules/vfs_audit.o VFS_EXTD_AUDIT_OBJ = modules/vfs_extd_audit.o @@ -877,7 +877,7 @@ bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy @echo Linking $@ @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(SMBD_OBJ) $(LDFLAGS) $(LDAP_LIBS) \ $(KRB5LIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) \ - $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ + $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ @SMBD_LIBS@ bin/nmbd@EXEEXT@: $(NMBD_OBJ) @BUILD_POPT@ bin/.dummy @echo Linking $@ @@ -1008,7 +1008,7 @@ bin/nsstest@EXEEXT@: $(NSSTEST_OBJ) bin/.dummy bin/vfstest@EXEEXT@: $(VFSTEST_OBJ) @BUILD_POPT@ bin/.dummy @echo Linking $@ - @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) $(ACL_LIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) + @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(VFSTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) $(ACL_LIBS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(LDAP_LIBS) @SMBD_LIBS@ bin/smbiconv@EXEEXT@: $(SMBICONV_OBJ) @BUILD_POPT@ bin/.dummy @echo Linking $@ diff --git a/source/configure.in b/source/configure.in index 147038a9301..44517ae6eab 100644 --- a/source/configure.in +++ b/source/configure.in @@ -2174,6 +2174,33 @@ if test x"$samba_cv_HAVE_KERNEL_CHANGE_NOTIFY" = x"yes"; then AC_DEFINE(HAVE_KERNEL_CHANGE_NOTIFY,1,[Whether kernel notifies changes]) fi +################################################# +# Check if FAM notifications are available. For FAM info, see +# http://oss.sgi.com/projects/fam/ +# http://savannah.nongnu.org/projects/fam/ + +AC_CHECK_HEADERS(fam.h, [samba_cv_HAVE_FAM_H=yes], [samba_cv_HAVE_FAM_H=no]) +if test x"$samba_cv_HAVE_FAM_H" = x"yes"; then + # On IRIX, libfam requires libC, but other FAM implementations might not + # need it. + AC_CHECK_LIB(fam, FAMOpen2, + [samba_cv_HAVE_LIBFAM=yes; samba_fam_libs="-lfam"], + [samba_cv_HAVE_LIBFAM=no]) + + if test x"$samba_cv_HAVE_LIBFAM" = x"no" ; then + samba_fam_xtra=-lC + AC_CHECK_LIB_EXT(fam, samba_fam_xtra, FAMOpen2, + [samba_cv_HAVE_LIBFAM=yes; samba_fam_libs="-lfam -lC"], + [samba_cv_HAVE_LIBFAM=no]) + unset samba_fam_xtra + fi +fi + +if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then + AC_DEFINE(HAVE_FAM_CHANGE_NOTIFY, 1, + [Whether FAM is file notifications are available]) +fi + AC_CACHE_CHECK([for kernel share modes],samba_cv_HAVE_KERNEL_SHARE_MODES,[ AC_TRY_RUN([ #include @@ -2194,8 +2221,6 @@ if test x"$samba_cv_HAVE_KERNEL_SHARE_MODES" = x"yes"; then fi - - AC_CACHE_CHECK([for IRIX kernel oplock type definitions],samba_cv_HAVE_KERNEL_OPLOCKS_IRIX,[ AC_TRY_COMPILE([#include #include ], @@ -5231,6 +5256,10 @@ AC_TRY_RUN([#include "${srcdir-.}/tests/summary.c"], builddir=`pwd` AC_SUBST(builddir) +# Stuff the FAM libraries at the end of the smbd link path (if we have them). +SMBD_LIBS="$samba_fam_libs" +AC_SUBST(SMBD_LIBS) + dnl Remove -L/usr/lib/? from LDFLAGS and LIBS LIB_REMOVE_USR_LIB(LDFLAGS) LIB_REMOVE_USR_LIB(LIBS) diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 526bce9b60e..83a5b2fc3cf 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -294,6 +294,7 @@ typedef struct BOOL bUnixExtensions; BOOL bDisableNetbios; BOOL bKernelChangeNotify; + BOOL bFamChangeNotify; BOOL bUseKerberosKeytab; BOOL bDeferSharingViolations; BOOL bEnablePrivileges; @@ -992,6 +993,7 @@ static struct parm_struct parm_table[] = { {"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, {"keepalive", P_INTEGER, P_GLOBAL, &keepalive, NULL, NULL, FLAG_ADVANCED}, {"kernel change notify", P_BOOL, P_GLOBAL, &Globals.bKernelChangeNotify, NULL, NULL, FLAG_ADVANCED}, + {"fam change notify", P_BOOL, P_GLOBAL, &Globals.bFamChangeNotify, NULL, NULL, FLAG_ADVANCED}, {"lpq cache time", P_INTEGER, P_GLOBAL, &Globals.lpqcachetime, NULL, NULL, FLAG_ADVANCED}, {"max smbd processes", P_INTEGER, P_GLOBAL, &Globals.iMaxSmbdProcesses, NULL, NULL, FLAG_ADVANCED}, @@ -1486,6 +1488,7 @@ static void init_globals(void) Globals.machine_password_timeout = 60 * 60 * 24 * 7; /* 7 days default. */ Globals.change_notify_timeout = 60; /* 1 minute default. */ Globals.bKernelChangeNotify = True; /* On if we have it. */ + Globals.bFamChangeNotify = True; /* On if we have it. */ Globals.lm_announce = 2; /* = Auto: send only if LM clients found */ Globals.lm_interval = 60; Globals.announce_as = ANNOUNCE_AS_NT_SERVER; @@ -1868,6 +1871,7 @@ FN_GLOBAL_BOOL(lp_use_spnego, &Globals.bUseSpnego) FN_GLOBAL_BOOL(lp_client_use_spnego, &Globals.bClientUseSpnego) FN_GLOBAL_BOOL(lp_hostname_lookups, &Globals.bHostnameLookups) FN_GLOBAL_BOOL(lp_kernel_change_notify, &Globals.bKernelChangeNotify) +FN_GLOBAL_BOOL(lp_fam_change_notify, &Globals.bFamChangeNotify) FN_GLOBAL_BOOL(lp_use_kerberos_keytab, &Globals.bUseKerberosKeytab) FN_GLOBAL_BOOL(lp_defer_sharing_violations, &Globals.bDeferSharingViolations) FN_GLOBAL_BOOL(lp_enable_privileges, &Globals.bEnablePrivileges) diff --git a/source/smbd/notify.c b/source/smbd/notify.c index bc76cfb322f..df3d45d20b5 100644 --- a/source/smbd/notify.c +++ b/source/smbd/notify.c @@ -212,9 +212,15 @@ BOOL change_notify_set(char *inbuf, files_struct *fsp, connection_struct *conn, BOOL init_change_notify(void) { + cnotify = NULL; + #if HAVE_KERNEL_CHANGE_NOTIFY - if (lp_kernel_change_notify()) + if (cnotify == NULL && lp_kernel_change_notify()) cnotify = kernel_notify_init(); +#endif +#if HAVE_FAM_CHANGE_NOTIFY + if (cnotify == NULL && lp_fam_change_notify()) + cnotify = fam_notify_init(); #endif if (!cnotify) cnotify = hash_notify_init(); diff --git a/source/smbd/notify_fam.c b/source/smbd/notify_fam.c new file mode 100644 index 00000000000..413340266ec --- /dev/null +++ b/source/smbd/notify_fam.c @@ -0,0 +1,446 @@ +/* + * FAM file notification support. + * + * Copyright (c) James Peach 2005 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "includes.h" + +#ifdef HAVE_FAM_CHANGE_NOTIFY + +#include + +/* NOTE: There are multiple versions of FAM floating around the net, each with + * slight differences from the original SGI FAM implementation. In this file, + * we rely only on the SGI features and do not assume any extensions. For + * example, we do not look at FAMErrno, because it is not set by the original + * implementation. + * + * Random FAM links: + * http://oss.sgi.com/projects/fam/ + * http://savannah.nongnu.org/projects/fam/ + * http://sourceforge.net/projects/bsdfam/ + */ + +struct fam_req_info +{ + FAMRequest req; + int generation; + enum FAMCodes code; + enum + { + /* We are waiting for an event. */ + FAM_REQ_MONITORING, + /* An event has been receive, but we haven't been able to send it back + * to the client yet. It is stashed in the code member. + */ + FAM_REQ_FIRED + } state; +}; + +/* Don't initialise this until the first register request. We want a single + * FAM connection for each worker smbd. If we allow the master (parent) smbd to + * open a FAM connection, multiple processes talking on the same socket will + * undoubtedly create havoc. + */ +static FAMConnection global_fc; +static int global_fc_generation; + +#define FAM_TRACE 8 +#define FAM_TRACE_LOW 10 + +#define FAM_NOTIFY_CHECK_TIMEOUT 1 /* secs */ +#define FAM_EVENT_DRAIN ((uint32_t)(-1)) + +/* Turn a FAM event code into a string. Don't rely on specific code values, + * because that might not work across all flavours of FAM. + */ +static const char * +fam_event_str(enum FAMCodes code) +{ + static struct { enum FAMCodes code; const char * name; } evstr[] = + { + { FAMChanged, "FAMChanged"}, + { FAMDeleted, "FAMDeleted"}, + { FAMStartExecuting, "FAMStartExecuting"}, + { FAMStopExecuting, "FAMStopExecuting"}, + { FAMCreated, "FAMCreated"}, + { FAMMoved, "FAMMoved"}, + { FAMAcknowledge, "FAMAcknowledge"}, + { FAMExists, "FAMExists"}, + { FAMEndExist, "FAMEndExist"} + }; + + int i; + + for (i = 0; i < ARRAY_SIZE(evstr); ++i) { + if (code == evstr[i].code) + return(evstr[i].name); + } + + return(""); +} + +static BOOL +fam_check_reconnect(void) +{ + if (FAMCONNECTION_GETFD(&global_fc) < 0) { + fstring name; + + global_fc_generation++; + snprintf(name, sizeof(name), "smbd (%lu)", (unsigned long)sys_getpid()); + + if (FAMOpen2(&global_fc, name) < 0) { + DEBUG(0, ("failed to connect to FAM service\n")); + return(False); + } + } + + return(True); +} + +static BOOL +fam_monitor_path(connection_struct * conn, + struct fam_req_info * info, + const char * path, + uint32 flags) +{ + SMB_STRUCT_STAT st; + pstring fullpath; + + DEBUG(FAM_TRACE, ("requesting FAM notifications for '%s'\n", path)); + + /* FAM needs an absolute pathname. */ + + /* It would be better to use reduce_name() here, but reduce_name does not + * actually return the reduced result. How utterly un-useful. + */ + pstrcpy(fullpath, path); + if (!canonicalize_path(conn, fullpath)) { + DEBUG(0, ("failed to canonicalize path '%s'\n", path)); + return(False); + } + + if (*fullpath != '/') { + DEBUG(0, ("canonicalized path '%s' into `%s`\n", path, fullpath)); + DEBUGADD(0, ("but expected an absolute path\n")); + return(False); + } + + if (SMB_VFS_STAT(conn, path, &st) < 0) { + DEBUG(0, ("stat of '%s' failed: %s\n", path, strerror(errno))); + return(False); + } + /* Start monitoring this file or directory. We hand the state structure to + * both the caller and the FAM library so we can match up the caller's + * status requests with FAM notifications. + */ + if (S_ISDIR(st.st_mode)) { + FAMMonitorDirectory(&global_fc, fullpath, &(info->req), info); + } else { + FAMMonitorFile(&global_fc, fullpath, &(info->req), info); + } + + /* Grr. On IRIX, neither of the monitor functions return a status. */ + + /* We will stay in initialising state until we see the FAMendExist message + * for this file. + */ + info->state = FAM_REQ_MONITORING; + info->generation = global_fc_generation; + return(True); +} + +static BOOL +fam_handle_event(enum FAMCodes code, uint32 flags) +{ +#define F_CHANGE_MASK (FILE_NOTIFY_CHANGE_FILE | \ + FILE_NOTIFY_CHANGE_ATTRIBUTES | \ + FILE_NOTIFY_CHANGE_SIZE | \ + FILE_NOTIFY_CHANGE_LAST_WRITE | \ + FILE_NOTIFY_CHANGE_LAST_ACCESS | \ + FILE_NOTIFY_CHANGE_CREATION | \ + FILE_NOTIFY_CHANGE_EA | \ + FILE_NOTIFY_CHANGE_SECURITY) + +#define F_DELETE_MASK (FILE_NOTIFY_CHANGE_FILE_NAME | \ + FILE_NOTIFY_CHANGE_DIR_NAME) + +#define F_CREATE_MASK (FILE_NOTIFY_CHANGE_FILE_NAME | \ + FILE_NOTIFY_CHANGE_DIR_NAME) + + switch (code) { + case FAMChanged: + if (flags & F_CHANGE_MASK) + return(True); + break; + case FAMDeleted: + if (flags & F_DELETE_MASK) + return(True); + break; + case FAMCreated: + if (flags & F_CREATE_MASK) + return(True); + break; + default: + /* Ignore anything else. */ + break; + } + + return(False); + +#undef F_CHANGE_MASK +#undef F_DELETE_MASK +#undef F_CREATE_MASK +} + +static BOOL +fam_pump_events(struct fam_req_info * info, uint32_t flags) +{ + FAMEvent ev; + + for (;;) { + + /* If we are draining the event queue we must keep going until we find + * the correct FAMAcknowledge event or the connection drops. Otherwise + * we should stop when there are no more events pending. + */ + if (flags != FAM_EVENT_DRAIN && !FAMPending(&global_fc)) { + break; + } + + if (FAMNextEvent(&global_fc, &ev) < 0) { + DEBUG(0, ("failed to fetch pending FAM event\n")); + DEBUGADD(0, ("resetting FAM connection\n")); + FAMClose(&global_fc); + FAMCONNECTION_GETFD(&global_fc) = -1; + return(False); + } + + DEBUG(FAM_TRACE_LOW, ("FAM event %s on '%s' for request %d\n", + fam_event_str(ev.code), ev.filename, ev.fr.reqnum)); + + switch (ev.code) { + case FAMAcknowledge: + /* FAM generates an ACK event when we cancel a monitor. We need + * this to know when it is safe to free out request state + * structure. + */ + if (info->generation == global_fc_generation && + info->req.reqnum == ev.fr.reqnum && + flags == FAM_EVENT_DRAIN) { + return(True); + } + + case FAMEndExist: + case FAMExists: + /* Ignore these. FAM sends these enumeration events when we + * start monitoring. If we are monitoring a directory, we will + * get a FAMExists event for each directory entry. + */ + + /* TODO: we might be able to use these to implement recursive + * monitoring of entire subtrees. + */ + case FAMMoved: + /* These events never happen. A move or rename shows up as a + * create/delete pair. + */ + case FAMStartExecuting: + case FAMStopExecuting: + /* We might get these, but we just don't care. */ + break; + + case FAMChanged: + case FAMDeleted: + case FAMCreated: + if (info->generation != global_fc_generation) { + /* Ignore this; the req number can't be matched. */ + break; + } + + if (info->req.reqnum == ev.fr.reqnum) { + /* This is the event the caller was interested in. */ + DEBUG(FAM_TRACE, ("handling FAM %s event on '%s'\n", + fam_event_str(ev.code), ev.filename)); + /* Ignore events if we are draining this request. */ + if (flags != FAM_EVENT_DRAIN) { + return(fam_handle_event(ev.code, flags)); + } + break; + } else { + /* Caller doesn't want this event. Stash the result so we + * can come back to it. Unfortunately, FAM doesn't + * guarantee to give us back evinfo. + */ + struct fam_req_info * evinfo = + (struct fam_req_info *)ev.userdata; + + if (evinfo) { + DEBUG(FAM_TRACE, ("storing FAM %s event for winter\n", + fam_event_str(ev.code))); + evinfo->state = FAM_REQ_FIRED; + evinfo->code = ev.code; + } else { + DEBUG(2, ("received FAM %s notification for %s, " + "but userdata was unexpectedly NULL\n", + fam_event_str(ev.code), ev.filename)); + } + break; + } + + default: + DEBUG(0, ("ignoring unknown FAM event code %d for `%s`\n", + ev.code, ev.filename)); + } + } + + /* No more notifications pending. */ + return(False); +} + +static BOOL +fam_test_connection(void) +{ + FAMConnection fc; + + /* On IRIX FAMOpen2 leaks 960 bytes in 48 blocks. It's a deliberate leak + * in the library and there's nothing we can do about it here. + */ + if (FAMOpen2(&fc, "smbd probe") < 0) + return(False); + + FAMClose(&fc); + return(True); +} + +/* ------------------------------------------------------------------------- */ + +static void * +fam_register_notify(connection_struct * conn, + char * path, + uint32 flags) +{ + struct fam_req_info * info; + + if (!fam_check_reconnect()) { + return(False); + } + + if ((info = SMB_MALLOC_P(struct fam_req_info)) == NULL) { + DEBUG(0, ("malloc of %d bytes failed\n", sizeof(struct fam_req_info))); + return(NULL); + } + + if (fam_monitor_path(conn, info, path, flags)) { + return(info); + } else { + SAFE_FREE(info); + return(NULL); + } +} + +static BOOL +fam_check_notify(connection_struct * conn, + uint16_t vuid, + char * path, + uint32_t flags, + void * data, + time_t when) +{ + struct fam_req_info * info; + + info = (struct fam_req_info *)data; + SMB_ASSERT(info != NULL); + + DEBUG(10, ("checking FAM events for `%s`\n", path)); + + if (info->state == FAM_REQ_FIRED) { + DEBUG(FAM_TRACE, ("handling previously fired FAM %s event\n", + fam_event_str(info->code))); + info->state = FAM_REQ_MONITORING; + return(fam_handle_event(info->code, flags)); + } + + if (!fam_check_reconnect()) { + return(False); + } + + if (info->generation != global_fc_generation) { + DEBUG(FAM_TRACE, ("reapplying stale FAM monitor to %s\n", path)); + fam_monitor_path(conn, info, path, flags); + return(False); + } + + return(fam_pump_events(info, flags)); +} + +static void +fam_remove_notify(void * data) +{ + struct fam_req_info * info; + + if ((info = (struct fam_req_info *)data) == NULL) + return; + + /* No need to reconnect. If the FAM connection is gone, there's no need to + * cancel and we can safely let FAMCancelMonitor fail. If it we + * reconnected, then the generation check will stop us cancelling the wrong + * request. + */ + + if (info->generation == global_fc_generation) { + DEBUG(FAM_TRACE, ("removing FAM notification for request %d\n", + info->req.reqnum)); + FAMCancelMonitor(&global_fc, &(info->req)); + + /* Soak up all events until the FAMAcknowledge. We can't free + * our request state until we are sure there are no more events in + * flight. + */ + fam_pump_events(info, FAM_EVENT_DRAIN); + } + + SAFE_FREE(info); +} + +struct cnotify_fns * fam_notify_init(void) +{ + static struct cnotify_fns global_fam_notify = + { + fam_register_notify, + fam_check_notify, + fam_remove_notify, + FAM_NOTIFY_CHECK_TIMEOUT + }; + + /* TODO: rather than relying on FAM_NOTIFY_CHECK_TIMEOUT, we should have an + * API to push the FAM fd into the global server fd set. + */ + + FAMCONNECTION_GETFD(&global_fc) = -1; + + if (!fam_test_connection()) { + DEBUG(0, ("FAM file change notifications not available\n")); + return(NULL); + } + + DEBUG(FAM_TRACE, ("enabling FAM change notifications\n")); + return &global_fam_notify; +} + +#endif /* HAVE_FAM_CHANGE_NOTIFY */ -- cgit From 2c25c04d2670b7f5dc8da6f81cd1d4164d5acd22 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Jan 2006 00:34:48 +0000 Subject: r13028: Fix for #3419 - vfs_full_audit *never* worked correctly. Static variables were used ! Jeremy. --- source/modules/vfs_full_audit.c | 84 +++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/source/modules/vfs_full_audit.c b/source/modules/vfs_full_audit.c index d9d898dc0ea..52e245a1763 100644 --- a/source/modules/vfs_full_audit.c +++ b/source/modules/vfs_full_audit.c @@ -35,6 +35,9 @@ * full_audit:success = open opendir * full_audit:failure = all * + * vfs op can be "all" which means log all operations. + * vfs op can be "none" which means no logging. + * * This leads to syslog entries of the form: * smbd_audit: nobody|192.168.234.1|opendir|ok|. * smbd_audit: nobody|192.168.234.1|open|fail (File not found)|r|x.txt @@ -61,6 +64,11 @@ extern struct current_user current_user; static int vfs_full_audit_debug_level = DBGC_VFS; +struct vfs_full_audit_private_data { + struct bitmap *success_ops; + struct bitmap *failure_ops; +}; + #undef DBGC_CLASS #define DBGC_CLASS vfs_full_audit_debug_level @@ -662,24 +670,33 @@ static char *audit_prefix(connection_struct *conn) return prefix; } -static struct bitmap *success_ops = NULL; - -static BOOL log_success(vfs_op_type op) +static BOOL log_success(vfs_handle_struct *handle, vfs_op_type op) { - if (success_ops == NULL) + struct vfs_full_audit_private_data *pd = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, pd, + struct vfs_full_audit_private_data, + return True); + + if (pd->success_ops == NULL) { return True; + } - return bitmap_query(success_ops, op); + return bitmap_query(pd->success_ops, op); } -static struct bitmap *failure_ops = NULL; - -static BOOL log_failure(vfs_op_type op) +static BOOL log_failure(vfs_handle_struct *handle, vfs_op_type op) { - if (failure_ops == NULL) + struct vfs_full_audit_private_data *pd = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, pd, + struct vfs_full_audit_private_data, + return True); + + if (pd->failure_ops == NULL) return True; - return bitmap_query(failure_ops, op); + return bitmap_query(pd->failure_ops, op); } static void init_bitmap(struct bitmap **bm, const char **ops) @@ -706,6 +723,10 @@ static void init_bitmap(struct bitmap **bm, const char **ops) break; } + if (strequal(*ops, "none")) { + break; + } + for (i=0; isuccess_ops) { + bitmap_free(pd->success_ops); + } + if (pd->failure_ops) { + bitmap_free(pd->failure_ops); + } + SAFE_FREE(pd); + *p_data = NULL; +} + /* Implementation of vfs_ops. Pass everything on to the default operation but log event first. */ @@ -775,18 +812,29 @@ static int smb_full_audit_connect(vfs_handle_struct *handle, connection_struct * const char *svc, const char *user) { int result; + struct vfs_full_audit_private_data *pd = NULL; const char *none[] = { NULL }; const char *all [] = { "all" }; + pd = SMB_MALLOC_P(struct vfs_full_audit_private_data); + if (!pd) { + return -1; + } + ZERO_STRUCTP(pd); + openlog("smbd_audit", 0, audit_syslog_facility(handle)); - init_bitmap(&success_ops, + init_bitmap(&pd->success_ops, lp_parm_string_list(SNUM(conn), "full_audit", "success", none)); - init_bitmap(&failure_ops, + init_bitmap(&pd->failure_ops, lp_parm_string_list(SNUM(conn), "full_audit", "failure", all)); + /* Store the private data. */ + SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data, + struct vfs_full_audit_private_data, return -1); + result = SMB_VFS_NEXT_CONNECT(handle, conn, svc, user); do_log(SMB_VFS_OP_CONNECT, True, handle, @@ -803,11 +851,8 @@ static void smb_full_audit_disconnect(vfs_handle_struct *handle, do_log(SMB_VFS_OP_DISCONNECT, True, handle, "%s", lp_servicename(SNUM(conn))); - bitmap_free(success_ops); - success_ops = NULL; - - bitmap_free(failure_ops); - failure_ops = NULL; + /* The bitmaps will be disconnected when the private + data is deleted. */ return; } @@ -2003,4 +2048,3 @@ NTSTATUS vfs_full_audit_init(void) return ret; } - -- cgit From f777e983b87bd93dcfd2c803c9d189e42b9f9c7f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Jan 2006 22:26:26 +0000 Subject: r13042: Fix for bug #3248 Stefan Burkei . When doing auth_crap authentication use the client given workstation name not our own. Jeremy. --- source/nsswitch/winbindd_pam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/nsswitch/winbindd_pam.c b/source/nsswitch/winbindd_pam.c index 1d9b77afee1..890007ae389 100644 --- a/source/nsswitch/winbindd_pam.c +++ b/source/nsswitch/winbindd_pam.c @@ -640,7 +640,8 @@ enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain, contact_domain->dcname, name_user, name_domain, - global_myname(), + /* Bug #3248 - found by Stefan Burkei. */ + workstation, /* We carefully set this above so use it... */ state->request.data.auth_crap.chal, lm_resp, nt_resp, -- cgit From 25a4db093d71f10224009c16e6850402f4e15df9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 20 Jan 2006 01:09:44 +0000 Subject: r13047: specfile updates from John T. --- packaging/Fedora/samba.spec.tmpl | 208 ++++++++++++++++++++++----------------- packaging/Fedora/samba.xinetd | 15 --- packaging/Fedora/swat | 15 +++ 3 files changed, 135 insertions(+), 103 deletions(-) delete mode 100644 packaging/Fedora/samba.xinetd create mode 100644 packaging/Fedora/swat diff --git a/packaging/Fedora/samba.spec.tmpl b/packaging/Fedora/samba.spec.tmpl index 4f4299470b1..9afd9238084 100644 --- a/packaging/Fedora/samba.spec.tmpl +++ b/packaging/Fedora/samba.spec.tmpl @@ -1,19 +1,19 @@ %define initdir %{_sysconfdir}/rc.d/init.d %define auth %(test -f /etc/pam.d/system-auth && echo /etc/pam.d/system-auth || echo) -Summary: The Samba SMB server. +Summary: Samba SMB client and server +Vendor: Samba Team +Packager: Samba Team Name: samba Version: PVERSION Release: PRELEASE -License: GNU GPL Version 2 +License: GNU GPL version 2 Group: System Environment/Daemons URL: http://www.samba.org/ -Source: ftp://www.samba.org/pub/samba/%{name}-%{version}.tar.bz2 - -# Red Hat specific replacement-files +Source: samba-%{version}.tar.gz Source1: samba.log -Source2: samba.xinetd +Source3: swat Source4: samba.sysconfig Source5: smb.init Source6: winbind.init @@ -25,18 +25,17 @@ Source10: smb.conf # Don't depend on Net::LDAP Source999: filter-requires-samba.sh -# generic patches - -Requires: pam >= 0.64 %{auth} samba-common = %{version} -Requires: logrotate >= 3.4 initscripts >= 5.54-1 +Requires: pam >= 0.64 %{auth} samba-common = %{version} +Requires: logrotate >= 3.4 initscripts >= 5.54-1 BuildRoot: %{_tmppath}/%{name}-%{version}-root Prereq: /sbin/chkconfig /bin/mktemp /usr/bin/killall -Prereq: fileutils sed /etc/init.d +Prereq: fileutils sed /etc/init.d BuildRequires: pam-devel, readline-devel, ncurses-devel, fileutils, libacl-devel, openldap-devel, krb5-devel, cups-devel +Provides: samba = %{version} +Obsoletes: samba-common, samba-client, samba-swat - -# Working around perl dependency problem from docs -%define __perl_requires %{SOURCE999} +BuildRoot: %{_tmppath}/%{name}-%{version}-root +Prefix: /usr %description Samba is the protocol by which a lot of PC-related machines share @@ -49,6 +48,7 @@ SMB (sometimes called "Lan Manager") clients. Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT need the NetBEUI (Microsoft Raw NetBIOS frame) protocol. + %package client Summary: Samba (SMB) client programs. Group: Applications/System @@ -60,6 +60,7 @@ The samba-client package provides some SMB clients to compliment the built-in SMB filesystem in Linux. These clients allow access of SMB shares and printing to SMB printers. + %package common Summary: Files used by both Samba servers and clients. Group: Applications/System @@ -68,6 +69,7 @@ Group: Applications/System Samba-common provides files necessary for both the server and client packages of Samba. + %package swat Summary: The Samba SMB server configuration program. Group: Applications/System @@ -78,6 +80,7 @@ The samba-swat package includes the new SWAT (Samba Web Administration Tool), for remotely managing Samba's smb.conf file using your favorite Web browser. + %prep %setup -q @@ -88,134 +91,166 @@ cp %{SOURCE7} packaging/Fedora/ cp %{SOURCE8} packaging/Fedora/winbind.init %build - cd source %ifarch i386 sparc RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D_FILE_OFFSET_BITS=64" %endif %ifarch ia64 libtoolize --copy --force # get it to recognize IA-64 -autoheader +autoheader autoconf EXTRA="-D_LARGEFILE64_SOURCE" %endif ## run autogen if missing the configure script if [ ! -f "configure" ]; then - ./autogen.sh + ./autogen.sh fi -CFLAGS="$RPM_OPT_FLAGS" ./configure \ +CFLAGS="$RPM_OPT_FLAGS $EXTRA -D_GNU_SOURCE" ./configure \ --prefix=%{_prefix} \ --localstatedir=/var \ - --sysconfdir=/etc \ + --with-configdir=%{_sysconfdir}/samba \ + --with-libdir=%{_libdir}/samba \ + --with-lockdir=/var/cache/samba \ + --with-logfilebase=/var/log/samba \ + --with-mandir=%{_mandir} \ + --with-piddir=/var/run \ --with-privatedir=%{_sysconfdir}/samba \ - --with-fhs \ - --with-quotas \ - --with-smbmount \ - --with-pam \ + --with-sambabook=%{_datadir}/swat/using_samba \ + --with-swatdir=%{_datadir}/swat \ + --enable-cups \ + --with-acl-support \ + --with-ads \ + --with-automount \ + --with-fhs \ --with-pam_smbpass \ - --with-syslog \ - --with-utmp \ - --with-sambabook=%{_datadir}/swat/using_samba \ - --with-swatdir=%{_datadir}/swat \ --with-libsmbclient \ - --with-acl-support \ + --with-libsmbsharemodes \ + --without-smbwrapper \ + --with-pam \ + --with-quotas \ --with-shared-modules=idmap_rid \ - --enable-cups=yes + --with-smbmount \ + --with-syslog \ + --with-utmp + make showlayout -make proto -make %{?_smp_mflags} all modules nsswitch/libnss_wins.so + +make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" proto pch + +make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{?_smp_mflags} \ + all modules pam_smbpass ## build the cifs fs mount helper -gcc -o mount.cifs $RPM_OPT_FLAGS -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE client/mount.cifs.c -gcc -o umount.cifs $RPM_OPT_FLAGS -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE client/umount.cifs.c +cd client +gcc -o mount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE mount.cifs.c +gcc -o umount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE umount.cifs.c +cd .. +# Remove some permission bits to avoid to many dependencies +cd .. +find examples docs -type f | xargs -r chmod -x %install +# Clean up in case there is trash left from a previous build rm -rf $RPM_BUILD_ROOT +# Create the target build directory hierarchy +mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/{help,include,using_samba/{figs,gifsa}} +mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/using_samba +mkdir -p $RPM_BUILD_ROOT%{_includedir} +mkdir -p $RPM_BUILD_ROOT%{_initrddir} +mkdir -p $RPM_BUILD_ROOT{%{_libdir},%{_includedir}} +mkdir -p $RPM_BUILD_ROOT%{_libdir}/samba/{auth,charset,idmap,vfs,pdb} +mkdir -p $RPM_BUILD_ROOT/%{_lib}/security +mkdir -p $RPM_BUILD_ROOT%{_mandir} +mkdir -p $RPM_BUILD_ROOT%{_prefix}/{bin,sbin} +mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib mkdir -p $RPM_BUILD_ROOT/sbin -mkdir -p $RPM_BUILD_ROOT/usr/{sbin,bin} -mkdir -p $RPM_BUILD_ROOT/%{initdir} -mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/{pam.d,logrotate.d} -mkdir -p $RPM_BUILD_ROOT/var/{log,spool,lib}/samba -mkdir -p $RPM_BUILD_ROOT/%{_datadir}/swat/using_samba -mkdir -p $RPM_BUILD_ROOT/%{_datadir}/samba/codepages +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{logrotate.d,pam.d,samba} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{pam.d,logrotate.d} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{samba,sysconfig} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d +mkdir -p $RPM_BUILD_ROOT/var/cache/samba/winbindd_privileged +mkdir -p $RPM_BUILD_ROOT/var/{log,run/winbindd,spool}/samba cd source - make DESTDIR=$RPM_BUILD_ROOT \ - install - + install cd .. -# Install other stuff -install -m644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smb.conf -install -m644 %{SOURCE9} $RPM_BUILD_ROOT/etc/samba/smbusers -install -m755 %{SOURCE8} $RPM_BUILD_ROOT%{_bindir} -install -m644 %{SOURCE7} $RPM_BUILD_ROOT/etc/pam.d/samba -install -m644 %{SOURCE1} $RPM_BUILD_ROOT/etc/logrotate.d/samba -install -m755 source/script/mksmbpasswd.sh $RPM_BUILD_ROOT%{_bindir} -install -m755 source/mount.cifs $RPM_BUILD_ROOT/sbin/mount.cifs -install -m755 source/umount.cifs $RPM_BUILD_ROOT/sbin/umount.cifs - -install -m755 %{SOURCE5} $RPM_BUILD_ROOT%{initdir}/smb -install -m755 %{SOURCE6} $RPM_BUILD_ROOT%{initdir}/winbind -ln -s ../..%{initdir}/smb $RPM_BUILD_ROOT%{_sbindir}/samba -ln -s ../..%{initdir}/winbind $RPM_BUILD_ROOT%{_sbindir}/winbind - -ln -s ../usr/bin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb -## Samba's Makefile is breaking this currently. Remove it and set our own -/bin/rm -f $RPM_BUILD_ROOT/sbin/mount.smbfs -ln -s ../usr/bin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs - -echo 127.0.0.1 localhost > $RPM_BUILD_ROOT%{_sysconfdir}/samba/lmhosts - - # pam_smbpass -mkdir -p $RPM_BUILD_ROOT/%{_lib}/security -mv source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so +cp source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so -# winbind -mkdir -p $RPM_BUILD_ROOT/%{_lib}/security +# NSS & PAM winbind support install -m 755 source/nsswitch/pam_winbind.so $RPM_BUILD_ROOT/%{_lib}/security/pam_winbind.so install -m 755 source/nsswitch/libnss_winbind.so $RPM_BUILD_ROOT/%{_lib}/libnss_winbind.so install -m 755 source/nsswitch/libnss_wins.so $RPM_BUILD_ROOT/%{_lib}/libnss_wins.so -( cd $RPM_BUILD_ROOT/%{_lib}; +( cd $RPM_BUILD_ROOT/%{_lib}; ln -sf libnss_winbind.so libnss_winbind.so.2; ln -sf libnss_wins.so libnss_wins.so.2 ) -# libsmbclient - # make install puts libsmbclient.so in the wrong place on x86_64 -rm -f $RPM_BUILD_ROOT/usr/lib || true -mkdir -p $RPM_BUILD_ROOT%{_libdir} $RPM_BUILD_ROOT%{_includedir} +rm -f $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.so $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.a || true install -m 755 source/bin/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so install -m 755 source/bin/libsmbclient.a $RPM_BUILD_ROOT%{_libdir}/libsmbclient.a install -m 644 source/include/libsmbclient.h $RPM_BUILD_ROOT%{_includedir} -rm -f $RPM_BUILD_ROOT%{_libdir}/samba/libsmbclient.* +ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so.0 +if [ %{_libdir} == /usr/lib64 ];then + ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so.0 + ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so +fi # make install puts libmsrpc.so in the wrong place on x86_64 -rm -f $RPM_BUILD_ROOT/usr/lib || true -mkdir -p $RPM_BUILD_ROOT%{_libdir} $RPM_BUILD_ROOT%{_includedir} install -m 755 source/bin/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so install -m 755 source/bin/libmsrpc.a $RPM_BUILD_ROOT%{_libdir}/libmsrpc.a install -m 644 source/include/libmsrpc.h $RPM_BUILD_ROOT%{_includedir} rm -f $RPM_BUILD_ROOT%{_libdir}/samba/libmsrpc.* +ln -s /%{_libdir}/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so.0 -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d -install -m644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d/swat +# Install pam_smbpass.so +install -m755 source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig +# we need a symlink for mount to recognise the smb and smbfs filesystem types +ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs +ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb + +# Install the miscellany +echo 127.0.0.1 localhost > $RPM_BUILD_ROOT%{_sysconfdir}/samba/lmhosts + +install -m644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/samba +install -m644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d/swat install -m644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/samba +install -m755 %{SOURCE5} $RPM_BUILD_ROOT%{initdir}/smb +install -m755 %{SOURCE6} $RPM_BUILD_ROOT%{initdir}/winbind +install -m644 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/samba +install -m755 %{SOURCE8} $RPM_BUILD_ROOT%{_bindir} +install -m644 %{SOURCE9} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smbusers +install -m644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smb.conf +install -m755 source/client/mount.cifs $RPM_BUILD_ROOT/sbin/mount.cifs +install -m755 source/client/umount.cifs $RPM_BUILD_ROOT/sbin/umount.cifs +install -m755 source/script/mksmbpasswd.sh $RPM_BUILD_ROOT%{_bindir} + +ln -s ../..%{initdir}/smb $RPM_BUILD_ROOT%{_sbindir}/samba +ln -s ../..%{initdir}/winbind $RPM_BUILD_ROOT%{_sbindir}/winbind + +# Remove "*.old" files +find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; + +## don't duplicate the docs. These are installed by/with SWAT +rm -rf docs/htmldocs +rm -rf docs/manpages +( cd docs; ln -s %{_prefix}/share/swat/help htmldocs ) ## ## Clean out man pages for tools not installed here ## rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/vfstest.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man5/vfstest.1* + %clean rm -rf $RPM_BUILD_ROOT @@ -292,8 +327,10 @@ fi %attr(755,root,root) %config %{initdir}/smb %config(noreplace) %{_sysconfdir}/logrotate.d/samba %config(noreplace) %{_sysconfdir}/pam.d/samba +%{_sysconfdir}/samba/samba.xinetd %{_mandir}/man1/smbcontrol.1* %{_mandir}/man1/smbstatus.1* +%{_mandir}/man1/vfstest.1* %{_mandir}/man5/smbpasswd.5* %{_mandir}/man7/samba.7* %{_mandir}/man8/nmbd.8* @@ -357,9 +394,6 @@ fi %{_mandir}/man1/smbtar.1* %{_mandir}/man1/smbtree.1* %{_mandir}/man8/net.8* -#%{_mandir}/ja/man1/smbtar.1* -#%{_mandir}/ja/man1/smbclient.1* -#%{_mandir}/ja/man1/nmblookup.1* %files common %defattr(-,root,root) @@ -369,6 +403,8 @@ fi %{_includedir}/libsmbclient.h %{_libdir}/libsmbclient.a %{_libdir}/libsmbclient.so +%{_libdir}/libsmbclient.so.0 +%{_prefix}/lib/* %{_includedir}/libmsrpc.h %{_libdir}/libmsrpc.a %{_libdir}/libmsrpc.so @@ -386,12 +422,8 @@ fi %{_sbindir}/winbindd %config(noreplace) %{_sysconfdir}/samba/smb.conf %config(noreplace) %{_sysconfdir}/samba/lmhosts -%dir %{_datadir}/samba -%dir %{_datadir}/samba/codepages %dir %{_sysconfdir}/samba %{initdir}/winbind -# %{_datadir}/samba/codepages/* -# %{_mandir}/man1/make_smbcodepage.1* %{_mandir}/man1/ntlm_auth.1* %{_mandir}/man1/profiles.1* %{_mandir}/man1/smbcquotas.1* diff --git a/packaging/Fedora/samba.xinetd b/packaging/Fedora/samba.xinetd deleted file mode 100644 index 8b62348dde3..00000000000 --- a/packaging/Fedora/samba.xinetd +++ /dev/null @@ -1,15 +0,0 @@ -# default: off -# description: SWAT is the Samba Web Admin Tool. Use swat \ -# to configure your Samba server. To use SWAT, \ -# connect to port 901 with your favorite web browser. -service swat -{ - port = 901 - socket_type = stream - wait = no - only_from = 127.0.0.1 - user = root - server = /usr/sbin/swat - log_on_failure += USERID - disable = yes -} diff --git a/packaging/Fedora/swat b/packaging/Fedora/swat new file mode 100644 index 00000000000..8b62348dde3 --- /dev/null +++ b/packaging/Fedora/swat @@ -0,0 +1,15 @@ +# default: off +# description: SWAT is the Samba Web Admin Tool. Use swat \ +# to configure your Samba server. To use SWAT, \ +# connect to port 901 with your favorite web browser. +service swat +{ + port = 901 + socket_type = stream + wait = no + only_from = 127.0.0.1 + user = root + server = /usr/sbin/swat + log_on_failure += USERID + disable = yes +} -- cgit From 39af5278974fc8603e9c914608b94cc32e39084c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 20 Jan 2006 01:11:26 +0000 Subject: r13048: trying to fix the confusion over packaging platforms --- packaging/Fedora/filter-requires-samba.sh | 4 - packaging/Fedora/makerpms.sh.tmpl | 68 ---- packaging/Fedora/samba.log | 9 - packaging/Fedora/samba.pamd | 4 - packaging/Fedora/samba.spec.tmpl | 442 ---------------------- packaging/Fedora/samba.sysconfig | 6 - packaging/Fedora/smb.conf | 288 -------------- packaging/Fedora/smb.init | 135 ------- packaging/Fedora/smbprint | 84 ----- packaging/Fedora/smbusers | 3 - packaging/Fedora/swat | 15 - packaging/Fedora/swat.desktop | 8 - packaging/Fedora/winbind.init | 100 ----- packaging/RHEL/filter-requires-samba.sh | 4 + packaging/RHEL/makerpms.sh.tmpl | 68 ++++ packaging/RHEL/samba.log | 9 + packaging/RHEL/samba.pamd | 4 + packaging/RHEL/samba.spec.tmpl | 442 ++++++++++++++++++++++ packaging/RHEL/samba.sysconfig | 6 + packaging/RHEL/smb.conf | 288 ++++++++++++++ packaging/RHEL/smb.init | 135 +++++++ packaging/RHEL/smbprint | 84 +++++ packaging/RHEL/smbusers | 3 + packaging/RHEL/swat | 15 + packaging/RHEL/swat.desktop | 8 + packaging/RHEL/winbind.init | 100 +++++ packaging/RedHat-9/README | 13 + packaging/RedHat-9/filter-requires-samba_rh8.sh | 2 + packaging/RedHat-9/filter-requires-samba_rh9.sh | 4 + packaging/RedHat-9/makerpms.sh.tmpl | 71 ++++ packaging/RedHat-9/samba.log | 9 + packaging/RedHat-9/samba.pamd | 4 + packaging/RedHat-9/samba.pamd.stack | 6 + packaging/RedHat-9/samba.spec.tmpl | 475 ++++++++++++++++++++++++ packaging/RedHat-9/samba.xinetd | 15 + packaging/RedHat-9/smb.conf | 288 ++++++++++++++ packaging/RedHat-9/smb.init | 59 +++ packaging/RedHat-9/smbprint | 77 ++++ packaging/RedHat-9/smbusers | 3 + packaging/RedHat-9/winbind.init | 84 +++++ packaging/RedHat/README | 13 - packaging/RedHat/filter-requires-samba_rh8.sh | 2 - packaging/RedHat/filter-requires-samba_rh9.sh | 4 - packaging/RedHat/makerpms.sh.tmpl | 71 ---- packaging/RedHat/samba.log | 9 - packaging/RedHat/samba.pamd | 4 - packaging/RedHat/samba.pamd.stack | 6 - packaging/RedHat/samba.spec.tmpl | 475 ------------------------ packaging/RedHat/samba.xinetd | 15 - packaging/RedHat/smb.conf | 288 -------------- packaging/RedHat/smb.init | 59 --- packaging/RedHat/smbprint | 77 ---- packaging/RedHat/smbusers | 3 - packaging/RedHat/winbind.init | 84 ----- 54 files changed, 2276 insertions(+), 2276 deletions(-) delete mode 100755 packaging/Fedora/filter-requires-samba.sh delete mode 100644 packaging/Fedora/makerpms.sh.tmpl delete mode 100644 packaging/Fedora/samba.log delete mode 100644 packaging/Fedora/samba.pamd delete mode 100644 packaging/Fedora/samba.spec.tmpl delete mode 100644 packaging/Fedora/samba.sysconfig delete mode 100644 packaging/Fedora/smb.conf delete mode 100644 packaging/Fedora/smb.init delete mode 100644 packaging/Fedora/smbprint delete mode 100644 packaging/Fedora/smbusers delete mode 100644 packaging/Fedora/swat delete mode 100644 packaging/Fedora/swat.desktop delete mode 100644 packaging/Fedora/winbind.init create mode 100755 packaging/RHEL/filter-requires-samba.sh create mode 100644 packaging/RHEL/makerpms.sh.tmpl create mode 100644 packaging/RHEL/samba.log create mode 100644 packaging/RHEL/samba.pamd create mode 100644 packaging/RHEL/samba.spec.tmpl create mode 100644 packaging/RHEL/samba.sysconfig create mode 100644 packaging/RHEL/smb.conf create mode 100644 packaging/RHEL/smb.init create mode 100644 packaging/RHEL/smbprint create mode 100644 packaging/RHEL/smbusers create mode 100644 packaging/RHEL/swat create mode 100644 packaging/RHEL/swat.desktop create mode 100644 packaging/RHEL/winbind.init create mode 100644 packaging/RedHat-9/README create mode 100755 packaging/RedHat-9/filter-requires-samba_rh8.sh create mode 100755 packaging/RedHat-9/filter-requires-samba_rh9.sh create mode 100644 packaging/RedHat-9/makerpms.sh.tmpl create mode 100644 packaging/RedHat-9/samba.log create mode 100644 packaging/RedHat-9/samba.pamd create mode 100644 packaging/RedHat-9/samba.pamd.stack create mode 100644 packaging/RedHat-9/samba.spec.tmpl create mode 100644 packaging/RedHat-9/samba.xinetd create mode 100644 packaging/RedHat-9/smb.conf create mode 100755 packaging/RedHat-9/smb.init create mode 100755 packaging/RedHat-9/smbprint create mode 100644 packaging/RedHat-9/smbusers create mode 100644 packaging/RedHat-9/winbind.init delete mode 100644 packaging/RedHat/README delete mode 100755 packaging/RedHat/filter-requires-samba_rh8.sh delete mode 100755 packaging/RedHat/filter-requires-samba_rh9.sh delete mode 100644 packaging/RedHat/makerpms.sh.tmpl delete mode 100644 packaging/RedHat/samba.log delete mode 100644 packaging/RedHat/samba.pamd delete mode 100644 packaging/RedHat/samba.pamd.stack delete mode 100644 packaging/RedHat/samba.spec.tmpl delete mode 100644 packaging/RedHat/samba.xinetd delete mode 100644 packaging/RedHat/smb.conf delete mode 100755 packaging/RedHat/smb.init delete mode 100755 packaging/RedHat/smbprint delete mode 100644 packaging/RedHat/smbusers delete mode 100644 packaging/RedHat/winbind.init diff --git a/packaging/Fedora/filter-requires-samba.sh b/packaging/Fedora/filter-requires-samba.sh deleted file mode 100755 index 5545cf6c858..00000000000 --- a/packaging/Fedora/filter-requires-samba.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -/usr/lib/rpm/perl.req $* | grep -E -v '(Net::LDAP|Crypt::SmbHash|CGI)' - diff --git a/packaging/Fedora/makerpms.sh.tmpl b/packaging/Fedora/makerpms.sh.tmpl deleted file mode 100644 index 361d8418761..00000000000 --- a/packaging/Fedora/makerpms.sh.tmpl +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -# Copyright (C) John H Terpstra 1998-2002 -# Gerald (Jerry) Carter 2003 - -# The following allows environment variables to override the target directories -# the alternative is to have a file in your home directory calles .rpmmacros -# containing the following: -# %_topdir /home/mylogin/redhat -# -# Note: Under this directory rpm expects to find the same directories that are under the -# /usr/src/redhat directory -# - -SPECDIR=`rpm --eval %_specdir` -SRCDIR=`rpm --eval %_sourcedir` - -# At this point the SPECDIR and SRCDIR vaiables must have a value! - -USERID=`id -u` -GRPID=`id -g` -VERSION='PVERSION' -SPECFILE="samba.spec" -RPMVER=`rpm --version | awk '{print $3}'` -RPM="rpmbuild" - -## -## Check the RPM version (paranoid) -## -case $RPMVER in - 4*) - echo "Supported RPM version [$RPMVER]" - ;; - *) - echo "Unknown RPM version: `rpm --version`" - exit 1 - ;; -esac - -( cd ../../source; if [ -f Makefile ]; then make distclean; fi ) -( cd ../../.. ; chown -R ${USERID}.${GRPID} samba-${VERSION} ) - -( cd ../../.. ; tar --exclude=CVS -cf - samba-${VERSION}/. | bzip2 > ${SRCDIR}/samba-${VERSION}.tar.bz2 ) - -## -## copy additional source files -## -for file in samba.pamd samba.sysconfig samba.spec \ - smb.init swat.desktop filter-requires-samba.sh \ - samba.log samba.xinetd smbprint winbind.init \ - smb.conf smbusers -do - cp -p $file ${SRCDIR} - -done - -chmod 755 ${SRCDIR}/filter-requires-samba.sh - -cp -p ${SPECFILE} ${SPECDIR} - -## -## Build -## -echo Getting Ready to build release package -cd ${SPECDIR} -${RPM} -ba --clean --rmsource $SPECFILE - -echo Done. - diff --git a/packaging/Fedora/samba.log b/packaging/Fedora/samba.log deleted file mode 100644 index a3c000ea788..00000000000 --- a/packaging/Fedora/samba.log +++ /dev/null @@ -1,9 +0,0 @@ -/var/log/samba/*.log /var/log/samba/log.smbd /var/log/samba/log.nmbd { - notifempty - missingok - sharedscripts - copytruncate - postrotate - /bin/kill -HUP `cat /var/run/smbd.pid /var/run/nmbd.pid /var/run/winbindd.pid 2> /dev/null` 2> /dev/null || true - endscript -} diff --git a/packaging/Fedora/samba.pamd b/packaging/Fedora/samba.pamd deleted file mode 100644 index f88aae628c2..00000000000 --- a/packaging/Fedora/samba.pamd +++ /dev/null @@ -1,4 +0,0 @@ -auth required /lib/security/pam_stack.so service=system-auth -session required /lib/security/pam_stack.so service=system-auth -account required /lib/security/pam_stack.so service=system-auth -password required /lib/security/pam_stack.so service=system-auth diff --git a/packaging/Fedora/samba.spec.tmpl b/packaging/Fedora/samba.spec.tmpl deleted file mode 100644 index 9afd9238084..00000000000 --- a/packaging/Fedora/samba.spec.tmpl +++ /dev/null @@ -1,442 +0,0 @@ -%define initdir %{_sysconfdir}/rc.d/init.d -%define auth %(test -f /etc/pam.d/system-auth && echo /etc/pam.d/system-auth || echo) - -Summary: Samba SMB client and server -Vendor: Samba Team -Packager: Samba Team -Name: samba -Version: PVERSION -Release: PRELEASE -License: GNU GPL version 2 -Group: System Environment/Daemons -URL: http://www.samba.org/ - -Source: samba-%{version}.tar.gz -Source1: samba.log -Source3: swat -Source4: samba.sysconfig -Source5: smb.init -Source6: winbind.init -Source7: samba.pamd -Source8: smbprint -Source9: smbusers -Source10: smb.conf - -# Don't depend on Net::LDAP -Source999: filter-requires-samba.sh - -Requires: pam >= 0.64 %{auth} samba-common = %{version} -Requires: logrotate >= 3.4 initscripts >= 5.54-1 -BuildRoot: %{_tmppath}/%{name}-%{version}-root -Prereq: /sbin/chkconfig /bin/mktemp /usr/bin/killall -Prereq: fileutils sed /etc/init.d -BuildRequires: pam-devel, readline-devel, ncurses-devel, fileutils, libacl-devel, openldap-devel, krb5-devel, cups-devel -Provides: samba = %{version} -Obsoletes: samba-common, samba-client, samba-swat - -BuildRoot: %{_tmppath}/%{name}-%{version}-root -Prefix: /usr - -%description -Samba is the protocol by which a lot of PC-related machines share -files, printers, and other information (such as lists of available -files and printers). The Windows NT, OS/2, and Linux operating systems -support this natively, and add-on packages can enable the same thing -for DOS, Windows, VMS, UNIX of all kinds, MVS, and more. This package -provides an SMB server that can be used to provide network services to -SMB (sometimes called "Lan Manager") clients. Samba uses NetBIOS over -TCP/IP (NetBT) protocols and does NOT need the NetBEUI (Microsoft Raw -NetBIOS frame) protocol. - - -%package client -Summary: Samba (SMB) client programs. -Group: Applications/System -Requires: samba-common = %{version} -Obsoletes: smbfs - -%description client -The samba-client package provides some SMB clients to compliment the -built-in SMB filesystem in Linux. These clients allow access of SMB -shares and printing to SMB printers. - - -%package common -Summary: Files used by both Samba servers and clients. -Group: Applications/System - -%description common -Samba-common provides files necessary for both the server and client -packages of Samba. - - -%package swat -Summary: The Samba SMB server configuration program. -Group: Applications/System -Requires: samba = %{version} xinetd - -%description swat -The samba-swat package includes the new SWAT (Samba Web Administration -Tool), for remotely managing Samba's smb.conf file using your favorite -Web browser. - - -%prep -%setup -q - -# copy Red Hat specific scripts -cp %{SOURCE5} packaging/Fedora/ -cp %{SOURCE6} packaging/Fedora/ -cp %{SOURCE7} packaging/Fedora/ -cp %{SOURCE8} packaging/Fedora/winbind.init - -%build -cd source -%ifarch i386 sparc -RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D_FILE_OFFSET_BITS=64" -%endif -%ifarch ia64 -libtoolize --copy --force # get it to recognize IA-64 -autoheader -autoconf -EXTRA="-D_LARGEFILE64_SOURCE" -%endif - -## run autogen if missing the configure script -if [ ! -f "configure" ]; then - ./autogen.sh -fi - -CFLAGS="$RPM_OPT_FLAGS $EXTRA -D_GNU_SOURCE" ./configure \ - --prefix=%{_prefix} \ - --localstatedir=/var \ - --with-configdir=%{_sysconfdir}/samba \ - --with-libdir=%{_libdir}/samba \ - --with-lockdir=/var/cache/samba \ - --with-logfilebase=/var/log/samba \ - --with-mandir=%{_mandir} \ - --with-piddir=/var/run \ - --with-privatedir=%{_sysconfdir}/samba \ - --with-sambabook=%{_datadir}/swat/using_samba \ - --with-swatdir=%{_datadir}/swat \ - --enable-cups \ - --with-acl-support \ - --with-ads \ - --with-automount \ - --with-fhs \ - --with-pam_smbpass \ - --with-libsmbclient \ - --with-libsmbsharemodes \ - --without-smbwrapper \ - --with-pam \ - --with-quotas \ - --with-shared-modules=idmap_rid \ - --with-smbmount \ - --with-syslog \ - --with-utmp - -make showlayout - -make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" proto pch - -make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{?_smp_mflags} \ - all modules pam_smbpass - -## build the cifs fs mount helper -cd client -gcc -o mount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE mount.cifs.c -gcc -o umount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE umount.cifs.c -cd .. - -# Remove some permission bits to avoid to many dependencies -cd .. -find examples docs -type f | xargs -r chmod -x - -%install -# Clean up in case there is trash left from a previous build -rm -rf $RPM_BUILD_ROOT - -# Create the target build directory hierarchy -mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/{help,include,using_samba/{figs,gifsa}} -mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/using_samba -mkdir -p $RPM_BUILD_ROOT%{_includedir} -mkdir -p $RPM_BUILD_ROOT%{_initrddir} -mkdir -p $RPM_BUILD_ROOT{%{_libdir},%{_includedir}} -mkdir -p $RPM_BUILD_ROOT%{_libdir}/samba/{auth,charset,idmap,vfs,pdb} -mkdir -p $RPM_BUILD_ROOT/%{_lib}/security -mkdir -p $RPM_BUILD_ROOT%{_mandir} -mkdir -p $RPM_BUILD_ROOT%{_prefix}/{bin,sbin} -mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib -mkdir -p $RPM_BUILD_ROOT/sbin -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{logrotate.d,pam.d,samba} -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{pam.d,logrotate.d} -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{samba,sysconfig} -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d -mkdir -p $RPM_BUILD_ROOT/var/cache/samba/winbindd_privileged -mkdir -p $RPM_BUILD_ROOT/var/{log,run/winbindd,spool}/samba - -cd source -make DESTDIR=$RPM_BUILD_ROOT \ - install -cd .. - -# pam_smbpass -cp source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so - -# NSS & PAM winbind support -install -m 755 source/nsswitch/pam_winbind.so $RPM_BUILD_ROOT/%{_lib}/security/pam_winbind.so -install -m 755 source/nsswitch/libnss_winbind.so $RPM_BUILD_ROOT/%{_lib}/libnss_winbind.so -install -m 755 source/nsswitch/libnss_wins.so $RPM_BUILD_ROOT/%{_lib}/libnss_wins.so -( cd $RPM_BUILD_ROOT/%{_lib}; - ln -sf libnss_winbind.so libnss_winbind.so.2; - ln -sf libnss_wins.so libnss_wins.so.2 ) - -# make install puts libsmbclient.so in the wrong place on x86_64 -rm -f $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.so $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.a || true -install -m 755 source/bin/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so -install -m 755 source/bin/libsmbclient.a $RPM_BUILD_ROOT%{_libdir}/libsmbclient.a -install -m 644 source/include/libsmbclient.h $RPM_BUILD_ROOT%{_includedir} -ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so.0 -if [ %{_libdir} == /usr/lib64 ];then - ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so.0 - ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so -fi - -# make install puts libmsrpc.so in the wrong place on x86_64 -install -m 755 source/bin/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so -install -m 755 source/bin/libmsrpc.a $RPM_BUILD_ROOT%{_libdir}/libmsrpc.a -install -m 644 source/include/libmsrpc.h $RPM_BUILD_ROOT%{_includedir} -rm -f $RPM_BUILD_ROOT%{_libdir}/samba/libmsrpc.* -ln -s /%{_libdir}/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so.0 - -# Install pam_smbpass.so -install -m755 source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so - -# we need a symlink for mount to recognise the smb and smbfs filesystem types -ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs -ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb - -# Install the miscellany -echo 127.0.0.1 localhost > $RPM_BUILD_ROOT%{_sysconfdir}/samba/lmhosts - -install -m644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/samba -install -m644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d/swat -install -m644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/samba -install -m755 %{SOURCE5} $RPM_BUILD_ROOT%{initdir}/smb -install -m755 %{SOURCE6} $RPM_BUILD_ROOT%{initdir}/winbind -install -m644 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/samba -install -m755 %{SOURCE8} $RPM_BUILD_ROOT%{_bindir} -install -m644 %{SOURCE9} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smbusers -install -m644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smb.conf -install -m755 source/client/mount.cifs $RPM_BUILD_ROOT/sbin/mount.cifs -install -m755 source/client/umount.cifs $RPM_BUILD_ROOT/sbin/umount.cifs -install -m755 source/script/mksmbpasswd.sh $RPM_BUILD_ROOT%{_bindir} - -ln -s ../..%{initdir}/smb $RPM_BUILD_ROOT%{_sbindir}/samba -ln -s ../..%{initdir}/winbind $RPM_BUILD_ROOT%{_sbindir}/winbind - -# Remove "*.old" files -find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; - -## don't duplicate the docs. These are installed by/with SWAT -rm -rf docs/htmldocs -rm -rf docs/manpages -( cd docs; ln -s %{_prefix}/share/swat/help htmldocs ) - -## -## Clean out man pages for tools not installed here -## -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man5/vfstest.1* - - -%clean -rm -rf $RPM_BUILD_ROOT - -%post -/sbin/chkconfig --add smb - -%preun -if [ $1 = 0 ] ; then - /sbin/chkconfig --del smb - rm -rf /var/log/samba/* /var/cache/samba/* - /sbin/service smb stop >/dev/null 2>&1 -fi -exit 0 - -%postun -if [ "$1" -ge "1" ]; then - %{initdir}/smb condrestart >/dev/null 2>&1 -fi - - -%post swat -# Add swat entry to /etc/services if not already there. -if [ ! "`grep ^\s**swat /etc/services`" ]; then - echo 'swat 901/tcp # Add swat service used via inetd' >> /etc/services -fi - -%post common -/sbin/chkconfig --add winbind -/sbin/ldconfig - -%preun common -if [ $1 = 0 ] ; then - /sbin/chkconfig --del winbind - /sbin/service winbind stop >/dev/null 2>&1 -fi -exit 0 - -%postun common -p /sbin/ldconfig - -%triggerpostun -- samba < 1.9.18p7 -if [ $1 != 0 ]; then - /sbin/chkconfig --add smb -fi - -%triggerpostun -- samba < 2.0.5a-3 -if [ $1 != 0 ]; then - [ ! -d /var/lock/samba ] && mkdir -m 0755 /var/lock/samba - [ ! -d /var/spool/samba ] && mkdir -m 1777 /var/spool/samba - chmod 644 /etc/services - [ -f /etc/inetd.conf ] && chmod 644 /etc/inetd.conf -fi - -%files -%defattr(-,root,root) -%doc README COPYING Manifest -%doc WHATSNEW.txt Roadmap -%doc docs -%doc examples/autofs examples/LDAP examples/libsmbclient examples/misc examples/printer-accounting -%doc examples/printing - -%attr(755,root,root) /%{_lib}/security/pam_smbpass.so -%{_sbindir}/samba -%{_sbindir}/winbind -%{_sbindir}/smbd -%{_sbindir}/nmbd -%{_bindir}/mksmbpasswd.sh -%{_bindir}/smbcontrol -%{_bindir}/smbstatus -%{_bindir}/tdbbackup -%{_bindir}/tdbtool -%config(noreplace) %{_sysconfdir}/sysconfig/samba -%config(noreplace) %{_sysconfdir}/samba/smbusers -%attr(755,root,root) %config %{initdir}/smb -%config(noreplace) %{_sysconfdir}/logrotate.d/samba -%config(noreplace) %{_sysconfdir}/pam.d/samba -%{_sysconfdir}/samba/samba.xinetd -%{_mandir}/man1/smbcontrol.1* -%{_mandir}/man1/smbstatus.1* -%{_mandir}/man1/vfstest.1* -%{_mandir}/man5/smbpasswd.5* -%{_mandir}/man7/samba.7* -%{_mandir}/man8/nmbd.8* -%{_mandir}/man8/pdbedit.8* -%{_mandir}/man8/smbd.8* -%{_mandir}/man7/pam_winbind.7* -%{_mandir}/man8/tdbbackup.8* -%{_mandir}/man7/libsmbclient.7* - -%{_libdir}/samba/vfs - -%attr(0700,root,root) %dir /var/log/samba -%attr(1777,root,root) %dir /var/spool/samba - -%files swat -%defattr(-,root,root) -%config(noreplace) %{_sysconfdir}/xinetd.d/swat -%{_datadir}/swat -%{_sbindir}/swat -%{_mandir}/man8/swat.8* -%attr(755,root,root) %{_libdir}/samba/*.msg - -%files client -%defattr(-,root,root) -/sbin/mount.smb -/sbin/mount.smbfs -/sbin/mount.cifs -/sbin/umount.cifs -%{_libdir}/samba/lowcase.dat -%{_libdir}/samba/upcase.dat -%{_libdir}/samba/valid.dat -%{_bindir}/rpcclient -%{_bindir}/smbcacls -%{_bindir}/smbmount -%{_bindir}/smbmnt -%{_bindir}/smbumount -%{_bindir}/findsmb -%{_bindir}/tdbdump -%{_mandir}/man8/tdbdump.8* -%{_mandir}/man8/smbmnt.8* -%{_mandir}/man8/smbmount.8* -%{_mandir}/man8/smbumount.8* -%{_mandir}/man8/mount.cifs.8.* -%{_mandir}/man8/umount.cifs.8.* -%{_mandir}/man8/smbspool.8* -%{_bindir}/nmblookup -%{_bindir}/smbget -%{_bindir}/smbclient -%{_bindir}/smbprint -%{_bindir}/smbspool -%{_bindir}/smbtar -%{_bindir}/net -%{_bindir}/smbtree -%{_mandir}/man1/smbget.1* -%{_mandir}/man5/smbgetrc.5* -%{_mandir}/man1/findsmb.1* -%{_mandir}/man1/nmblookup.1* -%{_mandir}/man1/rpcclient.1* -%{_mandir}/man1/smbcacls.1* -%{_mandir}/man1/smbclient.1* -%{_mandir}/man1/smbtar.1* -%{_mandir}/man1/smbtree.1* -%{_mandir}/man8/net.8* - -%files common -%defattr(-,root,root) -/%{_lib}/libnss_wins.so* -/%{_lib}/libnss_winbind.so* -/%{_lib}/security/pam_winbind.so -%{_includedir}/libsmbclient.h -%{_libdir}/libsmbclient.a -%{_libdir}/libsmbclient.so -%{_libdir}/libsmbclient.so.0 -%{_prefix}/lib/* -%{_includedir}/libmsrpc.h -%{_libdir}/libmsrpc.a -%{_libdir}/libmsrpc.so -%{_libdir}/samba/charset/CP*.so -%{_libdir}/samba/idmap/idmap*.so -%{_libdir}/samba/auth/script.so -%{_bindir}/testparm -%{_bindir}/smbpasswd -%{_bindir}/wbinfo -%{_bindir}/ntlm_auth -%{_bindir}/pdbedit -%{_bindir}/eventlogadm -%{_bindir}/profiles -%{_bindir}/smbcquotas -%{_sbindir}/winbindd -%config(noreplace) %{_sysconfdir}/samba/smb.conf -%config(noreplace) %{_sysconfdir}/samba/lmhosts -%dir %{_sysconfdir}/samba -%{initdir}/winbind -%{_mandir}/man1/ntlm_auth.1* -%{_mandir}/man1/profiles.1* -%{_mandir}/man1/smbcquotas.1* -%{_mandir}/man1/testparm.1* -%{_mandir}/man5/smb.conf.5* -%{_mandir}/man5/lmhosts.5* -%{_mandir}/man8/smbpasswd.8* -%{_mandir}/man1/wbinfo.1* -%{_mandir}/man8/winbindd.8* - -%changelog -* Fri Jan 16 2004 Gerald (Jerry) Carter -- Removed ChangeLog entries since they are kept in CVS - - - diff --git a/packaging/Fedora/samba.sysconfig b/packaging/Fedora/samba.sysconfig deleted file mode 100644 index 944b72fcc28..00000000000 --- a/packaging/Fedora/samba.sysconfig +++ /dev/null @@ -1,6 +0,0 @@ -# Options to smbd -SMBDOPTIONS="-D" -# Options to nmbd -NMBDOPTIONS="-D" -# Options for winbindd -WINBINDOPTIONS="" diff --git a/packaging/Fedora/smb.conf b/packaging/Fedora/smb.conf deleted file mode 100644 index 133e442b1e7..00000000000 --- a/packaging/Fedora/smb.conf +++ /dev/null @@ -1,288 +0,0 @@ -# This is the main Samba configuration file. You should read the -# smb.conf(5) manual page in order to understand the options listed -# here. Samba has a huge number of configurable options (perhaps too -# many!) most of which are not shown in this example -# -# Any line which starts with a ; (semi-colon) or a # (hash) -# is a comment and is ignored. In this example we will use a # -# for commentry and a ; for parts of the config file that you -# may wish to enable -# -# NOTE: Whenever you modify this file you should run the command "testparm" -# to check that you have not made any basic syntactic errors. -# -#======================= Global Settings ===================================== -[global] - -# workgroup = NT-Domain-Name or Workgroup-Name - workgroup = MYGROUP - -# server string is the equivalent of the NT Description field - server string = Samba Server - -# This option is important for security. It allows you to restrict -# connections to machines which are on your local network. The -# following example restricts access to two C class networks and -# the "loopback" interface. For more examples of the syntax see -# the smb.conf man page -; hosts allow = 192.168.1. 192.168.2. 127. - -# if you want to automatically load your printer list rather -# than setting them up individually then you'll need this - printcap name = /etc/printcap - load printers = yes - -# It should not be necessary to spell out the print system type unless -# yours is non-standard. Currently supported print systems include: -# bsd, sysv, plp, lprng, aix, hpux, qnx -; printing = bsd - -# Uncomment this if you want a guest account, you must add this to /etc/passwd -# otherwise the user "nobody" is used -; guest account = pcguest - -# this tells Samba to use a separate log file for each machine -# that connects - #log file = /var/log/samba/%m.log -# all information in one file - log file = /var/log/samba/log.smbd - -# Put a capping on the size of the log files (in Kb). - max log size = 50 - -# Security mode. Most people will want user level security. See -# security_level.txt for details. - security = user -# Use password server option only with security = server -; password server = - -# Password Level allows matching of _n_ characters of the password for -# all combinations of upper and lower case. -; password level = 8 -; username level = 8 - -# You may wish to use password encryption. Please read -# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation. -# Do not enable this option unless you have read those documents -; encrypt passwords = yes -; smb passwd file = /etc/samba/smbpasswd - -# The following are needed to allow password changing from Windows to -# update the Linux system password also. -# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above. -# NOTE2: You do NOT need these to allow workstations to change only -# the encrypted SMB passwords. They allow the Unix password -# to be kept in sync with the SMB password. -; unix password sync = Yes -; passwd program = /usr/bin/passwd %u -; passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully* - -# Unix users can map to different SMB User names -; username map = /etc/samba/smbusers - -# Using the following line enables you to customise your configuration -# on a per machine basis. The %m gets replaced with the netbios name -# of the machine that is connecting -; include = /etc/samba/smb.conf.%m - -# Most people will find that this option gives better performance. -# See speed.txt and the manual pages for details - socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 - -# Configure Samba to use multiple interfaces -# If you have multiple network interfaces then you must list them -# here. See the man page for details. -; interfaces = 192.168.12.2/24 192.168.13.2/24 - -# Configure remote browse list synchronisation here -# request announcement to, or browse list sync from: -# a specific host or from / to a whole subnet (see below) -; remote browse sync = 192.168.3.25 192.168.5.255 -# Cause this host to announce itself to local subnets here -; remote announce = 192.168.1.255 192.168.2.44 - -# Browser Control Options: -# set local master to no if you don't want Samba to become a master -# browser on your network. Otherwise the normal election rules apply -; local master = no - -# OS Level determines the precedence of this server in master browser -# elections. The default value should be reasonable -; os level = 33 - -# Domain Master specifies Samba to be the Domain Master Browser. This -# allows Samba to collate browse lists between subnets. Don't use this -# if you already have a Windows NT domain controller doing this job -; domain master = yes - -# Preferred Master causes Samba to force a local browser election on startup -# and gives it a slightly higher chance of winning the election -; preferred master = yes - -# Enable this if you want Samba to be a domain logon server for -# Windows95 workstations. -; domain logons = yes - -# if you enable domain logons then you may want a per-machine or -# per user logon script -# run a specific logon batch file per workstation (machine) -; logon script = %m.bat -# run a specific logon batch file per username -; logon script = %U.bat - -# Where to store roving profiles (only for Win95 and WinNT) -# %L substitutes for this servers netbios name, %U is username -# You must uncomment the [Profiles] share below -; logon path = \\%L\Profiles\%U - -# All NetBIOS names must be resolved to IP Addresses -# 'Name Resolve Order' allows the named resolution mechanism to be specified -# the default order is "host lmhosts wins bcast". "host" means use the unix -# system gethostbyname() function call that will use either /etc/hosts OR -# DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf -# and the /etc/resolv.conf file. "host" therefore is system configuration -# dependant. This parameter is most often of use to prevent DNS lookups -# in order to resolve NetBIOS names to IP Addresses. Use with care! -# The example below excludes use of name resolution for machines that are NOT -# on the local network segment -# - OR - are not deliberately to be known via lmhosts or via WINS. -; name resolve order = wins lmhosts bcast - -# Windows Internet Name Serving Support Section: -# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server -; wins support = yes - -# WINS Server - Tells the NMBD components of Samba to be a WINS Client -# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both -; wins server = w.x.y.z - -# WINS Proxy - Tells Samba to answer name resolution queries on -# behalf of a non WINS capable client, for this to work there must be -# at least one WINS Server on the network. The default is NO. -; wins proxy = yes - -# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names -# via DNS nslookups. The built-in default for versions 1.9.17 is yes, -# this has been changed in version 1.9.18 to no. - dns proxy = no - -# Case Preservation can be handy - system default is _no_ -# NOTE: These can be set on a per share basis -; preserve case = no -; short preserve case = no -# Default case is normally upper case for all DOS files -; default case = lower -# Be very careful with case sensitivity - it can break things! -; case sensitive = no - -#============================ Share Definitions ============================== -[homes] - comment = Home Directories - browseable = no - writable = yes - -# Un-comment the following and create the netlogon directory for Domain Logons -; [netlogon] -; comment = Network Logon Service -; path = /home/netlogon -; guest ok = yes -; writable = no -; share modes = no - - -# Un-comment the following to provide a specific roving profile share -# the default is to use the user's home directory -;[Profiles] -; path = /home/profiles -; browseable = no -; guest ok = yes - - -# NOTE: If you have a BSD-style print system there is no need to -# specifically define each individual printer -[printers] - comment = All Printers - path = /var/spool/samba - browseable = no -# Set public = yes to allow user 'guest account' to print - guest ok = no - writable = no - printable = yes - -# This one is useful for people to share files -;[tmp] -; comment = Temporary file space -; path = /tmp -; read only = no -; public = yes - -# A publicly accessible directory, but read only, except for people in -# the "staff" group -;[public] -; comment = Public Stuff -; path = /home/samba -; public = yes -; read only = yes -; write list = @staff - -# Other examples. -# -# A private printer, usable only by fred. Spool data will be placed in fred's -# home directory. Note that fred must have write access to the spool directory, -# wherever it is. -;[fredsprn] -; comment = Fred's Printer -; valid users = fred -; path = /homes/fred -; printer = freds_printer -; public = no -; writable = no -; printable = yes - -# A private directory, usable only by fred. Note that fred requires write -# access to the directory. -;[fredsdir] -; comment = Fred's Service -; path = /usr/somewhere/private -; valid users = fred -; public = no -; writable = yes -; printable = no - -# a service which has a different directory for each machine that connects -# this allows you to tailor configurations to incoming machines. You could -# also use the %u option to tailor it by user name. -# The %m gets replaced with the machine name that is connecting. -;[pchome] -; comment = PC Directories -; path = /usr/pc/%m -; public = no -; writable = yes - -# A publicly accessible directory, read/write to all users. Note that all files -# created in the directory by users will be owned by the default user, so -# any user with access can delete any other user's files. Obviously this -# directory must be writable by the default user. Another user could of course -# be specified, in which case all files would be owned by that user instead. -;[public] -; path = /usr/somewhere/else/public -; public = yes -; only guest = yes -; writable = yes -; printable = no - -# The following two entries demonstrate how to share a directory so that two -# users can place files there that will be owned by the specific users. In this -# setup, the directory should be writable by both users and should have the -# sticky bit set on it to prevent abuse. Obviously this could be extended to -# as many users as required. -;[myshare] -; comment = Mary's and Fred's stuff -; path = /usr/somewhere/shared -; valid users = mary fred -; public = no -; writable = yes -; printable = no -; create mask = 0765 - - diff --git a/packaging/Fedora/smb.init b/packaging/Fedora/smb.init deleted file mode 100644 index 30d7d403dd9..00000000000 --- a/packaging/Fedora/smb.init +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/sh -# -# chkconfig: - 91 35 -# description: Starts and stops the Samba smbd and nmbd daemons \ -# used to provide SMB network services. -# -# pidfile: /var/run/samba/smbd.pid -# pidfile: /var/run/samba/nmbd.pid -# config: /etc/samba/smb.conf - - -# Source function library. -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions -else - exit 0 -fi - -# Avoid using root's TMPDIR -unset TMPDIR - -# Source networking configuration. -. /etc/sysconfig/network - -if [ -f /etc/sysconfig/samba ]; then - . /etc/sysconfig/samba -fi - -# Check that networking is up. -[ ${NETWORKING} = "no" ] && exit 0 - -# Check that smb.conf exists. -[ -f /etc/samba/smb.conf ] || exit 0 - -# Check that we can write to it... so non-root users stop here -[ -w /etc/samba/smb.conf ] || exit 0 - -# Check whether "netbios disabled" is true -ISNETBIOSDISABLED=$(testparm -s 2>/dev/null | \ - sed -n '/\[global\]/,/^$/p' | \ - grep "disable netbios = Yes" | \ - awk 'BEGIN{FS=" = "}{print $2}') - - -RETVAL=0 - - -start() { - KIND="SMB" - echo -n $"Starting $KIND services: " - daemon smbd $SMBDOPTIONS - RETVAL=$? - echo - KIND="NMB" - if [ x"$ISNETBIOSDISABLED" != x"Yes" ]; then - echo -n $"Starting $KIND services: " - daemon nmbd $NMBDOPTIONS - RETVAL2=$? - echo - [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/smb || \ - RETVAL=1 - else - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/smb || \ - RETVAL=1 - fi - return $RETVAL -} - -stop() { - KIND="SMB" - echo -n $"Shutting down $KIND services: " - killproc smbd -TERM - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f /var/run/smbd.pid - echo - KIND="NMB" - if [ x"$ISNETBIOSDISABLED" != x"Yes" ]; then - echo -n $"Shutting down $KIND services: " - killproc nmbd -TERM - RETVAL2=$? - [ $RETVAL2 -eq 0 ] && rm -f /var/run/nmbd.pid - [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/smb - echo "" - else - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/smb - echo "" - fi - return $RETVAL -} - -restart() { - stop - start -} - -reload() { - echo -n $"Reloading smb.conf file: " - killproc smbd -HUP - RETVAL=$? - echo - return $RETVAL -} - -rhstatus() { - status smbd - status nmbd -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - reload) - reload - ;; - status) - rhstatus - ;; - condrestart) - [ -f /var/lock/subsys/smb ] && restart || : - ;; - *) - echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}" - exit 1 -esac - -exit $? diff --git a/packaging/Fedora/smbprint b/packaging/Fedora/smbprint deleted file mode 100644 index 1c3959d49b5..00000000000 --- a/packaging/Fedora/smbprint +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh -# This script is an input filter for printcap printing on a unix machine. It -# uses the smbclient program to print the file to the specified smb-based -# server and service. -# For example you could have a printcap entry like this -# -# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint -# -# which would create a unix printer called "smb" that will print via this -# script. You will need to create the spool directory /usr/spool/smb with -# appropriate permissions and ownerships for your system. - -# Set these to the server and service you wish to print to -# In this example I have a WfWg PC called "lapland" that has a printer -# exported called "printer" with no password. - -# -# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) -# so that the server, service, and password can be read from -# a /usr/var/spool/lpd/PRINTNAME/.config file. -# -# In order for this to work the /etc/printcap entry must include an -# accounting file (af=...): -# -# cdcolour:\ -# :cm=CD IBM Colorjet on 6th:\ -# :sd=/var/spool/lpd/cdcolour:\ -# :af=/var/spool/lpd/cdcolour/acct:\ -# :if=/usr/local/etc/smbprint:\ -# :mx=0:\ -# :lp=/dev/null: -# -# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: -# share=PC_SERVER -# user="user" -# password="password" -# -# Please, do not modify the order in the file. -# Example: -# share=\\server\deskjet -# user="fred" -# password="" - -# -# The last parameter to the filter is the accounting file name. -# Extract the directory name from the file name. -# Concat this with /.config to get the config file. -# -eval acct_file=\${$#} -spool_dir=`dirname $acct_file` -config_file=$spool_dir/.config - -# Should read the following variables set in the config file: -# share -# hostip -# user -# password - -eval `cat $config_file` - -share=`echo $share | sed "s/[\]/\//g"` - -if [ "$user" != "" ]; then - usercmd="-U" -else - usercmd="" -fi - -if [ "$workgroup" != "" ]; then - workgroupcmd="-W" -else - workgroupcmd="" -fi - -if [ "$translate" = "yes" ]; then - command="translate ; print -" -else - command="print -" -fi -#echo $share $password $translate $x_command > /tmp/smbprint.log - -cat | /usr/bin/smbclient "$share" "$password" -E ${hostip:+-I} \ - $hostip -N -P $usercmd "$user" $workgroupcmd "$workgroup" \ - -c "$command" 2>/dev/null diff --git a/packaging/Fedora/smbusers b/packaging/Fedora/smbusers deleted file mode 100644 index ae3389f53f8..00000000000 --- a/packaging/Fedora/smbusers +++ /dev/null @@ -1,3 +0,0 @@ -# Unix_name = SMB_name1 SMB_name2 ... -root = administrator admin -nobody = guest pcguest smbguest diff --git a/packaging/Fedora/swat b/packaging/Fedora/swat deleted file mode 100644 index 8b62348dde3..00000000000 --- a/packaging/Fedora/swat +++ /dev/null @@ -1,15 +0,0 @@ -# default: off -# description: SWAT is the Samba Web Admin Tool. Use swat \ -# to configure your Samba server. To use SWAT, \ -# connect to port 901 with your favorite web browser. -service swat -{ - port = 901 - socket_type = stream - wait = no - only_from = 127.0.0.1 - user = root - server = /usr/sbin/swat - log_on_failure += USERID - disable = yes -} diff --git a/packaging/Fedora/swat.desktop b/packaging/Fedora/swat.desktop deleted file mode 100644 index 0d7b4b5c48c..00000000000 --- a/packaging/Fedora/swat.desktop +++ /dev/null @@ -1,8 +0,0 @@ -[Desktop Entry] -Name=Samba Configuration -Name[de]=Samba Konfiguration -Type=Application -Comment=Configure Samba with a web based interface -Exec=htmlview http://127.0.0.1:901/ -Terminal=false -Categories=X-Red-Hat-Extra;Application;System;X-Red-Hat-ServerConfig; diff --git a/packaging/Fedora/winbind.init b/packaging/Fedora/winbind.init deleted file mode 100644 index e778e61e9cf..00000000000 --- a/packaging/Fedora/winbind.init +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/sh -# -# chkconfig: - 91 35 -# description: Starts and stops the Samba winbind daemon -# # -# pidfile: /var/cache/samba/winbind.pid -# config: /etc/samba/smb.conf - - -# Source function library. -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions -else - exit 0 -fi - -# Avoid using root's TMPDIR -unset TMPDIR - -# Source networking configuration. -. /etc/sysconfig/network - -if [ -f /etc/sysconfig/samba ]; then - . /etc/sysconfig/samba -fi - -# Check that networking is up. -[ ${NETWORKING} = "no" ] && exit 0 - -# Check that smb.conf exists. -[ -f /etc/samba/smb.conf ] || exit 0 - -RETVAL=0 - - -start() { - KIND="Winbind" - echo -n $"Starting $KIND services: " - daemon winbindd "$WINBINDOPTIONS" - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/winbindd || RETVAL=1 - return $RETVAL -} - -stop() { - echo - KIND="Winbind" - echo -n $"Shutting down $KIND services: " - killproc winbindd -TERM - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f /var/run/winbindd.pid && rm -f /var/lock/subsys/winbindd - echo "" - return $RETVAL -} - -restart() { - stop - start -} - -reload() { - echo -n $"Reloading smb.conf file: " - killproc winbindd -HUP - RETVAL=$? - echo - return $RETVAL -} - -rhstatus() { - status winbindd -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - reload) - reload - ;; - status) - rhstatus - ;; - condrestart) - [ -f /var/lock/subsys/winbindd ] && restart || : - ;; - *) - echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}" - exit 1 -esac - -exit $? diff --git a/packaging/RHEL/filter-requires-samba.sh b/packaging/RHEL/filter-requires-samba.sh new file mode 100755 index 00000000000..5545cf6c858 --- /dev/null +++ b/packaging/RHEL/filter-requires-samba.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +/usr/lib/rpm/perl.req $* | grep -E -v '(Net::LDAP|Crypt::SmbHash|CGI)' + diff --git a/packaging/RHEL/makerpms.sh.tmpl b/packaging/RHEL/makerpms.sh.tmpl new file mode 100644 index 00000000000..361d8418761 --- /dev/null +++ b/packaging/RHEL/makerpms.sh.tmpl @@ -0,0 +1,68 @@ +#!/bin/sh +# Copyright (C) John H Terpstra 1998-2002 +# Gerald (Jerry) Carter 2003 + +# The following allows environment variables to override the target directories +# the alternative is to have a file in your home directory calles .rpmmacros +# containing the following: +# %_topdir /home/mylogin/redhat +# +# Note: Under this directory rpm expects to find the same directories that are under the +# /usr/src/redhat directory +# + +SPECDIR=`rpm --eval %_specdir` +SRCDIR=`rpm --eval %_sourcedir` + +# At this point the SPECDIR and SRCDIR vaiables must have a value! + +USERID=`id -u` +GRPID=`id -g` +VERSION='PVERSION' +SPECFILE="samba.spec" +RPMVER=`rpm --version | awk '{print $3}'` +RPM="rpmbuild" + +## +## Check the RPM version (paranoid) +## +case $RPMVER in + 4*) + echo "Supported RPM version [$RPMVER]" + ;; + *) + echo "Unknown RPM version: `rpm --version`" + exit 1 + ;; +esac + +( cd ../../source; if [ -f Makefile ]; then make distclean; fi ) +( cd ../../.. ; chown -R ${USERID}.${GRPID} samba-${VERSION} ) + +( cd ../../.. ; tar --exclude=CVS -cf - samba-${VERSION}/. | bzip2 > ${SRCDIR}/samba-${VERSION}.tar.bz2 ) + +## +## copy additional source files +## +for file in samba.pamd samba.sysconfig samba.spec \ + smb.init swat.desktop filter-requires-samba.sh \ + samba.log samba.xinetd smbprint winbind.init \ + smb.conf smbusers +do + cp -p $file ${SRCDIR} + +done + +chmod 755 ${SRCDIR}/filter-requires-samba.sh + +cp -p ${SPECFILE} ${SPECDIR} + +## +## Build +## +echo Getting Ready to build release package +cd ${SPECDIR} +${RPM} -ba --clean --rmsource $SPECFILE + +echo Done. + diff --git a/packaging/RHEL/samba.log b/packaging/RHEL/samba.log new file mode 100644 index 00000000000..a3c000ea788 --- /dev/null +++ b/packaging/RHEL/samba.log @@ -0,0 +1,9 @@ +/var/log/samba/*.log /var/log/samba/log.smbd /var/log/samba/log.nmbd { + notifempty + missingok + sharedscripts + copytruncate + postrotate + /bin/kill -HUP `cat /var/run/smbd.pid /var/run/nmbd.pid /var/run/winbindd.pid 2> /dev/null` 2> /dev/null || true + endscript +} diff --git a/packaging/RHEL/samba.pamd b/packaging/RHEL/samba.pamd new file mode 100644 index 00000000000..f88aae628c2 --- /dev/null +++ b/packaging/RHEL/samba.pamd @@ -0,0 +1,4 @@ +auth required /lib/security/pam_stack.so service=system-auth +session required /lib/security/pam_stack.so service=system-auth +account required /lib/security/pam_stack.so service=system-auth +password required /lib/security/pam_stack.so service=system-auth diff --git a/packaging/RHEL/samba.spec.tmpl b/packaging/RHEL/samba.spec.tmpl new file mode 100644 index 00000000000..9afd9238084 --- /dev/null +++ b/packaging/RHEL/samba.spec.tmpl @@ -0,0 +1,442 @@ +%define initdir %{_sysconfdir}/rc.d/init.d +%define auth %(test -f /etc/pam.d/system-auth && echo /etc/pam.d/system-auth || echo) + +Summary: Samba SMB client and server +Vendor: Samba Team +Packager: Samba Team +Name: samba +Version: PVERSION +Release: PRELEASE +License: GNU GPL version 2 +Group: System Environment/Daemons +URL: http://www.samba.org/ + +Source: samba-%{version}.tar.gz +Source1: samba.log +Source3: swat +Source4: samba.sysconfig +Source5: smb.init +Source6: winbind.init +Source7: samba.pamd +Source8: smbprint +Source9: smbusers +Source10: smb.conf + +# Don't depend on Net::LDAP +Source999: filter-requires-samba.sh + +Requires: pam >= 0.64 %{auth} samba-common = %{version} +Requires: logrotate >= 3.4 initscripts >= 5.54-1 +BuildRoot: %{_tmppath}/%{name}-%{version}-root +Prereq: /sbin/chkconfig /bin/mktemp /usr/bin/killall +Prereq: fileutils sed /etc/init.d +BuildRequires: pam-devel, readline-devel, ncurses-devel, fileutils, libacl-devel, openldap-devel, krb5-devel, cups-devel +Provides: samba = %{version} +Obsoletes: samba-common, samba-client, samba-swat + +BuildRoot: %{_tmppath}/%{name}-%{version}-root +Prefix: /usr + +%description +Samba is the protocol by which a lot of PC-related machines share +files, printers, and other information (such as lists of available +files and printers). The Windows NT, OS/2, and Linux operating systems +support this natively, and add-on packages can enable the same thing +for DOS, Windows, VMS, UNIX of all kinds, MVS, and more. This package +provides an SMB server that can be used to provide network services to +SMB (sometimes called "Lan Manager") clients. Samba uses NetBIOS over +TCP/IP (NetBT) protocols and does NOT need the NetBEUI (Microsoft Raw +NetBIOS frame) protocol. + + +%package client +Summary: Samba (SMB) client programs. +Group: Applications/System +Requires: samba-common = %{version} +Obsoletes: smbfs + +%description client +The samba-client package provides some SMB clients to compliment the +built-in SMB filesystem in Linux. These clients allow access of SMB +shares and printing to SMB printers. + + +%package common +Summary: Files used by both Samba servers and clients. +Group: Applications/System + +%description common +Samba-common provides files necessary for both the server and client +packages of Samba. + + +%package swat +Summary: The Samba SMB server configuration program. +Group: Applications/System +Requires: samba = %{version} xinetd + +%description swat +The samba-swat package includes the new SWAT (Samba Web Administration +Tool), for remotely managing Samba's smb.conf file using your favorite +Web browser. + + +%prep +%setup -q + +# copy Red Hat specific scripts +cp %{SOURCE5} packaging/Fedora/ +cp %{SOURCE6} packaging/Fedora/ +cp %{SOURCE7} packaging/Fedora/ +cp %{SOURCE8} packaging/Fedora/winbind.init + +%build +cd source +%ifarch i386 sparc +RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D_FILE_OFFSET_BITS=64" +%endif +%ifarch ia64 +libtoolize --copy --force # get it to recognize IA-64 +autoheader +autoconf +EXTRA="-D_LARGEFILE64_SOURCE" +%endif + +## run autogen if missing the configure script +if [ ! -f "configure" ]; then + ./autogen.sh +fi + +CFLAGS="$RPM_OPT_FLAGS $EXTRA -D_GNU_SOURCE" ./configure \ + --prefix=%{_prefix} \ + --localstatedir=/var \ + --with-configdir=%{_sysconfdir}/samba \ + --with-libdir=%{_libdir}/samba \ + --with-lockdir=/var/cache/samba \ + --with-logfilebase=/var/log/samba \ + --with-mandir=%{_mandir} \ + --with-piddir=/var/run \ + --with-privatedir=%{_sysconfdir}/samba \ + --with-sambabook=%{_datadir}/swat/using_samba \ + --with-swatdir=%{_datadir}/swat \ + --enable-cups \ + --with-acl-support \ + --with-ads \ + --with-automount \ + --with-fhs \ + --with-pam_smbpass \ + --with-libsmbclient \ + --with-libsmbsharemodes \ + --without-smbwrapper \ + --with-pam \ + --with-quotas \ + --with-shared-modules=idmap_rid \ + --with-smbmount \ + --with-syslog \ + --with-utmp + +make showlayout + +make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" proto pch + +make CFLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE" %{?_smp_mflags} \ + all modules pam_smbpass + +## build the cifs fs mount helper +cd client +gcc -o mount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE mount.cifs.c +gcc -o umount.cifs $RPM_OPT_FLAGS -D_GNU_SOURCE -Wall -D_GNU_SOURCE -D_LARGEFILE64_SOURCE umount.cifs.c +cd .. + +# Remove some permission bits to avoid to many dependencies +cd .. +find examples docs -type f | xargs -r chmod -x + +%install +# Clean up in case there is trash left from a previous build +rm -rf $RPM_BUILD_ROOT + +# Create the target build directory hierarchy +mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/{help,include,using_samba/{figs,gifsa}} +mkdir -p $RPM_BUILD_ROOT%{_datadir}/swat/using_samba +mkdir -p $RPM_BUILD_ROOT%{_includedir} +mkdir -p $RPM_BUILD_ROOT%{_initrddir} +mkdir -p $RPM_BUILD_ROOT{%{_libdir},%{_includedir}} +mkdir -p $RPM_BUILD_ROOT%{_libdir}/samba/{auth,charset,idmap,vfs,pdb} +mkdir -p $RPM_BUILD_ROOT/%{_lib}/security +mkdir -p $RPM_BUILD_ROOT%{_mandir} +mkdir -p $RPM_BUILD_ROOT%{_prefix}/{bin,sbin} +mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib +mkdir -p $RPM_BUILD_ROOT/sbin +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{logrotate.d,pam.d,samba} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{pam.d,logrotate.d} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/{samba,sysconfig} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d +mkdir -p $RPM_BUILD_ROOT/var/cache/samba/winbindd_privileged +mkdir -p $RPM_BUILD_ROOT/var/{log,run/winbindd,spool}/samba + +cd source +make DESTDIR=$RPM_BUILD_ROOT \ + install +cd .. + +# pam_smbpass +cp source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so + +# NSS & PAM winbind support +install -m 755 source/nsswitch/pam_winbind.so $RPM_BUILD_ROOT/%{_lib}/security/pam_winbind.so +install -m 755 source/nsswitch/libnss_winbind.so $RPM_BUILD_ROOT/%{_lib}/libnss_winbind.so +install -m 755 source/nsswitch/libnss_wins.so $RPM_BUILD_ROOT/%{_lib}/libnss_wins.so +( cd $RPM_BUILD_ROOT/%{_lib}; + ln -sf libnss_winbind.so libnss_winbind.so.2; + ln -sf libnss_wins.so libnss_wins.so.2 ) + +# make install puts libsmbclient.so in the wrong place on x86_64 +rm -f $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.so $RPM_BUILD_ROOT/usr/lib*/samba/libsmbclient.a || true +install -m 755 source/bin/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so +install -m 755 source/bin/libsmbclient.a $RPM_BUILD_ROOT%{_libdir}/libsmbclient.a +install -m 644 source/include/libsmbclient.h $RPM_BUILD_ROOT%{_includedir} +ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT%{_libdir}/libsmbclient.so.0 +if [ %{_libdir} == /usr/lib64 ];then + ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so.0 + ln -s %{_libdir}/libsmbclient.so $RPM_BUILD_ROOT/usr/lib/libsmbclient.so +fi + +# make install puts libmsrpc.so in the wrong place on x86_64 +install -m 755 source/bin/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so +install -m 755 source/bin/libmsrpc.a $RPM_BUILD_ROOT%{_libdir}/libmsrpc.a +install -m 644 source/include/libmsrpc.h $RPM_BUILD_ROOT%{_includedir} +rm -f $RPM_BUILD_ROOT%{_libdir}/samba/libmsrpc.* +ln -s /%{_libdir}/libmsrpc.so $RPM_BUILD_ROOT%{_libdir}/libmsrpc.so.0 + +# Install pam_smbpass.so +install -m755 source/bin/pam_smbpass.so $RPM_BUILD_ROOT/%{_lib}/security/pam_smbpass.so + +# we need a symlink for mount to recognise the smb and smbfs filesystem types +ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs +ln -sf %{_prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb + +# Install the miscellany +echo 127.0.0.1 localhost > $RPM_BUILD_ROOT%{_sysconfdir}/samba/lmhosts + +install -m644 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/samba +install -m644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/xinetd.d/swat +install -m644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/samba +install -m755 %{SOURCE5} $RPM_BUILD_ROOT%{initdir}/smb +install -m755 %{SOURCE6} $RPM_BUILD_ROOT%{initdir}/winbind +install -m644 %{SOURCE7} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/samba +install -m755 %{SOURCE8} $RPM_BUILD_ROOT%{_bindir} +install -m644 %{SOURCE9} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smbusers +install -m644 %{SOURCE10} $RPM_BUILD_ROOT%{_sysconfdir}/samba/smb.conf +install -m755 source/client/mount.cifs $RPM_BUILD_ROOT/sbin/mount.cifs +install -m755 source/client/umount.cifs $RPM_BUILD_ROOT/sbin/umount.cifs +install -m755 source/script/mksmbpasswd.sh $RPM_BUILD_ROOT%{_bindir} + +ln -s ../..%{initdir}/smb $RPM_BUILD_ROOT%{_sbindir}/samba +ln -s ../..%{initdir}/winbind $RPM_BUILD_ROOT%{_sbindir}/winbind + +# Remove "*.old" files +find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; + +## don't duplicate the docs. These are installed by/with SWAT +rm -rf docs/htmldocs +rm -rf docs/manpages +( cd docs; ln -s %{_prefix}/share/swat/help htmldocs ) + +## +## Clean out man pages for tools not installed here +## +rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man5/vfstest.1* + + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +/sbin/chkconfig --add smb + +%preun +if [ $1 = 0 ] ; then + /sbin/chkconfig --del smb + rm -rf /var/log/samba/* /var/cache/samba/* + /sbin/service smb stop >/dev/null 2>&1 +fi +exit 0 + +%postun +if [ "$1" -ge "1" ]; then + %{initdir}/smb condrestart >/dev/null 2>&1 +fi + + +%post swat +# Add swat entry to /etc/services if not already there. +if [ ! "`grep ^\s**swat /etc/services`" ]; then + echo 'swat 901/tcp # Add swat service used via inetd' >> /etc/services +fi + +%post common +/sbin/chkconfig --add winbind +/sbin/ldconfig + +%preun common +if [ $1 = 0 ] ; then + /sbin/chkconfig --del winbind + /sbin/service winbind stop >/dev/null 2>&1 +fi +exit 0 + +%postun common -p /sbin/ldconfig + +%triggerpostun -- samba < 1.9.18p7 +if [ $1 != 0 ]; then + /sbin/chkconfig --add smb +fi + +%triggerpostun -- samba < 2.0.5a-3 +if [ $1 != 0 ]; then + [ ! -d /var/lock/samba ] && mkdir -m 0755 /var/lock/samba + [ ! -d /var/spool/samba ] && mkdir -m 1777 /var/spool/samba + chmod 644 /etc/services + [ -f /etc/inetd.conf ] && chmod 644 /etc/inetd.conf +fi + +%files +%defattr(-,root,root) +%doc README COPYING Manifest +%doc WHATSNEW.txt Roadmap +%doc docs +%doc examples/autofs examples/LDAP examples/libsmbclient examples/misc examples/printer-accounting +%doc examples/printing + +%attr(755,root,root) /%{_lib}/security/pam_smbpass.so +%{_sbindir}/samba +%{_sbindir}/winbind +%{_sbindir}/smbd +%{_sbindir}/nmbd +%{_bindir}/mksmbpasswd.sh +%{_bindir}/smbcontrol +%{_bindir}/smbstatus +%{_bindir}/tdbbackup +%{_bindir}/tdbtool +%config(noreplace) %{_sysconfdir}/sysconfig/samba +%config(noreplace) %{_sysconfdir}/samba/smbusers +%attr(755,root,root) %config %{initdir}/smb +%config(noreplace) %{_sysconfdir}/logrotate.d/samba +%config(noreplace) %{_sysconfdir}/pam.d/samba +%{_sysconfdir}/samba/samba.xinetd +%{_mandir}/man1/smbcontrol.1* +%{_mandir}/man1/smbstatus.1* +%{_mandir}/man1/vfstest.1* +%{_mandir}/man5/smbpasswd.5* +%{_mandir}/man7/samba.7* +%{_mandir}/man8/nmbd.8* +%{_mandir}/man8/pdbedit.8* +%{_mandir}/man8/smbd.8* +%{_mandir}/man7/pam_winbind.7* +%{_mandir}/man8/tdbbackup.8* +%{_mandir}/man7/libsmbclient.7* + +%{_libdir}/samba/vfs + +%attr(0700,root,root) %dir /var/log/samba +%attr(1777,root,root) %dir /var/spool/samba + +%files swat +%defattr(-,root,root) +%config(noreplace) %{_sysconfdir}/xinetd.d/swat +%{_datadir}/swat +%{_sbindir}/swat +%{_mandir}/man8/swat.8* +%attr(755,root,root) %{_libdir}/samba/*.msg + +%files client +%defattr(-,root,root) +/sbin/mount.smb +/sbin/mount.smbfs +/sbin/mount.cifs +/sbin/umount.cifs +%{_libdir}/samba/lowcase.dat +%{_libdir}/samba/upcase.dat +%{_libdir}/samba/valid.dat +%{_bindir}/rpcclient +%{_bindir}/smbcacls +%{_bindir}/smbmount +%{_bindir}/smbmnt +%{_bindir}/smbumount +%{_bindir}/findsmb +%{_bindir}/tdbdump +%{_mandir}/man8/tdbdump.8* +%{_mandir}/man8/smbmnt.8* +%{_mandir}/man8/smbmount.8* +%{_mandir}/man8/smbumount.8* +%{_mandir}/man8/mount.cifs.8.* +%{_mandir}/man8/umount.cifs.8.* +%{_mandir}/man8/smbspool.8* +%{_bindir}/nmblookup +%{_bindir}/smbget +%{_bindir}/smbclient +%{_bindir}/smbprint +%{_bindir}/smbspool +%{_bindir}/smbtar +%{_bindir}/net +%{_bindir}/smbtree +%{_mandir}/man1/smbget.1* +%{_mandir}/man5/smbgetrc.5* +%{_mandir}/man1/findsmb.1* +%{_mandir}/man1/nmblookup.1* +%{_mandir}/man1/rpcclient.1* +%{_mandir}/man1/smbcacls.1* +%{_mandir}/man1/smbclient.1* +%{_mandir}/man1/smbtar.1* +%{_mandir}/man1/smbtree.1* +%{_mandir}/man8/net.8* + +%files common +%defattr(-,root,root) +/%{_lib}/libnss_wins.so* +/%{_lib}/libnss_winbind.so* +/%{_lib}/security/pam_winbind.so +%{_includedir}/libsmbclient.h +%{_libdir}/libsmbclient.a +%{_libdir}/libsmbclient.so +%{_libdir}/libsmbclient.so.0 +%{_prefix}/lib/* +%{_includedir}/libmsrpc.h +%{_libdir}/libmsrpc.a +%{_libdir}/libmsrpc.so +%{_libdir}/samba/charset/CP*.so +%{_libdir}/samba/idmap/idmap*.so +%{_libdir}/samba/auth/script.so +%{_bindir}/testparm +%{_bindir}/smbpasswd +%{_bindir}/wbinfo +%{_bindir}/ntlm_auth +%{_bindir}/pdbedit +%{_bindir}/eventlogadm +%{_bindir}/profiles +%{_bindir}/smbcquotas +%{_sbindir}/winbindd +%config(noreplace) %{_sysconfdir}/samba/smb.conf +%config(noreplace) %{_sysconfdir}/samba/lmhosts +%dir %{_sysconfdir}/samba +%{initdir}/winbind +%{_mandir}/man1/ntlm_auth.1* +%{_mandir}/man1/profiles.1* +%{_mandir}/man1/smbcquotas.1* +%{_mandir}/man1/testparm.1* +%{_mandir}/man5/smb.conf.5* +%{_mandir}/man5/lmhosts.5* +%{_mandir}/man8/smbpasswd.8* +%{_mandir}/man1/wbinfo.1* +%{_mandir}/man8/winbindd.8* + +%changelog +* Fri Jan 16 2004 Gerald (Jerry) Carter +- Removed ChangeLog entries since they are kept in CVS + + + diff --git a/packaging/RHEL/samba.sysconfig b/packaging/RHEL/samba.sysconfig new file mode 100644 index 00000000000..944b72fcc28 --- /dev/null +++ b/packaging/RHEL/samba.sysconfig @@ -0,0 +1,6 @@ +# Options to smbd +SMBDOPTIONS="-D" +# Options to nmbd +NMBDOPTIONS="-D" +# Options for winbindd +WINBINDOPTIONS="" diff --git a/packaging/RHEL/smb.conf b/packaging/RHEL/smb.conf new file mode 100644 index 00000000000..133e442b1e7 --- /dev/null +++ b/packaging/RHEL/smb.conf @@ -0,0 +1,288 @@ +# This is the main Samba configuration file. You should read the +# smb.conf(5) manual page in order to understand the options listed +# here. Samba has a huge number of configurable options (perhaps too +# many!) most of which are not shown in this example +# +# Any line which starts with a ; (semi-colon) or a # (hash) +# is a comment and is ignored. In this example we will use a # +# for commentry and a ; for parts of the config file that you +# may wish to enable +# +# NOTE: Whenever you modify this file you should run the command "testparm" +# to check that you have not made any basic syntactic errors. +# +#======================= Global Settings ===================================== +[global] + +# workgroup = NT-Domain-Name or Workgroup-Name + workgroup = MYGROUP + +# server string is the equivalent of the NT Description field + server string = Samba Server + +# This option is important for security. It allows you to restrict +# connections to machines which are on your local network. The +# following example restricts access to two C class networks and +# the "loopback" interface. For more examples of the syntax see +# the smb.conf man page +; hosts allow = 192.168.1. 192.168.2. 127. + +# if you want to automatically load your printer list rather +# than setting them up individually then you'll need this + printcap name = /etc/printcap + load printers = yes + +# It should not be necessary to spell out the print system type unless +# yours is non-standard. Currently supported print systems include: +# bsd, sysv, plp, lprng, aix, hpux, qnx +; printing = bsd + +# Uncomment this if you want a guest account, you must add this to /etc/passwd +# otherwise the user "nobody" is used +; guest account = pcguest + +# this tells Samba to use a separate log file for each machine +# that connects + #log file = /var/log/samba/%m.log +# all information in one file + log file = /var/log/samba/log.smbd + +# Put a capping on the size of the log files (in Kb). + max log size = 50 + +# Security mode. Most people will want user level security. See +# security_level.txt for details. + security = user +# Use password server option only with security = server +; password server = + +# Password Level allows matching of _n_ characters of the password for +# all combinations of upper and lower case. +; password level = 8 +; username level = 8 + +# You may wish to use password encryption. Please read +# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation. +# Do not enable this option unless you have read those documents +; encrypt passwords = yes +; smb passwd file = /etc/samba/smbpasswd + +# The following are needed to allow password changing from Windows to +# update the Linux system password also. +# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above. +# NOTE2: You do NOT need these to allow workstations to change only +# the encrypted SMB passwords. They allow the Unix password +# to be kept in sync with the SMB password. +; unix password sync = Yes +; passwd program = /usr/bin/passwd %u +; passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully* + +# Unix users can map to different SMB User names +; username map = /etc/samba/smbusers + +# Using the following line enables you to customise your configuration +# on a per machine basis. The %m gets replaced with the netbios name +# of the machine that is connecting +; include = /etc/samba/smb.conf.%m + +# Most people will find that this option gives better performance. +# See speed.txt and the manual pages for details + socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 + +# Configure Samba to use multiple interfaces +# If you have multiple network interfaces then you must list them +# here. See the man page for details. +; interfaces = 192.168.12.2/24 192.168.13.2/24 + +# Configure remote browse list synchronisation here +# request announcement to, or browse list sync from: +# a specific host or from / to a whole subnet (see below) +; remote browse sync = 192.168.3.25 192.168.5.255 +# Cause this host to announce itself to local subnets here +; remote announce = 192.168.1.255 192.168.2.44 + +# Browser Control Options: +# set local master to no if you don't want Samba to become a master +# browser on your network. Otherwise the normal election rules apply +; local master = no + +# OS Level determines the precedence of this server in master browser +# elections. The default value should be reasonable +; os level = 33 + +# Domain Master specifies Samba to be the Domain Master Browser. This +# allows Samba to collate browse lists between subnets. Don't use this +# if you already have a Windows NT domain controller doing this job +; domain master = yes + +# Preferred Master causes Samba to force a local browser election on startup +# and gives it a slightly higher chance of winning the election +; preferred master = yes + +# Enable this if you want Samba to be a domain logon server for +# Windows95 workstations. +; domain logons = yes + +# if you enable domain logons then you may want a per-machine or +# per user logon script +# run a specific logon batch file per workstation (machine) +; logon script = %m.bat +# run a specific logon batch file per username +; logon script = %U.bat + +# Where to store roving profiles (only for Win95 and WinNT) +# %L substitutes for this servers netbios name, %U is username +# You must uncomment the [Profiles] share below +; logon path = \\%L\Profiles\%U + +# All NetBIOS names must be resolved to IP Addresses +# 'Name Resolve Order' allows the named resolution mechanism to be specified +# the default order is "host lmhosts wins bcast". "host" means use the unix +# system gethostbyname() function call that will use either /etc/hosts OR +# DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf +# and the /etc/resolv.conf file. "host" therefore is system configuration +# dependant. This parameter is most often of use to prevent DNS lookups +# in order to resolve NetBIOS names to IP Addresses. Use with care! +# The example below excludes use of name resolution for machines that are NOT +# on the local network segment +# - OR - are not deliberately to be known via lmhosts or via WINS. +; name resolve order = wins lmhosts bcast + +# Windows Internet Name Serving Support Section: +# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server +; wins support = yes + +# WINS Server - Tells the NMBD components of Samba to be a WINS Client +# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both +; wins server = w.x.y.z + +# WINS Proxy - Tells Samba to answer name resolution queries on +# behalf of a non WINS capable client, for this to work there must be +# at least one WINS Server on the network. The default is NO. +; wins proxy = yes + +# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names +# via DNS nslookups. The built-in default for versions 1.9.17 is yes, +# this has been changed in version 1.9.18 to no. + dns proxy = no + +# Case Preservation can be handy - system default is _no_ +# NOTE: These can be set on a per share basis +; preserve case = no +; short preserve case = no +# Default case is normally upper case for all DOS files +; default case = lower +# Be very careful with case sensitivity - it can break things! +; case sensitive = no + +#============================ Share Definitions ============================== +[homes] + comment = Home Directories + browseable = no + writable = yes + +# Un-comment the following and create the netlogon directory for Domain Logons +; [netlogon] +; comment = Network Logon Service +; path = /home/netlogon +; guest ok = yes +; writable = no +; share modes = no + + +# Un-comment the following to provide a specific roving profile share +# the default is to use the user's home directory +;[Profiles] +; path = /home/profiles +; browseable = no +; guest ok = yes + + +# NOTE: If you have a BSD-style print system there is no need to +# specifically define each individual printer +[printers] + comment = All Printers + path = /var/spool/samba + browseable = no +# Set public = yes to allow user 'guest account' to print + guest ok = no + writable = no + printable = yes + +# This one is useful for people to share files +;[tmp] +; comment = Temporary file space +; path = /tmp +; read only = no +; public = yes + +# A publicly accessible directory, but read only, except for people in +# the "staff" group +;[public] +; comment = Public Stuff +; path = /home/samba +; public = yes +; read only = yes +; write list = @staff + +# Other examples. +# +# A private printer, usable only by fred. Spool data will be placed in fred's +# home directory. Note that fred must have write access to the spool directory, +# wherever it is. +;[fredsprn] +; comment = Fred's Printer +; valid users = fred +; path = /homes/fred +; printer = freds_printer +; public = no +; writable = no +; printable = yes + +# A private directory, usable only by fred. Note that fred requires write +# access to the directory. +;[fredsdir] +; comment = Fred's Service +; path = /usr/somewhere/private +; valid users = fred +; public = no +; writable = yes +; printable = no + +# a service which has a different directory for each machine that connects +# this allows you to tailor configurations to incoming machines. You could +# also use the %u option to tailor it by user name. +# The %m gets replaced with the machine name that is connecting. +;[pchome] +; comment = PC Directories +; path = /usr/pc/%m +; public = no +; writable = yes + +# A publicly accessible directory, read/write to all users. Note that all files +# created in the directory by users will be owned by the default user, so +# any user with access can delete any other user's files. Obviously this +# directory must be writable by the default user. Another user could of course +# be specified, in which case all files would be owned by that user instead. +;[public] +; path = /usr/somewhere/else/public +; public = yes +; only guest = yes +; writable = yes +; printable = no + +# The following two entries demonstrate how to share a directory so that two +# users can place files there that will be owned by the specific users. In this +# setup, the directory should be writable by both users and should have the +# sticky bit set on it to prevent abuse. Obviously this could be extended to +# as many users as required. +;[myshare] +; comment = Mary's and Fred's stuff +; path = /usr/somewhere/shared +; valid users = mary fred +; public = no +; writable = yes +; printable = no +; create mask = 0765 + + diff --git a/packaging/RHEL/smb.init b/packaging/RHEL/smb.init new file mode 100644 index 00000000000..30d7d403dd9 --- /dev/null +++ b/packaging/RHEL/smb.init @@ -0,0 +1,135 @@ +#!/bin/sh +# +# chkconfig: - 91 35 +# description: Starts and stops the Samba smbd and nmbd daemons \ +# used to provide SMB network services. +# +# pidfile: /var/run/samba/smbd.pid +# pidfile: /var/run/samba/nmbd.pid +# config: /etc/samba/smb.conf + + +# Source function library. +if [ -f /etc/init.d/functions ] ; then + . /etc/init.d/functions +elif [ -f /etc/rc.d/init.d/functions ] ; then + . /etc/rc.d/init.d/functions +else + exit 0 +fi + +# Avoid using root's TMPDIR +unset TMPDIR + +# Source networking configuration. +. /etc/sysconfig/network + +if [ -f /etc/sysconfig/samba ]; then + . /etc/sysconfig/samba +fi + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +# Check that smb.conf exists. +[ -f /etc/samba/smb.conf ] || exit 0 + +# Check that we can write to it... so non-root users stop here +[ -w /etc/samba/smb.conf ] || exit 0 + +# Check whether "netbios disabled" is true +ISNETBIOSDISABLED=$(testparm -s 2>/dev/null | \ + sed -n '/\[global\]/,/^$/p' | \ + grep "disable netbios = Yes" | \ + awk 'BEGIN{FS=" = "}{print $2}') + + +RETVAL=0 + + +start() { + KIND="SMB" + echo -n $"Starting $KIND services: " + daemon smbd $SMBDOPTIONS + RETVAL=$? + echo + KIND="NMB" + if [ x"$ISNETBIOSDISABLED" != x"Yes" ]; then + echo -n $"Starting $KIND services: " + daemon nmbd $NMBDOPTIONS + RETVAL2=$? + echo + [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/smb || \ + RETVAL=1 + else + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/smb || \ + RETVAL=1 + fi + return $RETVAL +} + +stop() { + KIND="SMB" + echo -n $"Shutting down $KIND services: " + killproc smbd -TERM + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f /var/run/smbd.pid + echo + KIND="NMB" + if [ x"$ISNETBIOSDISABLED" != x"Yes" ]; then + echo -n $"Shutting down $KIND services: " + killproc nmbd -TERM + RETVAL2=$? + [ $RETVAL2 -eq 0 ] && rm -f /var/run/nmbd.pid + [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/smb + echo "" + else + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/smb + echo "" + fi + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + echo -n $"Reloading smb.conf file: " + killproc smbd -HUP + RETVAL=$? + echo + return $RETVAL +} + +rhstatus() { + status smbd + status nmbd +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + reload) + reload + ;; + status) + rhstatus + ;; + condrestart) + [ -f /var/lock/subsys/smb ] && restart || : + ;; + *) + echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}" + exit 1 +esac + +exit $? diff --git a/packaging/RHEL/smbprint b/packaging/RHEL/smbprint new file mode 100644 index 00000000000..1c3959d49b5 --- /dev/null +++ b/packaging/RHEL/smbprint @@ -0,0 +1,84 @@ +#!/bin/sh +# This script is an input filter for printcap printing on a unix machine. It +# uses the smbclient program to print the file to the specified smb-based +# server and service. +# For example you could have a printcap entry like this +# +# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint +# +# which would create a unix printer called "smb" that will print via this +# script. You will need to create the spool directory /usr/spool/smb with +# appropriate permissions and ownerships for your system. + +# Set these to the server and service you wish to print to +# In this example I have a WfWg PC called "lapland" that has a printer +# exported called "printer" with no password. + +# +# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) +# so that the server, service, and password can be read from +# a /usr/var/spool/lpd/PRINTNAME/.config file. +# +# In order for this to work the /etc/printcap entry must include an +# accounting file (af=...): +# +# cdcolour:\ +# :cm=CD IBM Colorjet on 6th:\ +# :sd=/var/spool/lpd/cdcolour:\ +# :af=/var/spool/lpd/cdcolour/acct:\ +# :if=/usr/local/etc/smbprint:\ +# :mx=0:\ +# :lp=/dev/null: +# +# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: +# share=PC_SERVER +# user="user" +# password="password" +# +# Please, do not modify the order in the file. +# Example: +# share=\\server\deskjet +# user="fred" +# password="" + +# +# The last parameter to the filter is the accounting file name. +# Extract the directory name from the file name. +# Concat this with /.config to get the config file. +# +eval acct_file=\${$#} +spool_dir=`dirname $acct_file` +config_file=$spool_dir/.config + +# Should read the following variables set in the config file: +# share +# hostip +# user +# password + +eval `cat $config_file` + +share=`echo $share | sed "s/[\]/\//g"` + +if [ "$user" != "" ]; then + usercmd="-U" +else + usercmd="" +fi + +if [ "$workgroup" != "" ]; then + workgroupcmd="-W" +else + workgroupcmd="" +fi + +if [ "$translate" = "yes" ]; then + command="translate ; print -" +else + command="print -" +fi +#echo $share $password $translate $x_command > /tmp/smbprint.log + +cat | /usr/bin/smbclient "$share" "$password" -E ${hostip:+-I} \ + $hostip -N -P $usercmd "$user" $workgroupcmd "$workgroup" \ + -c "$command" 2>/dev/null diff --git a/packaging/RHEL/smbusers b/packaging/RHEL/smbusers new file mode 100644 index 00000000000..ae3389f53f8 --- /dev/null +++ b/packaging/RHEL/smbusers @@ -0,0 +1,3 @@ +# Unix_name = SMB_name1 SMB_name2 ... +root = administrator admin +nobody = guest pcguest smbguest diff --git a/packaging/RHEL/swat b/packaging/RHEL/swat new file mode 100644 index 00000000000..8b62348dde3 --- /dev/null +++ b/packaging/RHEL/swat @@ -0,0 +1,15 @@ +# default: off +# description: SWAT is the Samba Web Admin Tool. Use swat \ +# to configure your Samba server. To use SWAT, \ +# connect to port 901 with your favorite web browser. +service swat +{ + port = 901 + socket_type = stream + wait = no + only_from = 127.0.0.1 + user = root + server = /usr/sbin/swat + log_on_failure += USERID + disable = yes +} diff --git a/packaging/RHEL/swat.desktop b/packaging/RHEL/swat.desktop new file mode 100644 index 00000000000..0d7b4b5c48c --- /dev/null +++ b/packaging/RHEL/swat.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Samba Configuration +Name[de]=Samba Konfiguration +Type=Application +Comment=Configure Samba with a web based interface +Exec=htmlview http://127.0.0.1:901/ +Terminal=false +Categories=X-Red-Hat-Extra;Application;System;X-Red-Hat-ServerConfig; diff --git a/packaging/RHEL/winbind.init b/packaging/RHEL/winbind.init new file mode 100644 index 00000000000..e778e61e9cf --- /dev/null +++ b/packaging/RHEL/winbind.init @@ -0,0 +1,100 @@ +#!/bin/sh +# +# chkconfig: - 91 35 +# description: Starts and stops the Samba winbind daemon +# # +# pidfile: /var/cache/samba/winbind.pid +# config: /etc/samba/smb.conf + + +# Source function library. +if [ -f /etc/init.d/functions ] ; then + . /etc/init.d/functions +elif [ -f /etc/rc.d/init.d/functions ] ; then + . /etc/rc.d/init.d/functions +else + exit 0 +fi + +# Avoid using root's TMPDIR +unset TMPDIR + +# Source networking configuration. +. /etc/sysconfig/network + +if [ -f /etc/sysconfig/samba ]; then + . /etc/sysconfig/samba +fi + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +# Check that smb.conf exists. +[ -f /etc/samba/smb.conf ] || exit 0 + +RETVAL=0 + + +start() { + KIND="Winbind" + echo -n $"Starting $KIND services: " + daemon winbindd "$WINBINDOPTIONS" + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/winbindd || RETVAL=1 + return $RETVAL +} + +stop() { + echo + KIND="Winbind" + echo -n $"Shutting down $KIND services: " + killproc winbindd -TERM + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f /var/run/winbindd.pid && rm -f /var/lock/subsys/winbindd + echo "" + return $RETVAL +} + +restart() { + stop + start +} + +reload() { + echo -n $"Reloading smb.conf file: " + killproc winbindd -HUP + RETVAL=$? + echo + return $RETVAL +} + +rhstatus() { + status winbindd +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + reload) + reload + ;; + status) + rhstatus + ;; + condrestart) + [ -f /var/lock/subsys/winbindd ] && restart || : + ;; + *) + echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}" + exit 1 +esac + +exit $? diff --git a/packaging/RedHat-9/README b/packaging/RedHat-9/README new file mode 100644 index 00000000000..646b10dbbbf --- /dev/null +++ b/packaging/RedHat-9/README @@ -0,0 +1,13 @@ +Preparer: Gerald Carter + +Instructions: Preparing Samba Packages for Red Hat Linux +=============================================================== + +We provide support only for the latest stable release of major +branches (e.g 6.2, 7.3, and 8.0). The makerpms.sh script +supports rpm version 2.x, 3.x, and 4.x + +To produce the RPMS simply type: + + root# sh makerpms.sh + diff --git a/packaging/RedHat-9/filter-requires-samba_rh8.sh b/packaging/RedHat-9/filter-requires-samba_rh8.sh new file mode 100755 index 00000000000..8428a6ad013 --- /dev/null +++ b/packaging/RedHat-9/filter-requires-samba_rh8.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/usr/lib/rpm/find-requires $* | egrep -v '(Net::LDAP|CGI)' diff --git a/packaging/RedHat-9/filter-requires-samba_rh9.sh b/packaging/RedHat-9/filter-requires-samba_rh9.sh new file mode 100755 index 00000000000..5545cf6c858 --- /dev/null +++ b/packaging/RedHat-9/filter-requires-samba_rh9.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +/usr/lib/rpm/perl.req $* | grep -E -v '(Net::LDAP|Crypt::SmbHash|CGI)' + diff --git a/packaging/RedHat-9/makerpms.sh.tmpl b/packaging/RedHat-9/makerpms.sh.tmpl new file mode 100644 index 00000000000..8da4a5d520e --- /dev/null +++ b/packaging/RedHat-9/makerpms.sh.tmpl @@ -0,0 +1,71 @@ +#!/bin/sh +# Copyright (C) John H Terpstra 1998-2002 +# Updated for RPM 3 by Jochen Wiedmann, joe@ispsoft.de +# Changed for a generic tar file rebuild by abartlet@pcug.org.au +# Changed by John H Terpstra to build on RH7.2 - should also work for earlier versions jht@samba.org + +# The following allows environment variables to override the target directories +# the alternative is to have a file in your home directory calles .rpmmacros +# containing the following: +# %_topdir /home/mylogin/redhat +# +# Note: Under this directory rpm expects to find the same directories that are under the +# /usr/src/redhat directory +# + +SPECDIR=`rpm --eval %_specdir` +SRCDIR=`rpm --eval %_sourcedir` + +# At this point the SPECDIR and SRCDIR vaiables must have a value! + +USERID=`id -u` +GRPID=`id -g` +VERSION='PVERSION' +SPECFILE="samba3.spec" +RPMVER=`rpm --version | awk '{print $3}'` +RPM="rpm" +echo The RPM Version on this machine is: $RPMVER + +## +## fix the mandir macro +## +case $RPMVER in + [23]*) + sed -e "s/MANDIR_MACRO/\%\{prefix\}\/man/g" < samba.spec > $SPECFILE + ;; + 4*) + sed -e "s/MANDIR_MACRO/\%\{_mandir\}/g" < samba.spec > $SPECFILE + ;; + *) + echo "Unknown RPM version: `rpm --version`" + exit 1 + ;; +esac + +## +## now catch the right command to build an RPM (defaults ro 'rpm' +## +case $RPMVER in + 4.[123]*) + RPM="rpmbuild" + ;; +esac + +echo "RPM build command is \"$RPM\"" + +( cd ../../source; if [ -f Makefile ]; then make distclean; fi ) +( cd ../../.. ; chown -R ${USERID}.${GRPID} samba-${VERSION} ) + +( cd ../../.. ; tar --exclude=CVS -cf - samba-${VERSION}/. | bzip2 > ${SRCDIR}/samba-${VERSION}.tar.bz2 ) + +/bin/cp -p filter-requires-samba_rh8.sh ${SRCDIR} +/bin/cp -p filter-requires-samba_rh9.sh ${SRCDIR} +chmod 755 ${SRCDIR}/filter-requires-samba_rh?.sh +/bin/cp -av $SPECFILE ${SPECDIR} + +echo Getting Ready to build release package +cd ${SPECDIR} +${RPM} -ba --clean --rmsource $SPECFILE + +echo Done. + diff --git a/packaging/RedHat-9/samba.log b/packaging/RedHat-9/samba.log new file mode 100644 index 00000000000..a3c000ea788 --- /dev/null +++ b/packaging/RedHat-9/samba.log @@ -0,0 +1,9 @@ +/var/log/samba/*.log /var/log/samba/log.smbd /var/log/samba/log.nmbd { + notifempty + missingok + sharedscripts + copytruncate + postrotate + /bin/kill -HUP `cat /var/run/smbd.pid /var/run/nmbd.pid /var/run/winbindd.pid 2> /dev/null` 2> /dev/null || true + endscript +} diff --git a/packaging/RedHat-9/samba.pamd b/packaging/RedHat-9/samba.pamd new file mode 100644 index 00000000000..bf7a5b392ca --- /dev/null +++ b/packaging/RedHat-9/samba.pamd @@ -0,0 +1,4 @@ +auth required /lib/security/pam_pwdb.so nullok +account required /lib/security/pam_pwdb.so +session required /lib/security/pam_pwdb.so +password required /lib/security/pam_pwdb.so # shadow md5 nullok audit diff --git a/packaging/RedHat-9/samba.pamd.stack b/packaging/RedHat-9/samba.pamd.stack new file mode 100644 index 00000000000..6a948f92cbd --- /dev/null +++ b/packaging/RedHat-9/samba.pamd.stack @@ -0,0 +1,6 @@ +#%PAM-1.0 +auth required pam_nologin.so +auth required pam_stack.so service=system-auth +account required pam_stack.so service=system-auth +session required pam_stack.so service=system-auth +password required pam_stack.so service=system-auth diff --git a/packaging/RedHat-9/samba.spec.tmpl b/packaging/RedHat-9/samba.spec.tmpl new file mode 100644 index 00000000000..b19a8874983 --- /dev/null +++ b/packaging/RedHat-9/samba.spec.tmpl @@ -0,0 +1,475 @@ +## grab the major and minor version of rpm +%define rpm_version `rpm --version | awk '{print $3}' | awk -F. '{print $1$2}'` + +Summary: Samba SMB client and server +Vendor: Samba Team +Name: samba +Version: PVERSION +Release: PRELEASE +License: GNU GPL version 2 +Group: Networking +Source: http://download.samba.org/samba/ftp/samba-%{version}.tar.bz2 + +# Don't depend on Net::LDAP +# one filter for RH 8 and one for 9 +Source998: filter-requires-samba_rh8.sh +Source999: filter-requires-samba_rh9.sh + +Packager: Gerald Carter [Samba-Team] +Requires: pam openldap krb5-libs cups +BuildRequires: openldap-devel krb5-devel pam-devel cups-devel +Prereq: chkconfig fileutils /sbin/ldconfig +Provides: samba = %{version} +Obsoletes: samba-common, samba-client, samba-swat +BuildRoot: %{_tmppath}/%{name}-%{version}-root +Prefix: /usr + +%description +Samba provides an SMB/CIFS server which can be used to provide +network file and print services to SMB/CIFS clients, including +various versions of MS Windows, OS/2, and other Linux machines. +Samba also provides some SMB clients, which complement the +built-in SMB filesystem in Linux. Samba uses NetBIOS over TCP/IP +(NetBT) protocols and does NOT need NetBEUI (Microsoft Raw NetBIOS +frame) protocol. + +Samba 3.0 also introduces UNICODE support and kerberos/ldap +integration as a member server in a Windows 2000 domain. + +Please refer to the WHATSNEW.txt document for fixup information. +docs directory for implementation details. + +%changelog +* Mon Nov 18 2002 Gerald Carter + - removed change log entries since history + is being maintained in CVS + +%prep +%setup + +%build + +# Working around perl dependency problem from docs +# Only > RH 8.0 seems to care here + +echo "rpm_version == %{rpm_version}" +if [ "%{rpm_version}" == "42" ]; then + %define __perl_requires %{SOURCE999} + echo "%{__perl_requires}" +elif [ "%{rpm_version}" == "41" ]; then + %define __find_requires %{SOURCE998} + echo "%{__find_requires}" +fi + +## Build main Samba source +cd source + +%ifarch ia64 +libtoolize --copy --force # get it to recognize IA-64 +autoheader +autoconf +EXTRA="-D_LARGEFILE64_SOURCE" +%endif + +## Get number of cpu's, default for 1 cpu on error +NUMCPU=`grep processor /proc/cpuinfo | wc -l` +if [ $NUMCPU -eq 0 ]; then + NUMCPU=1; +fi + +## run autogen if missing the configure script +if [ ! -f "configure" ]; then + ./autogen.sh +fi + +CFLAGS="$RPM_OPT_FLAGS $EXTRA" ./configure \ + --prefix=%{prefix} \ + --localstatedir=/var \ + --with-configdir=/etc/samba \ + --with-privatedir=/etc/samba \ + --with-fhs \ + --with-quotas \ + --with-smbmount \ + --enable-cups \ + --with-pam \ + --with-pam_smbpass \ + --with-syslog \ + --with-utmp \ + --with-swatdir=%{prefix}/share/swat \ + --with-shared-modules=idmap_rid \ + --with-libsmbclient +make -j${NUMCPU} proto +make -j${NUMCPU} all modules nsswitch/libnss_wins.so +make -j${NUMCPU} debug2html + +# Remove some permission bits to avoid to many dependencies +cd .. +find examples docs -type f | xargs -r chmod -x + +%install +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/sbin +mkdir -p $RPM_BUILD_ROOT/etc/samba +mkdir -p $RPM_BUILD_ROOT/etc/{logrotate.d,pam.d,samba} +mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d +mkdir -p $RPM_BUILD_ROOT%{prefix}/{bin,sbin} +mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/{help,include,using_samba} +mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/help/using_samba/{figs,gifs} +mkdir -p $RPM_BUILD_ROOTMANDIR_MACRO +mkdir -p $RPM_BUILD_ROOT/var/lib/samba +mkdir -p $RPM_BUILD_ROOT/var/{log,run}/samba +mkdir -p $RPM_BUILD_ROOT/var/spool/samba +mkdir -p $RPM_BUILD_ROOT/lib/security +mkdir -p $RPM_BUILD_ROOT%{prefix}/lib/samba/vfs +mkdir -p $RPM_BUILD_ROOT%{prefix}/{lib,include} + +# Install standard binary files +for i in nmblookup smbget smbclient smbpasswd smbstatus testparm \ + rpcclient smbspool smbcacls smbcontrol wbinfo smbmnt net \ + smbcacls pdbedit eventlogadm tdbbackup smbtree ntlm_auth smbcquotas +do + install -m755 source/bin/$i $RPM_BUILD_ROOT%{prefix}/bin +done + +for i in mksmbpasswd.sh smbtar findsmb +do + install -m755 source/script/$i $RPM_BUILD_ROOT%{prefix}/bin +done + +# Install secure binary files +for i in smbd nmbd swat smbmount smbumount debug2html winbindd +do + install -m755 source/bin/$i $RPM_BUILD_ROOT%{prefix}/sbin +done + +# we need a symlink for mount to recognise the smb and smbfs filesystem types +ln -sf %{prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs +ln -sf %{prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb + +# This allows us to get away without duplicating code that +# sombody else can maintain for us. +cd source +make DESTDIR=$RPM_BUILD_ROOT \ + BASEDIR=/usr \ + CONFIGDIR=/etc/samba \ + LIBDIR=%{prefix}/lib/samba \ + VARDIR=/var \ + SBINDIR=%{prefix}/sbin \ + BINDIR=%{prefix}/bin \ + MANDIR=MANDIR_MACRO \ + SWATDIR=%{prefix}/share/swat \ + SAMBABOOK=%{prefix}/share/swat/using_samba \ + installman installswat installdat installmodules +cd .. + +## don't duplicate the docs. These are installed with SWAT +rm -rf docs/htmldocs +rm -rf docs/manpages +( cd docs; ln -s %{prefix}/share/swat/help htmldocs ) + + + +# Install the nsswitch wins library +install -m755 source/nsswitch/libnss_wins.so $RPM_BUILD_ROOT/lib +( cd $RPM_BUILD_ROOT/lib; ln -sf libnss_wins.so libnss_wins.so.2 ) + +# Install winbind shared libraries +install -m755 source/nsswitch/libnss_winbind.so $RPM_BUILD_ROOT/lib +( cd $RPM_BUILD_ROOT/lib; ln -sf libnss_winbind.so libnss_winbind.so.2 ) +install -m755 source/nsswitch/pam_winbind.so $RPM_BUILD_ROOT/lib/security + +# Install pam_smbpass.so +install -m755 source/bin/pam_smbpass.so $RPM_BUILD_ROOT/lib/security + +# libsmbclient +install -m 755 source/bin/libsmbclient.so $RPM_BUILD_ROOT%{prefix}/lib/ +install -m 755 source/bin/libsmbclient.a $RPM_BUILD_ROOT%{prefix}/lib/ +install -m 644 source/include/libsmbclient.h $RPM_BUILD_ROOT%{prefix}/include/ + +# libmsrpc +install -m 755 source/bin/libmsrpc.so $RPM_BUILD_ROOT%{prefix}/lib/ +install -m 755 source/bin/libmsrpc.a $RPM_BUILD_ROOT%{prefix}/lib/ +install -m 644 source/include/libmsrpc.h $RPM_BUILD_ROOT%{prefix}/include/ + +# Install the miscellany +install -m755 packaging/RedHat/smbprint $RPM_BUILD_ROOT%{prefix}/bin +install -m755 packaging/RedHat/smb.init $RPM_BUILD_ROOT/etc/rc.d/init.d/smb +install -m755 packaging/RedHat/winbind.init $RPM_BUILD_ROOT/etc/rc.d/init.d/winbind +install -m755 packaging/RedHat/smb.init $RPM_BUILD_ROOT%{prefix}/sbin/samba +install -m644 packaging/RedHat/samba.log $RPM_BUILD_ROOT/etc/logrotate.d/samba +install -m644 packaging/RedHat/smb.conf $RPM_BUILD_ROOT/etc/samba/smb.conf +install -m644 packaging/RedHat/smbusers $RPM_BUILD_ROOT/etc/samba/smbusers +install -m644 packaging/RedHat/samba.pamd $RPM_BUILD_ROOT/etc/pam.d/samba +install -m644 packaging/RedHat/samba.pamd.stack $RPM_BUILD_ROOT/etc/samba/samba.stack +install -m644 packaging/RedHat/samba.xinetd $RPM_BUILD_ROOT/etc/samba/samba.xinetd +echo 127.0.0.1 localhost > $RPM_BUILD_ROOT/etc/samba/lmhosts + +# Remove "*.old" files +find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; + +## +## Clean out man pages for tools not installed here +## +rm -f $RPM_BUILD_ROOT/%{_mandir}/man1/editreg.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* +rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* +rm -f $RPM_BUILD_ROOT/%{_mandir}/man8/mount.cifs.8* + + +%clean +rm -rf $RPM_BUILD_ROOT + +%post +## +## only needed if this is a new install (not an upgrade) +## +if [ "$1" -eq "1" ]; then + /sbin/chkconfig --add smb + /sbin/chkconfig --add winbind + /sbin/chkconfig smb off + /sbin/chkconfig winbind off +fi + +## +## we only have to wory about this if we are upgrading +## +if [ "$1" -eq "2" ]; then + if [ -f /etc/smb.conf -a ! -f /etc/samba/smb.conf ]; then + echo "Moving old /etc/smb.conf to /etc/samba/smb.conf" + mv /etc/smb.conf /etc/samba/smb.conf + fi + + if [ -f /etc/smbusers -a ! -f /etc/samba/smbusers ]; then + echo "Moving old /etc/smbusers to /etc/samba/smbusers" + mv /etc/smbusers /etc/samba/smbusers + fi + + if [ -f /etc/lmhosts -a ! -f /etc/samba/lmhosts ]; then + echo "Moving old /etc/lmhosts to /etc/samba/lmhosts" + mv /etc/lmhosts /etc/samba/lmhosts + fi + + if [ -f /etc/MACHINE.SID -a ! -f /etc/samba/MACHINE.SID ]; then + echo "Moving old /etc/MACHINE.SID to /etc/samba/MACHINE.SID" + mv /etc/MACHINE.SID /etc/samba/MACHINE.SID + fi + + if [ -f /etc/smbpasswd -a ! -f /etc/samba/smbpasswd ]; then + echo "Moving old /etc/smbpasswd to /etc/samba/smbpasswd" + mv /etc/smbpasswd /etc/samba/smbpasswd + fi + + # + # For 2.2.1 we move the tdb files from /var/lock/samba to /var/cache/samba + # to preserve across reboots. + # + for i in /var/lock/samba/*.tdb; do + if [ -f $i ]; then + newname="/var/lib/samba/`basename $i`" + echo "Moving $i to $newname" + mv $i $newname + fi + done + + # + # For 3.0.1 we move the tdb files from /var/cache/samba to /var/lib/samba + # + echo "Moving tdb files in /var/cache/samba/*.tdb to /var/lib/samba/*.tdb" + for i in /var/cache/samba/*.tdb; do + if [ -f $i ]; then + newname="/var/lib/samba/`basename $i`" + echo "Moving $i to $newname" + mv $i $newname + fi + done +fi + +## +## New things +## + +# Add swat entry to /etc/services if not already there. +if [ ! "`grep ^\s**swat /etc/services`" ]; then + echo 'swat 901/tcp # Add swat service used via inetd' >> /etc/services +fi + +# Add swat entry to /etc/inetd.conf if needed. +if [ -f /etc/inetd.conf ]; then + if [ ! "`grep ^\s*swat /etc/inetd.conf`" ]; then + echo 'swat stream tcp nowait.400 root %{prefix}/sbin/swat swat' >> /etc/inetd.conf + killall -HUP inetd || : + fi +fi + +# Add swat entry to xinetd.d if needed. +if [ -d /etc/xinetd.d -a ! -f /etc/xinetd.d/swat ]; then + mv /etc/samba/samba.xinetd /etc/xinetd.d/swat +else + rm -f /etc/samba/samba.xinetd +fi + +# Install the correct version of the samba pam file +if [ -f /lib/security/pam_stack.so ]; then + echo "Installing stack version of /etc/pam.d/samba..." + mv /etc/samba/samba.stack /etc/pam.d/samba +else + echo "Installing non-stack version of /etc/pam.d/samba..." + rm -f /etc/samba/samba.stack +fi + +## call ldconfig to create the version symlink for libsmbclient.so +/sbin/ldconfig + +%preun +if [ "$1" -eq "0" ] ; then + /sbin/chkconfig --del smb + /sbin/chkconfig --del winbind + + # We want to remove the browse.dat and wins.dat files + # so they can not interfer with a new version of samba! + if [ -e /var/lib/samba/browse.dat ]; then + rm -f /var/lib/samba/browse.dat + fi + if [ -e /var/lib/samba/wins.dat ]; then + rm -f /var/lib/samba/wins.dat + fi + + # Remove the transient tdb files. + if [ -e /var/lib/samba/brlock.tdb ]; then + rm -f /var/lib/samba/brlock.tdb + fi + + if [ -e /var/lib/samba/unexpected.tdb ]; then + rm -f /var/lib/samba/unexpected.tdb + fi + + if [ -e /var/lib/samba/connections.tdb ]; then + rm -f /var/lib/samba/connections.tdb + fi + + if [ -e /var/lib/samba/locking.tdb ]; then + rm -f /var/lib/samba/locking.tdb + fi + + if [ -e /var/lib/samba/messages.tdb ]; then + rm -f /var/lib/samba/messages.tdb + fi +fi + +%postun +# Only delete remnants of samba if this is the final deletion. +if [ "$1" -eq "0" ] ; then + if [ -x /etc/pam.d/samba ]; then + rm -f /etc/pam.d/samba + fi + + if [ -e /var/log/samba ]; then + rm -rf /var/log/samba + fi + + if [ -e /var/lib/samba ]; then + rm -rf /var/lib/samba + fi + + # Remove swat entries from /etc/inetd.conf and /etc/services + cd /etc + tmpfile=/etc/tmp.$$ + if [ -f /etc/inetd.conf ]; then + # preserve inetd.conf permissions. + cp -p /etc/inetd.conf $tmpfile + sed -e '/^[:space:]*swat.*$/d' /etc/inetd.conf > $tmpfile + mv $tmpfile inetd.conf + fi + + # preserve services permissions. + cp -p /etc/services $tmpfile + sed -e '/^[:space:]*swat.*$/d' /etc/services > $tmpfile + mv $tmpfile /etc/services + + # Remove swat entry from /etc/xinetd.d + if [ -f /etc/xinetd.d/swat ]; then + rm -r /etc/xinetd.d/swat + fi +fi + +/sbin/ldconfig + +%files +%defattr(-,root,root) +%doc README COPYING Manifest Read-Manifest-Now +%doc WHATSNEW.txt Roadmap +%doc docs +%doc examples +%{prefix}/sbin/smbd +%{prefix}/sbin/nmbd +%{prefix}/sbin/swat +%{prefix}/bin/smbmnt +%{prefix}/sbin/smbmount +%{prefix}/sbin/smbumount +%{prefix}/sbin/winbindd +%{prefix}/sbin/samba +%{prefix}/sbin/debug2html +/sbin/mount.smbfs +/sbin/mount.smb +%{prefix}/bin/mksmbpasswd.sh +%{prefix}/bin/smbclient +%{prefix}/bin/smbget +%{prefix}/bin/smbspool +%{prefix}/bin/rpcclient +%{prefix}/bin/testparm +%{prefix}/bin/findsmb +%{prefix}/bin/smbstatus +%{prefix}/bin/nmblookup +%{prefix}/bin/smbpasswd +%{prefix}/bin/smbtar +%{prefix}/bin/smbprint +%{prefix}/bin/smbcontrol +%{prefix}/bin/wbinfo +%{prefix}/bin/net +%{prefix}/bin/ntlm_auth +%{prefix}/bin/smbcquotas +%{prefix}/bin/smbcacls +%{prefix}/bin/pdbedit +%{prefix}/bin/eventlogadm +%{prefix}/bin/tdbbackup +%{prefix}/bin/smbtree +%attr(755,root,root) /lib/libnss_wins.s* +%attr(755,root,root) %{prefix}/lib/samba/vfs/*.so +%attr(755,root,root) %{prefix}/lib/samba/auth/*.so +%attr(755,root,root) %{prefix}/lib/samba/charset/*.so +%attr(755,root,root) %{prefix}/lib/samba/idmap/*.so +#%attr(755,root,root) %{prefix}/lib/samba/pdb/*.so +%attr(755,root,root) %{prefix}/lib/samba/*.dat +%attr(755,root,root) %{prefix}/lib/samba/*.msg +%{prefix}/include/libsmbclient.h +%{prefix}/lib/libsmbclient.a +%{prefix}/lib/libsmbclient.so +%{prefix}/include/libmsrpc.h +%{prefix}/lib/libmsrpc.a +%{prefix}/lib/libmsrpc.so +%{prefix}/share/swat/help/* +%{prefix}/share/swat/images/*.gif +%{prefix}/share/swat/include/*.html +%{prefix}/share/swat/lang/*/help/* +%{prefix}/share/swat/lang/*/images/*.gif +%config(noreplace) /etc/samba/lmhosts +%config(noreplace) /etc/samba/smb.conf +%config(noreplace) /etc/samba/smbusers +/etc/samba/samba.stack +/etc/samba/samba.xinetd +/etc/rc.d/init.d/smb +/etc/rc.d/init.d/winbind +/etc/logrotate.d/samba +%config(noreplace) /etc/pam.d/samba +MANDIR_MACRO/man1/* +MANDIR_MACRO/man5/* +MANDIR_MACRO/man7/* +MANDIR_MACRO/man8/* +%attr(755,root,root) %dir /var/lib/samba +%dir /var/log/samba +%dir /var/run/samba +%attr(1777,root,root) %dir /var/spool/samba +%attr(-,root,root) /lib/libnss_winbind.so* +%attr(-,root,root) /lib/security/pam_winbind.so +%attr(-,root,root) /lib/security/pam_smbpass.so diff --git a/packaging/RedHat-9/samba.xinetd b/packaging/RedHat-9/samba.xinetd new file mode 100644 index 00000000000..8c38b354218 --- /dev/null +++ b/packaging/RedHat-9/samba.xinetd @@ -0,0 +1,15 @@ +# default: off +# description: SWAT is the Samba Web Admin Tool. Use swat \ +# to configure your Samba server. To use SWAT, \ +# connect to port 901 with your favorite web browser. +service swat +{ + port = 901 + socket_type = stream + wait = no + only_from = localhost + user = root + server = /usr/sbin/swat + log_on_failure += USERID + disable = yes +} diff --git a/packaging/RedHat-9/smb.conf b/packaging/RedHat-9/smb.conf new file mode 100644 index 00000000000..ba64dad729c --- /dev/null +++ b/packaging/RedHat-9/smb.conf @@ -0,0 +1,288 @@ +# This is the main Samba configuration file. You should read the +# smb.conf(5) manual page in order to understand the options listed +# here. Samba has a huge number of configurable options (perhaps too +# many!) most of which are not shown in this example +# +# Any line which starts with a ; (semi-colon) or a # (hash) +# is a comment and is ignored. In this example we will use a # +# for commentry and a ; for parts of the config file that you +# may wish to enable +# +# NOTE: Whenever you modify this file you should run the command "testparm" +# to check that you have not made any basic syntactic errors. +# +#======================= Global Settings ===================================== +[global] + +# workgroup = NT-Domain-Name or Workgroup-Name + workgroup = MYGROUP + +# server string is the equivalent of the NT Description field + server string = Samba Server + +# This option is important for security. It allows you to restrict +# connections to machines which are on your local network. The +# following example restricts access to two C class networks and +# the "loopback" interface. For more examples of the syntax see +# the smb.conf man page +; hosts allow = 192.168.1. 192.168.2. 127. + +# if you want to automatically load your printer list rather +# than setting them up individually then you'll need this + printcap name = /etc/printcap + load printers = yes + +# It should not be necessary to spell out the print system type unless +# yours is non-standard. Currently supported print systems include: +# bsd, sysv, plp, lprng, aix, hpux, qnx +; printing = bsd + +# Uncomment this if you want a guest account, you must add this to /etc/passwd +# otherwise the user "nobody" is used +; guest account = pcguest + +# this tells Samba to use a separate log file for each machine +# that connects + # log file = /var/log/samba/%m.log +# all log information in one file + log file = /var/log/samba/log.smbd + +# Put a capping on the size of the log files (in Kb). + max log size = 50 + +# Security mode. Most people will want user level security. See +# security_level.txt for details. + security = user +# Use password server option only with security = server +; password server = + +# Password Level allows matching of _n_ characters of the password for +# all combinations of upper and lower case. +; password level = 8 +; username level = 8 + +# You may wish to use password encryption. Please read +# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation. +# Do not enable this option unless you have read those documents +; encrypt passwords = yes +; smb passwd file = /etc/samba/smbpasswd + +# The following are needed to allow password changing from Windows to +# update the Linux system password also. +# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above. +# NOTE2: You do NOT need these to allow workstations to change only +# the encrypted SMB passwords. They allow the Unix password +# to be kept in sync with the SMB password. +; unix password sync = Yes +; passwd program = /usr/bin/passwd %u +; passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully* + +# Unix users can map to different SMB User names +; username map = /etc/samba/smbusers + +# Using the following line enables you to customise your configuration +# on a per machine basis. The %m gets replaced with the netbios name +# of the machine that is connecting +; include = /etc/samba/smb.conf.%m + +# Most people will find that this option gives better performance. +# See speed.txt and the manual pages for details + socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 + +# Configure Samba to use multiple interfaces +# If you have multiple network interfaces then you must list them +# here. See the man page for details. +; interfaces = 192.168.12.2/24 192.168.13.2/24 + +# Configure remote browse list synchronisation here +# request announcement to, or browse list sync from: +# a specific host or from / to a whole subnet (see below) +; remote browse sync = 192.168.3.25 192.168.5.255 +# Cause this host to announce itself to local subnets here +; remote announce = 192.168.1.255 192.168.2.44 + +# Browser Control Options: +# set local master to no if you don't want Samba to become a master +# browser on your network. Otherwise the normal election rules apply +; local master = no + +# OS Level determines the precedence of this server in master browser +# elections. The default value should be reasonable +; os level = 33 + +# Domain Master specifies Samba to be the Domain Master Browser. This +# allows Samba to collate browse lists between subnets. Don't use this +# if you already have a Windows NT domain controller doing this job +; domain master = yes + +# Preferred Master causes Samba to force a local browser election on startup +# and gives it a slightly higher chance of winning the election +; preferred master = yes + +# Enable this if you want Samba to be a domain logon server for +# Windows95 workstations. +; domain logons = yes + +# if you enable domain logons then you may want a per-machine or +# per user logon script +# run a specific logon batch file per workstation (machine) +; logon script = %m.bat +# run a specific logon batch file per username +; logon script = %U.bat + +# Where to store roving profiles (only for Win95 and WinNT) +# %L substitutes for this servers netbios name, %U is username +# You must uncomment the [Profiles] share below +; logon path = \\%L\Profiles\%U + +# All NetBIOS names must be resolved to IP Addresses +# 'Name Resolve Order' allows the named resolution mechanism to be specified +# the default order is "host lmhosts wins bcast". "host" means use the unix +# system gethostbyname() function call that will use either /etc/hosts OR +# DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf +# and the /etc/resolv.conf file. "host" therefore is system configuration +# dependant. This parameter is most often of use to prevent DNS lookups +# in order to resolve NetBIOS names to IP Addresses. Use with care! +# The example below excludes use of name resolution for machines that are NOT +# on the local network segment +# - OR - are not deliberately to be known via lmhosts or via WINS. +; name resolve order = wins lmhosts bcast + +# Windows Internet Name Serving Support Section: +# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server +; wins support = yes + +# WINS Server - Tells the NMBD components of Samba to be a WINS Client +# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both +; wins server = w.x.y.z + +# WINS Proxy - Tells Samba to answer name resolution queries on +# behalf of a non WINS capable client, for this to work there must be +# at least one WINS Server on the network. The default is NO. +; wins proxy = yes + +# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names +# via DNS nslookups. The built-in default for versions 1.9.17 is yes, +# this has been changed in version 1.9.18 to no. + dns proxy = no + +# Case Preservation can be handy - system default is _no_ +# NOTE: These can be set on a per share basis +; preserve case = no +; short preserve case = no +# Default case is normally upper case for all DOS files +; default case = lower +# Be very careful with case sensitivity - it can break things! +; case sensitive = no + +#============================ Share Definitions ============================== +[homes] + comment = Home Directories + browseable = no + writable = yes + +# Un-comment the following and create the netlogon directory for Domain Logons +; [netlogon] +; comment = Network Logon Service +; path = /home/netlogon +; guest ok = yes +; writable = no +; share modes = no + + +# Un-comment the following to provide a specific roving profile share +# the default is to use the user's home directory +;[Profiles] +; path = /home/profiles +; browseable = no +; guest ok = yes + + +# NOTE: If you have a BSD-style print system there is no need to +# specifically define each individual printer +[printers] + comment = All Printers + path = /var/spool/samba + browseable = no +# Set public = yes to allow user 'guest account' to print + guest ok = no + writable = no + printable = yes + +# This one is useful for people to share files +;[tmp] +; comment = Temporary file space +; path = /tmp +; read only = no +; public = yes + +# A publicly accessible directory, but read only, except for people in +# the "staff" group +;[public] +; comment = Public Stuff +; path = /home/samba +; public = yes +; read only = yes +; write list = @staff + +# Other examples. +# +# A private printer, usable only by fred. Spool data will be placed in fred's +# home directory. Note that fred must have write access to the spool directory, +# wherever it is. +;[fredsprn] +; comment = Fred's Printer +; valid users = fred +; path = /homes/fred +; printer = freds_printer +; public = no +; writable = no +; printable = yes + +# A private directory, usable only by fred. Note that fred requires write +# access to the directory. +;[fredsdir] +; comment = Fred's Service +; path = /usr/somewhere/private +; valid users = fred +; public = no +; writable = yes +; printable = no + +# a service which has a different directory for each machine that connects +# this allows you to tailor configurations to incoming machines. You could +# also use the %u option to tailor it by user name. +# The %m gets replaced with the machine name that is connecting. +;[pchome] +; comment = PC Directories +; path = /usr/pc/%m +; public = no +; writable = yes + +# A publicly accessible directory, read/write to all users. Note that all files +# created in the directory by users will be owned by the default user, so +# any user with access can delete any other user's files. Obviously this +# directory must be writable by the default user. Another user could of course +# be specified, in which case all files would be owned by that user instead. +;[public] +; path = /usr/somewhere/else/public +; public = yes +; only guest = yes +; writable = yes +; printable = no + +# The following two entries demonstrate how to share a directory so that two +# users can place files there that will be owned by the specific users. In this +# setup, the directory should be writable by both users and should have the +# sticky bit set on it to prevent abuse. Obviously this could be extended to +# as many users as required. +;[myshare] +; comment = Mary's and Fred's stuff +; path = /usr/somewhere/shared +; valid users = mary fred +; public = no +; writable = yes +; printable = no +; create mask = 0765 + + diff --git a/packaging/RedHat-9/smb.init b/packaging/RedHat-9/smb.init new file mode 100755 index 00000000000..79f4f322d03 --- /dev/null +++ b/packaging/RedHat-9/smb.init @@ -0,0 +1,59 @@ +#!/bin/sh +# +# chkconfig: 345 81 35 +# description: Starts and stops the Samba smbd and nmbd daemons \ +# used to provide SMB network services. + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +CONFIG=/etc/samba/smb.conf + +# Check that smb.conf exists. +[ -f $CONFIG ] || exit 0 + +# See how we were called. +case "$1" in + start) + echo -n "Starting SMB services: " + daemon smbd -D + daemon nmbd -D + echo + touch /var/lock/subsys/smb + ;; + stop) + echo -n "Shutting down SMB services: " + + ## we have to get all the smbd process here instead of just the + ## main parent (i.e. killproc) because it can take a long time + ## for an individual process to process a TERM signal + smbdpids=`ps guax | grep smbd | grep -v grep | awk '{print $2}'` + for pid in $smbdpids; do + kill -TERM $pid + done + ## nmbd is ok to kill using killproc() + killproc nmbd -TERM + rm -f /var/lock/subsys/smb + echo "" + ;; + status) + status smbd + status nmbd + ;; + restart) + echo -n "Restarting SMB services: " + $0 stop + $0 start + echo "done." + ;; + *) + echo "Usage: smb {start|stop|restart|status}" + exit 1 +esac + diff --git a/packaging/RedHat-9/smbprint b/packaging/RedHat-9/smbprint new file mode 100755 index 00000000000..a0fd2e481b5 --- /dev/null +++ b/packaging/RedHat-9/smbprint @@ -0,0 +1,77 @@ +#!/bin/sh + +# This script is an input filter for printcap printing on a unix machine. It +# uses the smbclient program to print the file to the specified smb-based +# server and service. +# For example you could have a printcap entry like this +# +# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint +# +# which would create a unix printer called "smb" that will print via this +# script. You will need to create the spool directory /usr/spool/smb with +# appropriate permissions and ownerships for your system. + +# Set these to the server and service you wish to print to +# In this example I have a WfWg PC called "lapland" that has a printer +# exported called "printer" with no password. + +# +# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) +# so that the server, service, and password can be read from +# a /var/spool/lpd/PRINTNAME/.config file. +# +# In order for this to work the /etc/printcap entry must include an +# accounting file (af=...): +# +# cdcolour:\ +# :cm=CD IBM Colorjet on 6th:\ +# :sd=/var/spool/lpd/cdcolour:\ +# :af=/var/spool/lpd/cdcolour/acct:\ +# :if=/usr/local/etc/smbprint:\ +# :mx=0:\ +# :lp=/dev/null: +# +# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: +# server=PC_SERVER +# service=PR_SHARENAME +# password="password" +# +# E.g. +# server=PAULS_PC +# service=CJET_371 +# password="" + +# +# Debugging log file, change to /dev/null if you like. +# +# logfile=/tmp/smb-print.log +logfile=/dev/null + + +# +# The last parameter to the filter is the accounting file name. +# Extract the directory name from the file name. +# Concat this with /.config to get the config file. +# +eval acct_file=\${$#} +spool_dir=`dirname $acct_file` +config_file=$spool_dir/.config + +# Should read the following variables set in the config file: +# server +# service +# password +eval `cat $config_file` + +# +# Some debugging help, change the >> to > if you want to same space. +# +echo "server $server, service $service" >> $logfile + +( +# NOTE You may wish to add the line `echo translate' if you want automatic +# CR/LF translation when printing. +# echo translate + echo "print -" + cat +) | /usr/bin/smbclient "\\\\$server\\$service" $password -U $server -N >> $logfile diff --git a/packaging/RedHat-9/smbusers b/packaging/RedHat-9/smbusers new file mode 100644 index 00000000000..ae3389f53f8 --- /dev/null +++ b/packaging/RedHat-9/smbusers @@ -0,0 +1,3 @@ +# Unix_name = SMB_name1 SMB_name2 ... +root = administrator admin +nobody = guest pcguest smbguest diff --git a/packaging/RedHat-9/winbind.init b/packaging/RedHat-9/winbind.init new file mode 100644 index 00000000000..289ca590834 --- /dev/null +++ b/packaging/RedHat-9/winbind.init @@ -0,0 +1,84 @@ +#!/bin/sh +# +# chkconfig: 345 91 45 +# description: Starts and stops the Samba winbind daemon to provide \ +# user and group information from a domain controller to linux. + +# Source function library. +if [ -f /etc/init.d/functions ] ; then + . /etc/init.d/functions +elif [ -f /etc/rc.d/init.d/functions ] ; then + . /etc/rc.d/init.d/functions +else + exit 0 +fi + +# Source networking configuration. +. /etc/sysconfig/network + +# Check that networking is up. +[ ${NETWORKING} = "no" ] && exit 0 + +CONFIG=/etc/samba/smb.conf + +# Check that smb.conf exists. +[ -f $CONFIG ] || exit 0 + +start() { + echo -n "Starting Winbind services: " + daemon winbindd + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/winbind || \ + RETVAL=1 + return $RETVAL +} +stop() { + echo -n "Shutting down Winbind services: " + killproc winbindd + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/winbind + return $RETVAL +} +restart() { + stop + start +} +reload() { + export TMPDIR="/var/tmp" + echo -n "Checking domain trusts: " + killproc winbindd -HUP + RETVAL=$? + echo + return $RETVAL +} +mdkstatus() { + status winbindd +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + restart + ;; + reload) + reload + ;; + status) + mdkstatus + ;; + condrestart) + [ -f /var/lock/subsys/winbindd ] && restart || : + ;; + *) + echo "Usage: $0 {start|stop|restart|status|condrestart}" + exit 1 +esac + +exit $? diff --git a/packaging/RedHat/README b/packaging/RedHat/README deleted file mode 100644 index 646b10dbbbf..00000000000 --- a/packaging/RedHat/README +++ /dev/null @@ -1,13 +0,0 @@ -Preparer: Gerald Carter - -Instructions: Preparing Samba Packages for Red Hat Linux -=============================================================== - -We provide support only for the latest stable release of major -branches (e.g 6.2, 7.3, and 8.0). The makerpms.sh script -supports rpm version 2.x, 3.x, and 4.x - -To produce the RPMS simply type: - - root# sh makerpms.sh - diff --git a/packaging/RedHat/filter-requires-samba_rh8.sh b/packaging/RedHat/filter-requires-samba_rh8.sh deleted file mode 100755 index 8428a6ad013..00000000000 --- a/packaging/RedHat/filter-requires-samba_rh8.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -/usr/lib/rpm/find-requires $* | egrep -v '(Net::LDAP|CGI)' diff --git a/packaging/RedHat/filter-requires-samba_rh9.sh b/packaging/RedHat/filter-requires-samba_rh9.sh deleted file mode 100755 index 5545cf6c858..00000000000 --- a/packaging/RedHat/filter-requires-samba_rh9.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -/usr/lib/rpm/perl.req $* | grep -E -v '(Net::LDAP|Crypt::SmbHash|CGI)' - diff --git a/packaging/RedHat/makerpms.sh.tmpl b/packaging/RedHat/makerpms.sh.tmpl deleted file mode 100644 index 8da4a5d520e..00000000000 --- a/packaging/RedHat/makerpms.sh.tmpl +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/sh -# Copyright (C) John H Terpstra 1998-2002 -# Updated for RPM 3 by Jochen Wiedmann, joe@ispsoft.de -# Changed for a generic tar file rebuild by abartlet@pcug.org.au -# Changed by John H Terpstra to build on RH7.2 - should also work for earlier versions jht@samba.org - -# The following allows environment variables to override the target directories -# the alternative is to have a file in your home directory calles .rpmmacros -# containing the following: -# %_topdir /home/mylogin/redhat -# -# Note: Under this directory rpm expects to find the same directories that are under the -# /usr/src/redhat directory -# - -SPECDIR=`rpm --eval %_specdir` -SRCDIR=`rpm --eval %_sourcedir` - -# At this point the SPECDIR and SRCDIR vaiables must have a value! - -USERID=`id -u` -GRPID=`id -g` -VERSION='PVERSION' -SPECFILE="samba3.spec" -RPMVER=`rpm --version | awk '{print $3}'` -RPM="rpm" -echo The RPM Version on this machine is: $RPMVER - -## -## fix the mandir macro -## -case $RPMVER in - [23]*) - sed -e "s/MANDIR_MACRO/\%\{prefix\}\/man/g" < samba.spec > $SPECFILE - ;; - 4*) - sed -e "s/MANDIR_MACRO/\%\{_mandir\}/g" < samba.spec > $SPECFILE - ;; - *) - echo "Unknown RPM version: `rpm --version`" - exit 1 - ;; -esac - -## -## now catch the right command to build an RPM (defaults ro 'rpm' -## -case $RPMVER in - 4.[123]*) - RPM="rpmbuild" - ;; -esac - -echo "RPM build command is \"$RPM\"" - -( cd ../../source; if [ -f Makefile ]; then make distclean; fi ) -( cd ../../.. ; chown -R ${USERID}.${GRPID} samba-${VERSION} ) - -( cd ../../.. ; tar --exclude=CVS -cf - samba-${VERSION}/. | bzip2 > ${SRCDIR}/samba-${VERSION}.tar.bz2 ) - -/bin/cp -p filter-requires-samba_rh8.sh ${SRCDIR} -/bin/cp -p filter-requires-samba_rh9.sh ${SRCDIR} -chmod 755 ${SRCDIR}/filter-requires-samba_rh?.sh -/bin/cp -av $SPECFILE ${SPECDIR} - -echo Getting Ready to build release package -cd ${SPECDIR} -${RPM} -ba --clean --rmsource $SPECFILE - -echo Done. - diff --git a/packaging/RedHat/samba.log b/packaging/RedHat/samba.log deleted file mode 100644 index a3c000ea788..00000000000 --- a/packaging/RedHat/samba.log +++ /dev/null @@ -1,9 +0,0 @@ -/var/log/samba/*.log /var/log/samba/log.smbd /var/log/samba/log.nmbd { - notifempty - missingok - sharedscripts - copytruncate - postrotate - /bin/kill -HUP `cat /var/run/smbd.pid /var/run/nmbd.pid /var/run/winbindd.pid 2> /dev/null` 2> /dev/null || true - endscript -} diff --git a/packaging/RedHat/samba.pamd b/packaging/RedHat/samba.pamd deleted file mode 100644 index bf7a5b392ca..00000000000 --- a/packaging/RedHat/samba.pamd +++ /dev/null @@ -1,4 +0,0 @@ -auth required /lib/security/pam_pwdb.so nullok -account required /lib/security/pam_pwdb.so -session required /lib/security/pam_pwdb.so -password required /lib/security/pam_pwdb.so # shadow md5 nullok audit diff --git a/packaging/RedHat/samba.pamd.stack b/packaging/RedHat/samba.pamd.stack deleted file mode 100644 index 6a948f92cbd..00000000000 --- a/packaging/RedHat/samba.pamd.stack +++ /dev/null @@ -1,6 +0,0 @@ -#%PAM-1.0 -auth required pam_nologin.so -auth required pam_stack.so service=system-auth -account required pam_stack.so service=system-auth -session required pam_stack.so service=system-auth -password required pam_stack.so service=system-auth diff --git a/packaging/RedHat/samba.spec.tmpl b/packaging/RedHat/samba.spec.tmpl deleted file mode 100644 index b19a8874983..00000000000 --- a/packaging/RedHat/samba.spec.tmpl +++ /dev/null @@ -1,475 +0,0 @@ -## grab the major and minor version of rpm -%define rpm_version `rpm --version | awk '{print $3}' | awk -F. '{print $1$2}'` - -Summary: Samba SMB client and server -Vendor: Samba Team -Name: samba -Version: PVERSION -Release: PRELEASE -License: GNU GPL version 2 -Group: Networking -Source: http://download.samba.org/samba/ftp/samba-%{version}.tar.bz2 - -# Don't depend on Net::LDAP -# one filter for RH 8 and one for 9 -Source998: filter-requires-samba_rh8.sh -Source999: filter-requires-samba_rh9.sh - -Packager: Gerald Carter [Samba-Team] -Requires: pam openldap krb5-libs cups -BuildRequires: openldap-devel krb5-devel pam-devel cups-devel -Prereq: chkconfig fileutils /sbin/ldconfig -Provides: samba = %{version} -Obsoletes: samba-common, samba-client, samba-swat -BuildRoot: %{_tmppath}/%{name}-%{version}-root -Prefix: /usr - -%description -Samba provides an SMB/CIFS server which can be used to provide -network file and print services to SMB/CIFS clients, including -various versions of MS Windows, OS/2, and other Linux machines. -Samba also provides some SMB clients, which complement the -built-in SMB filesystem in Linux. Samba uses NetBIOS over TCP/IP -(NetBT) protocols and does NOT need NetBEUI (Microsoft Raw NetBIOS -frame) protocol. - -Samba 3.0 also introduces UNICODE support and kerberos/ldap -integration as a member server in a Windows 2000 domain. - -Please refer to the WHATSNEW.txt document for fixup information. -docs directory for implementation details. - -%changelog -* Mon Nov 18 2002 Gerald Carter - - removed change log entries since history - is being maintained in CVS - -%prep -%setup - -%build - -# Working around perl dependency problem from docs -# Only > RH 8.0 seems to care here - -echo "rpm_version == %{rpm_version}" -if [ "%{rpm_version}" == "42" ]; then - %define __perl_requires %{SOURCE999} - echo "%{__perl_requires}" -elif [ "%{rpm_version}" == "41" ]; then - %define __find_requires %{SOURCE998} - echo "%{__find_requires}" -fi - -## Build main Samba source -cd source - -%ifarch ia64 -libtoolize --copy --force # get it to recognize IA-64 -autoheader -autoconf -EXTRA="-D_LARGEFILE64_SOURCE" -%endif - -## Get number of cpu's, default for 1 cpu on error -NUMCPU=`grep processor /proc/cpuinfo | wc -l` -if [ $NUMCPU -eq 0 ]; then - NUMCPU=1; -fi - -## run autogen if missing the configure script -if [ ! -f "configure" ]; then - ./autogen.sh -fi - -CFLAGS="$RPM_OPT_FLAGS $EXTRA" ./configure \ - --prefix=%{prefix} \ - --localstatedir=/var \ - --with-configdir=/etc/samba \ - --with-privatedir=/etc/samba \ - --with-fhs \ - --with-quotas \ - --with-smbmount \ - --enable-cups \ - --with-pam \ - --with-pam_smbpass \ - --with-syslog \ - --with-utmp \ - --with-swatdir=%{prefix}/share/swat \ - --with-shared-modules=idmap_rid \ - --with-libsmbclient -make -j${NUMCPU} proto -make -j${NUMCPU} all modules nsswitch/libnss_wins.so -make -j${NUMCPU} debug2html - -# Remove some permission bits to avoid to many dependencies -cd .. -find examples docs -type f | xargs -r chmod -x - -%install -rm -rf $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT -mkdir -p $RPM_BUILD_ROOT/sbin -mkdir -p $RPM_BUILD_ROOT/etc/samba -mkdir -p $RPM_BUILD_ROOT/etc/{logrotate.d,pam.d,samba} -mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d -mkdir -p $RPM_BUILD_ROOT%{prefix}/{bin,sbin} -mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/{help,include,using_samba} -mkdir -p $RPM_BUILD_ROOT%{prefix}/share/swat/help/using_samba/{figs,gifs} -mkdir -p $RPM_BUILD_ROOTMANDIR_MACRO -mkdir -p $RPM_BUILD_ROOT/var/lib/samba -mkdir -p $RPM_BUILD_ROOT/var/{log,run}/samba -mkdir -p $RPM_BUILD_ROOT/var/spool/samba -mkdir -p $RPM_BUILD_ROOT/lib/security -mkdir -p $RPM_BUILD_ROOT%{prefix}/lib/samba/vfs -mkdir -p $RPM_BUILD_ROOT%{prefix}/{lib,include} - -# Install standard binary files -for i in nmblookup smbget smbclient smbpasswd smbstatus testparm \ - rpcclient smbspool smbcacls smbcontrol wbinfo smbmnt net \ - smbcacls pdbedit eventlogadm tdbbackup smbtree ntlm_auth smbcquotas -do - install -m755 source/bin/$i $RPM_BUILD_ROOT%{prefix}/bin -done - -for i in mksmbpasswd.sh smbtar findsmb -do - install -m755 source/script/$i $RPM_BUILD_ROOT%{prefix}/bin -done - -# Install secure binary files -for i in smbd nmbd swat smbmount smbumount debug2html winbindd -do - install -m755 source/bin/$i $RPM_BUILD_ROOT%{prefix}/sbin -done - -# we need a symlink for mount to recognise the smb and smbfs filesystem types -ln -sf %{prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smbfs -ln -sf %{prefix}/sbin/smbmount $RPM_BUILD_ROOT/sbin/mount.smb - -# This allows us to get away without duplicating code that -# sombody else can maintain for us. -cd source -make DESTDIR=$RPM_BUILD_ROOT \ - BASEDIR=/usr \ - CONFIGDIR=/etc/samba \ - LIBDIR=%{prefix}/lib/samba \ - VARDIR=/var \ - SBINDIR=%{prefix}/sbin \ - BINDIR=%{prefix}/bin \ - MANDIR=MANDIR_MACRO \ - SWATDIR=%{prefix}/share/swat \ - SAMBABOOK=%{prefix}/share/swat/using_samba \ - installman installswat installdat installmodules -cd .. - -## don't duplicate the docs. These are installed with SWAT -rm -rf docs/htmldocs -rm -rf docs/manpages -( cd docs; ln -s %{prefix}/share/swat/help htmldocs ) - - - -# Install the nsswitch wins library -install -m755 source/nsswitch/libnss_wins.so $RPM_BUILD_ROOT/lib -( cd $RPM_BUILD_ROOT/lib; ln -sf libnss_wins.so libnss_wins.so.2 ) - -# Install winbind shared libraries -install -m755 source/nsswitch/libnss_winbind.so $RPM_BUILD_ROOT/lib -( cd $RPM_BUILD_ROOT/lib; ln -sf libnss_winbind.so libnss_winbind.so.2 ) -install -m755 source/nsswitch/pam_winbind.so $RPM_BUILD_ROOT/lib/security - -# Install pam_smbpass.so -install -m755 source/bin/pam_smbpass.so $RPM_BUILD_ROOT/lib/security - -# libsmbclient -install -m 755 source/bin/libsmbclient.so $RPM_BUILD_ROOT%{prefix}/lib/ -install -m 755 source/bin/libsmbclient.a $RPM_BUILD_ROOT%{prefix}/lib/ -install -m 644 source/include/libsmbclient.h $RPM_BUILD_ROOT%{prefix}/include/ - -# libmsrpc -install -m 755 source/bin/libmsrpc.so $RPM_BUILD_ROOT%{prefix}/lib/ -install -m 755 source/bin/libmsrpc.a $RPM_BUILD_ROOT%{prefix}/lib/ -install -m 644 source/include/libmsrpc.h $RPM_BUILD_ROOT%{prefix}/include/ - -# Install the miscellany -install -m755 packaging/RedHat/smbprint $RPM_BUILD_ROOT%{prefix}/bin -install -m755 packaging/RedHat/smb.init $RPM_BUILD_ROOT/etc/rc.d/init.d/smb -install -m755 packaging/RedHat/winbind.init $RPM_BUILD_ROOT/etc/rc.d/init.d/winbind -install -m755 packaging/RedHat/smb.init $RPM_BUILD_ROOT%{prefix}/sbin/samba -install -m644 packaging/RedHat/samba.log $RPM_BUILD_ROOT/etc/logrotate.d/samba -install -m644 packaging/RedHat/smb.conf $RPM_BUILD_ROOT/etc/samba/smb.conf -install -m644 packaging/RedHat/smbusers $RPM_BUILD_ROOT/etc/samba/smbusers -install -m644 packaging/RedHat/samba.pamd $RPM_BUILD_ROOT/etc/pam.d/samba -install -m644 packaging/RedHat/samba.pamd.stack $RPM_BUILD_ROOT/etc/samba/samba.stack -install -m644 packaging/RedHat/samba.xinetd $RPM_BUILD_ROOT/etc/samba/samba.xinetd -echo 127.0.0.1 localhost > $RPM_BUILD_ROOT/etc/samba/lmhosts - -# Remove "*.old" files -find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \; - -## -## Clean out man pages for tools not installed here -## -rm -f $RPM_BUILD_ROOT/%{_mandir}/man1/editreg.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/log2pcap.1* -rm -f $RPM_BUILD_ROOT%{_mandir}/man1/smbsh.1* -rm -f $RPM_BUILD_ROOT/%{_mandir}/man8/mount.cifs.8* - - -%clean -rm -rf $RPM_BUILD_ROOT - -%post -## -## only needed if this is a new install (not an upgrade) -## -if [ "$1" -eq "1" ]; then - /sbin/chkconfig --add smb - /sbin/chkconfig --add winbind - /sbin/chkconfig smb off - /sbin/chkconfig winbind off -fi - -## -## we only have to wory about this if we are upgrading -## -if [ "$1" -eq "2" ]; then - if [ -f /etc/smb.conf -a ! -f /etc/samba/smb.conf ]; then - echo "Moving old /etc/smb.conf to /etc/samba/smb.conf" - mv /etc/smb.conf /etc/samba/smb.conf - fi - - if [ -f /etc/smbusers -a ! -f /etc/samba/smbusers ]; then - echo "Moving old /etc/smbusers to /etc/samba/smbusers" - mv /etc/smbusers /etc/samba/smbusers - fi - - if [ -f /etc/lmhosts -a ! -f /etc/samba/lmhosts ]; then - echo "Moving old /etc/lmhosts to /etc/samba/lmhosts" - mv /etc/lmhosts /etc/samba/lmhosts - fi - - if [ -f /etc/MACHINE.SID -a ! -f /etc/samba/MACHINE.SID ]; then - echo "Moving old /etc/MACHINE.SID to /etc/samba/MACHINE.SID" - mv /etc/MACHINE.SID /etc/samba/MACHINE.SID - fi - - if [ -f /etc/smbpasswd -a ! -f /etc/samba/smbpasswd ]; then - echo "Moving old /etc/smbpasswd to /etc/samba/smbpasswd" - mv /etc/smbpasswd /etc/samba/smbpasswd - fi - - # - # For 2.2.1 we move the tdb files from /var/lock/samba to /var/cache/samba - # to preserve across reboots. - # - for i in /var/lock/samba/*.tdb; do - if [ -f $i ]; then - newname="/var/lib/samba/`basename $i`" - echo "Moving $i to $newname" - mv $i $newname - fi - done - - # - # For 3.0.1 we move the tdb files from /var/cache/samba to /var/lib/samba - # - echo "Moving tdb files in /var/cache/samba/*.tdb to /var/lib/samba/*.tdb" - for i in /var/cache/samba/*.tdb; do - if [ -f $i ]; then - newname="/var/lib/samba/`basename $i`" - echo "Moving $i to $newname" - mv $i $newname - fi - done -fi - -## -## New things -## - -# Add swat entry to /etc/services if not already there. -if [ ! "`grep ^\s**swat /etc/services`" ]; then - echo 'swat 901/tcp # Add swat service used via inetd' >> /etc/services -fi - -# Add swat entry to /etc/inetd.conf if needed. -if [ -f /etc/inetd.conf ]; then - if [ ! "`grep ^\s*swat /etc/inetd.conf`" ]; then - echo 'swat stream tcp nowait.400 root %{prefix}/sbin/swat swat' >> /etc/inetd.conf - killall -HUP inetd || : - fi -fi - -# Add swat entry to xinetd.d if needed. -if [ -d /etc/xinetd.d -a ! -f /etc/xinetd.d/swat ]; then - mv /etc/samba/samba.xinetd /etc/xinetd.d/swat -else - rm -f /etc/samba/samba.xinetd -fi - -# Install the correct version of the samba pam file -if [ -f /lib/security/pam_stack.so ]; then - echo "Installing stack version of /etc/pam.d/samba..." - mv /etc/samba/samba.stack /etc/pam.d/samba -else - echo "Installing non-stack version of /etc/pam.d/samba..." - rm -f /etc/samba/samba.stack -fi - -## call ldconfig to create the version symlink for libsmbclient.so -/sbin/ldconfig - -%preun -if [ "$1" -eq "0" ] ; then - /sbin/chkconfig --del smb - /sbin/chkconfig --del winbind - - # We want to remove the browse.dat and wins.dat files - # so they can not interfer with a new version of samba! - if [ -e /var/lib/samba/browse.dat ]; then - rm -f /var/lib/samba/browse.dat - fi - if [ -e /var/lib/samba/wins.dat ]; then - rm -f /var/lib/samba/wins.dat - fi - - # Remove the transient tdb files. - if [ -e /var/lib/samba/brlock.tdb ]; then - rm -f /var/lib/samba/brlock.tdb - fi - - if [ -e /var/lib/samba/unexpected.tdb ]; then - rm -f /var/lib/samba/unexpected.tdb - fi - - if [ -e /var/lib/samba/connections.tdb ]; then - rm -f /var/lib/samba/connections.tdb - fi - - if [ -e /var/lib/samba/locking.tdb ]; then - rm -f /var/lib/samba/locking.tdb - fi - - if [ -e /var/lib/samba/messages.tdb ]; then - rm -f /var/lib/samba/messages.tdb - fi -fi - -%postun -# Only delete remnants of samba if this is the final deletion. -if [ "$1" -eq "0" ] ; then - if [ -x /etc/pam.d/samba ]; then - rm -f /etc/pam.d/samba - fi - - if [ -e /var/log/samba ]; then - rm -rf /var/log/samba - fi - - if [ -e /var/lib/samba ]; then - rm -rf /var/lib/samba - fi - - # Remove swat entries from /etc/inetd.conf and /etc/services - cd /etc - tmpfile=/etc/tmp.$$ - if [ -f /etc/inetd.conf ]; then - # preserve inetd.conf permissions. - cp -p /etc/inetd.conf $tmpfile - sed -e '/^[:space:]*swat.*$/d' /etc/inetd.conf > $tmpfile - mv $tmpfile inetd.conf - fi - - # preserve services permissions. - cp -p /etc/services $tmpfile - sed -e '/^[:space:]*swat.*$/d' /etc/services > $tmpfile - mv $tmpfile /etc/services - - # Remove swat entry from /etc/xinetd.d - if [ -f /etc/xinetd.d/swat ]; then - rm -r /etc/xinetd.d/swat - fi -fi - -/sbin/ldconfig - -%files -%defattr(-,root,root) -%doc README COPYING Manifest Read-Manifest-Now -%doc WHATSNEW.txt Roadmap -%doc docs -%doc examples -%{prefix}/sbin/smbd -%{prefix}/sbin/nmbd -%{prefix}/sbin/swat -%{prefix}/bin/smbmnt -%{prefix}/sbin/smbmount -%{prefix}/sbin/smbumount -%{prefix}/sbin/winbindd -%{prefix}/sbin/samba -%{prefix}/sbin/debug2html -/sbin/mount.smbfs -/sbin/mount.smb -%{prefix}/bin/mksmbpasswd.sh -%{prefix}/bin/smbclient -%{prefix}/bin/smbget -%{prefix}/bin/smbspool -%{prefix}/bin/rpcclient -%{prefix}/bin/testparm -%{prefix}/bin/findsmb -%{prefix}/bin/smbstatus -%{prefix}/bin/nmblookup -%{prefix}/bin/smbpasswd -%{prefix}/bin/smbtar -%{prefix}/bin/smbprint -%{prefix}/bin/smbcontrol -%{prefix}/bin/wbinfo -%{prefix}/bin/net -%{prefix}/bin/ntlm_auth -%{prefix}/bin/smbcquotas -%{prefix}/bin/smbcacls -%{prefix}/bin/pdbedit -%{prefix}/bin/eventlogadm -%{prefix}/bin/tdbbackup -%{prefix}/bin/smbtree -%attr(755,root,root) /lib/libnss_wins.s* -%attr(755,root,root) %{prefix}/lib/samba/vfs/*.so -%attr(755,root,root) %{prefix}/lib/samba/auth/*.so -%attr(755,root,root) %{prefix}/lib/samba/charset/*.so -%attr(755,root,root) %{prefix}/lib/samba/idmap/*.so -#%attr(755,root,root) %{prefix}/lib/samba/pdb/*.so -%attr(755,root,root) %{prefix}/lib/samba/*.dat -%attr(755,root,root) %{prefix}/lib/samba/*.msg -%{prefix}/include/libsmbclient.h -%{prefix}/lib/libsmbclient.a -%{prefix}/lib/libsmbclient.so -%{prefix}/include/libmsrpc.h -%{prefix}/lib/libmsrpc.a -%{prefix}/lib/libmsrpc.so -%{prefix}/share/swat/help/* -%{prefix}/share/swat/images/*.gif -%{prefix}/share/swat/include/*.html -%{prefix}/share/swat/lang/*/help/* -%{prefix}/share/swat/lang/*/images/*.gif -%config(noreplace) /etc/samba/lmhosts -%config(noreplace) /etc/samba/smb.conf -%config(noreplace) /etc/samba/smbusers -/etc/samba/samba.stack -/etc/samba/samba.xinetd -/etc/rc.d/init.d/smb -/etc/rc.d/init.d/winbind -/etc/logrotate.d/samba -%config(noreplace) /etc/pam.d/samba -MANDIR_MACRO/man1/* -MANDIR_MACRO/man5/* -MANDIR_MACRO/man7/* -MANDIR_MACRO/man8/* -%attr(755,root,root) %dir /var/lib/samba -%dir /var/log/samba -%dir /var/run/samba -%attr(1777,root,root) %dir /var/spool/samba -%attr(-,root,root) /lib/libnss_winbind.so* -%attr(-,root,root) /lib/security/pam_winbind.so -%attr(-,root,root) /lib/security/pam_smbpass.so diff --git a/packaging/RedHat/samba.xinetd b/packaging/RedHat/samba.xinetd deleted file mode 100644 index 8c38b354218..00000000000 --- a/packaging/RedHat/samba.xinetd +++ /dev/null @@ -1,15 +0,0 @@ -# default: off -# description: SWAT is the Samba Web Admin Tool. Use swat \ -# to configure your Samba server. To use SWAT, \ -# connect to port 901 with your favorite web browser. -service swat -{ - port = 901 - socket_type = stream - wait = no - only_from = localhost - user = root - server = /usr/sbin/swat - log_on_failure += USERID - disable = yes -} diff --git a/packaging/RedHat/smb.conf b/packaging/RedHat/smb.conf deleted file mode 100644 index ba64dad729c..00000000000 --- a/packaging/RedHat/smb.conf +++ /dev/null @@ -1,288 +0,0 @@ -# This is the main Samba configuration file. You should read the -# smb.conf(5) manual page in order to understand the options listed -# here. Samba has a huge number of configurable options (perhaps too -# many!) most of which are not shown in this example -# -# Any line which starts with a ; (semi-colon) or a # (hash) -# is a comment and is ignored. In this example we will use a # -# for commentry and a ; for parts of the config file that you -# may wish to enable -# -# NOTE: Whenever you modify this file you should run the command "testparm" -# to check that you have not made any basic syntactic errors. -# -#======================= Global Settings ===================================== -[global] - -# workgroup = NT-Domain-Name or Workgroup-Name - workgroup = MYGROUP - -# server string is the equivalent of the NT Description field - server string = Samba Server - -# This option is important for security. It allows you to restrict -# connections to machines which are on your local network. The -# following example restricts access to two C class networks and -# the "loopback" interface. For more examples of the syntax see -# the smb.conf man page -; hosts allow = 192.168.1. 192.168.2. 127. - -# if you want to automatically load your printer list rather -# than setting them up individually then you'll need this - printcap name = /etc/printcap - load printers = yes - -# It should not be necessary to spell out the print system type unless -# yours is non-standard. Currently supported print systems include: -# bsd, sysv, plp, lprng, aix, hpux, qnx -; printing = bsd - -# Uncomment this if you want a guest account, you must add this to /etc/passwd -# otherwise the user "nobody" is used -; guest account = pcguest - -# this tells Samba to use a separate log file for each machine -# that connects - # log file = /var/log/samba/%m.log -# all log information in one file - log file = /var/log/samba/log.smbd - -# Put a capping on the size of the log files (in Kb). - max log size = 50 - -# Security mode. Most people will want user level security. See -# security_level.txt for details. - security = user -# Use password server option only with security = server -; password server = - -# Password Level allows matching of _n_ characters of the password for -# all combinations of upper and lower case. -; password level = 8 -; username level = 8 - -# You may wish to use password encryption. Please read -# ENCRYPTION.txt, Win95.txt and WinNT.txt in the Samba documentation. -# Do not enable this option unless you have read those documents -; encrypt passwords = yes -; smb passwd file = /etc/samba/smbpasswd - -# The following are needed to allow password changing from Windows to -# update the Linux system password also. -# NOTE: Use these with 'encrypt passwords' and 'smb passwd file' above. -# NOTE2: You do NOT need these to allow workstations to change only -# the encrypted SMB passwords. They allow the Unix password -# to be kept in sync with the SMB password. -; unix password sync = Yes -; passwd program = /usr/bin/passwd %u -; passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully* - -# Unix users can map to different SMB User names -; username map = /etc/samba/smbusers - -# Using the following line enables you to customise your configuration -# on a per machine basis. The %m gets replaced with the netbios name -# of the machine that is connecting -; include = /etc/samba/smb.conf.%m - -# Most people will find that this option gives better performance. -# See speed.txt and the manual pages for details - socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 - -# Configure Samba to use multiple interfaces -# If you have multiple network interfaces then you must list them -# here. See the man page for details. -; interfaces = 192.168.12.2/24 192.168.13.2/24 - -# Configure remote browse list synchronisation here -# request announcement to, or browse list sync from: -# a specific host or from / to a whole subnet (see below) -; remote browse sync = 192.168.3.25 192.168.5.255 -# Cause this host to announce itself to local subnets here -; remote announce = 192.168.1.255 192.168.2.44 - -# Browser Control Options: -# set local master to no if you don't want Samba to become a master -# browser on your network. Otherwise the normal election rules apply -; local master = no - -# OS Level determines the precedence of this server in master browser -# elections. The default value should be reasonable -; os level = 33 - -# Domain Master specifies Samba to be the Domain Master Browser. This -# allows Samba to collate browse lists between subnets. Don't use this -# if you already have a Windows NT domain controller doing this job -; domain master = yes - -# Preferred Master causes Samba to force a local browser election on startup -# and gives it a slightly higher chance of winning the election -; preferred master = yes - -# Enable this if you want Samba to be a domain logon server for -# Windows95 workstations. -; domain logons = yes - -# if you enable domain logons then you may want a per-machine or -# per user logon script -# run a specific logon batch file per workstation (machine) -; logon script = %m.bat -# run a specific logon batch file per username -; logon script = %U.bat - -# Where to store roving profiles (only for Win95 and WinNT) -# %L substitutes for this servers netbios name, %U is username -# You must uncomment the [Profiles] share below -; logon path = \\%L\Profiles\%U - -# All NetBIOS names must be resolved to IP Addresses -# 'Name Resolve Order' allows the named resolution mechanism to be specified -# the default order is "host lmhosts wins bcast". "host" means use the unix -# system gethostbyname() function call that will use either /etc/hosts OR -# DNS or NIS depending on the settings of /etc/host.config, /etc/nsswitch.conf -# and the /etc/resolv.conf file. "host" therefore is system configuration -# dependant. This parameter is most often of use to prevent DNS lookups -# in order to resolve NetBIOS names to IP Addresses. Use with care! -# The example below excludes use of name resolution for machines that are NOT -# on the local network segment -# - OR - are not deliberately to be known via lmhosts or via WINS. -; name resolve order = wins lmhosts bcast - -# Windows Internet Name Serving Support Section: -# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server -; wins support = yes - -# WINS Server - Tells the NMBD components of Samba to be a WINS Client -# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both -; wins server = w.x.y.z - -# WINS Proxy - Tells Samba to answer name resolution queries on -# behalf of a non WINS capable client, for this to work there must be -# at least one WINS Server on the network. The default is NO. -; wins proxy = yes - -# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names -# via DNS nslookups. The built-in default for versions 1.9.17 is yes, -# this has been changed in version 1.9.18 to no. - dns proxy = no - -# Case Preservation can be handy - system default is _no_ -# NOTE: These can be set on a per share basis -; preserve case = no -; short preserve case = no -# Default case is normally upper case for all DOS files -; default case = lower -# Be very careful with case sensitivity - it can break things! -; case sensitive = no - -#============================ Share Definitions ============================== -[homes] - comment = Home Directories - browseable = no - writable = yes - -# Un-comment the following and create the netlogon directory for Domain Logons -; [netlogon] -; comment = Network Logon Service -; path = /home/netlogon -; guest ok = yes -; writable = no -; share modes = no - - -# Un-comment the following to provide a specific roving profile share -# the default is to use the user's home directory -;[Profiles] -; path = /home/profiles -; browseable = no -; guest ok = yes - - -# NOTE: If you have a BSD-style print system there is no need to -# specifically define each individual printer -[printers] - comment = All Printers - path = /var/spool/samba - browseable = no -# Set public = yes to allow user 'guest account' to print - guest ok = no - writable = no - printable = yes - -# This one is useful for people to share files -;[tmp] -; comment = Temporary file space -; path = /tmp -; read only = no -; public = yes - -# A publicly accessible directory, but read only, except for people in -# the "staff" group -;[public] -; comment = Public Stuff -; path = /home/samba -; public = yes -; read only = yes -; write list = @staff - -# Other examples. -# -# A private printer, usable only by fred. Spool data will be placed in fred's -# home directory. Note that fred must have write access to the spool directory, -# wherever it is. -;[fredsprn] -; comment = Fred's Printer -; valid users = fred -; path = /homes/fred -; printer = freds_printer -; public = no -; writable = no -; printable = yes - -# A private directory, usable only by fred. Note that fred requires write -# access to the directory. -;[fredsdir] -; comment = Fred's Service -; path = /usr/somewhere/private -; valid users = fred -; public = no -; writable = yes -; printable = no - -# a service which has a different directory for each machine that connects -# this allows you to tailor configurations to incoming machines. You could -# also use the %u option to tailor it by user name. -# The %m gets replaced with the machine name that is connecting. -;[pchome] -; comment = PC Directories -; path = /usr/pc/%m -; public = no -; writable = yes - -# A publicly accessible directory, read/write to all users. Note that all files -# created in the directory by users will be owned by the default user, so -# any user with access can delete any other user's files. Obviously this -# directory must be writable by the default user. Another user could of course -# be specified, in which case all files would be owned by that user instead. -;[public] -; path = /usr/somewhere/else/public -; public = yes -; only guest = yes -; writable = yes -; printable = no - -# The following two entries demonstrate how to share a directory so that two -# users can place files there that will be owned by the specific users. In this -# setup, the directory should be writable by both users and should have the -# sticky bit set on it to prevent abuse. Obviously this could be extended to -# as many users as required. -;[myshare] -; comment = Mary's and Fred's stuff -; path = /usr/somewhere/shared -; valid users = mary fred -; public = no -; writable = yes -; printable = no -; create mask = 0765 - - diff --git a/packaging/RedHat/smb.init b/packaging/RedHat/smb.init deleted file mode 100755 index 79f4f322d03..00000000000 --- a/packaging/RedHat/smb.init +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -# -# chkconfig: 345 81 35 -# description: Starts and stops the Samba smbd and nmbd daemons \ -# used to provide SMB network services. - -# Source function library. -. /etc/rc.d/init.d/functions - -# Source networking configuration. -. /etc/sysconfig/network - -# Check that networking is up. -[ ${NETWORKING} = "no" ] && exit 0 - -CONFIG=/etc/samba/smb.conf - -# Check that smb.conf exists. -[ -f $CONFIG ] || exit 0 - -# See how we were called. -case "$1" in - start) - echo -n "Starting SMB services: " - daemon smbd -D - daemon nmbd -D - echo - touch /var/lock/subsys/smb - ;; - stop) - echo -n "Shutting down SMB services: " - - ## we have to get all the smbd process here instead of just the - ## main parent (i.e. killproc) because it can take a long time - ## for an individual process to process a TERM signal - smbdpids=`ps guax | grep smbd | grep -v grep | awk '{print $2}'` - for pid in $smbdpids; do - kill -TERM $pid - done - ## nmbd is ok to kill using killproc() - killproc nmbd -TERM - rm -f /var/lock/subsys/smb - echo "" - ;; - status) - status smbd - status nmbd - ;; - restart) - echo -n "Restarting SMB services: " - $0 stop - $0 start - echo "done." - ;; - *) - echo "Usage: smb {start|stop|restart|status}" - exit 1 -esac - diff --git a/packaging/RedHat/smbprint b/packaging/RedHat/smbprint deleted file mode 100755 index a0fd2e481b5..00000000000 --- a/packaging/RedHat/smbprint +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh - -# This script is an input filter for printcap printing on a unix machine. It -# uses the smbclient program to print the file to the specified smb-based -# server and service. -# For example you could have a printcap entry like this -# -# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint -# -# which would create a unix printer called "smb" that will print via this -# script. You will need to create the spool directory /usr/spool/smb with -# appropriate permissions and ownerships for your system. - -# Set these to the server and service you wish to print to -# In this example I have a WfWg PC called "lapland" that has a printer -# exported called "printer" with no password. - -# -# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) -# so that the server, service, and password can be read from -# a /var/spool/lpd/PRINTNAME/.config file. -# -# In order for this to work the /etc/printcap entry must include an -# accounting file (af=...): -# -# cdcolour:\ -# :cm=CD IBM Colorjet on 6th:\ -# :sd=/var/spool/lpd/cdcolour:\ -# :af=/var/spool/lpd/cdcolour/acct:\ -# :if=/usr/local/etc/smbprint:\ -# :mx=0:\ -# :lp=/dev/null: -# -# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: -# server=PC_SERVER -# service=PR_SHARENAME -# password="password" -# -# E.g. -# server=PAULS_PC -# service=CJET_371 -# password="" - -# -# Debugging log file, change to /dev/null if you like. -# -# logfile=/tmp/smb-print.log -logfile=/dev/null - - -# -# The last parameter to the filter is the accounting file name. -# Extract the directory name from the file name. -# Concat this with /.config to get the config file. -# -eval acct_file=\${$#} -spool_dir=`dirname $acct_file` -config_file=$spool_dir/.config - -# Should read the following variables set in the config file: -# server -# service -# password -eval `cat $config_file` - -# -# Some debugging help, change the >> to > if you want to same space. -# -echo "server $server, service $service" >> $logfile - -( -# NOTE You may wish to add the line `echo translate' if you want automatic -# CR/LF translation when printing. -# echo translate - echo "print -" - cat -) | /usr/bin/smbclient "\\\\$server\\$service" $password -U $server -N >> $logfile diff --git a/packaging/RedHat/smbusers b/packaging/RedHat/smbusers deleted file mode 100644 index ae3389f53f8..00000000000 --- a/packaging/RedHat/smbusers +++ /dev/null @@ -1,3 +0,0 @@ -# Unix_name = SMB_name1 SMB_name2 ... -root = administrator admin -nobody = guest pcguest smbguest diff --git a/packaging/RedHat/winbind.init b/packaging/RedHat/winbind.init deleted file mode 100644 index 289ca590834..00000000000 --- a/packaging/RedHat/winbind.init +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh -# -# chkconfig: 345 91 45 -# description: Starts and stops the Samba winbind daemon to provide \ -# user and group information from a domain controller to linux. - -# Source function library. -if [ -f /etc/init.d/functions ] ; then - . /etc/init.d/functions -elif [ -f /etc/rc.d/init.d/functions ] ; then - . /etc/rc.d/init.d/functions -else - exit 0 -fi - -# Source networking configuration. -. /etc/sysconfig/network - -# Check that networking is up. -[ ${NETWORKING} = "no" ] && exit 0 - -CONFIG=/etc/samba/smb.conf - -# Check that smb.conf exists. -[ -f $CONFIG ] || exit 0 - -start() { - echo -n "Starting Winbind services: " - daemon winbindd - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/winbind || \ - RETVAL=1 - return $RETVAL -} -stop() { - echo -n "Shutting down Winbind services: " - killproc winbindd - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/winbind - return $RETVAL -} -restart() { - stop - start -} -reload() { - export TMPDIR="/var/tmp" - echo -n "Checking domain trusts: " - killproc winbindd -HUP - RETVAL=$? - echo - return $RETVAL -} -mdkstatus() { - status winbindd -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - restart) - restart - ;; - reload) - reload - ;; - status) - mdkstatus - ;; - condrestart) - [ -f /var/lock/subsys/winbindd ] && restart || : - ;; - *) - echo "Usage: $0 {start|stop|restart|status|condrestart}" - exit 1 -esac - -exit $? -- cgit From 5822cc275ac5d6af0635b20e48393015279c5d07 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Fri, 20 Jan 2006 20:22:23 +0000 Subject: r13058: Add %w macro for the winbind seperator which allows us for example valid users = %S, %D%w%S --- source/lib/substitute.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/lib/substitute.c b/source/lib/substitute.c index 4d22518230f..344f6e06fdf 100644 --- a/source/lib/substitute.c +++ b/source/lib/substitute.c @@ -448,6 +448,9 @@ void standard_sub_basic(const char *smb_name, char *str,size_t len) case 'v' : string_sub(p,"%v", SAMBA_VERSION_STRING,l); break; + case 'w' : + string_sub(p,"%w", lp_winbind_separator(),l); + break; case '$' : p += expand_env_var(p,l); break; /* Expand environment variables */ @@ -615,6 +618,9 @@ char *alloc_sub_basic(const char *smb_name, const char *str) case 'v' : t = realloc_string_sub(t, "%v", SAMBA_VERSION_STRING); break; + case 'w' : + t = realloc_string_sub(t, "%w", lp_winbind_separator()); + break; case '$' : t = realloc_expand_env_var(t, p); /* Expand environment variables */ break; -- cgit From 51763121149c4c0031804f338f17b2b066f17dee Mon Sep 17 00:00:00 2001 From: Deryck Hodge Date: Mon, 23 Jan 2006 00:19:45 +0000 Subject: r13072: Fix segfault in vfstest and smbtorture. deryck --- source/torture/torture.c | 2 ++ source/torture/vfstest.c | 1 + 2 files changed, 3 insertions(+) diff --git a/source/torture/torture.c b/source/torture/torture.c index 0bd9aa1728b..e995c3cc58a 100644 --- a/source/torture/torture.c +++ b/source/torture/torture.c @@ -4914,6 +4914,8 @@ static void usage(void) setbuffer(stdout, NULL, 0); #endif + load_case_tables(); + lp_load(dyn_CONFIGFILE,True,False,False); load_interfaces(); diff --git a/source/torture/vfstest.c b/source/torture/vfstest.c index b5ccf930bc6..1914a4acb50 100644 --- a/source/torture/vfstest.c +++ b/source/torture/vfstest.c @@ -495,6 +495,7 @@ int main(int argc, char *argv[]) POPT_TABLEEND }; + load_case_tables(); setlinebuf(stdout); -- cgit From e6d82c2061d217b7ef4403a98cd7ded0d6125a2c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:02:17 +0000 Subject: r13081: correct fix for the segv in nmbd caused by a double free on namerec. --- source/nmbd/nmbd_namelistdb.c | 11 +++++------ source/nmbd/nmbd_winsserver.c | 5 +++-- source/rpc_server/srv_srvsvc_nt.c | 19 +++++++++++-------- source/utils/status.c | 8 ++++---- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/source/nmbd/nmbd_namelistdb.c b/source/nmbd/nmbd_namelistdb.c index baaf5dbd548..60023a7ed5e 100644 --- a/source/nmbd/nmbd_namelistdb.c +++ b/source/nmbd/nmbd_namelistdb.c @@ -80,14 +80,13 @@ static void upcase_name( struct nmb_name *target, const struct nmb_name *source void remove_name_from_namelist(struct subnet_record *subrec, struct name_record *namerec ) { - if (subrec == wins_server_subnet) { + if (subrec == wins_server_subnet) remove_name_from_wins_namelist(namerec); - return; - } - - subrec->namelist_changed = True; + else { + subrec->namelist_changed = True; + DLIST_REMOVE(subrec->namelist, namerec); + } - DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); diff --git a/source/nmbd/nmbd_winsserver.c b/source/nmbd/nmbd_winsserver.c index 5c234bf8dcc..9983efe5ebb 100644 --- a/source/nmbd/nmbd_winsserver.c +++ b/source/nmbd/nmbd_winsserver.c @@ -290,8 +290,9 @@ BOOL remove_name_from_wins_namelist(struct name_record *namerec) DLIST_REMOVE(wins_server_subnet->namelist, namerec); SAFE_FREE(namerec->data.ip); - ZERO_STRUCTP(namerec); - SAFE_FREE(namerec); + + /* namerec must be freed by the caller */ + return (ret == 0) ? True : False; } diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index 230f0626628..b0e8111f62a 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -2,8 +2,8 @@ * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1997, - * Copyright (C) Jeremy Allison 2001. - * Copyright (C) Nigel Williams 2001. + * Copyright (C) Jeremy Allison 2001. + * Copyright (C) Nigel Williams 2001. * * 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 @@ -1539,6 +1539,7 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S SEC_DESC *psd = NULL; SE_PRIV se_diskop = SE_DISK_OPERATOR; BOOL is_disk_op = False; + int max_connections = 0; DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__)); @@ -1583,6 +1584,7 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment)); unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname)); type = q_u->info.share.info2.info_2.type; + max_connections = (q_u->info.share.info2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.max_uses; psd = NULL; break; #if 0 @@ -1658,8 +1660,8 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S return WERR_ACCESS_DENIED; } - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"", - lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d", + lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment, max_connections ); DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command )); @@ -1951,16 +1953,17 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET TIME_OF_DAY_INFO *tod; struct tm *t; time_t unixdate = time(NULL); + /* We do this call first as if we do it *after* the gmtime call it overwrites the pointed-to values. JRA */ + uint32 zone = get_time_zone(unixdate)/60; - tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO); - if (!tod) + DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__)); + + if ( !(tod = TALLOC_ZERO_P(p->mem_ctx, TIME_OF_DAY_INFO)) ) return WERR_NOMEM; - ZERO_STRUCTP(tod); - r_u->tod = tod; r_u->ptr_srv_tod = 0x1; r_u->status = WERR_OK; diff --git a/source/utils/status.c b/source/utils/status.c index f19a217aa65..b9f1c161e48 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -103,13 +103,13 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share static int count; if (count==0) { d_printf("Locked files:\n"); - d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); - d_printf("----------------------------------------------------------------------------------\n"); + d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); + d_printf("----------------------------------------------------------------------------------------\n"); } count++; if (Ucrit_checkPid(procid_to_pid(&e->pid))) { - d_printf("%s ",procid_str_static(&e->pid)); + d_printf("%-11s ",procid_str_static(&e->pid)); switch (map_share_mode_to_deny_mode(e->share_access, e->private_options)) { case DENY_NONE: d_printf("DENY_NONE "); break; @@ -166,7 +166,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, } count++; - d_printf("%s %05x:%05x %s %9.0f %9.0f\n", + d_printf("%08s %05x:%05x %s %9.0f %9.0f\n", procid_str_static(&pid), (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); -- cgit From e29655983addd3f60c5ce5fe6305c3056fb9c038 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:04:40 +0000 Subject: r13082: revert an accidentally commited patch (still in progress) --- source/rpc_server/srv_srvsvc_nt.c | 19 ++++++++----------- source/utils/status.c | 8 ++++---- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index b0e8111f62a..230f0626628 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -2,8 +2,8 @@ * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1997, - * Copyright (C) Jeremy Allison 2001. - * Copyright (C) Nigel Williams 2001. + * Copyright (C) Jeremy Allison 2001. + * Copyright (C) Nigel Williams 2001. * * 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 @@ -1539,7 +1539,6 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S SEC_DESC *psd = NULL; SE_PRIV se_diskop = SE_DISK_OPERATOR; BOOL is_disk_op = False; - int max_connections = 0; DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__)); @@ -1584,7 +1583,6 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment)); unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname)); type = q_u->info.share.info2.info_2.type; - max_connections = (q_u->info.share.info2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.max_uses; psd = NULL; break; #if 0 @@ -1660,8 +1658,8 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S return WERR_ACCESS_DENIED; } - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d", - lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment, max_connections ); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"", + lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment); DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command )); @@ -1953,17 +1951,16 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET TIME_OF_DAY_INFO *tod; struct tm *t; time_t unixdate = time(NULL); - /* We do this call first as if we do it *after* the gmtime call it overwrites the pointed-to values. JRA */ - uint32 zone = get_time_zone(unixdate)/60; - DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__)); - - if ( !(tod = TALLOC_ZERO_P(p->mem_ctx, TIME_OF_DAY_INFO)) ) + tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO); + if (!tod) return WERR_NOMEM; + ZERO_STRUCTP(tod); + r_u->tod = tod; r_u->ptr_srv_tod = 0x1; r_u->status = WERR_OK; diff --git a/source/utils/status.c b/source/utils/status.c index b9f1c161e48..f19a217aa65 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -103,13 +103,13 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share static int count; if (count==0) { d_printf("Locked files:\n"); - d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); - d_printf("----------------------------------------------------------------------------------------\n"); + d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); + d_printf("----------------------------------------------------------------------------------\n"); } count++; if (Ucrit_checkPid(procid_to_pid(&e->pid))) { - d_printf("%-11s ",procid_str_static(&e->pid)); + d_printf("%s ",procid_str_static(&e->pid)); switch (map_share_mode_to_deny_mode(e->share_access, e->private_options)) { case DENY_NONE: d_printf("DENY_NONE "); break; @@ -166,7 +166,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, } count++; - d_printf("%08s %05x:%05x %s %9.0f %9.0f\n", + d_printf("%s %05x:%05x %s %9.0f %9.0f\n", procid_str_static(&pid), (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); -- cgit From 521f4d15c7d3ed726b68e97c06c225bbc9c86167 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:26:48 +0000 Subject: r13083: patch suggested by Adam Nielsen for better smbstatus formatting --- source/utils/status.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/utils/status.c b/source/utils/status.c index f19a217aa65..b9f1c161e48 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -103,13 +103,13 @@ static void print_share_mode(const struct share_mode_entry *e, const char *share static int count; if (count==0) { d_printf("Locked files:\n"); - d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); - d_printf("----------------------------------------------------------------------------------\n"); + d_printf("Pid DenyMode Access R/W Oplock SharePath Name\n"); + d_printf("----------------------------------------------------------------------------------------\n"); } count++; if (Ucrit_checkPid(procid_to_pid(&e->pid))) { - d_printf("%s ",procid_str_static(&e->pid)); + d_printf("%-11s ",procid_str_static(&e->pid)); switch (map_share_mode_to_deny_mode(e->share_access, e->private_options)) { case DENY_NONE: d_printf("DENY_NONE "); break; @@ -166,7 +166,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, } count++; - d_printf("%s %05x:%05x %s %9.0f %9.0f\n", + d_printf("%08s %05x:%05x %s %9.0f %9.0f\n", procid_str_static(&pid), (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); -- cgit From 02f78556e7335c8352a78baac11e0c4ebe22fa48 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:34:26 +0000 Subject: r13085: hook the max connections spin box in the share properties MMC plugin dialog to the 'max connections' smb.conf parameter. Also added the max uses int from the SHARE_INFO_2 structure to the 'modify share command' --- source/rpc_server/srv_srvsvc_nt.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index 230f0626628..b3af4b71689 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -2,8 +2,8 @@ * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-1997, - * Copyright (C) Jeremy Allison 2001. - * Copyright (C) Nigel Williams 2001. + * Copyright (C) Jeremy Allison 2001. + * Copyright (C) Nigel Williams 2001. * * 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 @@ -109,6 +109,8 @@ static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int sn pstring remark; pstring path; pstring passwd; + int max_connections = lp_max_connections(snum); + uint32 max_uses = max_connections!=0 ? max_connections : 0xffffffff; char *net_name = lp_servicename(snum); pstrcpy(remark, lp_comment(snum)); @@ -125,7 +127,7 @@ static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int sn pstrcpy(passwd, ""); - init_srv_share_info2(&sh2->info_2, net_name, get_share_type(snum), remark, 0, 0xffffffff, 1, path, passwd); + init_srv_share_info2(&sh2->info_2, net_name, get_share_type(snum), remark, 0, max_uses, 1, path, passwd); init_srv_share_info2_str(&sh2->info_2_str, net_name, remark, path, passwd); } @@ -1539,6 +1541,7 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S SEC_DESC *psd = NULL; SE_PRIV se_diskop = SE_DISK_OPERATOR; BOOL is_disk_op = False; + int max_connections = 0; DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__)); @@ -1583,6 +1586,7 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment)); unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname)); type = q_u->info.share.info2.info_2.type; + max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses; psd = NULL; break; #if 0 @@ -1651,15 +1655,16 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S /* Only call modify function if something changed. */ - if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) ) + if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) + || (lp_max_connections(snum) != max_connections) ) { if (!lp_change_share_cmd() || !*lp_change_share_cmd()) { DEBUG(10,("_srv_net_share_set_info: No change share command\n")); return WERR_ACCESS_DENIED; } - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"", - lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d", + lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment, max_connections ); DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command )); @@ -1951,16 +1956,17 @@ WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET TIME_OF_DAY_INFO *tod; struct tm *t; time_t unixdate = time(NULL); + /* We do this call first as if we do it *after* the gmtime call it overwrites the pointed-to values. JRA */ + uint32 zone = get_time_zone(unixdate)/60; - tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO); - if (!tod) + DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__)); + + if ( !(tod = TALLOC_ZERO_P(p->mem_ctx, TIME_OF_DAY_INFO)) ) return WERR_NOMEM; - ZERO_STRUCTP(tod); - r_u->tod = tod; r_u->ptr_srv_tod = 0x1; r_u->status = WERR_OK; -- cgit From fa71fc267a321a4093cc50d5bb5fad85318b3a34 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:47:55 +0000 Subject: r13086: hooking max connections into 'add share' as well (although the WinXP UI doesn't give you a way to set the value on add --- source/rpc_server/srv_srvsvc_nt.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/source/rpc_server/srv_srvsvc_nt.c b/source/rpc_server/srv_srvsvc_nt.c index b3af4b71689..65e0504e678 100644 --- a/source/rpc_server/srv_srvsvc_nt.c +++ b/source/rpc_server/srv_srvsvc_nt.c @@ -1711,7 +1711,8 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S } /******************************************************************* - Net share add. Call 'add_share_command "sharename" "pathname" "comment" "read only = xxx"' + Net share add. Call 'add_share_command "sharename" "pathname" + "comment" "max connections = " ********************************************************************/ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u) @@ -1728,6 +1729,7 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S SEC_DESC *psd = NULL; SE_PRIV se_diskop = SE_DISK_OPERATOR; BOOL is_disk_op; + int max_connections = 0; DEBUG(5,("_srv_net_share_add: %d\n", __LINE__)); @@ -1756,6 +1758,7 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S unistr2_to_ascii(share_name, &q_u->info.share.info2.info_2_str.uni_netname, sizeof(share_name)); unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name)); unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name)); + max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses; type = q_u->info.share.info2.info_2.type; break; case 501: @@ -1792,9 +1795,8 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S return WERR_INVALID_NAME; } - if ( strequal(share_name,"IPC$") - || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") ) - || strequal(share_name,"global") ) + if ( strequal(share_name,"IPC$") || strequal(share_name,"global") + || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") ) ) { return WERR_ACCESS_DENIED; } @@ -1818,8 +1820,13 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S string_replace(path, '"', ' '); string_replace(comment, '"', ' '); - slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"", - lp_add_share_cmd(), dyn_CONFIGFILE, share_name, path, comment); + slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d", + lp_add_share_cmd(), + dyn_CONFIGFILE, + share_name, + path, + comment, + max_connections); DEBUG(10,("_srv_net_share_add: Running [%s]\n", command )); -- cgit From 5c68e96ea4f2c61f4a44b738b1421ce599522464 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 21:57:36 +0000 Subject: r13089: quick fix to work around building ilbnss_winbind.so on SOlaris when --enable-developer is specified --- source/nsswitch/winbind_nss_solaris.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/nsswitch/winbind_nss_solaris.c b/source/nsswitch/winbind_nss_solaris.c index 8076c043e04..b94b444fb4c 100644 --- a/source/nsswitch/winbind_nss_solaris.c +++ b/source/nsswitch/winbind_nss_solaris.c @@ -25,6 +25,8 @@ Boston, MA 02111-1307, USA. */ +#undef DEVELOPER + #include #include #include -- cgit From dfc8937fbea1dc4d263d09cd271df519b6c4e20a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 23 Jan 2006 21:57:58 +0000 Subject: r13091: Fix gcc warning about using '0' with %s. Jeremy. --- source/utils/status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/utils/status.c b/source/utils/status.c index b9f1c161e48..eeaf83d1772 100644 --- a/source/utils/status.c +++ b/source/utils/status.c @@ -166,7 +166,7 @@ static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, struct process_id pid, } count++; - d_printf("%08s %05x:%05x %s %9.0f %9.0f\n", + d_printf("%8s %05x:%05x %s %9.0f %9.0f\n", procid_str_static(&pid), (int)dev, (int)ino, lock_type==READ_LOCK?"R":"W", (double)start, (double)size); -- cgit From ef00f14ba32e13399f4aac9a011609c706b71e7b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 22:02:52 +0000 Subject: r13093: adding vendor patch level string as announced on samba-technical ml --- source/VERSION | 7 +++++++ source/lib/version.c | 6 ++++++ source/script/mkversion.sh | 33 +++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/source/VERSION b/source/VERSION index 5e2b8df3865..5119a954012 100644 --- a/source/VERSION +++ b/source/VERSION @@ -1,6 +1,12 @@ ######################################################## # SAMBA Version # # # +# Samba versions are as follows # +# 3.0.x New production series # +# 3.0.x{pre,rc}y Preview/Testing & RC # +# 3.0.x[a-z] Patch releases # +# 3.0.x[a-z]-VENDOR-z Vendor patch releases # +# # # script/mkversion.sh # # will use this file to create # # include/version.h # @@ -91,3 +97,4 @@ SAMBA_VERSION_IS_SVN_SNAPSHOT=yes # -> "CVS 3.0.0rc2-VendorVersion" # ######################################################## SAMBA_VERSION_VENDOR_SUFFIX= +SAMBA_VENDOR_PATCH= diff --git a/source/lib/version.c b/source/lib/version.c index 99f836c2d5b..3bd8304012c 100644 --- a/source/lib/version.c +++ b/source/lib/version.c @@ -27,6 +27,7 @@ const char *samba_version_string(void) return SAMBA_VERSION_OFFICIAL_STRING; #else static fstring samba_version; + fstring tmp_version; static BOOL init_samba_version; if (init_samba_version) @@ -36,6 +37,11 @@ const char *samba_version_string(void) SAMBA_VERSION_OFFICIAL_STRING, SAMBA_VERSION_VENDOR_SUFFIX); +#ifdef SAMBA_VENDOR_PATCH + fstr_sprintf( tmp_version, "-%d", SAMBA_VENDOR_PATCH ); + fstrcat( samba_version, tmp_version ); +#endif + init_samba_version = True; return samba_version; #endif diff --git a/source/script/mkversion.sh b/source/script/mkversion.sh index 9d919cfe34b..1ba7cd63699 100755 --- a/source/script/mkversion.sh +++ b/source/script/mkversion.sh @@ -1,5 +1,4 @@ #!/bin/sh -# VERSION_FILE=$1 OUTPUT_FILE=$2 @@ -17,16 +16,12 @@ SOURCE_DIR=$3 SAMBA_VERSION_MAJOR=`sed -n 's/^SAMBA_VERSION_MAJOR=//p' $SOURCE_DIR$VERSION_FILE` SAMBA_VERSION_MINOR=`sed -n 's/^SAMBA_VERSION_MINOR=//p' $SOURCE_DIR$VERSION_FILE` SAMBA_VERSION_RELEASE=`sed -n 's/^SAMBA_VERSION_RELEASE=//p' $SOURCE_DIR$VERSION_FILE` - SAMBA_VERSION_REVISION=`sed -n 's/^SAMBA_VERSION_REVISION=//p' $SOURCE_DIR$VERSION_FILE` - SAMBA_VERSION_PRE_RELEASE=`sed -n 's/^SAMBA_VERSION_PRE_RELEASE=//p' $SOURCE_DIR$VERSION_FILE` - SAMBA_VERSION_RC_RELEASE=`sed -n 's/^SAMBA_VERSION_RC_RELEASE=//p' $SOURCE_DIR$VERSION_FILE` - SAMBA_VERSION_IS_SVN_SNAPSHOT=`sed -n 's/^SAMBA_VERSION_IS_SVN_SNAPSHOT=//p' $SOURCE_DIR$VERSION_FILE` - SAMBA_VERSION_VENDOR_SUFFIX=`sed -n 's/^SAMBA_VERSION_VENDOR_SUFFIX=//p' $SOURCE_DIR$VERSION_FILE` +SAMBA_VENDOR_PATCH=`sed -n 's/^SAMBA_VENDOR_PATCH=//p' $SOURCE_DIR$VERSION_FILE` echo "/* Autogenerated by script/mkversion.sh */" > $OUTPUT_FILE @@ -35,13 +30,21 @@ echo "#define SAMBA_VERSION_MINOR ${SAMBA_VERSION_MINOR}" >> $OUTPUT_FILE echo "#define SAMBA_VERSION_RELEASE ${SAMBA_VERSION_RELEASE}" >> $OUTPUT_FILE +## +## start with "3.0.22" +## SAMBA_VERSION_STRING="${SAMBA_VERSION_MAJOR}.${SAMBA_VERSION_MINOR}.${SAMBA_VERSION_RELEASE}" +## +## maybe add "3.0.22a" or "3.0.22pre1" or "3.0.22rc1" +## We do not do pre or rc version on patch/letter releases +## if test -n "${SAMBA_VERSION_REVISION}";then SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}${SAMBA_VERSION_REVISION}" echo "#define SAMBA_VERSION_REVISION \"${SAMBA_VERSION_REVISION}\"" >> $OUTPUT_FILE elif test -n "${SAMBA_VERSION_PRE_RELEASE}";then + ## maybe add "3.0.22pre2" SAMBA_VERSION_STRING="${SAMBA_VERSION_STRING}pre${SAMBA_VERSION_PRE_RELEASE}" echo "#define SAMBA_VERSION_PRE_RELEASE ${SAMBA_VERSION_PRE_RELEASE}" >> $OUTPUT_FILE elif test -n "${SAMBA_VERSION_RC_RELEASE}";then @@ -49,7 +52,21 @@ elif test -n "${SAMBA_VERSION_RC_RELEASE}";then echo "#define SAMBA_VERSION_RC_RELEASE ${SAMBA_VERSION_RC_RELEASE}" >> $OUTPUT_FILE fi +## +## Add the vendor string if present +## +if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then + echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE + if test -n "${SAMBA_VENDOR_PATCH}";then + echo "#define SAMBA_VENDOR_PATCH ${SAMBA_VENDOR_PATCH}" >> $OUTPUT_FILE + fi +fi + + +## +## SVN revision number? +## if test x"${SAMBA_VERSION_IS_SVN_SNAPSHOT}" = x"yes";then _SAVE_LANG=${LANG} LANG="" @@ -78,10 +95,6 @@ if test x"${SAMBA_VERSION_IS_SVN_SNAPSHOT}" = x"yes";then LANG=${_SAVE_LANG} fi -if test -n "${SAMBA_VERSION_VENDOR_SUFFIX}";then - echo "#define SAMBA_VERSION_VENDOR_SUFFIX ${SAMBA_VERSION_VENDOR_SUFFIX}" >> $OUTPUT_FILE -fi - echo "#define SAMBA_VERSION_OFFICIAL_STRING \"${SAMBA_VERSION_STRING}\"" >> $OUTPUT_FILE echo "#define SAMBA_VERSION_STRING samba_version_string()" >> $OUTPUT_FILE -- cgit From c7aedeefd3f13202871d809bf66dfe04559336a3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 23 Jan 2006 23:19:31 +0000 Subject: r13095: Fix warnings assigning int to a size_t. Jeremy. --- source/include/auth.h | 2 +- source/include/smb.h | 2 +- source/smbd/service.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/include/auth.h b/source/include/auth.h index f3dae1108b3..03206c03c6a 100644 --- a/source/include/auth.h +++ b/source/include/auth.h @@ -58,7 +58,7 @@ typedef struct auth_serversupplied_info { gid_t gid; /* This groups info is needed for when we become_user() for this uid */ - int n_groups; + size_t n_groups; gid_t *groups; /* NT group information taken from the info3 structure */ diff --git a/source/include/smb.h b/source/include/smb.h index 6ceb4ec1cdd..f899a71dc6d 100644 --- a/source/include/smb.h +++ b/source/include/smb.h @@ -514,7 +514,7 @@ typedef struct connection_struct /* following groups stuff added by ih */ /* This groups info is valid for the user that *opened* the connection */ - int ngroups; + size_t ngroups; gid_t *groups; NT_USER_TOKEN *nt_user_token; diff --git a/source/smbd/service.c b/source/smbd/service.c index fb9dbf0489c..7640559d538 100644 --- a/source/smbd/service.c +++ b/source/smbd/service.c @@ -592,6 +592,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, } if (conn->force_user || conn->force_group) { + int ngroups = 0; /* groups stuff added by ih */ conn->ngroups = 0; @@ -600,7 +601,8 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, /* Find all the groups this uid is in and store them. Used by change_to_user() */ initialise_groups(conn->user, conn->uid, conn->gid); - get_current_groups(conn->gid, &conn->ngroups,&conn->groups); + get_current_groups(conn->gid, &ngroups, &conn->groups); + conn->ngroups = ngroups; conn->nt_user_token = create_nt_token(conn->uid, conn->gid, -- cgit