@@ -0,0 +1,2880 @@
+package hudson.os;%0A%0Aimport ndr.NdrObject;%0Aimport ndr.NetworkDataRepresentation;%0Aimport org.jinterop.dcom.common.JISystem;%0Aimport org.jinterop.dcom.transport.JIComTransportFactory;%0Aimport rpc.Endpoint;%0Aimport rpc.Stub;%0A%0Aimport java.io.IOException;%0Aimport java.util.Properties;%0A%0A/**%0A * My attempt to see if ServerAlive calls can be used to detect an authentication failure%0A * (so that I can differentiate authentication problem against authorization problem in%0A * creating an instance.%0A *%0A * %3Cp%3E%0A * It turns out that the bogus credential works with ServerAlive.  The protocol specification%0A * %3Chttp://download.microsoft.com/download/a/e/6/ae6e4142-aa58-45c6-8dcf-a657e5900cd3/%255BMS-DCOM%255D.pdf%3E%0A * explicitly says this RPC must not check the credential.%0A *%0A * %3Cp%3E%0A * The feature in question of Windows is called %22ForceGuest%22, and it's recorded in the registry at%0A * HKLM%5CSYSTEM%5CCurrentControlSet%5CControl%5CLSA%5Cforceguest (0=classic, 1=forceguest).%0A * %3Chttp://support.microsoft.com/kb/290403%3E%0A *%0A * @author Kohsuke Kawaguchi%0A */%0Apublic class DCOMSandbox %7B%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        new JIComOxidStub(%22129.145.133.224%22, %22%22, %22bogus%22, %22bogus%22).serverAlive();%0A    %7D%0A%0A    static final class JIComOxidStub extends Stub %7B%0A%0A        private static Properties defaults = new Properties();%0A%0A        static %7B%0A                defaults.put(%22rpc.ntlm.lanManagerKey%22,%22false%22);%0A                defaults.put(%22rpc.ntlm.sign%22,%22false%22);%0A                defaults.put(%22rpc.ntlm.seal%22,%22false%22);%0A                defaults.put(%22rpc.ntlm.keyExchange%22,%22false%22);%0A                defaults.put(%22rpc.connectionContext%22,%22rpc.security.ntlm.NtlmConnectionContext%22);%0A        %7D%0A%0A        protected String getSyntax() %7B%0A            return %2299fcfec4-5260-101b-bbcb-00aa0021347a:0.0%22;%0A        %7D%0A%0A        public JIComOxidStub(String address, String domain, String username, String password) %7B%0A            setTransportFactory(JIComTransportFactory.getSingleTon());%0A            setProperties(new Properties(defaults));%0A            getProperties().setProperty(%22rpc.security.username%22, username);%0A            getProperties().setProperty(%22rpc.security.password%22, password);%0A            getProperties().setProperty(%22rpc.ntlm.domain%22, domain);%0A            setAddress(%22ncacn_ip_tcp:%22 + address + %22%5B135%5D%22);%0A%0A        %7D%0A%0A        public void serverAlive() throws Exception %7B%0A            call(Endpoint.IDEMPOTENT, new ServerAlive());%0A        %7D%0A    %7D%0A%0A    static class ServerAlive extends NdrObject %7B%0A        // see http://www.hsc.fr/ressources/articles/win_net_srv/rpcss_dcom_interfaces.html%0A%0A        public int getOpnum() %7B%0A            return 3;%0A        %7D%0A%0A        public void write(NetworkDataRepresentation ndr) %7B%0A            // no parameter%0A        %7D%0A%0A        public void read(NetworkDataRepresentation ndr) %7B%0A            System.out.println(%22Got %22 + ndr.readUnsignedLong());%0A        %7D%0A    %7D%0A%7D%0A

recording my failed experiment.