Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit e1e6508fec
1095 changed files with 230566 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE Buffer Exception Class
*/
public class DCEBufferException extends Exception
{
private static final long serialVersionUID = 3833460725724494132L;
/**
* Class constructor
*/
public DCEBufferException()
{
super();
}
/**
* Class constructor
*
* @param str String
*/
public DCEBufferException(String str)
{
super(str);
}
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Command Codes
*/
public class DCECommand
{
// DCE/RPC Packet Types
public final static byte REQUEST = 0x00;
public final static byte RESPONSE = 0x02;
public final static byte FAULT = 0x03;
public final static byte BIND = 0x0B;
public final static byte BINDACK = 0x0C;
public final static byte ALTCONT = 0x0E;
public final static byte AUTH3 = 0x0F;
public final static byte BINDCONT = 0x10;
/**
* Convert the command type to a string
*
* @param cmd int
* @return String
*/
public final static String getCommandString(int cmd)
{
// Determine the PDU command type
String ret = "";
switch (cmd)
{
case REQUEST:
ret = "Request";
break;
case RESPONSE:
ret = "Repsonse";
break;
case FAULT:
ret = "Fault";
break;
case BIND:
ret = "Bind";
break;
case BINDACK:
ret = "BindAck";
break;
case ALTCONT:
ret = "AltCont";
break;
case AUTH3:
ret = "Auth3";
break;
case BINDCONT:
ret = "BindCont";
break;
}
return ret;
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
import org.alfresco.filesys.util.DataPacker;
/**
* DCE Data Packer Class
*/
public class DCEDataPacker
{
/**
* Unpack a DCE string from the buffer
*
* @param buf byte[]
* @param off int
* @return String
* @exception java.lang.IndexOutOfBoundsException If there is not enough data in the buffer.
*/
public final static String getDCEString(byte[] buf, int off) throws IndexOutOfBoundsException
{
// Check if the buffer is big enough to hold the String header
if (buf.length < off + 12)
throw new IndexOutOfBoundsException();
// Get the maximum and actual string length
int maxLen = DataPacker.getIntelInt(buf, off);
int strLen = DataPacker.getIntelInt(buf, off + 8);
// Read the Unicode string
return DataPacker.getUnicodeString(buf, off + 12, strLen);
}
/**
* Pack a DCE string into the buffer
*
* @param buf byte[]
* @param off int
* @param str String
* @param incNul boolean
* @return int
*/
public final static int putDCEString(byte[] buf, int off, String str, boolean incNul)
{
// Pack the string header
DataPacker.putIntelInt(str.length() + 1, buf, off);
DataPacker.putZeros(buf, off + 4, 4);
if (incNul == false)
DataPacker.putIntelInt(str.length(), buf, off + 8);
else
DataPacker.putIntelInt(str.length() + 1, buf, off + 8);
// Pack the string
return DataPacker.putUnicodeString(str, buf, off + 12, incNul);
}
/**
* Align a buffer offset on a longword boundary
*
* @param pos int
* @return int
*/
public final static int wordAlign(int pos)
{
return (pos + 1) & 0xFFFFFFFE;
}
/**
* Align a buffer offset on a longword boundary
*
* @param pos int
* @return int
*/
public final static int longwordAlign(int pos)
{
return (pos + 3) & 0xFFFFFFFC;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Exception Class
*/
public class DCEException extends Exception
{
private static final long serialVersionUID = 3258688788954625072L;
/**
* Class constructor
*
* @param str String
*/
public DCEException(String str)
{
super(str);
}
}

View File

@@ -0,0 +1,332 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
import java.util.Vector;
/**
* DCE/RPC List Class
* <p>
* Base class for lists of objects that are DCE/RPC readable and/or writeable.
*/
public abstract class DCEList
{
// Information level
private int m_infoLevel;
// List of DCE/RPC readable/writeable objects
private Vector<Object> m_dceObjects;
/**
* Default constructor
*/
protected DCEList()
{
m_dceObjects = new Vector<Object>();
}
/**
* Class constructor
*
* @param infoLevel int
*/
protected DCEList(int infoLevel)
{
m_dceObjects = new Vector<Object>();
m_infoLevel = infoLevel;
}
/**
* Class constructor
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
protected DCEList(DCEBuffer buf) throws DCEBufferException
{
// Read the header from the DCE/RPC buffer that contains the information level and container
// pointer
m_infoLevel = buf.getInt();
buf.skipBytes(4);
if (buf.getPointer() != 0)
{
// Indicate that the container is valid
m_dceObjects = new Vector<Object>();
}
else
{
// Container is not valid, no more data to follow
m_dceObjects = null;
}
}
/**
* Return the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Return the number of entries in the list
*
* @return int
*/
public final int numberOfEntries()
{
return m_dceObjects != null ? m_dceObjects.size() : 0;
}
/**
* Return the object list
*
* @return Vector
*/
public final Vector getList()
{
return m_dceObjects;
}
/**
* Return an element from the list
*
* @param idx int
* @return Object
*/
public final Object getElement(int idx)
{
// Range check the index
if (m_dceObjects == null || idx < 0 || idx >= m_dceObjects.size())
return null;
// Return the object
return m_dceObjects.elementAt(idx);
}
/**
* Determine if the container is valid
*
* @return boolean
*/
protected final boolean containerIsValid()
{
return m_dceObjects != null ? true : false;
}
/**
* Add an object to the list
*
* @param obj Object
*/
protected final void addObject(Object obj)
{
m_dceObjects.addElement(obj);
}
/**
* Set the information level
*
* @param infoLevel int
*/
protected final void setInformationLevel(int infoLevel)
{
m_infoLevel = infoLevel;
}
/**
* Set the object list
*
* @param list Vector
*/
protected final void setList(Vector<Object> list)
{
m_dceObjects = list;
}
/**
* Get a new object for the list to fill in
*
* @return DCEReadable
*/
protected abstract DCEReadable getNewObject();
/**
* Read a list of objects from the DCE buffer
*
* @param buf DCEBuffer
* @throws DCEBufferException
*/
public void readList(DCEBuffer buf) throws DCEBufferException
{
// Check if the container is valid, if so the object list will be valid
if (containerIsValid() == false)
return;
// Read the container object count and array pointer
int numEntries = buf.getInt();
if (buf.getPointer() != 0)
{
// Get the array element count
int elemCnt = buf.getInt();
if (elemCnt > 0)
{
// Read in the array elements
while (elemCnt-- > 0)
{
// Create a readable object and add to the list
DCEReadable element = getNewObject();
addObject(element);
// Load the main object details
element.readObject(buf);
}
// Load the strings for the readable information objects
for (int i = 0; i < numberOfEntries(); i++)
{
// Get a readable object
DCEReadable element = (DCEReadable) getList().elementAt(i);
// Load the strings for the readable object
element.readStrings(buf);
}
}
}
}
/**
* Write the list of objects to a DCE buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public final void writeList(DCEBuffer buf) throws DCEBufferException
{
// Pack the container header
buf.putInt(getInformationLevel());
buf.putInt(getInformationLevel());
// Check if the object list is valid
if (m_dceObjects != null)
{
// Add a pointer to the container and the number of objects
buf.putPointer(true);
buf.putInt(m_dceObjects.size());
// Add the pointer to the array of objects and number of objects
buf.putPointer(true);
buf.putInt(m_dceObjects.size());
// Create a seperate DCE buffer to build the string list which may follow the main
// object list, depending on the object
DCEBuffer strBuf = new DCEBuffer();
// Pack the object information
for (int i = 0; i < m_dceObjects.size(); i++)
{
// Get an object from the list
DCEWriteable object = (DCEWriteable) m_dceObjects.elementAt(i);
// Write the object to the buffer, strings may go into the seperate string buffer
// which will be appended
// to the main buffer after all the objects have been written
object.writeObject(buf, strBuf);
}
// If the string buffer has been used append it to the main buffer
buf.putBuffer(strBuf);
// Add the trailing list size
buf.putInt(m_dceObjects.size());
// Add the enum handle
buf.putInt(0);
}
else
{
// Add an empty container/array
buf.putZeroInts(4);
}
}
/**
* Return the list as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[Level=");
str.append(getInformationLevel());
str.append(",Entries=");
str.append(numberOfEntries());
str.append(",Class=");
str.append(getNewObject().getClass().getName());
str.append("]");
return str.toString();
}
}

View File

@@ -0,0 +1,188 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* <p>
* Defines the special DCE/RPC pipe names.
*/
public class DCEPipeType
{
// IPC$ client pipe names
private static final String[] _pipeNames = { "\\PIPE\\srvsvc",
"\\PIPE\\samr",
"\\PIPE\\winreg",
"\\PIPE\\wkssvc",
"\\PIPE\\NETLOGON",
"\\PIPE\\lsarpc",
"\\PIPE\\spoolss",
"\\PIPE\\netdfs",
"\\PIPE\\svcctl",
"\\PIPE\\EVENTLOG",
"\\PIPE\\NETLOGON"
};
// IPC$ server pipe names
private static final String[] _srvNames = { "\\PIPE\\ntsvcs",
"\\PIPE\\lsass",
"\\PIPE\\winreg",
"\\PIPE\\ntsvcs",
"\\PIPE\\lsass",
"\\PIPE\\lsass",
"\\PIPE\\spoolss",
"\\PIPE\\netdfs",
"\\PIPE\\svcctl",
"\\PIPE\\EVENTLOG"
};
// IPC$ pipe ids
public static final int PIPE_SRVSVC = 0;
public static final int PIPE_SAMR = 1;
public static final int PIPE_WINREG = 2;
public static final int PIPE_WKSSVC = 3;
public static final int PIPE_NETLOGON = 4;
public static final int PIPE_LSARPC = 5;
public static final int PIPE_SPOOLSS = 6;
public static final int PIPE_NETDFS = 7;
public static final int PIPE_SVCCTL = 8;
public static final int PIPE_EVENTLOG = 9;
public static final int PIPE_NETLOGON1= 10;
// IPC$ pipe UUIDs
private static UUID _uuidNetLogon = new UUID("8a885d04-1ceb-11c9-9fe8-08002b104860", 2);
private static UUID _uuidWinReg = new UUID("338cd001-2244-31f1-aaaa-900038001003", 1);
private static UUID _uuidSvcCtl = new UUID("367abb81-9844-35f1-ad32-98f038001003", 2);
private static UUID _uuidLsaRpc = new UUID("12345678-1234-abcd-ef00-0123456789ab", 0);
private static UUID _uuidSrvSvc = new UUID("4b324fc8-1670-01d3-1278-5a47bf6ee188", 3);
private static UUID _uuidWksSvc = new UUID("6bffd098-a112-3610-9833-46c3f87e345a", 1);
private static UUID _uuidSamr = new UUID("12345778-1234-abcd-ef00-0123456789ac", 1);
private static UUID _uuidSpoolss = new UUID("12345778-1234-abcd-ef00-0123456789ab", 1);
private static UUID _uuidSvcctl = new UUID("367abb81-9844-35f1-ad32-98f038001003", 2);
private static UUID _uuidEventLog = new UUID("82273FDC-E32A-18C3-3F78-827929DC23EA", 0);
private static UUID _uuidNetLogon1= new UUID("12345678-1234-abcd-ef00-01234567cffb", 1);
// private static UUID _uuidAtSvc = new UUID("1ff70682-0a51-30e8-076d-740be8cee98b", 1);
/**
* Convert a pipe name to a type
*
* @param name String
* @return int
*/
public final static int getNameAsType(String name)
{
for (int i = 0; i < _pipeNames.length; i++)
{
if (_pipeNames[i].equals(name))
return i;
}
return -1;
}
/**
* Convert a pipe type to a name
*
* @param typ int
* @return String
*/
public final static String getTypeAsString(int typ)
{
if (typ >= 0 && typ < _pipeNames.length)
return _pipeNames[typ];
return null;
}
/**
* Convert a pipe type to a short name
*
* @param typ int
* @return String
*/
public final static String getTypeAsStringShort(int typ)
{
if (typ >= 0 && typ < _pipeNames.length)
{
String name = _pipeNames[typ];
return name.substring(5);
}
return null;
}
/**
* Return the UUID for the pipe type
*
* @param typ int
* @return UUID
*/
public final static UUID getUUIDForType(int typ)
{
UUID ret = null;
switch (typ)
{
case PIPE_NETLOGON:
ret = _uuidNetLogon;
break;
case PIPE_NETLOGON1:
ret = _uuidNetLogon1;
break;
case PIPE_WINREG:
ret = _uuidWinReg;
break;
case PIPE_LSARPC:
ret = _uuidLsaRpc;
break;
case PIPE_WKSSVC:
ret = _uuidWksSvc;
break;
case PIPE_SAMR:
ret = _uuidSamr;
break;
case PIPE_SRVSVC:
ret = _uuidSrvSvc;
break;
case PIPE_SPOOLSS:
ret = _uuidSpoolss;
break;
case PIPE_SVCCTL:
ret = _uuidSvcCtl;
break;
case PIPE_EVENTLOG:
ret = _uuidEventLog;
break;
}
return ret;
}
/**
* Get the server-side pipe name for the specified pipe
*
* @param typ int
* @return String
*/
public final static String getServerPipeName(int typ)
{
if (typ >= 0 && typ < _srvNames.length)
return _srvNames[typ];
return null;
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Readable Interface
* <p>
* A class that implements the DCEReadable interface can load itself from a DCE buffer.
*/
public interface DCEReadable
{
/**
* Read the object state from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException;
/**
* Read the strings for object from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readStrings(DCEBuffer buf) throws DCEBufferException;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Readable List Interface
* <p>
* A class that implements the DCEReadableList interface can read a list of DCEReadable objects from
* a DCE/RPC buffer.
*/
public interface DCEReadableList
{
/**
* Read the object state from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException;
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Writeable Interface
* <p>
* A class that implements the DCEWriteable interface can save itself to a DCE buffer.
*/
public interface DCEWriteable
{
/**
* Write the object state to DCE/RPC buffers.
* <p>
* If a list of objects is being written the strings will be written after the objects so the
* second buffer will be specified.
* <p>
* If a single object is being written to the buffer the second buffer may be null or be the
* same buffer as the main buffer.
*
* @param buf DCEBuffer
* @param strBuf DCEBuffer
* @exception DCEBufferException
*/
public void writeObject(DCEBuffer buf, DCEBuffer strBuf) throws DCEBufferException;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* DCE/RPC Writeable List Interface
* <p>
* A class that implements the DCEWriteableList interface can write a list of DCEWriteable objects
* to a DCE/RPC buffer.
*/
public interface DCEWriteableList
{
/**
* Write the object state to DCE/RPC buffers.
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void writeObject(DCEBuffer buf) throws DCEBufferException;
}

View File

@@ -0,0 +1,215 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* Policy Handle Class
*/
public class PolicyHandle
{
// Length of a policy handle
public static final int POLICY_HANDLE_SIZE = 20;
// Policy handle bytes
private byte[] m_handle;
// Handle name
private String m_name;
/**
* Default constructor
*/
public PolicyHandle()
{
setName("");
}
/**
* Class constructor
*
* @param buf byte[]
* @param off int
*/
public PolicyHandle(byte[] buf, int off)
{
initialize(buf, off);
setName("");
}
/**
* Class constructor
*
* @param name String
* @param buf byte[]
* @param off int
*/
public PolicyHandle(String name, byte[] buf, int off)
{
initialize(buf, off);
setName(name);
}
/**
* Determine if the policy handle is valid
*
* @return boolean
*/
public final boolean isValid()
{
return m_handle != null ? true : false;
}
/**
* Return the policy handle bytes
*
* @return byte[]
*/
public final byte[] getBytes()
{
return m_handle;
}
/**
* Return the policy handle name
*
* @return String
*/
public final String getName()
{
return m_name;
}
/**
* Set the policy handle name
*
* @param name String
*/
public final void setName(String name)
{
m_name = name;
}
/**
* Store the policy handle into the specified buffer
*
* @param buf byte[]
* @param off int
* @return int
*/
public final int storePolicyHandle(byte[] buf, int off)
{
// Check if the policy handle is valid
if (isValid() == false)
return -1;
// Copy the policy handle bytes to the user buffer
for (int i = 0; i < POLICY_HANDLE_SIZE; i++)
buf[off + i] = m_handle[i];
// Return the new buffer position
return off + POLICY_HANDLE_SIZE;
}
/**
* Load the policy handle from the specified buffer
*
* @param buf byte[]
* @param off int
* @return int
*/
public final int loadPolicyHandle(byte[] buf, int off)
{
// Load the policy handle from the buffer
initialize(buf, off);
return off + POLICY_HANDLE_SIZE;
}
/**
* Clear the handle
*/
protected final void clearHandle()
{
m_handle = null;
}
/**
* Initialize the policy handle
*
* @param buf byte[]
* @param off int
*/
private final void initialize(byte[] buf, int off)
{
// Copy the policy handle bytes
if ((off + POLICY_HANDLE_SIZE) <= buf.length)
{
// Allocate the policy handle buffer
m_handle = new byte[POLICY_HANDLE_SIZE];
// Copy the policy handle
for (int i = 0; i < POLICY_HANDLE_SIZE; i++)
m_handle[i] = buf[off + i];
}
}
/**
* Return the policy handle as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
if (getName() != null)
str.append(getName());
str.append(":");
if (isValid())
{
for (int i = 0; i < POLICY_HANDLE_SIZE; i++)
{
int val = (int) (m_handle[i] & 0xFF);
if (val <= 16)
str.append("0");
str.append(Integer.toHexString(val).toUpperCase());
str.append("-");
}
str.setLength(str.length() - 1);
str.append("]");
}
return str.toString();
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* Policy Handle Cache Class
*/
public class PolicyHandleCache
{
// Policy handles
private Hashtable<String, PolicyHandle> m_cache;
/**
* Default constructor
*/
public PolicyHandleCache()
{
m_cache = new Hashtable<String, PolicyHandle>();
}
/**
* Return the number of handles in the cache
*
* @return int
*/
public final int numberOfHandles()
{
return m_cache.size();
}
/**
* Add a handle to the cache
*
* @param name String
* @param handle PolicyHandle
*/
public final void addHandle(String name, PolicyHandle handle)
{
m_cache.put(name, handle);
}
/**
* Return the handle for the specified index
*
* @param index String
* @return PolicyHandle
*/
public final PolicyHandle findHandle(String index)
{
return m_cache.get(index);
}
/**
* Delete a handle from the cache
*
* @param index String
* @return PolicyHandle
*/
public final PolicyHandle removeHandle(String index)
{
return m_cache.remove(index);
}
/**
* Enumerate the handles in the cache
*
* @return Enumeration<PolicyHandle>
*/
public final Enumeration<PolicyHandle> enumerateHandles()
{
return m_cache.elements();
}
/**
* Clear all handles from the cache
*/
public final void removeAllHandles()
{
m_cache.clear();
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* Srvsvc Operation Ids Class
*/
public class Srvsvc
{
// Srvsvc opcodes
public static final int NetrServerGetInfo = 0x15;
public static final int NetrServerSetInfo = 0x16;
public static final int NetrShareEnum = 0x0F;
public static final int NetrShareEnumSticky = 0x24;
public static final int NetrShareGetInfo = 0x10;
public static final int NetrShareSetInfo = 0x11;
public static final int NetrShareAdd = 0x0E;
public static final int NetrShareDel = 0x12;
public static final int NetrSessionEnum = 0x0C;
public static final int NetrSessionDel = 0x0D;
public static final int NetrConnectionEnum = 0x08;
public static final int NetrFileEnum = 0x09;
public static final int NetrRemoteTOD = 0x1C;
/**
* Convert an opcode to a function name
*
* @param opCode int
* @return String
*/
public final static String getOpcodeName(int opCode)
{
String ret = "";
switch (opCode)
{
case NetrServerGetInfo:
ret = "NetrServerGetInfo";
break;
case NetrServerSetInfo:
ret = "NetrServerSetInfo";
break;
case NetrShareEnum:
ret = "NetrShareEnum";
break;
case NetrShareEnumSticky:
ret = "NetrShareEnumSticky";
break;
case NetrShareGetInfo:
ret = "NetrShareGetInfo";
break;
case NetrShareSetInfo:
ret = "NetrShareSetInfo";
break;
case NetrShareAdd:
ret = "NetrShareAdd";
break;
case NetrShareDel:
ret = "NetrShareDel";
break;
case NetrSessionEnum:
ret = "NetrSessionEnum";
break;
case NetrSessionDel:
ret = "NetrSessionDel";
break;
case NetrConnectionEnum:
ret = "NetrConnectionEnum";
break;
case NetrFileEnum:
ret = "NetrFileEnum";
break;
case NetrRemoteTOD:
ret = "NetrRemoteTOD";
break;
}
return ret;
}
}

View File

@@ -0,0 +1,407 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
import org.alfresco.filesys.util.DataPacker;
/**
* Universal Unique Identifier Class
*/
public class UUID
{
// UUID constants
public static final int UUID_LENGTH = 36;
public static final int UUID_LENGTH_BINARY = 16;
private static final String UUID_VALIDCHARS = "0123456789ABCDEFabcdef";
// UUID string
private String m_uuid;
// Interface version
private int m_ifVersion;
// UUID bytes
private byte[] m_uuidBytes;
/**
* Class constructor
*
* @param id String
*/
public UUID(String id)
{
if (validateUUID(id))
{
m_uuid = id;
m_ifVersion = 1;
}
}
/**
* Class constructor
*
* @param id String
* @param ver int
*/
public UUID(String id, int ver)
{
if (validateUUID(id))
{
m_uuid = id;
m_ifVersion = ver;
}
}
/**
* Class constructor
*
* @param buf byte[]
* @param off int
*/
public UUID(byte[] buf, int off)
{
// Copy the UUID bytes and generate the UUID string
if ((off + UUID_LENGTH_BINARY) <= buf.length)
{
// Take a copy of the UUID bytes
m_uuidBytes = new byte[UUID_LENGTH_BINARY];
for (int i = 0; i < UUID_LENGTH_BINARY; i++)
m_uuidBytes[i] = buf[off + i];
// Generate the string version of the UUID
m_uuid = generateUUIDString(m_uuidBytes);
}
}
/**
* Determine if the UUID is valid
*
* @return boolean
*/
public final boolean isValid()
{
return m_uuid != null ? true : false;
}
/**
* Return the UUID string
*
* @return String
*/
public final String getUUID()
{
return m_uuid;
}
/**
* Return the interface version
*
* @return int
*/
public final int getVersion()
{
return m_ifVersion;
}
/**
* Set the interface version
*
* @param ver int
*/
public final void setVersion(int ver)
{
m_ifVersion = ver;
}
/**
* Return the UUID as a byte array
*
* @return byte[]
*/
public final byte[] getBytes()
{
// Check if the byte array has been created
if (m_uuidBytes == null)
{
// Allocate the byte array
m_uuidBytes = new byte[UUID_LENGTH_BINARY];
try
{
// Convert the first integer and pack into the buffer
String val = m_uuid.substring(0, 8);
long lval = Long.parseLong(val, 16);
DataPacker.putIntelInt((int) (lval & 0xFFFFFFFF), m_uuidBytes, 0);
// Convert the second word and pack into the buffer
val = m_uuid.substring(9, 13);
int ival = Integer.parseInt(val, 16);
DataPacker.putIntelShort(ival, m_uuidBytes, 4);
// Convert the third word and pack into the buffer
val = m_uuid.substring(14, 18);
ival = Integer.parseInt(val, 16);
DataPacker.putIntelShort(ival, m_uuidBytes, 6);
// Convert the fourth word and pack into the buffer
val = m_uuid.substring(19, 23);
ival = Integer.parseInt(val, 16);
DataPacker.putShort((short) (ival & 0xFFFF), m_uuidBytes, 8);
// Convert the final block of hex pairs to bytes
int strPos = 24;
int bytPos = 10;
for (int i = 0; i < 6; i++)
{
val = m_uuid.substring(strPos, strPos + 2);
m_uuidBytes[bytPos++] = (byte) (Short.parseShort(val, 16) & 0xFF);
strPos += 2;
}
}
catch (NumberFormatException ex)
{
m_uuidBytes = null;
}
}
// Return the UUID bytes
return m_uuidBytes;
}
/**
* Validate a UUID string
*
* @param idStr String
* @reutrn boolean
*/
public static final boolean validateUUID(String idStr)
{
// Check if the UUID string is the correct length
if (idStr == null || idStr.length() != UUID_LENGTH)
return false;
// Check for seperators
if (idStr.charAt(8) != '-' || idStr.charAt(13) != '-' || idStr.charAt(18) != '-' || idStr.charAt(23) != '-')
return false;
// Check for hex digits
int i = 0;
for (i = 0; i < 8; i++)
if (UUID_VALIDCHARS.indexOf(idStr.charAt(i)) == -1)
return false;
for (i = 9; i < 13; i++)
if (UUID_VALIDCHARS.indexOf(idStr.charAt(i)) == -1)
return false;
for (i = 14; i < 18; i++)
if (UUID_VALIDCHARS.indexOf(idStr.charAt(i)) == -1)
return false;
for (i = 19; i < 23; i++)
if (UUID_VALIDCHARS.indexOf(idStr.charAt(i)) == -1)
return false;
for (i = 24; i < 36; i++)
if (UUID_VALIDCHARS.indexOf(idStr.charAt(i)) == -1)
return false;
// Valid UUID string
return true;
}
/**
* Generate a UUID string from the binary representation
*
* @param buf byte[]
* @return String
*/
public static final String generateUUIDString(byte[] buf)
{
// Build up the UUID string
StringBuffer str = new StringBuffer(UUID_LENGTH);
// Convert the first longword
int ival = DataPacker.getIntelInt(buf, 0);
str.append(Integer.toHexString(ival));
while (str.length() != 8)
str.insert(0, ' ');
str.append("-");
// Convert the second word
ival = DataPacker.getIntelShort(buf, 4) & 0xFFFF;
str.append(Integer.toHexString(ival));
while (str.length() != 13)
str.insert(9, '0');
str.append("-");
// Convert the third word
ival = DataPacker.getIntelShort(buf, 6) & 0xFFFF;
str.append(Integer.toHexString(ival));
while (str.length() != 18)
str.insert(14, '0');
str.append("-");
// Convert the remaining bytes
for (int i = 8; i < UUID_LENGTH_BINARY; i++)
{
// Get the current byte value and add to the string
ival = (int) (buf[i] & 0xFF);
if (ival < 16)
str.append('0');
str.append(Integer.toHexString(ival));
// Add the final seperator
if (i == 9)
str.append("-");
}
// Return the UUID string
return str.toString();
}
/**
* Compare a UUID with the current UUID
*
* @param id UUID
* @return boolean
*/
public final boolean compareTo(UUID id)
{
// Compare the UUID versions
if (getVersion() != id.getVersion())
return false;
// Compare the UUID bytes
byte[] thisBytes = getBytes();
byte[] idBytes = id.getBytes();
for (int i = 0; i < UUID_LENGTH_BINARY; i++)
if (thisBytes[i] != idBytes[i])
return false;
return true;
}
/**
* Write the binary UUID to the specified buffer, and optionally the UUID version
*
* @param buf byte[]
* @param off int
* @param writeVer boolean
* @return int
*/
public final int storeUUID(byte[] buf, int off, boolean writeVer)
{
// Get the UUID bytes
int pos = off;
byte[] uuidByts = getBytes();
if (uuidByts == null)
return pos;
// Write the binary UUID to the buffer
for (int i = 0; i < UUID_LENGTH_BINARY; i++)
buf[pos + i] = uuidByts[i];
pos += UUID_LENGTH_BINARY;
// Check if version should be written to the buffer
if (writeVer)
{
DataPacker.putIntelInt(getVersion(), buf, pos);
pos += 4;
}
// Return the new buffer position
return pos;
}
/**
* Return the UUID as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
str.append(m_uuid);
str.append(":");
str.append(m_ifVersion);
str.append("]");
return str.toString();
}
/***********************************************************************************************
* Test Code
*
* @param args String[]
*/
/**
* public final static void main(String[] args) { System.out.println("UUID Test");
* System.out.println("---------"); String[] uuids = { "12345678-1234-abcd-ef00-01234567cffb",
* "8a885d04-1ceb-11c9-9fe8-08002b104860", "338cd001-2244-31f1-aaaa-900038001003",
* "367abb81-9844-35f1-ad32-98f038001003", "4b324fc8-1670-01d3-1278-5a47bf6ee188",
* "6bffd098-a112-3610-9833-46c3f87e345a", "12345678-1234-abcd-ef00-0123456789ac",
* "12345778-1234-abcd-ef00-0123456789ab", "1ff70682-0a51-30e8-076d-740be8cee98b" }; // Validate
* and convert the UUIDs for ( int i = 0; i < uuids.length; i++) { UUID u = new UUID(uuids[i]);
* if ( u.isValid()) { System.out.println("" + (i+1) + ": " + u.toString()); byte[] bytes =
* u.getBytes(); HexDump.Dump(bytes,bytes.length, 0); System.out.println("Convert to string: " +
* generateUUIDString(bytes)); } else System.out.println("Invalid UUID: " + uuids[i]); } }
*/
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc;
/**
* Wkssvc Operation Ids Class
*/
public class Wkssvc
{
// Wkssvc opcodes
public static final int NetWkstaGetInfo = 0x00;
/**
* Convert an opcode to a function name
*
* @param opCode int
* @return String
*/
public final static String getOpcodeName(int opCode)
{
String ret = "";
switch (opCode)
{
case NetWkstaGetInfo:
ret = "NetWkstaGetInfo";
break;
}
return ret;
}
}

View File

@@ -0,0 +1,253 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
/**
* Connection Information Class
* <p>
* Contains the details of a connection on a remote server.
*/
public class ConnectionInfo implements DCEReadable
{
// Information level
private int m_infoLevel;
// Connection id and type
private int m_connId;
private int m_connType;
// Count of open files
private int m_openFiles;
// Number of users
private int m_numUsers;
// Time connected, in minutes
private int m_connTime;
// User name
private String m_userName;
// Client name
private String m_clientName;
/**
* Default constructor
*/
public ConnectionInfo()
{
}
/**
* Class constructor
*
* @param infoLevel int
*/
public ConnectionInfo(int infoLevel)
{
m_infoLevel = infoLevel;
}
/**
* Get the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Get the connection id
*
* @return int
*/
public final int getConnectionId()
{
return m_connId;
}
/**
* Get the connection type
*
* @return int
*/
public final int getConnectionType()
{
return m_connType;
}
/**
* Get the number of open files on the connection
*
* @return int
*/
public final int getOpenFileCount()
{
return m_openFiles;
}
/**
* Return the number of users on the connection
*
* @return int
*/
public final int getNumberOfUsers()
{
return m_numUsers;
}
/**
* Return the connection time in seconds
*
* @return int
*/
public final int getConnectionTime()
{
return m_connTime;
}
/**
* Return the user name
*
* @return String
*/
public final String getUserName()
{
return m_userName;
}
/**
* Return the client name
*
* @return String
*/
public final String getClientName()
{
return m_clientName;
}
/**
* Read a connection information object from a DCE buffer
*
* @param buf DCEBuffer
* @throws DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException
{
// Unpack the connection information
switch (getInformationLevel())
{
// Information level 0
case 0:
m_connId = buf.getInt();
m_userName = null;
m_clientName = null;
break;
// Information level 1
case 1:
m_connId = buf.getInt();
m_connType = buf.getInt();
m_openFiles = buf.getInt();
m_numUsers = buf.getInt();
m_connTime = buf.getInt();
m_userName = buf.getPointer() != 0 ? "" : null;
m_clientName = buf.getPointer() != 0 ? "" : null;
break;
}
}
/**
* Read the strings for this connection information from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readStrings(DCEBuffer buf) throws DCEBufferException
{
// Read the strings for this connection information
switch (getInformationLevel())
{
// Information level 1
case 1:
if (getUserName() != null)
m_userName = buf.getString(DCEBuffer.ALIGN_INT);
if (getClientName() != null)
m_clientName = buf.getString(DCEBuffer.ALIGN_INT);
break;
}
}
/**
* Return the connection information as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[ID=");
str.append(getConnectionId());
str.append(":Level=");
str.append(getInformationLevel());
str.append(":");
if (getInformationLevel() == 1)
{
str.append("Type=");
str.append(getConnectionType());
str.append(",OpenFiles=");
str.append(getOpenFileCount());
str.append(",NumUsers=");
str.append(getNumberOfUsers());
str.append(",Connected=");
str.append(getConnectionTime());
str.append(",User=");
str.append(getUserName());
str.append(",Client=");
str.append(getClientName());
}
str.append("]");
return str.toString();
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEList;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
/**
* Connection Information List Class
*/
public class ConnectionInfoList extends DCEList
{
/**
* Default constructor
*/
public ConnectionInfoList()
{
super();
}
/**
* Class constructor
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public ConnectionInfoList(DCEBuffer buf) throws DCEBufferException
{
super(buf);
}
/**
* Create a new connection information object
*
* @return DCEReadable
*/
protected DCEReadable getNewObject()
{
return new ConnectionInfo(getInformationLevel());
}
}

View File

@@ -0,0 +1,338 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
import org.alfresco.filesys.smb.dcerpc.DCEWriteable;
/**
* Server Information Class
*/
public class ServerInfo implements DCEWriteable, DCEReadable
{
// Information levels supported
public static final int InfoLevel0 = 0;
public static final int InfoLevel1 = 1;
public static final int InfoLevel101 = 101;
public static final int InfoLevel102 = 102;
// Server platform ids
public final static int PLATFORM_OS2 = 400;
public final static int PLATFORM_NT = 500;
// Information level
private int m_infoLevel;
// Server information
private int m_platformId;
private String m_name;
private int m_verMajor;
private int m_verMinor;
private int m_srvType;
private String m_comment;
/**
* Default constructor
*/
public ServerInfo()
{
}
/**
* Class constructor
*
* @param lev int
*/
public ServerInfo(int lev)
{
m_infoLevel = lev;
}
/**
* Get the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Get the server name
*
* @return String
*/
public final String getServerName()
{
return m_name;
}
/**
* Get the server comment
*
* @return String
*/
public final String getComment()
{
return m_comment;
}
/**
* Get the server platform id
*
* @return int
*/
public final int getPlatformId()
{
return m_platformId;
}
/**
* Get the servev major version
*
* @return int
*/
public final int getMajorVersion()
{
return m_verMajor;
}
/**
* Get the server minor version
*
* @return int
*/
public final int getMinorVersion()
{
return m_verMinor;
}
/**
* Get the server type flags
*
* @return int
*/
public final int getServerType()
{
return m_srvType;
}
/**
* Set the server name
*
* @param name String
*/
public final void setServerName(String name)
{
m_name = name;
}
/**
* Set the server comment
*
* @param comment String
*/
public final void setComment(String comment)
{
m_comment = comment;
}
/**
* Set the information level
*
* @param lev int
*/
public final void setInformationLevel(int lev)
{
m_infoLevel = lev;
}
/**
* Set the server platform id
*
* @param id int
*/
public final void setPlatformId(int id)
{
m_platformId = id;
}
/**
* Set the server type flags
*
* @param typ int
*/
public final void setServerType(int typ)
{
m_srvType = typ;
}
/**
* Set the server version
*
* @param verMajor int
* @param verMinor int
*/
public final void setVersion(int verMajor, int verMinor)
{
m_verMajor = verMajor;
m_verMinor = verMinor;
}
/**
* Clear the string values
*/
protected final void clearStrings()
{
// Clear the string values
m_name = null;
m_comment = null;
}
/**
* Read the server information from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException
{
// Clear the string values
clearStrings();
// Read the server information details
m_infoLevel = buf.getInt();
buf.skipPointer();
// Unpack the server information
switch (getInformationLevel())
{
// Information level 0
case InfoLevel0:
if (buf.getPointer() != 0)
m_name = buf.getString(DCEBuffer.ALIGN_INT);
break;
// Information level 101/1
case InfoLevel1:
case InfoLevel101:
m_platformId = buf.getInt();
buf.skipPointer();
m_verMajor = buf.getInt();
m_verMinor = buf.getInt();
m_srvType = buf.getInt();
buf.skipPointer();
m_name = buf.getString(DCEBuffer.ALIGN_INT);
m_comment = buf.getString();
break;
// Level 102
case InfoLevel102:
break;
}
}
/**
* Read the strings for this object from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readStrings(DCEBuffer buf) throws DCEBufferException
{
// Not required
}
/**
* Write a server information structure
*
* @param buf DCEBuffer
* @param strBuf DCEBuffer
*/
public void writeObject(DCEBuffer buf, DCEBuffer strBuf)
{
// Output the server information structure
buf.putInt(getInformationLevel());
buf.putPointer(true);
// Output the required information level
switch (getInformationLevel())
{
// Information level 0
case InfoLevel0:
buf.putPointer(getServerName() != null);
if (getServerName() != null)
strBuf.putString(getServerName(), DCEBuffer.ALIGN_INT, true);
break;
// Information level 101/1
case InfoLevel1:
case InfoLevel101:
buf.putInt(getPlatformId());
buf.putPointer(true);
buf.putInt(getMajorVersion());
buf.putInt(getMinorVersion());
buf.putInt(getServerType());
buf.putPointer(true);
strBuf.putString(getServerName(), DCEBuffer.ALIGN_INT, true);
strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
break;
// Level 102
case InfoLevel102:
break;
}
}
/**
* Return the server information as a string
*
* @return String
*/
public String toString()
{
return "";
}
}

View File

@@ -0,0 +1,610 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
import org.alfresco.filesys.smb.dcerpc.DCEWriteable;
/**
* Share Information Class
* <p>
* Holds the details of a share from a DCE/RPC request/response.
*/
public class ShareInfo implements DCEWriteable, DCEReadable
{
// Information levels supported
public static final int InfoLevel0 = 0;
public static final int InfoLevel1 = 1;
public static final int InfoLevel2 = 2;
public static final int InfoLevel502 = 502;
public static final int InfoLevel1005 = 1005;
// Share types
public static final int Disk = 0x00000000;
public static final int PrintQueue = 0x00000001;
public static final int Device = 0x00000002;
public static final int IPC = 0x00000003;
public static final int Hidden = 0x80000000;
// Share permission flags
public static final int Read = 0x01;
public static final int Write = 0x02;
public static final int Create = 0x04;
public static final int Execute = 0x08;
public static final int Delete = 0x10;
public static final int Attrib = 0x20;
public static final int Perm = 0x40;
public static final int All = 0x7F;
// Information level
private int m_infoLevel;
// Share details
private String m_name;
private int m_type;
private String m_comment;
private int m_permissions;
private int m_maxUsers;
private int m_curUsers;
private String m_path;
private String m_password;
private int m_flags;
/**
* Class constructor
*/
public ShareInfo()
{
}
/**
* Class constructor
*
* @param lev int
*/
public ShareInfo(int lev)
{
m_infoLevel = lev;
}
/**
* Class constructor
*
* @param lev int
* @param name String
* @param typ int
* @param comment String
*/
public ShareInfo(int lev, String name, int typ, String comment)
{
m_infoLevel = lev;
m_name = name;
m_type = typ;
m_comment = comment;
}
/**
* Return the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Return the share name
*
* @return String
*/
public final String getName()
{
return m_name;
}
/**
* Return the share type
*
* @return int
*/
public final int getType()
{
return m_type;
}
/**
* Get the share flags
*
* @return int
*/
public final int getFlags()
{
return m_flags;
}
/**
* Check if this share is a hidden/admin share
*
* @return boolean
*/
public final boolean isHidden()
{
return (m_type & Hidden) != 0 ? true : false;
}
/**
* Check if this is a disk share
*
* @return boolean
*/
public final boolean isDisk()
{
return (m_type & 0x0000FFFF) == Disk ? true : false;
}
/**
* Check if this is a printer share
*
* @return boolean
*/
public final boolean isPrinter()
{
return (m_type & 0x0000FFFF) == PrintQueue ? true : false;
}
/**
* Check if this is a device share
*
* @return boolean
*/
public final boolean isDevice()
{
return (m_type & 0x0000FFFF) == Device ? true : false;
}
/**
* Check if this is a named pipe share
*
* @return boolean
*/
public final boolean isNamedPipe()
{
return (m_type & 0x0000FFFF) == IPC ? true : false;
}
/**
* Return the share permissions
*
* @return int
*/
public final int getPermissions()
{
return m_permissions;
}
/**
* Return the maximum number of users allowed
*
* @return int
*/
public final int getMaximumUsers()
{
return m_maxUsers;
}
/**
* Return the current number of users
*
* @return int
*/
public final int getCurrentUsers()
{
return m_curUsers;
}
/**
* Return the share local path
*
* @return String
*/
public final String getPath()
{
return m_path;
}
/**
* Return the share password
*
* @return String
*/
public final String getPassword()
{
return m_password;
}
/**
* Return the share type as a string
*
* @return String
*/
public final String getTypeAsString()
{
String typ = "";
switch (getType() & 0xFF)
{
case Disk:
typ = "Disk";
break;
case PrintQueue:
typ = "Printer";
break;
case Device:
typ = "Device";
break;
case IPC:
typ = "IPC";
break;
}
return typ;
}
/**
* Return the comment
*
* @return String
*/
public final String getComment()
{
return m_comment;
}
/**
* Set the information level
*
* @param lev int
*/
public final void setInformationLevel(int lev)
{
m_infoLevel = lev;
}
/**
* Set the share type
*
* @param int typ
*/
public final void setType(int typ)
{
m_type = typ;
}
/**
* Set the share flags
*
* @param flags int
*/
public final void setFlags(int flags)
{
m_flags = flags;
}
/**
* Set the share name
*
* @param name String
*/
public final void setName(String name)
{
m_name = name;
}
/**
* Set the share comment
*
* @param str String
*/
public final void setComment(String str)
{
m_comment = str;
}
/**
* Set the share permissions
*
* @param perm int
*/
public final void setPermissions(int perm)
{
m_permissions = perm;
}
/**
* Set the maximum number of users
*
* @param maxUsers int
*/
public final void setMaximumUsers(int maxUsers)
{
m_maxUsers = maxUsers;
}
/**
* Set the current number of users
*
* @param curUsers int
*/
public final void setCurrentUsers(int curUsers)
{
m_curUsers = curUsers;
}
/**
* Set the local path
*
* @param path String
*/
public final void setPath(String path)
{
m_path = path;
}
/**
* Clear all string values
*/
protected final void clearStrings()
{
// Clear the string values
m_name = null;
m_comment = null;
m_path = null;
m_password = null;
}
/**
* Read the share information from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException
{
// Clear all existing strings
clearStrings();
// Unpack the share information
switch (getInformationLevel())
{
// Information level 0
case InfoLevel0:
m_name = buf.getPointer() != 0 ? "" : null;
break;
// Information level 1
case InfoLevel1:
m_name = buf.getPointer() != 0 ? "" : null;
m_type = buf.getInt();
m_comment = buf.getPointer() != 0 ? "" : null;
break;
// Information level 2
case InfoLevel2:
m_name = buf.getPointer() != 0 ? "" : null;
m_type = buf.getInt();
m_comment = buf.getPointer() != 0 ? "" : null;
m_permissions = buf.getInt();
m_maxUsers = buf.getInt();
m_curUsers = buf.getInt();
m_path = buf.getPointer() != 0 ? "" : null;
m_password = buf.getPointer() != 0 ? "" : null;
break;
// Information level 502
case InfoLevel502:
m_name = buf.getPointer() != 0 ? "" : null;
m_type = buf.getInt();
m_comment = buf.getPointer() != 0 ? "" : null;
m_permissions = buf.getInt();
m_maxUsers = buf.getInt();
m_curUsers = buf.getInt();
m_path = buf.getPointer() != 0 ? "" : null;
m_password = buf.getPointer() != 0 ? "" : null;
buf.skipBytes(4); // Reserved value
// Security descriptor
break;
}
}
/**
* Read the strings for this share from the DCE/RPC buffer
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public void readStrings(DCEBuffer buf) throws DCEBufferException
{
// Read the strings for this share information
switch (getInformationLevel())
{
// Information level 0
case InfoLevel0:
if (getName() != null)
m_name = buf.getString(DCEBuffer.ALIGN_INT);
break;
// Information level 1
case InfoLevel1:
if (getName() != null)
m_name = buf.getString(DCEBuffer.ALIGN_INT);
if (getComment() != null)
m_comment = buf.getString(DCEBuffer.ALIGN_INT);
break;
// Information level 2 and 502
case InfoLevel2:
case InfoLevel502:
if (getName() != null)
m_name = buf.getString(DCEBuffer.ALIGN_INT);
if (getComment() != null)
m_comment = buf.getString(DCEBuffer.ALIGN_INT);
if (getPath() != null)
m_path = buf.getString(DCEBuffer.ALIGN_INT);
if (getPassword() != null)
m_password = buf.getString(DCEBuffer.ALIGN_INT);
break;
}
}
/**
* Write the share information to the DCE buffer
*
* @param buf DCEBuffer
* @param strBuf DCEBuffer
*/
public void writeObject(DCEBuffer buf, DCEBuffer strBuf)
{
// Pack the share information
switch (getInformationLevel())
{
// Information level 0
case InfoLevel0:
buf.putPointer(true);
strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
break;
// Information level 1
case InfoLevel1:
buf.putPointer(true);
buf.putInt(getType());
buf.putPointer(true);
strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
break;
// Information level 2
case InfoLevel2:
buf.putPointer(true);
buf.putInt(getType());
buf.putPointer(true);
buf.putInt(getPermissions());
buf.putInt(getMaximumUsers());
buf.putInt(getCurrentUsers());
buf.putPointer(getPath() != null);
buf.putPointer(getPassword() != null);
strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
if (getPath() != null)
strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true);
if (getPassword() != null)
strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true);
break;
// Information level 502
case InfoLevel502:
buf.putPointer(true);
buf.putInt(getType());
buf.putPointer(true);
buf.putInt(getPermissions());
buf.putInt(getMaximumUsers());
buf.putInt(getCurrentUsers());
buf.putPointer(getPath() != null);
buf.putPointer(getPassword() != null);
buf.putInt(0); // Reserved, must be zero
buf.putPointer(false); // Security descriptor
strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
if (getPath() != null)
strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true);
if (getPassword() != null)
strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true);
break;
// Information level 1005
case InfoLevel1005:
buf.putInt(getFlags());
break;
}
}
/**
* Return the share information as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
str.append(getName());
str.append(":");
str.append(getInformationLevel());
str.append(":");
if (getInformationLevel() == 1)
{
str.append("0x");
str.append(Integer.toHexString(getType()));
str.append(",");
str.append(getComment());
}
str.append("]");
return str.toString();
}
}

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import java.util.Vector;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEList;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
/**
* Server Share Information List Class
* <p>
* Holds the details for a DCE/RPC share enumeration request or response.
*/
public class ShareInfoList extends DCEList
{
/**
* Default constructor
*/
public ShareInfoList()
{
super();
}
/**
* Class constructor
*
* @param buf DCEBuffer
* @exception DCEBufferException
*/
public ShareInfoList(DCEBuffer buf) throws DCEBufferException
{
super(buf);
}
/**
* Class constructor
*
* @param infoLevel int
*/
public ShareInfoList(int infoLevel)
{
super(infoLevel);
}
/**
* Return share information object from the list
*
* @param idx int
* @return ShareInfo
*/
public final ShareInfo getShare(int idx)
{
return (ShareInfo) getElement(idx);
}
/**
* Create a new share information object
*
* @return DCEReadable
*/
protected DCEReadable getNewObject()
{
return new ShareInfo(getInformationLevel());
}
/**
* Add a share to the list
*
* @param share ShareInfo
*/
public final void addShare(ShareInfo share)
{
// Check if the share list is valid
if (getList() == null)
setList(new Vector());
// Add the share
getList().add(share);
}
/**
* Set the share information list
*
* @param list Vector
*/
public final void setShareList(Vector list)
{
setList(list);
}
}

View File

@@ -0,0 +1,773 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import java.util.BitSet;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.DCEReadable;
/**
* User Information Class
* <p>
* Contains the details of a user account on a remote server.
*/
public class UserInfo implements DCEReadable
{
// Information levels supported
public static final int InfoLevel1 = 1;
public static final int InfoLevel3 = 3;
public static final int InfoLevel21 = 21;
// public static final int InfoLevel2 = 2;
// public static final int InfoLevel4 = 4;
// public static final int InfoLevel5 = 5;
// public static final int InfoLevel6 = 6;
// public static final int InfoLevel7 = 7;
// public static final int InfoLevel8 = 8;
// public static final int InfoLevel9 = 9;
// public static final int InfoLevel10 = 10;
// public static final int InfoLevel11 = 11;
// public static final int InfoLevel12 = 12;
// public static final int InfoLevel13 = 13;
// public static final int InfoLevel14 = 14;
// public static final int InfoLevel16 = 16;
// public static final int InfoLevel17 = 17;
// public static final int InfoLevel20 = 20;
// Account privilege levels
public static final int PrivGuest = 0;
public static final int PrivUser = 1;
public static final int PrivAdmin = 2;
// Account operator privileges
public static final int OperPrint = 0;
public static final int OperComm = 1;
public static final int OperServer = 2;
public static final int OperAccounts = 3;
// Account flags
private static final int AccountDisabled = 0x0001;
private static final int AccountHomeDirRequired = 0x0002;
private static final int AccountPasswordNotRequired = 0x0004;
private static final int AccountTemporaryDuplicate = 0x0008;
private static final int AccountNormal = 0x0010;
private static final int AccountMNSUser = 0x0020;
private static final int AccountDomainTrust = 0x0040;
private static final int AccountWorkstationTrust = 0x0080;
private static final int AccountServerTrust = 0x0100;
private static final int AccountPasswordNotExpire = 0x0200;
private static final int AccountAutoLocked = 0x0400;
// Information level
private int m_infoLevel;
// User information
private String m_userName;
private int m_pwdAge;
private int m_priv;
private String m_homeDir;
private String m_comment;
private String m_description;
private String m_accComment;
private int m_flags;
private String m_scriptPath;
// private int m_authFlags;
private String m_fullName;
private String m_appParam;
private String m_workStations;
private long m_lastLogon;
private long m_lastLogoff;
private long m_acctExpires;
private long m_lastPwdChange;
private long m_pwdCanChange;
private long m_pwdMustchange;
// private int m_maxStorage;
private int m_unitsPerWeek;
private byte[] m_logonHoursRaw;
private BitSet m_logonHours;
private int m_badPwdCount;
private int m_numLogons;
private String logonSrv;
private int m_countryCode;
private int m_codePage;
private int m_userRID;
private int m_groupRID;
// private SID m_userSID;
private String m_profile;
private String m_homeDirDrive;
private int m_pwdExpired;
private String m_callBack;
private String m_unknown1;
private String m_unknown2;
private String m_unknown3;
/**
* Default constructor
*/
public UserInfo()
{
}
/**
* Class constructor
*
* @param lev int
*/
public UserInfo(int lev)
{
m_infoLevel = lev;
}
/**
* Get the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Return the logon server name
*
* @return String
*/
public final String getLogonServer()
{
return logonSrv;
}
/**
* Return the date/time the account expires, or NTTime.Infinity if it does not expire
*
* @return long
*/
public final long getAccountExpires()
{
return m_acctExpires;
}
/**
* Return the application parameter string
*
* @return String
*/
public final String getApplicationParameter()
{
return m_appParam;
}
/**
* Return the bad password count
*
* @return int
*/
public final int getBadPasswordCount()
{
return m_badPwdCount;
}
/**
* Return the code page
*
* @return int
*/
public final int getCodePage()
{
return m_codePage;
}
/**
* Return the account comment
*
* @return String
*/
public final String getComment()
{
return m_comment;
}
/**
* Return the account description
*
* @return String
*/
public final String getDescription()
{
return m_description;
}
/**
* Return the country code
*
* @return int
*/
public final int getCountryCode()
{
return m_countryCode;
}
/**
* Return the account flags
*
* @return int
*/
public final int getFlags()
{
return m_flags;
}
/**
* Check if the account is disabled
*
* @return boolean
*/
public final boolean isDisabled()
{
return (m_flags & AccountDisabled) != 0 ? true : false;
}
/**
* Check if the account does not require a home directory
*
* @return boolean
*/
public final boolean requiresHomeDirectory()
{
return (m_flags & AccountHomeDirRequired) != 0 ? true : false;
}
/**
* Check if the account does not require a password
*
* @return boolean
*/
public final boolean requiresPassword()
{
return (m_flags & AccountPasswordNotRequired) != 0 ? false : true;
}
/**
* Check if the account is a normal user account
*
* @return boolean
*/
public final boolean isNormalUser()
{
return (m_flags & AccountNormal) != 0 ? true : false;
}
/**
* Check if the account is a domain trust account
*
* @return boolean
*/
public final boolean isDomainTrust()
{
return (m_flags & AccountDomainTrust) != 0 ? true : false;
}
/**
* Check if the account is a workstation trust account
*
* @return boolean
*/
public final boolean isWorkstationTrust()
{
return (m_flags & AccountWorkstationTrust) != 0 ? true : false;
}
/**
* Check if the account is a server trust account
*
* @return boolean
*/
public final boolean isServerTrust()
{
return (m_flags & AccountServerTrust) != 0 ? true : false;
}
/**
* Check if the account password expires
*
* @return boolean
*/
public final boolean passwordExpires()
{
return (m_flags & AccountPasswordNotExpire) != 0 ? false : true;
}
/**
* Check if the account is auto locked
*
* @return boolean
*/
public final boolean isAutoLocked()
{
return (m_flags & AccountAutoLocked) != 0 ? true : false;
}
/**
* Return the full account name
*
* @return String
*/
public final String getFullName()
{
return m_fullName;
}
/**
* Return the group resource id
*
* @return int
*/
public final int getGroupRID()
{
return m_groupRID;
}
/**
* Return the home directory path
*
* @return String
*/
public final String getHomeDirectory()
{
return m_homeDir;
}
/**
* Return the home drive
*
* @return String
*/
public final String getHomeDirectoryDrive()
{
return m_homeDirDrive;
}
/**
* Return the date/time of last logoff
*
* @return long
*/
public final long getLastLogoff()
{
return m_lastLogoff;
}
/**
* Return the date/time of last logon, to this server
*
* @return long
*/
public final long getLastLogon()
{
return m_lastLogon;
}
/**
* Return the allowed logon hours bit set
*
* @return BitSet
*/
public final BitSet getLogonHours()
{
return m_logonHours;
}
/**
* Return the number of logons for the account, to this server
*
* @return int
*/
public final int numberOfLogons()
{
return m_numLogons;
}
/**
* Return the account provileges
*
* @return int
*/
public final int getPrivileges()
{
return m_priv;
}
/**
* Return the profile path
*
* @return String
*/
public final String getProfile()
{
return m_profile;
}
/**
* Return the password expired flag
*
* @return int
*/
public final int getPasswordExpired()
{
return m_pwdExpired;
}
/**
* Return the logon script path
*
* @return String
*/
public final String getLogonScriptPath()
{
return m_scriptPath;
}
/**
* Return the allowed units per week
*
* @return int
*/
public final int getUnitsPerWeek()
{
return m_unitsPerWeek;
}
/**
* Return the account name
*
* @return String
*/
public final String getUserName()
{
return m_userName;
}
/**
* Return the user resource id
*
* @return int
*/
public final int getUserRID()
{
return m_userRID;
}
/**
* Return the workstations that the account is allowed to logon from
*
* @return String
*/
public final String getWorkStations()
{
return m_workStations;
}
/**
* Return the date/time of the last password change
*
* @return long
*/
public final long getLastPasswordChange()
{
return m_lastPwdChange;
}
/**
* Return the date/time that the password must be changed by
*
* @return long
*/
public final long getPasswordMustChangeBy()
{
return m_pwdMustchange;
}
/**
* Clear all string values
*/
private final void clearStrings()
{
// Clear the string values
m_appParam = null;
m_comment = null;
m_fullName = null;
m_homeDir = null;
m_homeDirDrive = null;
m_profile = null;
m_scriptPath = null;
m_userName = null;
m_workStations = null;
m_description = null;
m_accComment = null;
}
/**
* Read the user information from the DCE buffer
*
* @param buf DCEBuffer
* @throws DCEBufferException
*/
public void readObject(DCEBuffer buf) throws DCEBufferException
{
// clear all existing string values
clearStrings();
// Unpack the user information
int ival = 0;
int pval = 0;
switch (getInformationLevel())
{
// Information level 1
case InfoLevel1:
m_userName = buf.getCharArrayPointer();
m_fullName = buf.getCharArrayPointer();
m_groupRID = buf.getInt();
m_description = buf.getCharArrayPointer();
m_comment = buf.getCharArrayPointer();
break;
// Information level 3
case InfoLevel3:
m_userName = buf.getCharArrayPointer();
m_fullName = buf.getCharArrayPointer();
m_userRID = buf.getInt();
m_groupRID = buf.getInt();
m_homeDir = buf.getCharArrayPointer();
m_homeDirDrive = buf.getCharArrayPointer();
m_scriptPath = buf.getCharArrayPointer();
m_profile = buf.getCharArrayPointer();
m_workStations = buf.getCharArrayPointer();
m_lastLogon = buf.getNTTime();
m_lastLogoff = buf.getNTTime();
m_lastPwdChange = buf.getNTTime();
buf.skipBytes(8); // allow password change NT time
buf.skipBytes(8); // force password change NT time
ival = buf.getShort(DCEBuffer.ALIGN_INT);
pval = buf.getPointer();
if (ival != 0 && pval != 0)
m_logonHoursRaw = new byte[ival / 8];
m_badPwdCount = buf.getShort();
m_numLogons = buf.getShort();
m_flags = buf.getInt();
break;
// Information level 21
case InfoLevel21:
m_lastLogon = buf.getNTTime();
m_lastLogoff = buf.getNTTime();
m_lastPwdChange = buf.getNTTime();
m_acctExpires = buf.getNTTime();
m_pwdCanChange = buf.getNTTime();
m_pwdMustchange = buf.getNTTime();
m_userName = buf.getCharArrayPointer();
m_fullName = buf.getCharArrayPointer();
m_homeDir = buf.getCharArrayPointer();
m_homeDirDrive = buf.getCharArrayPointer();
m_scriptPath = buf.getCharArrayPointer();
m_profile = buf.getCharArrayPointer();
m_description = buf.getCharArrayPointer();
m_workStations = buf.getCharArrayPointer();
m_accComment = buf.getCharArrayPointer();
m_callBack = buf.getCharArrayPointer();
m_unknown1 = buf.getCharArrayPointer();
m_unknown2 = buf.getCharArrayPointer();
m_unknown3 = buf.getCharArrayPointer();
buf.skipBytes(8); // buffer length and pointer
m_userRID = buf.getInt();
m_groupRID = buf.getInt();
m_flags = buf.getInt();
buf.getInt(); // fields present flags
ival = buf.getShort(DCEBuffer.ALIGN_INT);
pval = buf.getPointer();
if (ival != 0 && pval != 0)
m_logonHoursRaw = new byte[ival / 8];
m_badPwdCount = buf.getShort();
m_numLogons = buf.getShort();
m_countryCode = buf.getShort();
m_codePage = buf.getShort();
buf.skipBytes(2); // NT and LM pwd set flags
m_pwdExpired = buf.getByte(DCEBuffer.ALIGN_INT);
break;
}
}
/**
* Read the strings for this user information from the DCE buffer
*
* @param buf DCEBuffer
* @throws DCEBufferException
*/
public void readStrings(DCEBuffer buf) throws DCEBufferException
{
// Read the strings/structures for this user information
switch (getInformationLevel())
{
// Information level 1
case InfoLevel1:
m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
m_description = buf.getCharArrayNotNull(m_description, DCEBuffer.ALIGN_INT);
m_comment = buf.getCharArrayNotNull(m_comment, DCEBuffer.ALIGN_INT);
break;
// Information level 3
case InfoLevel3:
m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
m_homeDir = buf.getCharArrayNotNull(m_homeDir, DCEBuffer.ALIGN_INT);
m_homeDirDrive = buf.getCharArrayNotNull(m_homeDirDrive, DCEBuffer.ALIGN_INT);
m_scriptPath = buf.getCharArrayNotNull(m_scriptPath, DCEBuffer.ALIGN_INT);
m_profile = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
m_workStations = buf.getCharArrayNotNull(m_workStations, DCEBuffer.ALIGN_INT);
m_logonHoursRaw = buf.getByteStructure(m_logonHoursRaw);
break;
// Information level 21
case InfoLevel21:
m_userName = buf.getCharArrayNotNull(m_userName, DCEBuffer.ALIGN_INT);
m_fullName = buf.getCharArrayNotNull(m_fullName, DCEBuffer.ALIGN_INT);
m_homeDir = buf.getCharArrayNotNull(m_homeDir, DCEBuffer.ALIGN_INT);
m_homeDirDrive = buf.getCharArrayNotNull(m_homeDirDrive, DCEBuffer.ALIGN_INT);
m_scriptPath = buf.getCharArrayNotNull(m_scriptPath, DCEBuffer.ALIGN_INT);
m_profile = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
m_description = buf.getCharArrayNotNull(m_description, DCEBuffer.ALIGN_INT);
m_workStations = buf.getCharArrayNotNull(m_workStations, DCEBuffer.ALIGN_INT);
m_accComment = buf.getCharArrayNotNull(m_profile, DCEBuffer.ALIGN_INT);
m_callBack = buf.getCharArrayNotNull(m_callBack, DCEBuffer.ALIGN_INT);
m_unknown1 = buf.getCharArrayNotNull(m_unknown1, DCEBuffer.ALIGN_INT);
m_unknown2 = buf.getCharArrayNotNull(m_unknown2, DCEBuffer.ALIGN_INT);
m_unknown3 = buf.getCharArrayNotNull(m_unknown3, DCEBuffer.ALIGN_INT);
m_logonHoursRaw = buf.getByteStructure(m_logonHoursRaw);
break;
}
}
/**
* Return an account type as a string
*
* @param typ int
* @return String
*/
public final static String getAccountTypeAsString(int typ)
{
String ret = "";
switch (typ)
{
case PrivGuest:
ret = "Guest";
break;
case PrivUser:
ret = "User";
break;
case PrivAdmin:
ret = "Administrator";
break;
}
return ret;
}
/**
* Return the user information as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
str.append(getUserName());
str.append(":");
str.append(getInformationLevel());
str.append(":");
str.append("]");
return str.toString();
}
}

View File

@@ -0,0 +1,337 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.info;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEWriteable;
/**
* Workstation Information Class
*/
public class WorkstationInfo implements DCEWriteable
{
// Supported information levels
public static final int InfoLevel100 = 100;
// Information level
private int m_infoLevel;
// Server information
private int m_platformId;
private String m_name;
private String m_domain;
private int m_verMajor;
private int m_verMinor;
private String m_userName;
private String m_logonDomain;
private String m_otherDomain;
/**
* Default constructor
*/
public WorkstationInfo()
{
}
/**
* Class constructor
*
* @param lev int
*/
public WorkstationInfo(int lev)
{
m_infoLevel = lev;
}
/**
* Get the information level
*
* @return int
*/
public final int getInformationLevel()
{
return m_infoLevel;
}
/**
* Get the workstation name
*
* @return String
*/
public final String getWorkstationName()
{
return m_name;
}
/**
* Get the domain/workgroup
*
* @return String
*/
public final String getDomain()
{
return m_domain;
}
/**
* Get the workstation platform id
*
* @return int
*/
public final int getPlatformId()
{
return m_platformId;
}
/**
* Get the workstation major version
*
* @return int
*/
public final int getMajorVersion()
{
return m_verMajor;
}
/**
* Get the workstation minor version
*
* @return int
*/
public final int getMinorVersion()
{
return m_verMinor;
}
/**
* Reutrn the user name
*
* @return String
*/
public final String getUserName()
{
return m_userName;
}
/**
* Return the workstations logon domain.
*
* @return java.lang.String
*/
public String getLogonDomain()
{
return m_logonDomain;
}
/**
* Return the list of domains that the workstation is enlisted in.
*
* @return java.lang.String
*/
public String getOtherDomains()
{
return m_otherDomain;
}
/**
* Set the logon domain name.
*
* @param logdom java.lang.String
*/
public void setLogonDomain(String logdom)
{
m_logonDomain = logdom;
}
/**
* Set the other domains that this workstation is enlisted in.
*
* @param othdom java.lang.String
*/
public void setOtherDomains(String othdom)
{
m_otherDomain = othdom;
}
/**
* Set the workstation name
*
* @param name String
*/
public final void setWorkstationName(String name)
{
m_name = name;
}
/**
* Set the domain/workgroup
*
* @param domain String
*/
public final void setDomain(String domain)
{
m_domain = domain;
}
/**
* Set the information level
*
* @param lev int
*/
public final void setInformationLevel(int lev)
{
m_infoLevel = lev;
}
/**
* Set the platform id
*
* @param id int
*/
public final void setPlatformId(int id)
{
m_platformId = id;
}
/**
* Set the version
*
* @param verMajor int
* @param verMinor int
*/
public final void setVersion(int verMajor, int verMinor)
{
m_verMajor = verMajor;
m_verMinor = verMinor;
}
/**
* Set the logged in user name
*
* @param user String
*/
public final void setUserName(String user)
{
m_userName = user;
}
/**
* Clear the string values
*/
protected final void clearStrings()
{
// Clear the string values
m_userName = null;
m_domain = null;
m_logonDomain = null;
m_otherDomain = null;
}
/**
* Write a workstation information structure
*
* @param buf DCEBuffer
* @param strBuf DCEBuffer
*/
public void writeObject(DCEBuffer buf, DCEBuffer strBuf)
{
// Output the workstation information structure
buf.putInt(getInformationLevel());
buf.putPointer(true);
// Output the required information level
switch (getInformationLevel())
{
// Level 100
case InfoLevel100:
buf.putInt(getPlatformId());
buf.putPointer(true);
buf.putPointer(true);
buf.putInt(getMajorVersion());
buf.putInt(getMinorVersion());
strBuf.putString(getWorkstationName(), DCEBuffer.ALIGN_INT, true);
strBuf.putString(getDomain() != null ? getDomain() : "", DCEBuffer.ALIGN_INT, true);
break;
// Level 101
case 101:
break;
// Level 102
case 102:
break;
}
}
/**
* Return the workstation information as a string
*
* @return String
*/
public String toString()
{
StringBuffer str = new StringBuffer();
str.append("[");
str.append(getWorkstationName());
str.append(":Domain=");
str.append(getDomain());
str.append(":User=");
str.append(getUserName());
str.append(":Id=");
str.append(getPlatformId());
str.append(":v");
str.append(getMajorVersion());
str.append(".");
str.append(getMinorVersion());
// Optional strings
if (getLogonDomain() != null)
{
str.append(":Logon=");
str.append(getLogonDomain());
}
if (getOtherDomains() != null)
{
str.append(":Other=");
str.append(getOtherDomains());
}
// Return the workstation information as a string
str.append("]");
return str.toString();
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
import java.io.IOException;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.server.SMBSrvException;
import org.alfresco.filesys.smb.server.SMBSrvSession;
/**
* DCE Request Handler Interface
*/
public interface DCEHandler
{
/**
* Process a DCE/RPC request
*
* @param sess SMBSrvSession
* @param inBuf DCEBuffer
* @param pipeFile DCEPipeFile
* @exception IOException
* @exception SMBSrvException
*/
public void processRequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile) throws IOException,
SMBSrvException;
}

View File

@@ -0,0 +1,260 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
import java.io.IOException;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEPipeType;
/**
* DCE/RPC Pipe File Class
* <p>
* Contains the details and state of a DCE/RPC special named pipe.
*/
public class DCEPipeFile extends NetworkFile
{
// Maximum receive/transmit DCE fragment size
private int m_maxRxFragSize;
private int m_maxTxFragSize;
// Named pipe state flags
private int m_state;
// DCE/RPC handler for this named pipe
private DCEHandler m_handler;
// Current DCE buffered data
private DCEBuffer m_dceData;
/**
* Class constructor
*
* @param id int
*/
public DCEPipeFile(int id)
{
super(id);
setName(DCEPipeType.getTypeAsString(id));
// Set the DCE/RPC request handler for the pipe
setRequestHandler(DCEPipeHandler.getHandlerForType(id));
}
/**
* Return the maximum receive fragment size
*
* @return int
*/
public final int getMaxReceiveFragmentSize()
{
return m_maxRxFragSize;
}
/**
* Return the maximum transmit fragment size
*
* @return int
*/
public final int getMaxTransmitFragmentSize()
{
return m_maxTxFragSize;
}
/**
* Return the named pipe state
*
* @return int
*/
public final int getPipeState()
{
return m_state;
}
/**
* Return the pipe type id
*
* @return int
*/
public final int getPipeId()
{
return getFileId();
}
/**
* Determine if the pipe has a request handler
*
* @return boolean
*/
public final boolean hasRequestHandler()
{
return m_handler != null ? true : false;
}
/**
* Return the pipes DCE/RPC handler
*
* @return DCEHandler
*/
public final DCEHandler getRequestHandler()
{
return m_handler;
}
/**
* Determine if the pipe has any buffered data
*
* @return boolean
*/
public final boolean hasBufferedData()
{
return m_dceData != null ? true : false;
}
/**
* Get the buffered data for the pipe
*
* @return DCEBuffer
*/
public final DCEBuffer getBufferedData()
{
return m_dceData;
}
/**
* Set buffered data for the pipe
*
* @param buf DCEBuffer
*/
public final void setBufferedData(DCEBuffer buf)
{
m_dceData = buf;
}
/**
* Set the maximum receive fragment size
*
* @param siz int
*/
public final void setMaxReceiveFragmentSize(int siz)
{
m_maxRxFragSize = siz;
}
/**
* Set the maximum transmit fragment size
*
* @param siz int
*/
public final void setMaxTransmitFragmentSize(int siz)
{
m_maxTxFragSize = siz;
}
/**
* Set the named pipe state flags
*
* @param state int
*/
public final void setPipeState(int state)
{
m_state = state;
}
/**
* Set the pipes DCE/RPC handler
*
* @param handler DCEHandler
*/
public final void setRequestHandler(DCEHandler handler)
{
m_handler = handler;
}
/**
* Dump the file details
*/
public final void DumpFile()
{
System.out.println("** DCE/RPC Named Pipe: " + getName());
System.out.println(" File ID : " + getFileId());
System.out.println(" State : 0x" + Integer.toHexString(getPipeState()));
System.out.println(" Max Rx : " + getMaxReceiveFragmentSize());
System.out.println(" Max Tx : " + getMaxTransmitFragmentSize());
System.out.println(" Handler : " + getRequestHandler());
}
/**
* @see NetworkFile#closeFile()
*/
public void closeFile() throws IOException
{
}
/**
* @see NetworkFile#openFile(boolean)
*/
public void openFile(boolean createFlag) throws IOException
{
}
/**
* @see NetworkFile#readFile(byte[], int, int, long)
*/
public int readFile(byte[] buf, int len, int pos, long fileOff) throws IOException
{
return 0;
}
/**
* Flush any buffered output to the file
*
* @throws IOException
*/
public void flushFile() throws IOException
{
}
/**
* @see NetworkFile#seekFile(long, int)
*/
public long seekFile(long pos, int typ) throws IOException
{
return 0;
}
/**
* @see NetworkFile#truncateFile(long)
*/
public void truncateFile(long siz) throws IOException
{
}
/**
* @see NetworkFile#writeFile(byte[], int, int, long)
*/
public void writeFile(byte[] buf, int len, int pos, long fileOff) throws IOException
{
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
/**
* DCE Pipe Handler Class
* <p>
* Contains a list of the available DCE pipe handlers.
*/
public class DCEPipeHandler
{
// DCE/RPC pipe request handlers
private static DCEHandler[] _handlers = {
new SrvsvcDCEHandler(),
null, // samr
null, // winreg
new WkssvcDCEHandler(),
null, // NETLOGON
null, // lsarpc
null, // spoolss
null, // netdfs
null, // service control
null, // eventlog
null // netlogon1
};
/**
* Return the DCE/RPC request handler for the pipe type
*
* @param typ int
* @return DCEHandler
*/
public final static DCEHandler getHandlerForType(int typ)
{
if (typ >= 0 && typ < _handlers.length)
return _handlers[typ];
return null;
}
}

View File

@@ -0,0 +1,425 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
import org.alfresco.filesys.netbios.RFCNetBIOSProtocol;
import org.alfresco.filesys.smb.PacketType;
import org.alfresco.filesys.smb.dcerpc.DCECommand;
import org.alfresco.filesys.smb.dcerpc.DCEDataPacker;
import org.alfresco.filesys.smb.server.SMBTransPacket;
import org.alfresco.filesys.util.DataPacker;
/**
* DCE/RPC Server Packet Class
*/
public class DCESrvPacket extends SMBTransPacket
{
// DCE/RPC header offsets
private static final int VERSIONMAJOR = 0;
private static final int VERSIONMINOR = 1;
private static final int PDUTYPE = 2;
private static final int HEADERFLAGS = 3;
private static final int PACKEDDATAREP = 4;
private static final int FRAGMENTLEN = 8;
private static final int AUTHLEN = 10;
private static final int CALLID = 12;
private static final int DCEDATA = 16;
// DCE/RPC Request offsets
private static final int ALLOCATIONHINT = 16;
private static final int PRESENTIDENT = 20;
private static final int OPERATIONID = 22;
private static final int OPERATIONDATA = 24;
// Header flags
public static final int FLG_FIRSTFRAG = 0x01;
public static final int FLG_LASTFRAG = 0x02;
public static final int FLG_ONLYFRAG = 0x03;
// DCE/RPC header constants
private static final byte HDR_VERSIONMAJOR = 5;
private static final byte HDR_VERSIONMINOR = 0;
private static final int HDR_PACKEDDATAREP = 0x00000010;
// Offset to DCE/RPC header
private int m_offset;
/**
* Construct a DCE/RPC transaction packet
*
* @param buf Buffer that contains the SMB transaction packet.
*/
public DCESrvPacket(byte[] buf)
{
super(buf);
// m_offset = getParameterOffset();
}
/**
* Construct a DCE/RPC transaction packet
*
* @param siz Size of packet to allocate.
*/
public DCESrvPacket(int siz)
{
super(siz);
// Set the multiplex id for this transaction
setMultiplexId(getNextMultiplexId());
}
/**
* Return the major version number
*
* @return int
*/
public final int getMajorVersion()
{
return (int) (getBuffer()[m_offset + VERSIONMAJOR] & 0xFF);
}
/**
* Return the minor version number
*
* @return int
*/
public final int getMinorVersion()
{
return (int) (getBuffer()[m_offset + VERSIONMINOR] & 0xFF);
}
/**
* Return the PDU packet type
*
* @return int
*/
public final int getPDUType()
{
return (int) (getBuffer()[m_offset + PDUTYPE] & 0xFF);
}
/**
* Return the header flags
*
* @return int
*/
public final int getHeaderFlags()
{
return (int) (getBuffer()[m_offset + HEADERFLAGS] & 0xFF);
}
/**
* Return the packed data representation
*
* @return int
*/
public final int getPackedDataRepresentation()
{
return DataPacker.getIntelInt(getBuffer(), m_offset + PACKEDDATAREP);
}
/**
* Return the fragment length
*
* @return int
*/
public final int getFragmentLength()
{
return DataPacker.getIntelShort(getBuffer(), m_offset + FRAGMENTLEN);
}
/**
* Set the fragment length
*
* @param len int
*/
public final void setFragmentLength(int len)
{
// Set the DCE header fragment length
DataPacker.putIntelShort(len, getBuffer(), m_offset + FRAGMENTLEN);
}
/**
* Return the authentication length
*
* @return int
*/
public final int getAuthenticationLength()
{
return DataPacker.getIntelShort(getBuffer(), m_offset + AUTHLEN);
}
/**
* Return the call id
*
* @return int
*/
public final int getCallId()
{
return DataPacker.getIntelInt(getBuffer(), m_offset + CALLID);
}
/**
* Determine if this is the first fragment
*
* @return boolean
*/
public final boolean isFirstFragment()
{
if ((getHeaderFlags() & FLG_FIRSTFRAG) != 0)
return true;
return false;
}
/**
* Determine if this is the last fragment
*
* @return boolean
*/
public final boolean isLastFragment()
{
if ((getHeaderFlags() & FLG_LASTFRAG) != 0)
return true;
return false;
}
/**
* Determine if this is the only fragment in the request
*
* @return boolean
*/
public final boolean isOnlyFragment()
{
if ((getHeaderFlags() & FLG_ONLYFRAG) == FLG_ONLYFRAG)
return true;
return false;
}
/**
* Get the offset to the DCE/RPC data within the SMB packet
*
* @return int
*/
public final int getDCEDataOffset()
{
// Determine the data offset from the DCE/RPC packet type
int dataOff = -1;
switch (getPDUType())
{
// Bind/bind acknowledge
case DCECommand.BIND:
case DCECommand.BINDACK:
dataOff = m_offset + DCEDATA;
break;
// Request/response
case DCECommand.REQUEST:
case DCECommand.RESPONSE:
dataOff = m_offset + OPERATIONDATA;
break;
}
// Return the data offset
return dataOff;
}
/**
* Get the request allocation hint
*
* @return int
*/
public final int getAllocationHint()
{
return DataPacker.getIntelInt(getBuffer(), m_offset + ALLOCATIONHINT);
}
/**
* Set the allocation hint
*
* @param alloc int
*/
public final void setAllocationHint(int alloc)
{
DataPacker.putIntelInt(alloc, getBuffer(), m_offset + ALLOCATIONHINT);
}
/**
* Get the request presentation identifier
*
* @return int
*/
public final int getPresentationIdentifier()
{
return DataPacker.getIntelShort(getBuffer(), m_offset + PRESENTIDENT);
}
/**
* Set the presentation identifier
*
* @param ident int
*/
public final void setPresentationIdentifier(int ident)
{
DataPacker.putIntelShort(ident, getBuffer(), m_offset + PRESENTIDENT);
}
/**
* Get the request operation id
*
* @return int
*/
public final int getOperationId()
{
return DataPacker.getIntelShort(getBuffer(), m_offset + OPERATIONID);
}
/**
* Initialize the DCE/RPC request. Set the SMB transaction parameter count so that the data
* offset can be calculated.
*
* @param handle int
* @param typ byte
* @param flags int
* @param callId int
*/
public final void initializeDCERequest(int handle, byte typ, int flags, int callId)
{
// Initialize the transaction
InitializeTransact(16, null, 0, null, 0);
// Set the parameter byte count/offset for this packet
int bytPos = DCEDataPacker.longwordAlign(getByteOffset());
setParameter(3, 0);
setParameter(4, bytPos - RFCNetBIOSProtocol.HEADER_LEN);
// Set the parameter displacement
setParameter(5, 0);
// Set the data byte count/offset for this packet
setParameter(6, 0);
setParameter(7, bytPos - RFCNetBIOSProtocol.HEADER_LEN);
// Set the data displacement
setParameter(8, 0);
// Set up word count
setParameter(9, 0);
// Set the setup words
setSetupParameter(0, PacketType.TransactNmPipe);
setSetupParameter(1, handle);
// Reset the DCE offset for a DCE reply
m_offset = bytPos;
// Build the DCE/RPC header
byte[] buf = getBuffer();
DataPacker.putZeros(buf, m_offset, 24);
buf[m_offset + VERSIONMAJOR] = HDR_VERSIONMAJOR;
buf[m_offset + VERSIONMINOR] = HDR_VERSIONMINOR;
buf[m_offset + PDUTYPE] = typ;
buf[m_offset + HEADERFLAGS] = (byte) (flags & 0xFF);
DataPacker.putIntelInt(HDR_PACKEDDATAREP, buf, m_offset + PACKEDDATAREP);
DataPacker.putIntelInt(0, buf, m_offset + AUTHLEN);
DataPacker.putIntelInt(callId, buf, m_offset + CALLID);
}
/**
* Initialize the DCE/RPC reply. Set the SMB transaction parameter count so that the data offset
* can be calculated.
*/
public final void initializeDCEReply()
{
// Set the total parameter words
setParameterCount(10);
// Set the total parameter/data bytes
setParameter(0, 0);
setParameter(1, 0);
// Set the parameter byte count/offset for this packet
int bytPos = DCEDataPacker.longwordAlign(getByteOffset());
setParameter(3, 0);
setParameter(4, bytPos - RFCNetBIOSProtocol.HEADER_LEN);
// Set the parameter displacement
setParameter(5, 0);
// Set the data byte count/offset for this packet
setParameter(6, 0);
setParameter(7, bytPos - RFCNetBIOSProtocol.HEADER_LEN);
// Set the data displacement
setParameter(8, 0);
// Set up word count
setParameter(9, 0);
}
/**
* Dump the DCE/RPC header details
*/
public final void DumpHeader()
{
// Dump the PDU type
System.out.println("** DCE/RPC Header - PDU Type = " + DCECommand.getCommandString(getPDUType()));
System.out.println(" Version : " + getMajorVersion() + "." + getMinorVersion());
System.out.println(" Flags : 0x" + getHeaderFlags());
System.out.println(" Packed Data Rep : 0x" + getPackedDataRepresentation());
System.out.println(" Fragment Length : " + getFragmentLength());
System.out.println(" Auth Length : " + getAuthenticationLength());
System.out.println(" Call ID : " + getCallId());
}
}

View File

@@ -0,0 +1,401 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import org.alfresco.filesys.server.auth.acl.AccessControlManager;
import org.alfresco.filesys.server.config.ServerConfiguration;
import org.alfresco.filesys.server.core.ShareType;
import org.alfresco.filesys.server.core.SharedDevice;
import org.alfresco.filesys.server.core.SharedDeviceList;
import org.alfresco.filesys.smb.Dialect;
import org.alfresco.filesys.smb.SMBStatus;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.Srvsvc;
import org.alfresco.filesys.smb.dcerpc.info.ServerInfo;
import org.alfresco.filesys.smb.dcerpc.info.ShareInfo;
import org.alfresco.filesys.smb.dcerpc.info.ShareInfoList;
import org.alfresco.filesys.smb.server.SMBServer;
import org.alfresco.filesys.smb.server.SMBSrvException;
import org.alfresco.filesys.smb.server.SMBSrvSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Srvsvc DCE/RPC Handler Class
*/
public class SrvsvcDCEHandler implements DCEHandler
{
// Debug logging
private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol");
/**
* Process a SrvSvc DCE/RPC request
*
* @param sess SMBSrvSession
* @param inBuf DCEBuffer
* @param pipeFile DCEPipeFile
* @exception IOException
* @exception SMBSrvException
*/
public void processRequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile) throws IOException,
SMBSrvException
{
// Get the operation code and move the buffer pointer to the start of the request data
int opNum = inBuf.getHeaderValue(DCEBuffer.HDR_OPCODE);
try
{
inBuf.skipBytes(DCEBuffer.OPERATIONDATA);
}
catch (DCEBufferException ex)
{
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("DCE/RPC SrvSvc request=" + Srvsvc.getOpcodeName(opNum));
// Create the output DCE buffer and add the response header
DCEBuffer outBuf = new DCEBuffer();
outBuf.putResponseHeader(inBuf.getHeaderValue(DCEBuffer.HDR_CALLID), 0);
// Process the request
boolean processed = false;
switch (opNum)
{
// Enumerate shares
case Srvsvc.NetrShareEnum:
processed = netShareEnum(sess, inBuf, outBuf);
break;
// Enumerate all shares
case Srvsvc.NetrShareEnumSticky:
processed = netShareEnum(sess, inBuf, outBuf);
break;
// Get share information
case Srvsvc.NetrShareGetInfo:
processed = netShareGetInfo(sess, inBuf, outBuf);
break;
// Get server information
case Srvsvc.NetrServerGetInfo:
processed = netServerGetInfo(sess, inBuf, outBuf);
break;
// Unsupported function
default:
break;
}
// Return an error status if the request was not processed
if (processed == false)
{
sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
return;
}
// Set the allocation hint for the response
outBuf.setHeaderValue(DCEBuffer.HDR_ALLOCHINT, outBuf.getLength());
// Attach the output buffer to the pipe file
pipeFile.setBufferedData(outBuf);
}
/**
* Handle a share enumeration request
*
* @param sess SMBSrvSession
* @param inBuf DCEPacket
* @param outBuf DCEPacket
* @return boolean
*/
protected final boolean netShareEnum(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf)
{
// Decode the request
String srvName = null;
ShareInfoList shrInfo = null;
try
{
inBuf.skipPointer();
srvName = inBuf.getString(DCEBuffer.ALIGN_INT);
shrInfo = new ShareInfoList(inBuf);
}
catch (DCEBufferException ex)
{
return false;
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("NetShareEnum srvName=" + srvName + ", shrInfo=" + shrInfo.toString());
// Get the share list from the server
SharedDeviceList shareList = sess.getServer().getShareMapper().getShareList(srvName, sess, false);
// Check if there is an access control manager configured
if (sess.getServer().hasAccessControlManager())
{
// Filter the list of available shares by applying any access control rules
AccessControlManager aclMgr = sess.getServer().getAccessControlManager();
shareList = aclMgr.filterShareList(sess, shareList);
}
// Create a list of share information objects of the required information level
Vector infoList = new Vector();
Enumeration<SharedDevice> enm = shareList.enumerateShares();
while (enm.hasMoreElements())
{
// Get the current shared device details
SharedDevice share = enm.nextElement();
// Determine the share type
int shrTyp = ShareInfo.Disk;
if (share.getType() == ShareType.PRINTER)
shrTyp = ShareInfo.PrintQueue;
else if (share.getType() == ShareType.NAMEDPIPE)
shrTyp = ShareInfo.IPC;
else if (share.getType() == ShareType.ADMINPIPE)
shrTyp = ShareInfo.IPC + ShareInfo.Hidden;
// Create a share information object with the basic information
ShareInfo info = new ShareInfo(shrInfo.getInformationLevel(), share.getName(), shrTyp, share.getComment());
infoList.add(info);
// Add additional information
switch (shrInfo.getInformationLevel())
{
// Level 2
case 2:
if (share.getContext() != null)
info.setPath(share.getContext().getDeviceName());
break;
// Level 502
case 502:
if (share.getContext() != null)
info.setPath(share.getContext().getDeviceName());
break;
}
}
// Set the share information list in the server share information and write the
// share information to the output DCE buffer.
shrInfo.setShareList(infoList);
try
{
shrInfo.writeList(outBuf);
outBuf.putInt(0); // status code
}
catch (DCEBufferException ex)
{
}
// Indicate that the request was processed successfully
return true;
}
/**
* Handle a get share information request
*
* @param sess SMBSrvSession
* @param inBuf DCEPacket
* @param outBuf DCEPacket
* @return boolean
*/
protected final boolean netShareGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf)
{
// Decode the request
String srvName = null;
String shrName = null;
int infoLevel = 0;
try
{
inBuf.skipPointer();
srvName = inBuf.getString(DCEBuffer.ALIGN_INT);
shrName = inBuf.getString(DCEBuffer.ALIGN_INT);
infoLevel = inBuf.getInt();
}
catch (DCEBufferException ex)
{
return false;
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("netShareGetInfo srvname=" + srvName + ", share=" + shrName + ", infoLevel=" + infoLevel);
// Find the required shared device
SharedDevice share = null;
try
{
// Get the shared device details
share = sess.getServer().findShare(srvName, shrName, ShareType.UNKNOWN, sess, false);
}
catch (Exception ex)
{
}
// Check if the share details are valid
if (share == null)
return false;
// Determine the share type
int shrTyp = ShareInfo.Disk;
if (share.getType() == ShareType.PRINTER)
shrTyp = ShareInfo.PrintQueue;
else if (share.getType() == ShareType.NAMEDPIPE)
shrTyp = ShareInfo.IPC;
else if (share.getType() == ShareType.ADMINPIPE)
shrTyp = ShareInfo.IPC + ShareInfo.Hidden;
// Create the share information
ShareInfo shrInfo = new ShareInfo(infoLevel, share.getName(), shrTyp, share.getComment());
// Pack the information level, structure pointer and share information
outBuf.putInt(infoLevel);
outBuf.putPointer(true);
shrInfo.writeObject(outBuf, outBuf);
// Add the status and return a success status
outBuf.putInt(0);
return true;
}
/**
* Handle a get server information request
*
* @param sess SMBSrvSession
* @param inBuf DCEPacket
* @param outBuf DCEPacket
* @return boolean
*/
protected final boolean netServerGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf)
{
// Decode the request
String srvName = null;
int infoLevel = 0;
try
{
inBuf.skipPointer();
srvName = inBuf.getString(DCEBuffer.ALIGN_INT);
infoLevel = inBuf.getInt();
}
catch (DCEBufferException ex)
{
return false;
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("netServerGetInfo srvname=" + srvName + ", infoLevel=" + infoLevel);
// Create the server information and set the common values
ServerInfo srvInfo = new ServerInfo(infoLevel);
SMBServer srv = sess.getSMBServer();
srvInfo.setServerName(srv.getServerName());
srvInfo.setComment(srv.getComment());
srvInfo.setServerType(srv.getServerType());
// Determine if the server is using the NT SMB dialect and set the platofmr id accordingly
ServerConfiguration srvConfig = srv.getConfiguration();
if (srvConfig != null && srvConfig.getEnabledDialects().hasDialect(Dialect.NT) == true)
{
srvInfo.setPlatformId(ServerInfo.PLATFORM_NT);
srvInfo.setVersion(5, 1);
}
else
{
srvInfo.setPlatformId(ServerInfo.PLATFORM_OS2);
srvInfo.setVersion(4, 0);
}
// Write the server information to the DCE response
srvInfo.writeObject(outBuf, outBuf);
outBuf.putInt(0);
// Indicate that the request was processed successfully
return true;
}
}

View File

@@ -0,0 +1,178 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.filesys.smb.dcerpc.server;
import java.io.IOException;
import org.alfresco.filesys.server.config.ServerConfiguration;
import org.alfresco.filesys.smb.Dialect;
import org.alfresco.filesys.smb.SMBStatus;
import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
import org.alfresco.filesys.smb.dcerpc.Wkssvc;
import org.alfresco.filesys.smb.dcerpc.info.ServerInfo;
import org.alfresco.filesys.smb.dcerpc.info.WorkstationInfo;
import org.alfresco.filesys.smb.server.SMBServer;
import org.alfresco.filesys.smb.server.SMBSrvException;
import org.alfresco.filesys.smb.server.SMBSrvSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Wkssvc DCE/RPC Handler Class
*/
public class WkssvcDCEHandler implements DCEHandler
{
// Debug logging
private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol");
/**
* Process a WksSvc DCE/RPC request
*
* @param sess SMBSrvSession
* @param inBuf DCEBuffer
* @param pipeFile DCEPipeFile
* @exception IOException
* @exception SMBSrvException
*/
public void processRequest(SMBSrvSession sess, DCEBuffer inBuf, DCEPipeFile pipeFile) throws IOException,
SMBSrvException
{
// Get the operation code and move the buffer pointer to the start of the request data
int opNum = inBuf.getHeaderValue(DCEBuffer.HDR_OPCODE);
try
{
inBuf.skipBytes(DCEBuffer.OPERATIONDATA);
}
catch (DCEBufferException ex)
{
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("DCE/RPC WksSvc request=" + Wkssvc.getOpcodeName(opNum));
// Create the output DCE buffer and add the response header
DCEBuffer outBuf = new DCEBuffer();
outBuf.putResponseHeader(inBuf.getHeaderValue(DCEBuffer.HDR_CALLID), 0);
// Process the request
boolean processed = false;
switch (opNum)
{
// Get workstation information
case Wkssvc.NetWkstaGetInfo:
processed = netWkstaGetInfo(sess, inBuf, outBuf);
break;
// Unsupported function
default:
break;
}
// Return an error status if the request was not processed
if (processed == false)
{
sess.sendErrorResponseSMB(SMBStatus.SRVNotSupported, SMBStatus.ErrSrv);
return;
}
// Set the allocation hint for the response
outBuf.setHeaderValue(DCEBuffer.HDR_ALLOCHINT, outBuf.getLength());
// Attach the output buffer to the pipe file
pipeFile.setBufferedData(outBuf);
}
/**
* Get workstation infomation
*
* @param sess SMBSrvSession
* @param inBuf DCEPacket
* @param outBuf DCEPacket
* @return boolean
*/
protected final boolean netWkstaGetInfo(SMBSrvSession sess, DCEBuffer inBuf, DCEBuffer outBuf)
{
// Decode the request
String srvName = null;
int infoLevel = 0;
try
{
inBuf.skipPointer();
srvName = inBuf.getString(DCEBuffer.ALIGN_INT);
infoLevel = inBuf.getInt();
}
catch (DCEBufferException ex)
{
return false;
}
// Debug
if (logger.isDebugEnabled() && sess.hasDebug(SMBSrvSession.DBG_DCERPC))
logger.debug("NetWkstaGetInfo srvName=" + srvName + ", infoLevel=" + infoLevel);
// Create the workstation information and set the common values
WorkstationInfo wkstaInfo = new WorkstationInfo(infoLevel);
SMBServer srv = sess.getSMBServer();
wkstaInfo.setWorkstationName(srv.getServerName());
wkstaInfo.setDomain(srv.getConfiguration().getDomainName());
// Determine if the server is using the NT SMB dialect and set the platofmr id accordingly
ServerConfiguration srvConfig = sess.getServer().getConfiguration();
if (srvConfig != null && srvConfig.getEnabledDialects().hasDialect(Dialect.NT) == true)
{
wkstaInfo.setPlatformId(ServerInfo.PLATFORM_NT);
wkstaInfo.setVersion(5, 1);
}
else
{
wkstaInfo.setPlatformId(ServerInfo.PLATFORM_OS2);
wkstaInfo.setVersion(4, 0);
}
// Write the server information to the DCE response
wkstaInfo.writeObject(outBuf, outBuf);
outBuf.putInt(0);
// Indicate that the request was processed successfully
return true;
}
}