From 33032d591f8e39edae0ce4b35ca1b6e25f04a04b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 18 Oct 2008 17:49:41 +0200 Subject: Move ufc to libreplace. --- source3/Makefile.in | 2 +- source3/configure.in | 6 - source3/include/proto.h | 4 - source3/lib/ufc.c | 770 ------------------------------------------------ 4 files changed, 1 insertion(+), 781 deletions(-) delete mode 100644 source3/lib/ufc.c (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index c880f79eb5..1a607c463d 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -334,7 +334,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \ $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \ lib/interface.o lib/pidfile.o \ lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \ - lib/ufc.o lib/genrand.o lib/username.o \ + lib/genrand.o lib/username.o \ lib/util_pw.o lib/access.o lib/smbrun.o \ lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \ lib/wins_srv.o \ diff --git a/source3/configure.in b/source3/configure.in index 9388ebabc0..ce1c422bd1 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -4318,12 +4318,6 @@ AC_ARG_WITH(pam_smbpass, ) -############################################### -# test for where we get crypt() from -AC_SEARCH_LIBS(crypt, [crypt], - [test "$ac_cv_search_crypt" = "none required" || AUTH_LIBS="-lcrypt $AUTH_LIBS" - AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function])]) - ## ## moved after the check for -lcrypt in order to ## ensure that the necessary libraries are included diff --git a/source3/include/proto.h b/source3/include/proto.h index ba84574653..c4c89b0448 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1190,10 +1190,6 @@ const char *time_to_asc(const time_t t); const char *display_time(NTTIME nttime); bool nt_time_is_set(const NTTIME *nt); -/* The following definitions come from lib/ufc.c */ - -char *ufc_crypt(const char *key,const char *salt); - /* The following definitions come from lib/username.c */ char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user); diff --git a/source3/lib/ufc.c b/source3/lib/ufc.c deleted file mode 100644 index 89329808c9..0000000000 --- a/source3/lib/ufc.c +++ /dev/null @@ -1,770 +0,0 @@ -/* - This bit of code was derived from the UFC-crypt package which - carries the following copyright - - Modified for use by Samba by Andrew Tridgell, October 1994 - - Note that this routine is only faster on some machines. Under Linux 1.1.51 - libc 4.5.26 I actually found this routine to be slightly slower. - - Under SunOS I found a huge speedup by using these routines - (a factor of 20 or so) - - Warning: I've had a report from Steve Kennedy - that this crypt routine may sometimes get the wrong answer. Only - use UFC_CRYT if you really need it. - -*/ - -#include "includes.h" - -#ifndef HAVE_CRYPT - -/* - * UFC-crypt: ultra fast crypt(3) implementation - * - * Copyright (C) 1991-1998, Free Software Foundation, Inc. - * - * 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 3 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 Lesser General Public - * License along with this library; if not, see . - * - * @(#)crypt_util.c 2.31 02/08/92 - * - * Support routines - * - */ - - -#ifndef long32 -#define long32 int32 -#endif - -#ifndef long64 -#define long64 int64 -#endif - -#ifndef ufc_long -#define ufc_long unsigned -#endif - -#ifndef _UFC_64_ -#define _UFC_32_ -#endif - -/* - * Permutation done once on the 56 bit - * key derived from the original 8 byte ASCII key. - */ -static int pc1[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -/* - * How much to rotate each 28 bit half of the pc1 permutated - * 56 bit key before using pc2 to give the i' key - */ -static int rots[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -/* - * Permutation giving the key - * of the i' DES round - */ -static int pc2[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -/* - * The E expansion table which selects - * bits from the 32 bit intermediate result. - */ -static int esel[48] = { - 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, - 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, - 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, - 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1 -}; -static int e_inverse[64]; - -/* - * Permutation done on the - * result of sbox lookups - */ -static int perm32[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -/* - * The sboxes - */ -static int sbox[8][4][16]= { - { { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }, - { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 }, - { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 }, - { 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 } - }, - - { { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, - { 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 }, - { 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 }, - { 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 } - }, - - { { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, - { 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 }, - { 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 }, - { 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 } - }, - - { { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, - { 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 }, - { 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 }, - { 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 } - }, - - { { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }, - { 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 }, - { 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 }, - { 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 } - }, - - { { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }, - { 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 }, - { 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 }, - { 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 } - }, - - { { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }, - { 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 }, - { 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 }, - { 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 } - }, - - { { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }, - { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 }, - { 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 }, - { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } - } -}; - -/* - * This is the final - * permutation matrix - */ -static int final_perm[64] = { - 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, - 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, - 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, - 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25 -}; - -/* - * The 16 DES keys in BITMASK format - */ -#ifdef _UFC_32_ -long32 _ufc_keytab[16][2]; -#endif - -#ifdef _UFC_64_ -long64 _ufc_keytab[16]; -#endif - - -#define ascii_to_bin(c) ((c)>='a'?(c-59):(c)>='A'?((c)-53):(c)-'.') -#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.') - -/* Macro to set a bit (0..23) */ -#define BITMASK(i) ( (1<<(11-(i)%12+3)) << ((i)<12?16:0) ) - -/* - * sb arrays: - * - * Workhorses of the inner loop of the DES implementation. - * They do sbox lookup, shifting of this value, 32 bit - * permutation and E permutation for the next round. - * - * Kept in 'BITMASK' format. - */ - -#ifdef _UFC_32_ -long32 _ufc_sb0[8192], _ufc_sb1[8192], _ufc_sb2[8192], _ufc_sb3[8192]; -static long32 *sb[4] = {_ufc_sb0, _ufc_sb1, _ufc_sb2, _ufc_sb3}; -#endif - -#ifdef _UFC_64_ -long64 _ufc_sb0[4096], _ufc_sb1[4096], _ufc_sb2[4096], _ufc_sb3[4096]; -static long64 *sb[4] = {_ufc_sb0, _ufc_sb1, _ufc_sb2, _ufc_sb3}; -#endif - -/* - * eperm32tab: do 32 bit permutation and E selection - * - * The first index is the byte number in the 32 bit value to be permuted - * - second - is the value of this byte - * - third - selects the two 32 bit values - * - * The table is used and generated internally in init_des to speed it up - */ -static ufc_long eperm32tab[4][256][2]; - -/* - * do_pc1: permform pc1 permutation in the key schedule generation. - * - * The first index is the byte number in the 8 byte ASCII key - * - second - - the two 28 bits halfs of the result - * - third - selects the 7 bits actually used of each byte - * - * The result is kept with 28 bit per 32 bit with the 4 most significant - * bits zero. - */ -static ufc_long do_pc1[8][2][128]; - -/* - * do_pc2: permform pc2 permutation in the key schedule generation. - * - * The first index is the septet number in the two 28 bit intermediate values - * - second - - - septet values - * - * Knowledge of the structure of the pc2 permutation is used. - * - * The result is kept with 28 bit per 32 bit with the 4 most significant - * bits zero. - */ -static ufc_long do_pc2[8][128]; - -/* - * efp: undo an extra e selection and do final - * permutation giving the DES result. - * - * Invoked 6 bit a time on two 48 bit values - * giving two 32 bit longs. - */ -static ufc_long efp[16][64][2]; - -static unsigned char bytemask[8] = { - 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 -}; - -static ufc_long longmask[32] = { - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 -}; - - -/* - * Silly rewrite of 'bzero'. I do so - * because some machines don't have - * bzero and some don't have memset. - */ - -static void clearmem(char *start, int cnt) - { while(cnt--) - *start++ = '\0'; - } - -static int initialized = 0; - -/* lookup a 6 bit value in sbox */ - -#define s_lookup(i,s) sbox[(i)][(((s)>>4) & 0x2)|((s) & 0x1)][((s)>>1) & 0xf]; - -/* - * Initialize unit - may be invoked directly - * by fcrypt users. - */ - -static void ufc_init_des(void) - { int comes_from_bit; - int bit, sg; - ufc_long j; - ufc_long mask1, mask2; - - /* - * Create the do_pc1 table used - * to affect pc1 permutation - * when generating keys - */ - for(bit = 0; bit < 56; bit++) { - comes_from_bit = pc1[bit] - 1; - mask1 = bytemask[comes_from_bit % 8 + 1]; - mask2 = longmask[bit % 28 + 4]; - for(j = 0; j < 128; j++) { - if(j & mask1) - do_pc1[comes_from_bit / 8][bit / 28][j] |= mask2; - } - } - - /* - * Create the do_pc2 table used - * to affect pc2 permutation when - * generating keys - */ - for(bit = 0; bit < 48; bit++) { - comes_from_bit = pc2[bit] - 1; - mask1 = bytemask[comes_from_bit % 7 + 1]; - mask2 = BITMASK(bit % 24); - for(j = 0; j < 128; j++) { - if(j & mask1) - do_pc2[comes_from_bit / 7][j] |= mask2; - } - } - - /* - * Now generate the table used to do combined - * 32 bit permutation and e expansion - * - * We use it because we have to permute 16384 32 bit - * longs into 48 bit in order to initialize sb. - * - * Looping 48 rounds per permutation becomes - * just too slow... - * - */ - - clearmem((char*)eperm32tab, sizeof(eperm32tab)); - - for(bit = 0; bit < 48; bit++) { - ufc_long inner_mask1,comes_from; - - comes_from = perm32[esel[bit]-1]-1; - inner_mask1 = bytemask[comes_from % 8]; - - for(j = 256; j--;) { - if(j & inner_mask1) - eperm32tab[comes_from / 8][j][bit / 24] |= BITMASK(bit % 24); - } - } - - /* - * Create the sb tables: - * - * For each 12 bit segment of an 48 bit intermediate - * result, the sb table precomputes the two 4 bit - * values of the sbox lookups done with the two 6 - * bit halves, shifts them to their proper place, - * sends them through perm32 and finally E expands - * them so that they are ready for the next - * DES round. - * - */ - for(sg = 0; sg < 4; sg++) { - int j1, j2; - int s1, s2; - - for(j1 = 0; j1 < 64; j1++) { - s1 = s_lookup(2 * sg, j1); - for(j2 = 0; j2 < 64; j2++) { - ufc_long to_permute, inx; - - s2 = s_lookup(2 * sg + 1, j2); - to_permute = ((s1 << 4) | s2) << (24 - 8 * sg); - -#ifdef _UFC_32_ - inx = ((j1 << 6) | j2) << 1; - sb[sg][inx ] = eperm32tab[0][(to_permute >> 24) & 0xff][0]; - sb[sg][inx+1] = eperm32tab[0][(to_permute >> 24) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[1][(to_permute >> 16) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[1][(to_permute >> 16) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[2][(to_permute >> 8) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[2][(to_permute >> 8) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[3][(to_permute) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[3][(to_permute) & 0xff][1]; -#endif -#ifdef _UFC_64_ - inx = ((j1 << 6) | j2); - sb[sg][inx] = - ((long64)eperm32tab[0][(to_permute >> 24) & 0xff][0] << 32) | - (long64)eperm32tab[0][(to_permute >> 24) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[1][(to_permute >> 16) & 0xff][0] << 32) | - (long64)eperm32tab[1][(to_permute >> 16) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[2][(to_permute >> 8) & 0xff][0] << 32) | - (long64)eperm32tab[2][(to_permute >> 8) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[3][(to_permute) & 0xff][0] << 32) | - (long64)eperm32tab[3][(to_permute) & 0xff][1]; -#endif - } - } - } - - /* - * Create an inverse matrix for esel telling - * where to plug out bits if undoing it - */ - for(bit=48; bit--;) { - e_inverse[esel[bit] - 1 ] = bit; - e_inverse[esel[bit] - 1 + 32] = bit + 48; - } - - /* - * create efp: the matrix used to - * undo the E expansion and effect final permutation - */ - clearmem((char*)efp, sizeof efp); - for(bit = 0; bit < 64; bit++) { - int o_bit, o_long; - ufc_long word_value, inner_mask1, inner_mask2; - int comes_from_f_bit, comes_from_e_bit; - int comes_from_word, bit_within_word; - - /* See where bit i belongs in the two 32 bit long's */ - o_long = bit / 32; /* 0..1 */ - o_bit = bit % 32; /* 0..31 */ - - /* - * And find a bit in the e permutated value setting this bit. - * - * Note: the e selection may have selected the same bit several - * times. By the initialization of e_inverse, we only look - * for one specific instance. - */ - comes_from_f_bit = final_perm[bit] - 1; /* 0..63 */ - comes_from_e_bit = e_inverse[comes_from_f_bit]; /* 0..95 */ - comes_from_word = comes_from_e_bit / 6; /* 0..15 */ - bit_within_word = comes_from_e_bit % 6; /* 0..5 */ - - inner_mask1 = longmask[bit_within_word + 26]; - inner_mask2 = longmask[o_bit]; - - for(word_value = 64; word_value--;) { - if(word_value & inner_mask1) - efp[comes_from_word][word_value][o_long] |= inner_mask2; - } - } - initialized++; - } - -/* - * Process the elements of the sb table permuting the - * bits swapped in the expansion by the current salt. - */ - -#ifdef _UFC_32_ -static void shuffle_sb(long32 *k, ufc_long saltbits) - { ufc_long j; - long32 x; - for(j=4096; j--;) { - x = (k[0] ^ k[1]) & (long32)saltbits; - *k++ ^= x; - *k++ ^= x; - } - } -#endif - -#ifdef _UFC_64_ -static void shuffle_sb(long64 *k, ufc_long saltbits) - { ufc_long j; - long64 x; - for(j=4096; j--;) { - x = ((*k >> 32) ^ *k) & (long64)saltbits; - *k++ ^= (x << 32) | x; - } - } -#endif - -/* - * Setup the unit for a new salt - * Hopefully we'll not see a new salt in each crypt call. - */ - -static unsigned char current_salt[3] = "&&"; /* invalid value */ -static ufc_long current_saltbits = 0; -static int direction = 0; - -static void setup_salt(const char *s1) - { ufc_long i, j, saltbits; - const unsigned char *s2 = (const unsigned char *)s1; - - if(!initialized) - ufc_init_des(); - - if(s2[0] == current_salt[0] && s2[1] == current_salt[1]) - return; - current_salt[0] = s2[0]; current_salt[1] = s2[1]; - - /* - * This is the only crypt change to DES: - * entries are swapped in the expansion table - * according to the bits set in the salt. - */ - saltbits = 0; - for(i = 0; i < 2; i++) { - long c=ascii_to_bin(s2[i]); - if(c < 0 || c > 63) - c = 0; - for(j = 0; j < 6; j++) { - if((c >> j) & 0x1) - saltbits |= BITMASK(6 * i + j); - } - } - - /* - * Permute the sb table values - * to reflect the changed e - * selection table - */ - shuffle_sb(_ufc_sb0, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb1, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb2, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb3, current_saltbits ^ saltbits); - - current_saltbits = saltbits; - } - -static void ufc_mk_keytab(char *key) - { ufc_long v1, v2, *k1; - int i; -#ifdef _UFC_32_ - long32 v, *k2 = &_ufc_keytab[0][0]; -#endif -#ifdef _UFC_64_ - long64 v, *k2 = &_ufc_keytab[0]; -#endif - - v1 = v2 = 0; k1 = &do_pc1[0][0][0]; - for(i = 8; i--;) { - v1 |= k1[*key & 0x7f]; k1 += 128; - v2 |= k1[*key++ & 0x7f]; k1 += 128; - } - - for(i = 0; i < 16; i++) { - k1 = &do_pc2[0][0]; - - v1 = (v1 << rots[i]) | (v1 >> (28 - rots[i])); - v = k1[(v1 >> 21) & 0x7f]; k1 += 128; - v |= k1[(v1 >> 14) & 0x7f]; k1 += 128; - v |= k1[(v1 >> 7) & 0x7f]; k1 += 128; - v |= k1[(v1 ) & 0x7f]; k1 += 128; - -#ifdef _UFC_32_ - *k2++ = v; - v = 0; -#endif -#ifdef _UFC_64_ - v <<= 32; -#endif - - v2 = (v2 << rots[i]) | (v2 >> (28 - rots[i])); - v |= k1[(v2 >> 21) & 0x7f]; k1 += 128; - v |= k1[(v2 >> 14) & 0x7f]; k1 += 128; - v |= k1[(v2 >> 7) & 0x7f]; k1 += 128; - v |= k1[(v2 ) & 0x7f]; - - *k2++ = v; - } - - direction = 0; - } - -/* - * Undo an extra E selection and do final permutations - */ - -ufc_long *_ufc_dofinalperm(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2) - { ufc_long v1, v2, x; - static ufc_long ary[2]; - - x = (l1 ^ l2) & current_saltbits; l1 ^= x; l2 ^= x; - x = (r1 ^ r2) & current_saltbits; r1 ^= x; r2 ^= x; - - v1=v2=0; l1 >>= 3; l2 >>= 3; r1 >>= 3; r2 >>= 3; - - v1 |= efp[15][ r2 & 0x3f][0]; v2 |= efp[15][ r2 & 0x3f][1]; - v1 |= efp[14][(r2 >>= 6) & 0x3f][0]; v2 |= efp[14][ r2 & 0x3f][1]; - v1 |= efp[13][(r2 >>= 10) & 0x3f][0]; v2 |= efp[13][ r2 & 0x3f][1]; - v1 |= efp[12][(r2 >>= 6) & 0x3f][0]; v2 |= efp[12][ r2 & 0x3f][1]; - - v1 |= efp[11][ r1 & 0x3f][0]; v2 |= efp[11][ r1 & 0x3f][1]; - v1 |= efp[10][(r1 >>= 6) & 0x3f][0]; v2 |= efp[10][ r1 & 0x3f][1]; - v1 |= efp[ 9][(r1 >>= 10) & 0x3f][0]; v2 |= efp[ 9][ r1 & 0x3f][1]; - v1 |= efp[ 8][(r1 >>= 6) & 0x3f][0]; v2 |= efp[ 8][ r1 & 0x3f][1]; - - v1 |= efp[ 7][ l2 & 0x3f][0]; v2 |= efp[ 7][ l2 & 0x3f][1]; - v1 |= efp[ 6][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 6][ l2 & 0x3f][1]; - v1 |= efp[ 5][(l2 >>= 10) & 0x3f][0]; v2 |= efp[ 5][ l2 & 0x3f][1]; - v1 |= efp[ 4][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 4][ l2 & 0x3f][1]; - - v1 |= efp[ 3][ l1 & 0x3f][0]; v2 |= efp[ 3][ l1 & 0x3f][1]; - v1 |= efp[ 2][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 2][ l1 & 0x3f][1]; - v1 |= efp[ 1][(l1 >>= 10) & 0x3f][0]; v2 |= efp[ 1][ l1 & 0x3f][1]; - v1 |= efp[ 0][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 0][ l1 & 0x3f][1]; - - ary[0] = v1; ary[1] = v2; - return ary; - } - -/* - * crypt only: convert from 64 bit to 11 bit ASCII - * prefixing with the salt - */ - -static char *output_conversion(ufc_long v1, ufc_long v2, const char *salt) - { static char outbuf[14]; - int i, s; - - outbuf[0] = salt[0]; - outbuf[1] = salt[1] ? salt[1] : salt[0]; - - for(i = 0; i < 5; i++) - outbuf[i + 2] = bin_to_ascii((v1 >> (26 - 6 * i)) & 0x3f); - - s = (v2 & 0xf) << 2; - v2 = (v2 >> 2) | ((v1 & 0x3) << 30); - - for(i = 5; i < 10; i++) - outbuf[i + 2] = bin_to_ascii((v2 >> (56 - 6 * i)) & 0x3f); - - outbuf[12] = bin_to_ascii(s); - outbuf[13] = 0; - - return outbuf; - } - -/* - * UNIX crypt function - */ - -static ufc_long *_ufc_doit(ufc_long , ufc_long, ufc_long, ufc_long, ufc_long); - -char *ufc_crypt(const char *key,const char *salt) - { ufc_long *s; - char ktab[9]; - - /* - * Hack DES tables according to salt - */ - setup_salt(salt); - - /* - * Setup key schedule - */ - clearmem(ktab, sizeof ktab); - StrnCpy(ktab, key, 8); - ufc_mk_keytab(ktab); - - /* - * Go for the 25 DES encryptions - */ - s = _ufc_doit((ufc_long)0, (ufc_long)0, - (ufc_long)0, (ufc_long)0, (ufc_long)25); - - /* - * And convert back to 6 bit ASCII - */ - return output_conversion(s[0], s[1], salt); - } - - -#ifdef _UFC_32_ - -/* - * 32 bit version - */ - -extern long32 _ufc_keytab[16][2]; -extern long32 _ufc_sb0[], _ufc_sb1[], _ufc_sb2[], _ufc_sb3[]; - -#define SBA(sb, v) (*(long32*)((char*)(sb)+(v))) - -static ufc_long *_ufc_doit(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2, ufc_long itr) - { int i; - long32 s, *k; - - while(itr--) { - k = &_ufc_keytab[0][0]; - for(i=8; i--; ) { - s = *k++ ^ r1; - l1 ^= SBA(_ufc_sb1, s & 0xffff); l2 ^= SBA(_ufc_sb1, (s & 0xffff)+4); - l1 ^= SBA(_ufc_sb0, s >>= 16); l2 ^= SBA(_ufc_sb0, (s) +4); - s = *k++ ^ r2; - l1 ^= SBA(_ufc_sb3, s & 0xffff); l2 ^= SBA(_ufc_sb3, (s & 0xffff)+4); - l1 ^= SBA(_ufc_sb2, s >>= 16); l2 ^= SBA(_ufc_sb2, (s) +4); - - s = *k++ ^ l1; - r1 ^= SBA(_ufc_sb1, s & 0xffff); r2 ^= SBA(_ufc_sb1, (s & 0xffff)+4); - r1 ^= SBA(_ufc_sb0, s >>= 16); r2 ^= SBA(_ufc_sb0, (s) +4); - s = *k++ ^ l2; - r1 ^= SBA(_ufc_sb3, s & 0xffff); r2 ^= SBA(_ufc_sb3, (s & 0xffff)+4); - r1 ^= SBA(_ufc_sb2, s >>= 16); r2 ^= SBA(_ufc_sb2, (s) +4); - } - s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s; - } - return _ufc_dofinalperm(l1, l2, r1, r2); - } - -#endif - -#ifdef _UFC_64_ - -/* - * 64 bit version - */ - -extern long64 _ufc_keytab[16]; -extern long64 _ufc_sb0[], _ufc_sb1[], _ufc_sb2[], _ufc_sb3[]; - -#define SBA(sb, v) (*(long64*)((char*)(sb)+(v))) - -static ufc_long *_ufc_doit(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2, ufc_long itr) - { int i; - long64 l, r, s, *k; - - l = (((long64)l1) << 32) | ((long64)l2); - r = (((long64)r1) << 32) | ((long64)r2); - - while(itr--) { - k = &_ufc_keytab[0]; - for(i=8; i--; ) { - s = *k++ ^ r; - l ^= SBA(_ufc_sb3, (s >> 0) & 0xffff); - l ^= SBA(_ufc_sb2, (s >> 16) & 0xffff); - l ^= SBA(_ufc_sb1, (s >> 32) & 0xffff); - l ^= SBA(_ufc_sb0, (s >> 48) & 0xffff); - - s = *k++ ^ l; - r ^= SBA(_ufc_sb3, (s >> 0) & 0xffff); - r ^= SBA(_ufc_sb2, (s >> 16) & 0xffff); - r ^= SBA(_ufc_sb1, (s >> 32) & 0xffff); - r ^= SBA(_ufc_sb0, (s >> 48) & 0xffff); - } - s=l; l=r; r=s; - } - - l1 = l >> 32; l2 = l & 0xffffffff; - r1 = r >> 32; r2 = r & 0xffffffff; - return _ufc_dofinalperm(l1, l2, r1, r2); - } - -#endif - - -#else - int ufc_dummy_procedure(void); - int ufc_dummy_procedure(void) {return 0;} -#endif -- cgit From 6ba693b5de0ecf53638468b56ce3b93d2e33c919 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 19 Oct 2008 14:54:16 +0200 Subject: Make sure crypt libs get included. --- source3/configure.in | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3') diff --git a/source3/configure.in b/source3/configure.in index ce1c422bd1..a97d535c77 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -657,6 +657,8 @@ AC_SUBST(LIBREPLACE_OBJS) # add -ldl to the global LIBS LIBS="${LIBS} ${LIBDL} ${LIBREPLACE_NETWORK_LIBS}" +AUTH_LIBS="${AUTH_LIBS} ${CRYPT_LIBS}" + AC_CHECK_HEADERS(aio.h sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h rpc/nettype.h) AC_CHECK_HEADERS(unistd.h utime.h grp.h sys/id.h memory.h alloca.h) -- cgit From c88cbbfdf323c24f7d8a68491bcb1e0354db41d4 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sun, 19 Oct 2008 13:05:19 +0200 Subject: vlp: Move closer to the code tested. --- source3/Makefile.in | 2 +- source3/printing/tests/README.vlp | 19 ++ source3/printing/tests/vlp.c | 431 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 source3/printing/tests/README.vlp create mode 100644 source3/printing/tests/vlp.c (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index 12d37ce6b0..bb81dd2f70 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1125,7 +1125,7 @@ NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \ $(LIBNDR_GEN_OBJ0) $(LIBNDR_GEN_OBJ1) -VLP_OBJ1 = ../testsuite/printing/vlp.o $(RPC_CLIENT_OBJ1) $(RPC_PARSE_OBJ2) $(RPC_CLIENT_OBJ) ../librpc/rpc/binding.o +VLP_OBJ1 = printing/tests/vlp.o $(RPC_CLIENT_OBJ1) $(RPC_PARSE_OBJ2) $(RPC_CLIENT_OBJ) ../librpc/rpc/binding.o VLP_OBJ = $(VLP_OBJ1) $(PARAM_OBJ) $(LIBSMB_OBJ) \ $(LIB_NONSMBD_OBJ) $(KRBCLIENT_OBJ) $(LIBMSRPC_GEN_OBJ) \ diff --git a/source3/printing/tests/README.vlp b/source3/printing/tests/README.vlp new file mode 100644 index 0000000000..fc0b91ad69 --- /dev/null +++ b/source3/printing/tests/README.vlp @@ -0,0 +1,19 @@ +Virtual line printer test program (vlp) +======================================= + +This can be useful for testing/debugging Samba print code. It gives you a +virtual full-function printer. + +Setup + +Set up Samba to use vlp. + In your smb.conf file under [global], add the following option: + printing = vlp + and then add any number of print shares, without needing to make them + really exist. + + [testprinter] + printable = yes + + is all you need for the most basic virtual printer. + diff --git a/source3/printing/tests/vlp.c b/source3/printing/tests/vlp.c new file mode 100644 index 0000000000..15459889e9 --- /dev/null +++ b/source3/printing/tests/vlp.c @@ -0,0 +1,431 @@ +/* + Unix SMB/Netbios implementation. + + Virtual lp system for printer testing + + Copyright (C) Tim Potter 2000 + + 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 3 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, see . +*/ + +#include "includes.h" + +#define PRINT_TDB "/tmp/vlp.tdb" +#define PRINT_FIRSTJOB "100" + +static TDB_CONTEXT *tdb; + +struct vlp_job { + fstring owner; + int jobid; + fstring jobname; + int size; + int status; + time_t submit_time; + int deleted; +}; + +/* Print usage */ + +static void usage(void) +{ + printf("Usage: print-test lpq|lprm|print|queuepause|queueresume|" + "lppause|lpresume [args]\n"); +} + +/* Return an array of vlp jobs that is the printer queue */ + +static void get_job_list(char *printer, struct vlp_job **job_list, + int *num_jobs) +{ + fstring keystr; + TDB_DATA data; + + slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer); + data = tdb_fetch_bystring(tdb, keystr); + + *job_list = (struct vlp_job *)data.dptr; + *num_jobs = data.dsize / sizeof(struct vlp_job); +} + +/* Store an array of vl jobs for the queue */ + +static void set_job_list(char *printer, struct vlp_job *job_list, + int num_jobs) +{ + fstring keystr; + TDB_DATA data; + + slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer); + + data.dptr = (unsigned char *)job_list; + data.dsize = num_jobs * sizeof(struct vlp_job); + tdb_store_bystring(tdb, keystr, data, TDB_REPLACE); +} + +/* Return the next job number for a printer */ + +static int next_jobnum(char *printer) +{ + fstring keystr; + int jobnum; + + slprintf(keystr, sizeof(keystr) - 1, "JOBNUM/%s", printer); + + tdb_lock_bystring(tdb, keystr); + + jobnum = tdb_fetch_int32(tdb, keystr); + + /* Create next job index if none exists */ + + if (jobnum == -1) { + jobnum = atoi(PRINT_FIRSTJOB); + } + + jobnum++; + tdb_store_int32(tdb, keystr, jobnum); + + tdb_unlock_bystring(tdb, keystr); + + return jobnum; +} + +static void set_printer_status(char *printer, int status) +{ + fstring keystr; + int result; + + slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer); + result = tdb_store_int32(tdb, keystr, status); +} + +static int get_printer_status(char *printer) +{ + fstring keystr; + TDB_DATA data; + + slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer); + + data.dptr = (unsigned char *)keystr; + data.dsize = strlen(keystr) + 1; + + if (!tdb_exists(tdb, data)) { + set_printer_status(printer, LPSTAT_OK); + return LPSTAT_OK; + } + + return tdb_fetch_int32(tdb, keystr); +} + +/* Display printer queue */ + +static int lpq_command(int argc, char **argv) +{ + char *printer; + struct vlp_job *job_list = NULL; + int i, num_jobs, job_count = 0; + + if (argc != 2) { + printf("Usage: lpq \n"); + return 1; + } + + printer = argv[1]; + + /* Display printer status */ + + switch (get_printer_status(printer)) { + case LPSTAT_OK: + printf("enabled\n"); + break; + case LPSTAT_STOPPED: + printf("disabled\n"); + break; + case LPSTAT_ERROR: + default: + printf("error\n"); + break; + } + + /* Print queued documents */ + + get_job_list(printer, &job_list, &num_jobs); + + for (i = 0; i < num_jobs; i++) { + if (job_list[i].deleted) continue; + printf("%d\t%d\t%d\t%ld\t%s\t%s\n", job_list[i].jobid, + job_list[i].size, + (i == 0 && job_list[i].status == LPQ_QUEUED) ? + LPQ_SPOOLING : job_list[i].status, + job_list[i].submit_time, job_list[i].owner, + job_list[i].jobname); + job_count++; + } + + free(job_list); + + return 0; +} + +/* Remove a job */ + +static int lprm_command(int argc, char **argv) +{ + char *printer; + int jobid, num_jobs, i; + struct vlp_job *job_list; + + if (argc < 3) { + printf("Usage: lprm \n"); + return 1; + } + + printer = argv[1]; + jobid = atoi(argv[2]); + + get_job_list(printer, &job_list, &num_jobs); + + for (i = 0; i < num_jobs; i++) { + if (job_list[i].jobid == jobid) { + job_list[i].deleted = 1; + set_job_list(printer, job_list, num_jobs); + break; + } + } + + return 0; +} + +/* print command = print-test %p %s */ + +static int print_command(int argc, char **argv) +{ + char *printer; + fstring keystr; + struct passwd *pw; + TDB_DATA value, queue; + struct vlp_job job; + int i; + + if (argc < 3) { + printf("Usage: print \n"); + return 1; + } + + printer = argv[1]; + + ZERO_STRUCT(job); + + /* Create a job record */ + + for (i = 2; i < argc; i++) { + fstrcat(job.jobname, argv[i]); + if (i < argc - 1) { + fstrcat(job.jobname, " "); + } + } + + if (!(pw = getpwuid(getuid()))) { + return 1; + } + + fstrcpy(job.owner, pw->pw_name); + + job.jobid = next_jobnum(printer); + job.size = 666; + job.submit_time = time(NULL); + + /* Store job entry in queue */ + + slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer); + + value = tdb_fetch_bystring(tdb, keystr); + + if (value.dptr) { + + /* Add job to end of queue */ + + queue.dptr = (unsigned char *)SMB_MALLOC(value.dsize + + sizeof(struct vlp_job)); + if (!queue.dptr) return 1; + + memcpy(queue.dptr, value.dptr, value.dsize); + memcpy(queue.dptr + value.dsize, &job, sizeof(struct vlp_job)); + + queue.dsize = value.dsize + sizeof(struct vlp_job); + + tdb_store_bystring(tdb, keystr, queue, TDB_REPLACE); + + free(queue.dptr); + + } else { + + /* Create new queue */ + queue.dptr = (unsigned char *)&job; + queue.dsize = sizeof(struct vlp_job); + + tdb_store_bystring(tdb, keystr, queue, TDB_REPLACE); + } + + return 0; +} + +/* Pause the queue */ + +static int queuepause_command(int argc, char **argv) +{ + char *printer; + + if (argc != 2) { + printf("Usage: queuepause \n"); + return 1; + } + + printer = argv[1]; + set_printer_status(printer, LPSTAT_STOPPED); + + return 0; +} + +/* Resume the queue */ + +static int queueresume_command(int argc, char **argv) +{ + char *printer; + + if (argc != 2) { + printf("Usage: queueresume \n"); + return 1; + } + + printer = argv[1]; + set_printer_status(printer, LPSTAT_OK); + + return 0; +} + +/* Pause a job */ + +static int lppause_command(int argc, char **argv) +{ + struct vlp_job *job_list; + char *printer; + int jobid, num_jobs, i; + + if (argc != 3) { + printf("Usage: lppause \n"); + return 1; + } + + printer = argv[1]; + jobid = atoi(argv[2]); + + get_job_list(printer, &job_list, &num_jobs); + + for (i = 0; i < num_jobs; i++) { + if (job_list[i].jobid == jobid) { + job_list[i].status = LPQ_PAUSED; + set_job_list(printer, job_list, num_jobs); + return 0; + } + } + + return 1; +} + +/* Resume a job */ + +static int lpresume_command(int argc, char **argv) +{ + struct vlp_job *job_list; + char *printer; + int jobid, num_jobs, i; + + if (argc != 3) { + printf("Usage: lpresume \n"); + return 1; + } + + printer = argv[1]; + jobid = atoi(argv[2]); + + get_job_list(printer, &job_list, &num_jobs); + + for (i = 0; i < num_jobs; i++) { + if (job_list[i].jobid == jobid) { + job_list[i].status = LPQ_QUEUED; + set_job_list(printer, job_list, num_jobs); + return 0; + } + } + + return 1; +} + +int main(int argc, char **argv) +{ + /* Parameter check */ + + if (argc == 1) { + usage(); + return 1; + } + + /* Initialise */ + + if (!(tdb = tdb_open(PRINT_TDB, 0, 0, O_RDWR | O_CREAT, + 0666))) { + printf("%s: unable to open %s\n", argv[0], PRINT_TDB); + return 1; + } + + /* Ensure we are modes 666 */ + + chmod(PRINT_TDB, 0666); + + /* Do commands */ + + if (strcmp(argv[1], "lpq") == 0) { + return lpq_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "lprm") == 0) { + return lprm_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "print") == 0) { + return print_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "queuepause") == 0) { + return queuepause_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "queueresume") == 0) { + return queueresume_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "lppause") == 0) { + return lppause_command(argc - 1, &argv[1]); + } + + if (strcmp(argv[1], "lpresume") == 0) { + return lpresume_command(argc - 1, &argv[1]); + } + + /* Unknown command */ + + printf("%s: invalid command %s\n", argv[0], argv[1]); + return 1; +} -- cgit From ac647d03ac271b0a81b6c8041e2c6b84ada13aca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Oct 2008 13:44:11 +0200 Subject: Move the global hosts_allow() check out of the processing loop --- source3/smbd/process.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'source3') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index ceffd6f46c..7b0d14968a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1534,25 +1534,6 @@ static void process_smb(char *inbuf, size_t nread, size_t unread_bytes, bool enc DO_PROFILE_INC(smb_count); - if (trans_num == 0) { - char addr[INET6_ADDRSTRLEN]; - - /* on the first packet, check the global hosts allow/ hosts - deny parameters before doing any parsing of the packet - passed to us by the client. This prevents attacks on our - parsing code from hosts not in the hosts allow list */ - - if (!check_access(smbd_server_fd(), lp_hostsallow(-1), - lp_hostsdeny(-1))) { - /* send a negative session response "not listening on calling name" */ - static unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; - DEBUG( 1, ( "Connection denied from %s\n", - client_addr(get_client_fd(),addr,sizeof(addr)) ) ); - (void)srv_send_smb(smbd_server_fd(),(char *)buf,false); - exit_server_cleanly("connection denied"); - } - } - DEBUG( 6, ( "got message type 0x%x of len 0x%x\n", msg_type, smb_len(inbuf) ) ); DEBUG( 3, ( "Transaction %d of length %d (%u toread)\n", trans_num, @@ -1893,6 +1874,28 @@ void smbd_process(void) unsigned int num_smbs = 0; size_t unread_bytes = 0; + char addr[INET6_ADDRSTRLEN]; + + /* + * Before the first packet, check the global hosts allow/ hosts deny + * parameters before doing any parsing of packets passed to us by the + * client. This prevents attacks on our parsing code from hosts not in + * the hosts allow list. + */ + + if (!check_access(smbd_server_fd(), lp_hostsallow(-1), + lp_hostsdeny(-1))) { + /* + * send a negative session response "not listening on calling + * name" + */ + unsigned char buf[5] = {0x83, 0, 0, 1, 0x81}; + DEBUG( 1, ("Connection denied from %s\n", + client_addr(get_client_fd(),addr,sizeof(addr)) ) ); + (void)srv_send_smb(smbd_server_fd(),(char *)buf,false); + exit_server_cleanly("connection denied"); + } + max_recv = MIN(lp_maxxmit(),BUFFER_SIZE); while (True) { -- cgit From 1510b7b8c99ea64a8fabdb89c5868b2f5895fdbf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Oct 2008 14:50:55 +0200 Subject: Use a direct compare instead of calling strncmp in valid_smb_header --- source3/smbd/process.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 7b0d14968a..c74c7fd445 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -105,7 +105,11 @@ static bool valid_smb_header(const uint8_t *inbuf) if (is_encrypted_packet(inbuf)) { return true; } - return (strncmp(smb_base(inbuf),"\377SMB",4) == 0); + /* + * This used to be (strncmp(smb_base(inbuf),"\377SMB",4) == 0) + * but it just looks weird to call strncmp for this one. + */ + return (IVAL(smb_base(inbuf), 0) == 0x424D53FF); } /* Socket functions for smbd packet processing. */ -- cgit From 48d3a1d2fb5569ab11ffef8b903af91d77d326a3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Oct 2008 15:17:12 +0200 Subject: "fn_new"->"fn" in smb_messages[], we got beyond that :-) --- source3/smbd/process.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c74c7fd445..a8b93d8e1c 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -978,7 +978,7 @@ force write permissions on print services. */ static const struct smb_message_struct { const char *name; - void (*fn_new)(struct smb_request *req); + void (*fn)(struct smb_request *req); int flags; } smb_messages[256] = { @@ -1354,7 +1354,7 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req, in exit_server_cleanly("Non-SMB packet"); } - if (smb_messages[type].fn_new == NULL) { + if (smb_messages[type].fn == NULL) { DEBUG(0,("Unknown message type %d!\n",type)); smb_dump("Unknown", 1, (char *)req->inbuf, size); reply_unknown_new(req, type); @@ -1476,7 +1476,7 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req, in return conn; } - smb_messages[type].fn_new(req); + smb_messages[type].fn(req); return req->conn; } -- cgit From 2883c88ae46d3957564660213471e1d6f94cdb04 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 19 Oct 2008 15:30:12 +0200 Subject: Fix nonempty blank lines --- source3/smbd/reply.c | 182 +++++++++++++++++++++++++-------------------------- 1 file changed, 91 insertions(+), 91 deletions(-) (limited to 'source3') diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index b7763cb1cf..25480c6e3b 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -424,22 +424,22 @@ void reply_special(char *inbuf) * header. */ char outbuf[smb_size]; - + static bool already_got_session = False; *name1 = *name2 = 0; - + memset(outbuf, '\0', sizeof(outbuf)); smb_setlen(outbuf,0); - + switch (msg_type) { case 0x81: /* session request */ - + if (already_got_session) { exit_server_cleanly("multiple session request not permitted"); } - + SCVAL(outbuf,0,0x82); SCVAL(outbuf,3,0); if (name_len(inbuf+4) > 50 || @@ -478,24 +478,24 @@ void reply_special(char *inbuf) already_got_session = True; break; - + case 0x89: /* session keepalive request (some old clients produce this?) */ SCVAL(outbuf,0,SMBkeepalive); SCVAL(outbuf,3,0); break; - + case 0x82: /* positive session response */ case 0x83: /* negative session response */ case 0x84: /* retarget session response */ DEBUG(0,("Unexpected session response\n")); break; - + case SMBkeepalive: /* session keepalive */ default: return; } - + DEBUG(5,("init msg_type=0x%x msg_flags=0x%x\n", msg_type, msg_flags)); @@ -1062,7 +1062,7 @@ void reply_getatr(struct smb_request *req) SSVAL(req->outbuf, smb_flg2, SVAL(req->outbuf, smb_flg2) | FLAGS2_IS_LONG_NAME); } - + DEBUG(3,("reply_getatr: name=%s mode=%d size=%u\n", fname, mode, (unsigned int)size ) ); END_PROFILE(SMBgetatr); @@ -1169,9 +1169,9 @@ void reply_setatr(struct smb_request *req) } reply_outbuf(req, 0, 0); - + DEBUG( 3, ( "setatr name=%s mode=%d\n", fname, mode ) ); - + END_PROFILE(SMBsetatr); return; } @@ -1193,7 +1193,7 @@ void reply_dskattr(struct smb_request *req) } reply_outbuf(req, 5, 0); - + if (Protocol <= PROTOCOL_LANMAN2) { double total_space, free_space; /* we need to scale this to a number that DOS6 can handle. We @@ -1207,7 +1207,7 @@ void reply_dskattr(struct smb_request *req) dsize = (uint64_t)((total_space+63*512) / (64*512)); dfree = (uint64_t)((free_space+63*512) / (64*512)); - + if (dsize > 0xFFFF) dsize = 0xFFFF; if (dfree > 0xFFFF) dfree = 0xFFFF; @@ -1713,7 +1713,7 @@ void reply_open(struct smb_request *req) SCVAL(req->outbuf,smb_flg, CVAL(req->outbuf,smb_flg)|CORE_OPLOCK_GRANTED); } - + if(EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) { SCVAL(req->outbuf,smb_flg, CVAL(req->outbuf,smb_flg)|CORE_OPLOCK_GRANTED); @@ -2201,7 +2201,7 @@ void reply_ctemp(struct smb_request *req) SCVAL(req->outbuf, smb_flg, CVAL(req->outbuf,smb_flg)|CORE_OPLOCK_GRANTED); } - + if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) { SCVAL(req->outbuf, smb_flg, CVAL(req->outbuf,smb_flg)|CORE_OPLOCK_GRANTED); @@ -2914,14 +2914,14 @@ void reply_readbraw(struct smb_request *req) if (nread < mincount) nread = 0; #endif - + DEBUG( 3, ( "reply_readbraw: fnum=%d start=%.0f max=%lu " "min=%lu nread=%lu\n", fsp->fnum, (double)startpos, (unsigned long)maxcount, (unsigned long)mincount, (unsigned long)nread ) ); - + send_file_readbraw(conn, fsp, startpos, nread, mincount); DEBUG(5,("reply_readbraw finished\n")); @@ -2978,7 +2978,7 @@ void reply_lockread(struct smb_request *req) reply_outbuf(req, 5, numtoread + 3); data = smb_buf(req->outbuf) + 3; - + /* * NB. Discovered by Menny Hamburger at Mainsoft. This is a core+ * protocol request that predates the read/write lock concept. @@ -2986,7 +2986,7 @@ void reply_lockread(struct smb_request *req) * for a write lock. JRA. * Note that the requested lock size is unaffected by max_recv. */ - + br_lck = do_lock(smbd_messaging_context(), fsp, req->smbpid, @@ -3022,7 +3022,7 @@ Returning short read of maximum allowed for compatibility with Windows 2000.\n", END_PROFILE(SMBlockread); return; } - + srv_set_message((char *)req->outbuf, 5, nread+3, False); SSVAL(req->outbuf,smb_vwv0,nread); @@ -3030,7 +3030,7 @@ Returning short read of maximum allowed for compatibility with Windows 2000.\n", p = smb_buf(req->outbuf); SCVAL(p,0,0); /* pad byte. */ SSVAL(p,1,nread); - + DEBUG(3,("lockread fnum=%d num=%d nread=%d\n", fsp->fnum, (int)numtoread, (int)nread)); @@ -3094,7 +3094,7 @@ Returning short read of maximum allowed for compatibility with Windows 2000.\n", reply_outbuf(req, 5, numtoread+3); data = smb_buf(req->outbuf) + 3; - + if (is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtoread, (uint64_t)startpos, READ_LOCK)) { reply_doserror(req, ERRDOS,ERRlock); @@ -3117,7 +3117,7 @@ Returning short read of maximum allowed for compatibility with Windows 2000.\n", SSVAL(req->outbuf,smb_vwv5,nread+3); SCVAL(smb_buf(req->outbuf),0,1); SSVAL(smb_buf(req->outbuf),1,nread); - + DEBUG( 3, ( "read fnum=%d num=%d nread=%d\n", fsp->fnum, (int)numtoread, (int)nread ) ); @@ -3659,7 +3659,7 @@ void reply_writeunlock(struct smb_request *req) END_PROFILE(SMBwriteunlock); return; } - + fsp = file_fsp(req, SVAL(req->inbuf,smb_vwv0)); if (!check_fsp(conn, req, fsp)) { @@ -3676,7 +3676,7 @@ void reply_writeunlock(struct smb_request *req) numtowrite = SVAL(req->inbuf,smb_vwv1); startpos = IVAL_TO_SMB_OFF_T(req->inbuf,smb_vwv2); data = smb_buf(req->inbuf) + 3; - + if (numtowrite && is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite, (uint64_t)startpos, WRITE_LOCK)) { @@ -3693,7 +3693,7 @@ void reply_writeunlock(struct smb_request *req) } else { nwritten = write_file(req,fsp,data,startpos,numtowrite); } - + status = sync_file(conn, fsp, False /* write through */); if (!NT_STATUS_IS_OK(status)) { DEBUG(5,("reply_writeunlock: sync_file for %s returned %s\n", @@ -3725,12 +3725,12 @@ void reply_writeunlock(struct smb_request *req) } reply_outbuf(req, 1, 0); - + SSVAL(req->outbuf,smb_vwv0,nwritten); - + DEBUG(3,("writeunlock fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten)); - + END_PROFILE(SMBwriteunlock); return; } @@ -3783,7 +3783,7 @@ void reply_write(struct smb_request *req) numtowrite = SVAL(req->inbuf,smb_vwv1); startpos = IVAL_TO_SMB_OFF_T(req->inbuf,smb_vwv2); data = smb_buf(req->inbuf) + 3; - + if (is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite, (uint64_t)startpos, WRITE_LOCK)) { reply_doserror(req, ERRDOS, ERRlock); @@ -3834,14 +3834,14 @@ void reply_write(struct smb_request *req) } reply_outbuf(req, 1, 0); - + SSVAL(req->outbuf,smb_vwv0,nwritten); if (nwritten < (ssize_t)numtowrite) { SCVAL(req->outbuf,smb_rcls,ERRHRD); SSVAL(req->outbuf,smb_err,ERRdiskfull); } - + DEBUG(3,("write fnum=%d num=%d wrote=%d\n", fsp->fnum, (int)numtowrite, (int)nwritten)); END_PROFILE(SMBwrite); @@ -4062,7 +4062,7 @@ void reply_write_and_X(struct smb_request *req) END_PROFILE(SMBwriteX); return; } - + nwritten = write_file(req,fsp,data,startpos,numtowrite); } @@ -4178,7 +4178,7 @@ void reply_lseek(struct smb_request *req) reply_outbuf(req, 2, 0); SIVAL(req->outbuf,smb_vwv0,res); - + DEBUG(3,("lseek fnum=%d ofs=%.0f newpos = %.0f mode=%d\n", fsp->fnum, (double)startpos, (double)res, mode)); @@ -4209,7 +4209,7 @@ void reply_flush(struct smb_request *req) if ((fnum != 0xFFFF) && !check_fsp(conn, req, fsp)) { return; } - + if (!fsp) { file_sync_all(conn); } else { @@ -4222,7 +4222,7 @@ void reply_flush(struct smb_request *req) return; } } - + reply_outbuf(req, 0, 0); DEBUG(3,("flush\n")); @@ -4293,7 +4293,7 @@ void reply_close(struct smb_request *req) DEBUG(3,("close fd=%d fnum=%d (numopen=%d)\n", fsp->fh->fd, fsp->fnum, conn->num_files_open)); - + /* * Take care of any time sent in the close. */ @@ -4306,7 +4306,7 @@ void reply_close(struct smb_request *req) * was detected on close - normally this is due to * a disk full error. If not then it was probably an I/O error. */ - + status = close_file(req, fsp, NORMAL_CLOSE); } @@ -4361,7 +4361,7 @@ void reply_writeclose(struct smb_request *req) mtime = convert_time_t_to_timespec(srv_make_unix_date3( req->inbuf+smb_vwv4)); data = smb_buf(req->inbuf) + 1; - + if (numtowrite && is_locked(fsp, (uint32)req->smbpid, (uint64_t)numtowrite, (uint64_t)startpos, WRITE_LOCK)) { @@ -4369,7 +4369,7 @@ void reply_writeclose(struct smb_request *req) END_PROFILE(SMBwriteclose); return; } - + nwritten = write_file(req,fsp,data,startpos,numtowrite); set_close_write_time(fsp, mtime); @@ -4388,13 +4388,13 @@ void reply_writeclose(struct smb_request *req) DEBUG(3,("writeclose fnum=%d num=%d wrote=%d (numopen=%d)\n", fsp->fnum, (int)numtowrite, (int)nwritten, conn->num_files_open)); - + if(((nwritten == 0) && (numtowrite != 0))||(nwritten < 0)) { reply_doserror(req, ERRHRD, ERRdiskfull); END_PROFILE(SMBwriteclose); return; } - + if(!NT_STATUS_IS_OK(close_status)) { reply_nterror(req, close_status); END_PROFILE(SMBwriteclose); @@ -4402,7 +4402,7 @@ void reply_writeclose(struct smb_request *req) } reply_outbuf(req, 1, 0); - + SSVAL(req->outbuf,smb_vwv0,nwritten); END_PROFILE(SMBwriteclose); return; @@ -4496,10 +4496,10 @@ void reply_unlock(struct smb_request *req) END_PROFILE(SMBunlock); return; } - + count = (uint64_t)IVAL(req->inbuf,smb_vwv1); offset = (uint64_t)IVAL(req->inbuf,smb_vwv3); - + status = do_unlock(smbd_messaging_context(), fsp, req->smbpid, @@ -4620,7 +4620,7 @@ void reply_printopen(struct smb_request *req) connection_struct *conn = req->conn; files_struct *fsp; NTSTATUS status; - + START_PROFILE(SMBsplopen); if (req->wct < 2) { @@ -4646,7 +4646,7 @@ void reply_printopen(struct smb_request *req) reply_outbuf(req, 1, 0); SSVAL(req->outbuf,smb_vwv0,fsp->fnum); - + DEBUG(3,("openprint fd=%d fnum=%d\n", fsp->fh->fd, fsp->fnum)); @@ -4684,10 +4684,10 @@ void reply_printclose(struct smb_request *req) END_PROFILE(SMBsplclose); return; } - + DEBUG(3,("printclose fd=%d fnum=%d\n", fsp->fh->fd,fsp->fnum)); - + status = close_file(req, fsp, NORMAL_CLOSE); if(!NT_STATUS_IS_OK(status)) { @@ -4738,7 +4738,7 @@ void reply_printqueue(struct smb_request *req) SSVAL(req->outbuf,smb_vwv1,0); SCVAL(smb_buf(req->outbuf),0,1); SSVAL(smb_buf(req->outbuf),1,0); - + DEBUG(3,("printqueue start_index=%d max_count=%d\n", start_index, max_count)); @@ -4754,7 +4754,7 @@ void reply_printqueue(struct smb_request *req) num_to_get = 0; else num_to_get = MIN(num_to_get,count-first); - + for (i=first;iinbuf,smb_vwv0)); if (!check_fsp(conn, req, fsp)) { @@ -5211,7 +5211,7 @@ static bool resolve_wildcards(TALLOC_CTX *ctx, char *ext1 = NULL; char *ext2 = NULL; char *p,*p2, *pname1, *pname2; - + name2_copy = talloc_strdup(ctx, name2); if (!name2_copy) { return False; @@ -5223,7 +5223,7 @@ static bool resolve_wildcards(TALLOC_CTX *ctx, if (!pname1 || !pname2) { return False; } - + /* Truncate the copy of name2 at the last '/' */ *pname2 = '\0'; @@ -6540,26 +6540,26 @@ static uint32 map_lock_offset(uint32 high, uint32 low) unsigned int i; uint32 mask = 0; uint32 highcopy = high; - + /* * Try and find out how many significant bits there are in high. */ - + for(i = 0; highcopy; i++) highcopy >>= 1; - + /* * We use 31 bits not 32 here as POSIX * lock offsets may not be negative. */ - + mask = (~0) << (31 - i); - + if(low & mask) return 0; /* Fail. */ - + high <<= (31 - i); - + return (high|low); } #endif /* !defined(HAVE_LONGLONG) */ @@ -6589,7 +6589,7 @@ uint64_t get_lock_offset( char *data, int data_offset, bool large_file_format, b * negotiated. For boxes without large unsigned ints mangle the * lock offset by mapping the top 32 bits onto the lower 32. */ - + if(IVAL(data,SMB_LARGE_LKOFF_OFFSET_HIGH(data_offset)) != 0) { uint32 low = IVAL(data,SMB_LARGE_LKOFF_OFFSET_LOW(data_offset)); uint32 high = IVAL(data,SMB_LARGE_LKOFF_OFFSET_HIGH(data_offset)); @@ -6641,7 +6641,7 @@ void reply_lockingX(struct smb_request *req) END_PROFILE(SMBlockingX); return; } - + fsp = file_fsp(req, SVAL(req->inbuf,smb_vwv2)); locktype = CVAL(req->inbuf,smb_vwv3); oplocklevel = CVAL(req->inbuf,smb_vwv3+1); @@ -6654,7 +6654,7 @@ void reply_lockingX(struct smb_request *req) END_PROFILE(SMBlockingX); return; } - + data = smb_buf(req->inbuf); if (locktype & LOCKING_ANDX_CHANGE_LOCKTYPE) { @@ -6665,7 +6665,7 @@ void reply_lockingX(struct smb_request *req) END_PROFILE(SMBlockingX); return; } - + /* Check if this is an oplock break on a file we have granted an oplock on. */ @@ -6682,7 +6682,7 @@ void reply_lockingX(struct smb_request *req) * Make sure we have granted an exclusive or batch oplock on * this file. */ - + if (fsp->oplock_type == 0) { /* The Samba4 nbench simulator doesn't understand @@ -6714,7 +6714,7 @@ void reply_lockingX(struct smb_request *req) } else { result = downgrade_oplock(fsp); } - + if (!result) { DEBUG(0, ("reply_lockingX: error in removing " "oplock on file %s\n", fsp->fsp_name)); @@ -6743,7 +6743,7 @@ void reply_lockingX(struct smb_request *req) * We do this check *after* we have checked this is not a oplock break * response message. JRA. */ - + release_level_2_oplocks_on_change(fsp); if (smb_buflen(req->inbuf) < @@ -6752,14 +6752,14 @@ void reply_lockingX(struct smb_request *req) END_PROFILE(SMBlockingX); return; } - + /* Data now points at the beginning of the list of smb_unlkrng structs */ for(i = 0; i < (int)num_ulocks; i++) { lock_pid = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); - + /* * There is no error code marked "stupid client bug".... :-). */ @@ -6772,7 +6772,7 @@ void reply_lockingX(struct smb_request *req) DEBUG(10,("reply_lockingX: unlock start=%.0f, len=%.0f for " "pid %u, file %s\n", (double)offset, (double)count, (unsigned int)lock_pid, fsp->fsp_name )); - + status = do_unlock(smbd_messaging_context(), fsp, lock_pid, @@ -6792,20 +6792,20 @@ void reply_lockingX(struct smb_request *req) if (!lp_blocking_locks(SNUM(conn))) { lock_timeout = 0; } - + /* Now do any requested locks */ data += ((large_file_format ? 20 : 10)*num_ulocks); - + /* Data now points at the beginning of the list of smb_lkrng structs */ - + for(i = 0; i < (int)num_locks; i++) { enum brl_type lock_type = ((locktype & LOCKING_ANDX_SHARED_LOCK) ? READ_LOCK:WRITE_LOCK); lock_pid = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); - + /* * There is no error code marked "stupid client bug".... :-). */ @@ -6814,12 +6814,12 @@ void reply_lockingX(struct smb_request *req) reply_doserror(req, ERRDOS, ERRnoaccess); return; } - + DEBUG(10,("reply_lockingX: lock start=%.0f, len=%.0f for pid " "%u, file %s timeout = %d\n", (double)offset, (double)count, (unsigned int)lock_pid, fsp->fsp_name, (int)lock_timeout )); - + if (locktype & LOCKING_ANDX_CANCEL_LOCK) { if (lp_blocking_locks(SNUM(conn))) { @@ -6918,7 +6918,7 @@ void reply_lockingX(struct smb_request *req) return; } } - + /* If any of the above locks failed, then we must unlock all of the previous locks (X/Open spec). */ @@ -6935,7 +6935,7 @@ void reply_lockingX(struct smb_request *req) count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); - + /* * There is no error code marked "stupid client * bug".... :-). @@ -6945,7 +6945,7 @@ void reply_lockingX(struct smb_request *req) reply_doserror(req, ERRDOS, ERRnoaccess); return; } - + do_unlock(smbd_messaging_context(), fsp, lock_pid, @@ -6959,10 +6959,10 @@ void reply_lockingX(struct smb_request *req) } reply_outbuf(req, 2, 0); - + DEBUG(3, ("lockingX fnum=%d type=%d num_locks=%d num_ulocks=%d\n", fsp->fnum, (unsigned int)locktype, num_locks, num_ulocks)); - + END_PROFILE(SMBlockingX); chain_reply(req); } @@ -7036,7 +7036,7 @@ void reply_setattrE(struct smb_request *req) srv_make_unix_date2(req->inbuf+smb_vwv3)); /* atime. */ ts[1] = convert_time_t_to_timespec( srv_make_unix_date2(req->inbuf+smb_vwv5)); /* mtime. */ - + reply_outbuf(req, 0, 0); /* @@ -7068,7 +7068,7 @@ void reply_setattrE(struct smb_request *req) END_PROFILE(SMBsetattrE); return; } - + DEBUG( 3, ( "reply_setattrE fnum=%d actime=%u modtime=%u\n", fsp->fnum, (unsigned int)ts[0].tv_sec, @@ -7143,9 +7143,9 @@ void reply_getattrE(struct smb_request *req) END_PROFILE(SMBgetattrE); return; } - + mode = dos_mode(conn,fsp->fsp_name,&sbuf); - + /* * Convert the times into dos times. Set create * date to be last modify date as UNIX doesn't save @@ -7170,9 +7170,9 @@ void reply_getattrE(struct smb_request *req) SIVAL(req->outbuf, smb_vwv8, allocation_size); } SSVAL(req->outbuf,smb_vwv10, mode); - + DEBUG( 3, ( "reply_getattrE fnum=%d\n", fsp->fnum)); - + END_PROFILE(SMBgetattrE); return; } -- cgit