From deeaf5a142613be1606823ebd98719e7c2c11129 Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 3 Jul 2011 12:40:47 +0200 Subject: [PATCH] jcifs-1.3.15 from tgz Thu Oct 7 13:36:57 EDT 2010 jcifs-1.3.15 Adjusted locking on DcerpcHandle routines in jcifs.smb.SID which could result in "All pipe instances are busy". This is also believed to reduce occurances of NT_STATUS_TOO_MANY_OPENED_FILES errors (although when resolving SID names excessively, this error can still occur). Thu Aug 19 21:05:38 EDT 2010 jcifs-1.3.15a Fragmented request PDUs have been implemented. --- README.txt | 13 + build.xml | 4 +- examples/Format.java | 562 -------------------------------- examples/GetGroupMemberSids.java | 6 +- examples/Makefile | 2 +- examples/runtests.sh | 4 +- patches/jcifs_1.3.14-printing.patch | 346 ++++++++++++++++++++ src/jcifs/dcerpc/DcerpcHandle.java | 37 ++- src/jcifs/dcerpc/DcerpcHandle.java.0 | 285 ++++++++++++++++ src/jcifs/dcerpc/DcerpcMessage.java | 2 +- src/jcifs/netbios/NbtAddress.java | 2 +- src/jcifs/smb/SID.java | 14 +- src/jcifs/smb/SmbTransport.java | 10 +- src/jcifs/util/transport/Transport.java | 3 +- 14 files changed, 696 insertions(+), 594 deletions(-) delete mode 100644 examples/Format.java create mode 100644 patches/jcifs_1.3.14-printing.patch create mode 100644 src/jcifs/dcerpc/DcerpcHandle.java.0 diff --git a/README.txt b/README.txt index e78852c..27c94dd 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,16 @@ +Thu Oct 7 13:36:57 EDT 2010 +jcifs-1.3.15 + +Adjusted locking on DcerpcHandle routines in jcifs.smb.SID which could +result in "All pipe instances are busy". This is also believed to reduce +occurances of NT_STATUS_TOO_MANY_OPENED_FILES errors (although when +resolving SID names excessively, this error can still occur). + +Thu Aug 19 21:05:38 EDT 2010 +jcifs-1.3.15a + +Fragmented request PDUs have been implemented. + Thu Feb 11 15:10:26 EST 2010 jcifs-1.3.14 diff --git a/build.xml b/build.xml index 89ad2f0..36ab8fc 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - - + + diff --git a/examples/Format.java b/examples/Format.java deleted file mode 100644 index a04e50e..0000000 --- a/examples/Format.java +++ /dev/null @@ -1,562 +0,0 @@ -/* - * Cay S. Horstmann & Gary Cornell, Core Java - * Published By Sun Microsystems Press/Prentice-Hall - * Copyright (C) 1997 Sun Microsystems Inc. - * All Rights Reserved. - * - * Permission to use, copy, modify, and distribute this - * software and its documentation for NON-COMMERCIAL purposes - * and without fee is hereby granted provided that this - * copyright notice appears in all copies. - * - * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR - * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS - * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED - * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING - * THIS SOFTWARE OR ITS DERIVATIVES. - */ - -/** - * A class for formatting numbers that follows printf conventions. - * Also implements C-like atoi and atof functions - * @version 1.04 13 Sep 1998 - * @author Cay Horstmann - */ - -import java.io.*; - -public class Format - -{ /** - * Formats the number following printf conventions. - * Main limitation: Can only handle one format parameter at a time - * Use multiple Format objects to format more than one number - * @param s the format string following printf conventions - * The string has a prefix, a format code and a suffix. The prefix and suffix - * become part of the formatted output. The format code directs the - * formatting of the (single) parameter to be formatted. The code has the - * following structure - *
    - *
  • a % (required) - *
  • a modifier (optional) - *
    - *
    +
    forces display of + for positive numbers - *
    0
    show leading zeroes - *
    -
    align left in the field - *
    space
    prepend a space in front of positive numbers - *
    #
    use "alternate" format. Add 0 or 0x for octal or hexadecimal numbers. Don't suppress trailing zeroes in general floating point format. - *
    - *
  • an integer denoting field width (optional) - *
  • a period followed by an integer denoting precision (optional) - *
  • a format descriptor (required) - *
    - *
    f
    floating point number in fixed format - *
    e, E
    floating point number in exponential notation (scientific format). The E format results in an uppercase E for the exponent (1.14130E+003), the e format in a lowercase e. - *
    g, G
    floating point number in general format (fixed format for small numbers, exponential format for large numbers). Trailing zeroes are suppressed. The G format results in an uppercase E for the exponent (if any), the g format in a lowercase e. - *
    d, i
    integer in decimal - *
    x
    integer in hexadecimal - *
    o
    integer in octal - *
    s
    string - *
    c
    character - *
    - *
- * @exception IllegalArgumentException if bad format - */ - - public Format(String s) - { width = 0; - precision = -1; - pre = ""; - post = ""; - leading_zeroes = false; - show_plus = false; - alternate = false; - show_space = false; - left_align = false; - fmt = ' '; - - int state = 0; - int length = s.length(); - int parse_state = 0; - // 0 = prefix, 1 = flags, 2 = width, 3 = precision, - // 4 = format, 5 = end - int i = 0; - - while (parse_state == 0) - { if (i >= length) parse_state = 5; - else if (s.charAt(i) == '%') - { if (i < length - 1) - { if (s.charAt(i + 1) == '%') - { pre = pre + '%'; - i++; - } - else - parse_state = 1; - } - else throw new java.lang.IllegalArgumentException(); - } - else - pre = pre + s.charAt(i); - i++; - } - while (parse_state == 1) - { if (i >= length) parse_state = 5; - else if (s.charAt(i) == ' ') show_space = true; - else if (s.charAt(i) == '-') left_align = true; - else if (s.charAt(i) == '+') show_plus = true; - else if (s.charAt(i) == '0') leading_zeroes = true; - else if (s.charAt(i) == '#') alternate = true; - else { parse_state = 2; i--; } - i++; - } - while (parse_state == 2) - { if (i >= length) parse_state = 5; - else if ('0' <= s.charAt(i) && s.charAt(i) <= '9') - { width = width * 10 + s.charAt(i) - '0'; - i++; - } - else if (s.charAt(i) == '.') - { parse_state = 3; - precision = 0; - i++; - } - else - parse_state = 4; - } - while (parse_state == 3) - { if (i >= length) parse_state = 5; - else if ('0' <= s.charAt(i) && s.charAt(i) <= '9') - { precision = precision * 10 + s.charAt(i) - '0'; - i++; - } - else - parse_state = 4; - } - if (parse_state == 4) - { if (i >= length) parse_state = 5; - else fmt = s.charAt(i); - i++; - } - if (i < length) - post = s.substring(i, length); - } - - /** - * prints a formatted number following printf conventions - * @param s a PrintStream - * @param fmt the format string - * @param x the double to print - */ - - public static void print(java.io.PrintStream s, String fmt, double x) - { s.print(new Format(fmt).form(x)); - } - - /** - * prints a formatted number following printf conventions - * @param s a PrintStream - * @param fmt the format string - * @param x the long to print - */ - public static void print(java.io.PrintStream s, String fmt, long x) - { s.print(new Format(fmt).form(x)); - } - - /** - * prints a formatted number following printf conventions - * @param s a PrintStream - * @param fmt the format string - * @param x the character to - */ - - public static void print(java.io.PrintStream s, String fmt, char x) - { s.print(new Format(fmt).form(x)); - } - - /** - * prints a formatted number following printf conventions - * @param s a PrintStream, fmt the format string - * @param x a string that represents the digits to print - */ - - public static void print(java.io.PrintStream s, String fmt, String x) - { s.print(new Format(fmt).form(x)); - } - - /** - * Converts a string of digits (decimal, octal or hex) to an integer - * @param s a string - * @return the numeric value of the prefix of s representing a base 10 integer - */ - - public static int atoi(String s) - { return (int)atol(s); - } - - /** - * Converts a string of digits (decimal, octal or hex) to a long integer - * @param s a string - * @return the numeric value of the prefix of s representing a base 10 integer - */ - - public static long atol(String s) - { int i = 0; - - while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++; - if (i < s.length() && s.charAt(i) == '0') - { if (i + 1 < s.length() && (s.charAt(i + 1) == 'x' || s.charAt(i + 1) == 'X')) - return parseLong(s.substring(i + 2), 16); - else return parseLong(s, 8); - } - else return parseLong(s, 10); - } - - private static long parseLong(String s, int base) - { int i = 0; - int sign = 1; - long r = 0; - - while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++; - if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; } - else if (i < s.length() && s.charAt(i) == '+') { i++; } - while (i < s.length()) - { char ch = s.charAt(i); - if ('0' <= ch && ch < '0' + base) - r = r * base + ch - '0'; - else if ('A' <= ch && ch < 'A' + base - 10) - r = r * base + ch - 'A' + 10 ; - else if ('a' <= ch && ch < 'a' + base - 10) - r = r * base + ch - 'a' + 10 ; - else - return r * sign; - i++; - } - return r * sign; - } - - /** - * Converts a string of digits to an double - * @param s a string - */ - - public static double atof(String s) - { int i = 0; - int sign = 1; - double r = 0; // integer part - double f = 0; // fractional part - double p = 1; // exponent of fractional part - int state = 0; // 0 = int part, 1 = frac part - - while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++; - if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; } - else if (i < s.length() && s.charAt(i) == '+') { i++; } - while (i < s.length()) - { char ch = s.charAt(i); - if ('0' <= ch && ch <= '9') - { if (state == 0) - r = r * 10 + ch - '0'; - else if (state == 1) - { p = p / 10; - r = r + p * (ch - '0'); - } - } - else if (ch == '.') - { if (state == 0) state = 1; - else return sign * r; - } - else if (ch == 'e' || ch == 'E') - { long e = (int)parseLong(s.substring(i + 1), 10); - return sign * r * Math.pow(10, e); - } - else return sign * r; - i++; - } - return sign * r; - } - - /** - * Formats a double into a string (like sprintf in C) - * @param x the number to format - * @return the formatted string - * @exception IllegalArgumentException if bad argument - */ - - public String form(double x) - { String r; - if (precision < 0) precision = 6; - int s = 1; - if (x < 0) { x = -x; s = -1; } - if (fmt == 'f') - r = fixed_format(x); - else if (fmt == 'e' || fmt == 'E' || fmt == 'g' || fmt == 'G') - r = exp_format(x); - else throw new java.lang.IllegalArgumentException(); - - return pad(sign(s, r)); - } - - /** - * Formats a long integer into a string (like sprintf in C) - * @param x the number to format - * @return the formatted string - */ - - public String form(long x) - { String r; - int s = 0; - if (fmt == 'd' || fmt == 'i') - { if (x < 0) - { r = ("" + x).substring(1); - s = -1; - } - else - { r = "" + x; - s = 1; - } - } - else if (fmt == 'o') - r = convert(x, 3, 7, "01234567"); - else if (fmt == 'x') - r = convert(x, 4, 15, "0123456789abcdef"); - else if (fmt == 'X') - r = convert(x, 4, 15, "0123456789ABCDEF"); - else throw new java.lang.IllegalArgumentException(); - - return pad(sign(s, r)); - } - - /** - * Formats a character into a string (like sprintf in C) - * @param x the value to format - * @return the formatted string - */ - - public String form(char c) - { if (fmt != 'c') - throw new java.lang.IllegalArgumentException(); - - String r = "" + c; - return pad(r); - } - - /** - * Formats a string into a larger string (like sprintf in C) - * @param x the value to format - * @return the formatted string - */ - - public String form(String s) - { if (fmt != 's') - throw new java.lang.IllegalArgumentException(); - if (precision >= 0 && precision < s.length()) - s = s.substring(0, precision); - return pad(s); - } - - - /** - * a test stub for the format class - */ - - public static void main(String[] a) - { double x = 1.23456789012; - double y = 123; - double z = 1.2345e30; - double w = 1.02; - double u = 1.234e-5; - int d = 0xCAFE; - Format.print(System.out, "x = |%f|\n", x); - Format.print(System.out, "u = |%20f|\n", u); - Format.print(System.out, "x = |% .5f|\n", x); - Format.print(System.out, "w = |%20.5f|\n", w); - Format.print(System.out, "x = |%020.5f|\n", x); - Format.print(System.out, "x = |%+20.5f|\n", x); - Format.print(System.out, "x = |%+020.5f|\n", x); - Format.print(System.out, "x = |% 020.5f|\n", x); - Format.print(System.out, "y = |%#+20.5f|\n", y); - Format.print(System.out, "y = |%-+20.5f|\n", y); - Format.print(System.out, "z = |%20.5f|\n", z); - - Format.print(System.out, "x = |%e|\n", x); - Format.print(System.out, "u = |%20e|\n", u); - Format.print(System.out, "x = |% .5e|\n", x); - Format.print(System.out, "w = |%20.5e|\n", w); - Format.print(System.out, "x = |%020.5e|\n", x); - Format.print(System.out, "x = |%+20.5e|\n", x); - Format.print(System.out, "x = |%+020.5e|\n", x); - Format.print(System.out, "x = |% 020.5e|\n", x); - Format.print(System.out, "y = |%#+20.5e|\n", y); - Format.print(System.out, "y = |%-+20.5e|\n", y); - - Format.print(System.out, "x = |%g|\n", x); - Format.print(System.out, "z = |%g|\n", z); - Format.print(System.out, "w = |%g|\n", w); - Format.print(System.out, "u = |%g|\n", u); - Format.print(System.out, "y = |%.2g|\n", y); - Format.print(System.out, "y = |%#.2g|\n", y); - - Format.print(System.out, "d = |%d|\n", d); - Format.print(System.out, "d = |%20d|\n", d); - Format.print(System.out, "d = |%020d|\n", d); - Format.print(System.out, "d = |%+20d|\n", d); - Format.print(System.out, "d = |% 020d|\n", d); - Format.print(System.out, "d = |%-20d|\n", d); - Format.print(System.out, "d = |%20.8d|\n", d); - Format.print(System.out, "d = |%x|\n", d); - Format.print(System.out, "d = |%20X|\n", d); - Format.print(System.out, "d = |%#20x|\n", d); - Format.print(System.out, "d = |%020X|\n", d); - Format.print(System.out, "d = |%20.8x|\n", d); - Format.print(System.out, "d = |%o|\n", d); - Format.print(System.out, "d = |%020o|\n", d); - Format.print(System.out, "d = |%#20o|\n", d); - Format.print(System.out, "d = |%#020o|\n", d); - Format.print(System.out, "d = |%20.12o|\n", d); - - Format.print(System.out, "s = |%-20s|\n", "Hello"); - Format.print(System.out, "s = |%-20c|\n", '!'); - - // regression test to confirm fix of reported bugs - - Format.print(System.out, "|%i|\n", Long.MIN_VALUE); - - Format.print(System.out, "|%6.2e|\n", 0.0); - Format.print(System.out, "|%6.2g|\n", 0.0); - - Format.print(System.out, "|%6.2f|\n", 9.99); - Format.print(System.out, "|%6.2f|\n", 9.999); - - Format.print(System.out, "|%6.0f|\n", 9.999); - } - - private static String repeat(char c, int n) - { if (n <= 0) return ""; - StringBuffer s = new StringBuffer(n); - for (int i = 0; i < n; i++) s.append(c); - return s.toString(); - } - - private static String convert(long x, int n, int m, String d) - { if (x == 0) return "0"; - String r = ""; - while (x != 0) - { r = d.charAt((int)(x & m)) + r; - x = x >>> n; - } - return r; - } - - private String pad(String r) - { String p = repeat(' ', width - r.length()); - if (left_align) return pre + r + p + post; - else return pre + p + r + post; - } - - private String sign(int s, String r) - { String p = ""; - if (s < 0) p = "-"; - else if (s > 0) - { if (show_plus) p = "+"; - else if (show_space) p = " "; - } - else - { if (fmt == 'o' && alternate && r.length() > 0 && r.charAt(0) != '0') p = "0"; - else if (fmt == 'x' && alternate) p = "0x"; - else if (fmt == 'X' && alternate) p = "0X"; - } - int w = 0; - if (leading_zeroes) - w = width; - else if ((fmt == 'd' || fmt == 'i' || fmt == 'x' || fmt == 'X' || fmt == 'o') - && precision > 0) w = precision; - - return p + repeat('0', w - p.length() - r.length()) + r; - } - - private String fixed_format(double d) - { boolean removeTrailing - = (fmt == 'G' || fmt == 'g') && !alternate; - // remove trailing zeroes and decimal point - - if (d > 0x7FFFFFFFFFFFFFFFL) return exp_format(d); - if (precision == 0) - return (long)(d + 0.5) + (removeTrailing ? "" : "."); - - long whole = (long)d; - double fr = d - whole; // fractional part - if (fr >= 1 || fr < 0) return exp_format(d); - - double factor = 1; - String leading_zeroes = ""; - for (int i = 1; i <= precision && factor <= 0x7FFFFFFFFFFFFFFFL; i++) - { factor *= 10; - leading_zeroes = leading_zeroes + "0"; - } - long l = (long) (factor * fr + 0.5); - if (l >= factor) { l = 0; whole++; } // CSH 10-25-97 - - String z = leading_zeroes + l; - z = "." + z.substring(z.length() - precision, z.length()); - - if (removeTrailing) - { int t = z.length() - 1; - while (t >= 0 && z.charAt(t) == '0') t--; - if (t >= 0 && z.charAt(t) == '.') t--; - z = z.substring(0, t + 1); - } - - return whole + z; - } - - private String exp_format(double d) - { String f = ""; - int e = 0; - double dd = d; - double factor = 1; - if (d != 0) - { while (dd > 10) { e++; factor /= 10; dd = dd / 10; } - while (dd < 1) { e--; factor *= 10; dd = dd * 10; } - } - if ((fmt == 'g' || fmt == 'G') && e >= -4 && e < precision) - return fixed_format(d); - - d = d * factor; - f = f + fixed_format(d); - - if (fmt == 'e' || fmt == 'g') - f = f + "e"; - else - f = f + "E"; - - String p = "000"; - if (e >= 0) - { f = f + "+"; - p = p + e; - } - else - { f = f + "-"; - p = p + (-e); - } - - return f + p.substring(p.length() - 3, p.length()); - } - - private int width; - private int precision; - private String pre; - private String post; - private boolean leading_zeroes; - private boolean show_plus; - private boolean alternate; - private boolean show_space; - private boolean left_align; - private char fmt; // one of cdeEfgGiosxXos -} - - - - - diff --git a/examples/GetGroupMemberSids.java b/examples/GetGroupMemberSids.java index fe416f1..a2348a1 100644 --- a/examples/GetGroupMemberSids.java +++ b/examples/GetGroupMemberSids.java @@ -10,10 +10,12 @@ public class GetGroupMemberSids { } SmbFile file = new SmbFile(argv[0]); - SID sid = new SID(argv[1]); - String server = file.getServer(); NtlmPasswordAuthentication auth = (NtlmPasswordAuthentication)file.getPrincipal(); + SID sid = new SID(argv[1]); + sid.resolve(server, auth); + + System.out.println("type=" + sid.getType()); SID[] mems = sid.getGroupMemberSids(server, auth, SID.SID_FLAG_RESOLVE_SIDS); diff --git a/examples/Makefile b/examples/Makefile index bc76109..8aca995 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,7 +3,7 @@ CLASSPATH=../build:. .SUFFIXES: .java .class -CLASSFILES=GetGroupMemberSidsFromURL.class ListACL.class LargeListFiles.class GetShareSecurity.class CountPerms.class AclCrawler.class SidCacheTest.class GetSecurity.class SidCrawler.class InterruptTest.class AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class Format.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbShell.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class +CLASSFILES=GetGroupMemberSidsFromURL.class ListACL.class LargeListFiles.class GetShareSecurity.class CountPerms.class AclCrawler.class SidCacheTest.class GetSecurity.class SidCrawler.class InterruptTest.class AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class all: ${CLASSFILES} diff --git a/examples/runtests.sh b/examples/runtests.sh index cee995c..1041420 100644 --- a/examples/runtests.sh +++ b/examples/runtests.sh @@ -5,8 +5,8 @@ CLASSPATH=../build:. PROPERTIES=../../user2.prp RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}" -SERVER=192.168.2.110 -#SERVER=dc1.w.net +#SERVER=192.168.2.110 +SERVER=dc1.w.net SHARE=tmp DIR=test diff --git a/patches/jcifs_1.3.14-printing.patch b/patches/jcifs_1.3.14-printing.patch new file mode 100644 index 0000000..113d50c --- /dev/null +++ b/patches/jcifs_1.3.14-printing.patch @@ -0,0 +1,346 @@ +diff -rupN src/jcifs/smb/ServerMessageBlock.java ../src.patched/jcifs/smb/ServerMessageBlock.java +--- src/jcifs/smb/ServerMessageBlock.java 2010-02-11 21:12:21.000000000 +0100 ++++ ../src.patched/jcifs/smb/ServerMessageBlock.java 2010-02-26 09:51:25.000000000 +0100 +@@ -154,6 +154,9 @@ abstract class ServerMessageBlock extend + static final byte SMB_COM_NT_TRANSACT = (byte)0xA0; + static final byte SMB_COM_NT_TRANSACT_SECONDARY = (byte)0xA1; + static final byte SMB_COM_NT_CREATE_ANDX = (byte)0xA2; ++ static final byte SMB_COM_OPEN_PRINT_FILE = (byte)0xC0; ++ static final byte SMB_COM_WRITE_PRINT_FILE = (byte)0xC1; ++ static final byte SMB_COM_CLOSE_PRINT_FILE = (byte)0xC2; + + /* + * Some fields specify the offset from the beginning of the header. This +diff -rupN src/jcifs/smb/SmbComClosePrintFile.java ../src.patched/jcifs/smb/SmbComClosePrintFile.java +--- src/jcifs/smb/SmbComClosePrintFile.java 1970-01-01 01:00:00.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbComClosePrintFile.java 2010-02-26 09:51:25.000000000 +0100 +@@ -0,0 +1,36 @@ ++package jcifs.smb; ++ ++public class SmbComClosePrintFile extends ServerMessageBlock { ++ // File handle ++ /* USHORT */long fid; ++ ++ public SmbComClosePrintFile(long fid) { ++ this.fid = fid; ++ command = SMB_COM_CLOSE_PRINT_FILE; ++ } ++ ++ @Override ++ int readBytesWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int writeBytesWireFormat(byte[] dst, int dstIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int writeParameterWordsWireFormat(byte[] dst, int dstIndex) { ++ writeInt2(fid, dst, dstIndex); ++ return 2; ++ } ++ ++} +diff -rupN src/jcifs/smb/SmbComOpenPrintFile.java ../src.patched/jcifs/smb/SmbComOpenPrintFile.java +--- src/jcifs/smb/SmbComOpenPrintFile.java 1970-01-01 01:00:00.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbComOpenPrintFile.java 2010-02-26 09:51:25.000000000 +0100 +@@ -0,0 +1,52 @@ ++package jcifs.smb; ++ ++public class SmbComOpenPrintFile extends ServerMessageBlock { ++ // Length of printer setup data ++ /* USHORT */long setupLength; ++ ++ // 0 = Text mode (DOS expands TABs) ++ // 1 = Graphics mode ++ /* USHORT */long mode; ++ ++ /* UCHAR */long bufferFormat = 0x04; ++ ++ // Identifier string ++ /* STRING */String identifierString; ++ ++ public SmbComOpenPrintFile(String identifierString) { ++ setupLength = 0; ++ mode = 1; ++ this.identifierString = identifierString; ++ command = SMB_COM_OPEN_PRINT_FILE; ++ } ++ ++ @Override ++ int readBytesWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int writeBytesWireFormat(byte[] dst, int dstIndex) { ++ int start = dstIndex; ++ ++ dst[dstIndex++] = (byte) 0x04; ++ dstIndex += writeString(identifierString, dst, dstIndex); ++ ++ return dstIndex - start; ++ } ++ ++ @Override ++ int writeParameterWordsWireFormat(byte[] dst, int dstIndex) { ++ writeInt2(setupLength, dst, dstIndex); ++ writeInt2(mode, dst, dstIndex); ++ return 4; ++ } ++ ++} +diff -rupN src/jcifs/smb/SmbComOpenPrintFileResponse.java ../src.patched/jcifs/smb/SmbComOpenPrintFileResponse.java +--- src/jcifs/smb/SmbComOpenPrintFileResponse.java 1970-01-01 01:00:00.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbComOpenPrintFileResponse.java 2010-02-26 09:51:25.000000000 +0100 +@@ -0,0 +1,32 @@ ++package jcifs.smb; ++ ++public class SmbComOpenPrintFileResponse extends ServerMessageBlock { ++ // File handle ++ /* USHORT */long fid; ++ ++ @Override ++ int readBytesWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) { ++ fid = readInt2( buffer, bufferIndex ); ++ bufferIndex += 2; ++ return 2; ++ } ++ ++ @Override ++ int writeBytesWireFormat(byte[] dst, int dstIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int writeParameterWordsWireFormat(byte[] dst, int dstIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++} +diff -rupN src/jcifs/smb/SmbComWritePrintFile.java ../src.patched/jcifs/smb/SmbComWritePrintFile.java +--- src/jcifs/smb/SmbComWritePrintFile.java 1970-01-01 01:00:00.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbComWritePrintFile.java 2010-02-26 09:51:25.000000000 +0100 +@@ -0,0 +1,54 @@ ++package jcifs.smb; ++ ++public class SmbComWritePrintFile extends ServerMessageBlock { ++ ++ // File handle ++ /* USHORT */long fid; ++ ++ // 0x01 -- Data block ++ /* UCHAR */long bufferFormat = 0x01; ++ ++ // Length of data ++ /* USHORT */long dataLength; ++ ++ // data ++ /* UCHAR */byte[] data; ++ ++ public SmbComWritePrintFile(long fid, long datalength, byte[] data) { ++ this.fid = fid; ++ this.dataLength = datalength; ++ this.data = data; ++ command = SMB_COM_WRITE_PRINT_FILE; ++ } ++ ++ @Override ++ int readBytesWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) { ++ // TODO Auto-generated method stub ++ return 0; ++ } ++ ++ @Override ++ int writeBytesWireFormat(byte[] dst, int dstIndex) { ++ int start = dstIndex; ++ dst[dstIndex++] = 0x01; ++ writeInt2(dataLength, dst, dstIndex); ++ dstIndex += 2; ++ ++ System.arraycopy(data, 0, dst, dstIndex, data.length); ++ dstIndex += data.length; ++ return dstIndex - start; ++ } ++ ++ @Override ++ int writeParameterWordsWireFormat(byte[] dst, int dstIndex) { ++ writeInt2(fid, dst, dstIndex); ++ return 2; ++ } ++ ++} +diff -rupN src/jcifs/smb/SmbFile.java ../src.patched/jcifs/smb/SmbFile.java +--- src/jcifs/smb/SmbFile.java 2010-02-11 21:12:21.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbFile.java 2010-02-26 09:54:53.000000000 +0100 +@@ -970,15 +970,14 @@ int addressIndex; + /* + * NT Create AndX / Open AndX Request / Response + */ +- + if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) { + SmbComNTCreateAndXResponse response = new SmbComNTCreateAndXResponse(); +-SmbComNTCreateAndX request = new SmbComNTCreateAndX( unc, flags, access, shareAccess, attrs, options, null ); +-if (this instanceof SmbNamedPipe) { ++ SmbComNTCreateAndX request = new SmbComNTCreateAndX( unc, flags, access, shareAccess, attrs, options, null ); ++ if (this instanceof SmbNamedPipe) { + request.flags0 |= 0x16; + request.desiredAccess |= 0x20000; + response.isExtended = true; +-} ++ } + send( request, response ); + f = response.fid; + attributes = response.extFileAttributes & ATTR_GET_MASK; +@@ -992,6 +991,7 @@ if (this instanceof SmbNamedPipe) { + + return f; + } ++ + void open( int flags, int access, int attrs, int options ) throws SmbException { + if( isOpen() ) { + return; +@@ -1000,6 +1000,22 @@ if (this instanceof SmbNamedPipe) { + opened = true; + tree_num = tree.tree_num; + } ++ ++ void print_open(String printJobName) throws SmbException { ++ connect0(); ++ ++ if (log.level >= 3) ++ log.println("print_open: unc=" + unc + ", printJobName=" ++ + printJobName); ++ ++ SmbComOpenPrintFile request = new SmbComOpenPrintFile(printJobName); ++ SmbComOpenPrintFileResponse response = new SmbComOpenPrintFileResponse(); ++ send(request, response); ++ fid = (int) response.fid; ++ opened = true; ++ tree_num = tree.tree_num; ++ } ++ + boolean isOpen() { + boolean ans = opened && isConnected() && tree_num == tree.tree_num; + return ans; +@@ -1012,8 +1028,12 @@ if (this instanceof SmbNamedPipe) { + /* + * Close Request / Response + */ +- ++ if(this.type != TYPE_PRINTER){ + send( new SmbComClose( f, lastWriteTime ), blank_resp() ); ++ } else { ++ SmbComClosePrintFile request = new SmbComClosePrintFile(this.fid); ++ send(request, blank_resp()); ++ } + } + void close( long lastWriteTime ) throws SmbException { + if( isOpen() == false ) { +@@ -2867,6 +2887,62 @@ if (this instanceof SmbNamedPipe) { + } + } + } ++ ++ /** ++ * Prints contents of the given inputstream to this printer. This method ++ * does not check if the input stream contains content that the printer will ++ * understand, e.g. user may send PCL content to a PostScript printer, and ++ * this method would not report an error. Since this method is sychronized, ++ * one must create different instances of SmbFile to send print jobs in ++ * parallel to the same printer multiple times. This approach is slow, but ++ * this method is a first step to a proper printer queue implementation in ++ * SmbFile. ++ * ++ * @param input_stream ++ * The InputStream to read from. It will be read and sent to ++ * printer queue until its EOF. ++ * @param printJobName ++ * The printJobName the print server associates with this job. It ++ * is unique per client(??client is this SmbFile or this host??). ++ * @return Number of bytes sent to printer, or -1 if this file is not a ++ * printer. ++ * @throws IOException ++ */ ++ public synchronized int print(final InputStream input_stream, final String printJobName) ++ throws IOException { ++ if (getType() != TYPE_PRINTER) { ++ return -1; ++ } ++ int total = 0; ++ connect0(); ++ if (tree.inDfs) { ++ /* At this point the maxBufferSize values are from the server ++ * exporting the volumes, not the one that we will actually ++ * end up performing IO with. If the server hosting the ++ * actual files has a smaller maxBufSize this could be ++ * incorrect. To handle this properly it is necessary ++ * to redirect the tree to the target server first before ++ * establishing buffer size. These exists() calls facilitate ++ * that. ++ */ ++ exists(); ++ } ++ print_open(printJobName); ++ int sndBufSize = tree.session.transport.snd_buf_size; ++ ++ byte[] buf = new byte[sndBufSize <= 70 ? sndBufSize : sndBufSize - 70]; ++ long numRead = input_stream.read(buf); ++ while (numRead != -1 && numRead != 0) { ++ SmbComWritePrintFile request = new SmbComWritePrintFile(this.fid, ++ numRead, buf); ++ send(request, blank_resp()); ++ total += numRead; ++ numRead = input_stream.read(buf); ++ } ++ close(); ++ return total; ++ } ++ + /** + * Return an array of Access Control Entry (ACE) objects representing + * the security descriptor associated with this file or directory. +diff -rupN src/jcifs/smb/SmbTree.java ../src.patched/jcifs/smb/SmbTree.java +--- src/jcifs/smb/SmbTree.java 2010-02-11 21:12:21.000000000 +0100 ++++ ../src.patched/jcifs/smb/SmbTree.java 2010-02-26 09:51:25.000000000 +0100 +@@ -83,6 +83,9 @@ synchronized (session.transport()) { + case ServerMessageBlock.SMB_COM_WRITE_ANDX: + case ServerMessageBlock.SMB_COM_CLOSE: + case ServerMessageBlock.SMB_COM_TREE_DISCONNECT: ++ case ServerMessageBlock.SMB_COM_OPEN_PRINT_FILE: ++ case ServerMessageBlock.SMB_COM_CLOSE_PRINT_FILE: ++ case ServerMessageBlock.SMB_COM_WRITE_PRINT_FILE: + break; + case ServerMessageBlock.SMB_COM_TRANSACTION: + case ServerMessageBlock.SMB_COM_TRANSACTION2: diff --git a/src/jcifs/dcerpc/DcerpcHandle.java b/src/jcifs/dcerpc/DcerpcHandle.java index 7a60519..145b449 100644 --- a/src/jcifs/dcerpc/DcerpcHandle.java +++ b/src/jcifs/dcerpc/DcerpcHandle.java @@ -1,6 +1,6 @@ /* jcifs msrpc client library in Java * Copyright (C) 2006 "Michael B. Allen" - * "Eric Glass" + * "Eric Glass" * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -140,7 +140,7 @@ synchronized (this) { bind(); } - isDirect = msg instanceof DcerpcBind; + isDirect = true; stub = jcifs.smb.BufferCache.getBuffer(); try { @@ -149,7 +149,7 @@ synchronized (this) { buf = new NdrBuffer(stub, 0); msg.flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG; - msg.call_id = call_id; + msg.call_id = call_id++; msg.encode(buf); @@ -158,27 +158,36 @@ synchronized (this) { securityProvider.wrap(buf); } - tot = buf.getLength(); + tot = buf.getLength() - 24; off = 0; while (off < tot) { - msg.call_id = call_id++; + n = tot - off; - if ((tot - off) > max_xmit) { - /* Multiple fragments. Need to set flags and length - * and re-encode header - msg.length = n = max_xmit; + if ((24 + n) > max_xmit) { msg.flags &= ~DCERPC_LAST_FRAG; + n = max_xmit - 24; + } else { + msg.flags |= DCERPC_LAST_FRAG; + isDirect = false; + msg.alloc_hint = n; + } + + msg.length = 24 + n; + + if (off > 0) + msg.flags &= ~DCERPC_FIRST_FRAG; + + if ((msg.flags & (DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG)) != (DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG)) { buf.start = off; buf.reset(); msg.encode_header(buf); - */ - throw new DcerpcException("Fragmented request PDUs currently not supported"); - } else { - n = tot - off; + buf.enc_ndr_long(msg.alloc_hint); + buf.enc_ndr_short(0); /* context id */ + buf.enc_ndr_short(msg.getOpnum()); } - doSendFragment(stub, off, n, isDirect); + doSendFragment(stub, off, msg.length, isDirect); off += n; } diff --git a/src/jcifs/dcerpc/DcerpcHandle.java.0 b/src/jcifs/dcerpc/DcerpcHandle.java.0 new file mode 100644 index 0000000..e0bf573 --- /dev/null +++ b/src/jcifs/dcerpc/DcerpcHandle.java.0 @@ -0,0 +1,285 @@ +/* jcifs msrpc client library in Java + * Copyright (C) 2006 "Michael B. Allen" + * "Eric Glass" + * + * 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.1 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 + * 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 + */ + +package jcifs.dcerpc; + +import java.io.*; +import java.net.*; +import java.security.Principal; + +import jcifs.smb.NtlmPasswordAuthentication; +import jcifs.util.Hexdump; +import jcifs.dcerpc.ndr.NdrBuffer; + +public abstract class DcerpcHandle implements DcerpcConstants { + + /* Bindings are in the form: + * proto:\\server[key1=val1,key2=val2] + * or + * proto:server[key1=val1,key2=val2] + * or + * proto:[key1=val1,key2=val2] + * + * If a key is absent it is assumed to be 'endpoint'. Thus the + * following are equivalent: + * proto:\\ts0.win.net[endpoint=\pipe\srvsvc] + * proto:ts0.win.net[\pipe\srvsvc] + * + * If the server is absent it is set to "127.0.0.1" + */ + protected static DcerpcBinding parseBinding(String str) throws DcerpcException { + int state, mark, si; + char[] arr = str.toCharArray(); + String proto = null, key = null; + DcerpcBinding binding = null; + + state = mark = si = 0; + do { + char ch = arr[si]; + + switch (state) { + case 0: + if (ch == ':') { + proto = str.substring(mark, si); + mark = si + 1; + state = 1; + } + break; + case 1: + if (ch == '\\') { + mark = si + 1; + break; + } + state = 2; + case 2: + if (ch == '[') { + String server = str.substring(mark, si).trim(); + if (server.length() == 0) + server = "127.0.0.1"; + binding = new DcerpcBinding(proto, str.substring(mark, si)); + mark = si + 1; + state = 5; + } + break; + case 5: + if (ch == '=') { + key = str.substring(mark, si).trim(); + mark = si + 1; + } else if (ch == ',' || ch == ']') { + String val = str.substring(mark, si).trim(); + if (key == null) + key = "endpoint"; + binding.setOption(key, val); + key = null; + } + break; + default: + si = arr.length; + } + + si++; + } while (si < arr.length); + + if (binding == null || binding.endpoint == null) + throw new DcerpcException("Invalid binding URL: " + str); + + return binding; + } + + protected DcerpcBinding binding; + protected int max_xmit = 4280; + protected int max_recv = max_xmit; + protected int state = 0; + protected DcerpcSecurityProvider securityProvider = null; + private static int call_id = 1; + + public static DcerpcHandle getHandle(String url, + NtlmPasswordAuthentication auth) + throws UnknownHostException, MalformedURLException, DcerpcException { + if (url.startsWith("ncacn_np:")) { + return new DcerpcPipeHandle(url, auth); + } + throw new DcerpcException("DCERPC transport not supported: " + url); + } + + public void bind() throws DcerpcException, IOException { +synchronized (this) { + try { + state = 1; + DcerpcMessage bind = new DcerpcBind(binding, this); + sendrecv(bind); + } catch (IOException ioe) { + state = 0; + throw ioe; + } +} + } + public void sendrecv(DcerpcMessage msg) throws DcerpcException, IOException { + byte[] stub, frag; + NdrBuffer buf, fbuf; + boolean isLast, isDirect; + DcerpcException de; + + if (state == 0) { + bind(); + } + + isDirect = msg instanceof DcerpcBind; + + stub = jcifs.smb.BufferCache.getBuffer(); + try { + int off, tot, n; + + buf = new NdrBuffer(stub, 0); + + msg.flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG; + msg.call_id = call_id; + + msg.encode(buf); + + if (securityProvider != null) { + buf.setIndex(0); + securityProvider.wrap(buf); + } + + tot = buf.getLength(); + off = 0; + + while (off < tot) { +// msg.call_id = call_id++; + + if ((tot - off) > max_xmit) { + /* Multiple fragments. Need to set flags and length + * and re-encode header + throw new DcerpcException("Fragmented request PDUs currently not supported"); + msg.length = n = max_xmit; + */ + isDirect = true; + msg.length = n = max_xmit; + msg.flags &= ~DCERPC_LAST_FRAG; + buf.start = off; + buf.reset(); + msg.encode_header(buf); + } else { + isDirect = false; + n = tot - off; +System.err.println("n=" + n + " tot=" + tot + " off=" + off + " ptype=" + msg.ptype); + if (off > 0) { + msg.alloc_hint = n; + n += 24; + msg.length = n; + msg.flags &= ~DCERPC_FIRST_FRAG; + msg.flags |= DCERPC_LAST_FRAG; + buf.start = off; + buf.reset(); + msg.encode_header(buf); + buf.enc_ndr_long(msg.alloc_hint); + buf.enc_ndr_short(0); /* context id */ + buf.enc_ndr_short(msg.getOpnum()); + } + } + + doSendFragment(stub, off, n, isDirect); + off += n; + } + + doReceiveFragment(stub, isDirect); + buf.reset(); + buf.setIndex(8); + buf.setLength(buf.dec_ndr_short()); + + if (securityProvider != null) + securityProvider.unwrap(buf); + + buf.setIndex(0); + + msg.decode_header(buf); + + off = 24; + if (msg.ptype == 2 && msg.isFlagSet(DCERPC_LAST_FRAG) == false) + off = msg.length; + + frag = null; + fbuf = null; + while (msg.isFlagSet(DCERPC_LAST_FRAG) == false) { + int stub_frag_len; + + if (frag == null) { + frag = new byte[max_recv]; + fbuf = new NdrBuffer(frag, 0); + } + + doReceiveFragment(frag, isDirect); + fbuf.reset(); + fbuf.setIndex(8); + fbuf.setLength(fbuf.dec_ndr_short()); + + if (securityProvider != null) + securityProvider.unwrap(fbuf); + + fbuf.reset(); + msg.decode_header(fbuf); + stub_frag_len = msg.length - 24; + + if ((off + stub_frag_len) > stub.length) { + // shouldn't happen if alloc_hint is correct or greater + byte[] tmp = new byte[off + stub_frag_len]; + System.arraycopy(stub, 0, tmp, 0, off); + stub = tmp; + } + + System.arraycopy(frag, 24, stub, off, stub_frag_len); + off += stub_frag_len; + } + + buf = new NdrBuffer(stub, 0); + msg.decode(buf); + } finally { + jcifs.smb.BufferCache.releaseBuffer(stub); + } + + if ((de = msg.getResult()) != null) + throw de; + } + + public void setDcerpcSecurityProvider(DcerpcSecurityProvider securityProvider) + { + this.securityProvider = securityProvider; + } + public String getServer() { + if (this instanceof DcerpcPipeHandle) + return ((DcerpcPipeHandle)this).pipe.getServer(); + return null; + } + public Principal getPrincipal() { + if (this instanceof DcerpcPipeHandle) + return ((DcerpcPipeHandle)this).pipe.getPrincipal(); + return null; + } + public String toString() { + return binding.toString(); + } + + protected abstract void doSendFragment(byte[] buf, + int off, + int length, + boolean isDirect) throws IOException; + protected abstract void doReceiveFragment(byte[] buf, boolean isDirect) throws IOException; + public abstract void close() throws IOException; +} diff --git a/src/jcifs/dcerpc/DcerpcMessage.java b/src/jcifs/dcerpc/DcerpcMessage.java index 6edacd2..6a5883e 100644 --- a/src/jcifs/dcerpc/DcerpcMessage.java +++ b/src/jcifs/dcerpc/DcerpcMessage.java @@ -35,7 +35,7 @@ public abstract class DcerpcMessage extends NdrObject implements DcerpcConstants return (flags & flag) == flag; } public void unsetFlag(int flag) { - flags |= flag; + flags &= ~flag; } public void setFlag(int flag) { flags |= flag; diff --git a/src/jcifs/netbios/NbtAddress.java b/src/jcifs/netbios/NbtAddress.java index bd7f0fb..564bdca 100644 --- a/src/jcifs/netbios/NbtAddress.java +++ b/src/jcifs/netbios/NbtAddress.java @@ -298,7 +298,7 @@ public final class NbtAddress { addr = getCachedAddress( name ); if( addr == null ) { - /* This was copied amost verbatim from InetAddress.java. See the + /* This is almost exactly like InetAddress.java. See the * comments there for a description of how the LOOKUP_TABLE prevents * redundant queries from going out on the wire. */ diff --git a/src/jcifs/smb/SID.java b/src/jcifs/smb/SID.java index 76cf5a0..9f863a5 100644 --- a/src/jcifs/smb/SID.java +++ b/src/jcifs/smb/SID.java @@ -83,7 +83,7 @@ public class SID extends rpc.sid_t { } } - static Map sid_cache = Collections.synchronizedMap(new HashMap()); + static Map sid_cache = new HashMap(); static void resolveSids(DcerpcHandle handle, LsaPolicyHandle policyHandle, @@ -126,6 +126,7 @@ public class SID extends rpc.sid_t { DcerpcHandle handle = null; LsaPolicyHandle policyHandle = null; +synchronized (sid_cache) { try { handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\lsarpc]", auth); @@ -143,6 +144,7 @@ public class SID extends rpc.sid_t { handle.close(); } } +} } static public void resolveSids(String authorityServerName, @@ -153,6 +155,7 @@ public class SID extends rpc.sid_t { ArrayList list = new ArrayList(sids.length); int si; +synchronized (sid_cache) { for (si = 0; si < length; si++) { SID sid = (SID)sid_cache.get(sids[offset + si]); if (sid != null) { @@ -171,6 +174,7 @@ public class SID extends rpc.sid_t { sid_cache.put(sids[si], sids[si]); } } +} } /** * Resolve an array of SIDs using a cache and at most one MSRPC request. @@ -190,6 +194,7 @@ public class SID extends rpc.sid_t { ArrayList list = new ArrayList(sids.length); int si; +synchronized (sid_cache) { for (si = 0; si < sids.length; si++) { SID sid = (SID)sid_cache.get(sids[si]); if (sid != null) { @@ -208,6 +213,7 @@ public class SID extends rpc.sid_t { sid_cache.put(sids[si], sids[si]); } } +} } public static SID getServerSid(String server, NtlmPasswordAuthentication auth) throws IOException { @@ -216,6 +222,7 @@ public class SID extends rpc.sid_t { lsarpc.LsarDomainInfo info = new lsarpc.LsarDomainInfo(); MsrpcQueryInformationPolicy rpc; +synchronized (sid_cache) { try { handle = DcerpcHandle.getHandle("ncacn_np:" + server + "[\\PIPE\\lsarpc]", auth); @@ -241,6 +248,7 @@ public class SID extends rpc.sid_t { handle.close(); } } +} } public static byte[] toByteArray(rpc.sid_t sid) { byte[] dst = new byte[1 + 1 + 6 + sid.sub_authority_count * 4]; @@ -605,6 +613,7 @@ public class SID extends rpc.sid_t { SamrDomainHandle domainHandle = null; SID domsid = getDomainSid(); +synchronized (sid_cache) { try { handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]", auth); @@ -626,6 +635,7 @@ public class SID extends rpc.sid_t { handle.close(); } } +} } /** @@ -660,6 +670,7 @@ public class SID extends rpc.sid_t { samr.SamrSamArray sam = new samr.SamrSamArray(); MsrpcEnumerateAliasesInDomain rpc; +synchronized (sid_cache) { try { handle = DcerpcHandle.getHandle("ncacn_np:" + authorityServerName + "[\\PIPE\\samr]", auth); @@ -708,6 +719,7 @@ public class SID extends rpc.sid_t { handle.close(); } } +} } } diff --git a/src/jcifs/smb/SmbTransport.java b/src/jcifs/smb/SmbTransport.java index 42c0982..26b2be2 100644 --- a/src/jcifs/smb/SmbTransport.java +++ b/src/jcifs/smb/SmbTransport.java @@ -236,13 +236,6 @@ public class SmbTransport extends Transport implements SmbConstants { * until we have properly negotiated. */ synchronized (sbuf) { - /* If jcifs.netbios.hostname is set this *probably* means there - * is a policy regarding which hosts a user can connect from. This - * requires communicating over port 139 rather than 445. - */ - if (false && NETBIOS_HOSTNAME != null && NETBIOS_HOSTNAME.equals( "" ) == false) { - port = 139; - } if (port == 139) { ssn139(); } else { @@ -432,6 +425,9 @@ public class SmbTransport extends Transport implements SmbConstants { Hexdump.hexdump( log, BUF, 4, n ); } } + /* For some reason this can sometimes get broken up into another + * "NBSS Continuation Message" frame according to WireShark + */ out.write( BUF, 0, 4 + n ); } } diff --git a/src/jcifs/util/transport/Transport.java b/src/jcifs/util/transport/Transport.java index 56eec39..8e3c40a 100644 --- a/src/jcifs/util/transport/Transport.java +++ b/src/jcifs/util/transport/Transport.java @@ -240,7 +240,8 @@ public abstract class Transport implements Runnable { * doConnect returned too late, just ignore. */ if (ex0 != null) { - ex0.printStackTrace(); + if (log.level >= 2) + ex0.printStackTrace(log); } return; } -- 2.11.0