#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
+#include <string.h>
#include "usersfile.h"
+#include "msntauth.h"
static usersfile AllowUsers;
static int init = 0;
#include <time.h>
#include <sys/types.h>
#include <sys/param.h>
+#include <string.h>
#include "usersfile.h"
-
-extern int Check_ifuserallowed(const char *);
-extern void Check_forallowchange(void);
+#include "msntauth.h"
static usersfile DenyUsers;
static int init = 0;
return Read_usersfile(Denyuserpath, &DenyUsers);
}
-void
+static void
Check_fordenychange(void)
{
Check_forfilechange(&DenyUsers);
* user list. Returns 0 if the user was not found, and 1 if they were.
*/
-int
+static int
Check_ifuserdenied(char *ConnectingUser)
{
/* If user string is empty, deny */
*/
void
-Check_forchange()
+Check_forchange(int signal)
{
Check_fordenychange();
Check_forallowchange();
if (difftime(Currenttime, Lasttime) < 60)
return;
else {
- Check_forchange();
+ Check_forchange(-1);
Lasttime = Currenttime;
}
}
*/
#include <string.h>
+#include "md4.h"
/* NOTE: This code makes no attempt to be fast!
*
--- /dev/null
+/* md4.c */
+void mdfour(unsigned char *out, unsigned char *in, int n);
#include <stdio.h>
#include <signal.h>
#include <syslog.h>
+#include <string.h>
#include <sys/time.h>
#include "msntauth.h"
extern int OpenConfigFile(void);
extern int QueryServers(char *, char *);
extern void Checktimer(void);
-extern void Check_forchange();
+extern void Check_forchange(int);
extern int Read_denyusers(void);
extern int Read_allowusers(void);
extern int Check_user(char *);
extern int QueryServers(char *, char *);
+extern int Check_ifuserallowed(char *ConnectingUser);
+extern void Check_forallowchange(void);
+
/* Text strings for the error responses */
-extern char *RFCNB_Error_Strings[];
+extern const char *RFCNB_Error_Strings[];
#endif /* _RFCNB_ERROR_H_ */
int RFCNB_Timeout = 0; /* Timeout in seconds ... */
-void
+#ifdef NOT_USED
+static void
rfcnb_alarm(int sig)
{
syslog(LOG_ERR, "%s:%d: IO Timed out ...\n", __FILE__, __LINE__);
}
+#endif
/* Set timeout value and setup signal handling */
-int
+#ifdef NOT_USED
+static int
RFCNB_Set_Timeout(int seconds)
{
#ifdef SA_RESTART
}
return 0;
}
+#endif
/*
* in the buffer we allocated or were passed ...
*/
-int
+static int
RFCNB_Discard_Rest(struct RFCNB_Con *con, int len)
{
char temp[100]; /* Read into here */
#include <arpa/inet.h>
#include <string.h>
-char *RFCNB_Error_Strings[] =
+const char *RFCNB_Error_Strings[] =
{
"RFCNBE_OK: Routine completed successfully.",
};
+#ifdef RFCNB_DEBUG
extern void (*Prot_Print_Routine) (); /* Pointer to protocol print routine */
+#endif
/* Convert name and pad to 16 chars as needed */
/* Name 1 is a C string with null termination, name 2 may not be */
/* Definition of routines we define */
+struct RFCNB_Con;
+
void *RFCNB_Call(char *Called_Name, char *Calling_Name, char *Called_Address,
int port);
-int RFCNB_Send(void *Con_Handle, struct RFCNB_Pkt *Data, int Length);
-
-int RFCNB_Recv(void *Con_Handle, struct RFCNB_Pkt *Data, int Length);
+int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *Data, int Length);
-int RFCNB_Hangup(void *con_Handle);
+int RFCNB_Recv(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *Data, int Length);
-void *RFCNB_Listen();
+int RFCNB_Hangup(struct RFCNB_Con *Con_Handle);
void RFCNB_Get_Error(char *buffer, int buf_len);
+int RFCNB_Get_Last_Error(void);
+int RFCNB_Get_Last_Errno(void);
+void RFCNB_Get_Error_Msg(int code, char *msg_buf, int len);
+
#include "rfcnb-priv.h"
#include "rfcnb-util.h"
#include "rfcnb-io.h"
+#include "rfcnb.h"
#include <stdlib.h>
#include <unistd.h>
int RFCNB_Stats[RFCNB_MAX_STATS];
+#ifdef RFCNB_DEBUG
void (*Prot_Print_Routine) () = NULL; /* Pointer to print routine */
+#endif
/* Set up a session with a remote name. We are passed Called_Name as a
* string which we convert to a NetBIOS name, ie space terminated, up to
* non-message packets ... */
int
-RFCNB_Recv(void *con_Handle, struct RFCNB_Pkt *Data, int Length)
+RFCNB_Recv(struct RFCNB_Con *con_Handle, struct RFCNB_Pkt *Data, int Length)
{
struct RFCNB_Pkt *pkt;
int ret_len;
return 0;
-}
-
-/* Set TCP_NODELAY on the socket */
-
-int
-RFCNB_Set_Sock_NoDelay(struct RFCNB_Con *con_Handle, BOOL yn)
-{
-
- return (setsockopt(con_Handle->fd, IPPROTO_TCP, TCP_NODELAY,
- (char *) &yn, sizeof(yn)));
-
-}
-
-
-/* Listen for a connection on a port???, when */
-/* the connection comes in, we return with the connection */
-
-void
-RFCNB_Listen()
-{
-
}
/* Pick up the last error response as a string, hmmm, this routine should */
/* Pick up the last error response and returns as a code */
int
-RFCNB_Get_Last_Error()
+RFCNB_Get_Last_Error(void)
{
return (RFCNB_errno);
/* Pick up saved errno as well */
int
-RFCNB_Get_Last_Errno()
+RFCNB_Get_Last_Errno(void)
{
return (RFCNB_saved_errno);
/* Register a higher level protocol print routine */
+#ifdef RFCNB_DEBUG
void
RFCNB_Register_Print_Routine(void (*fn) ())
{
Prot_Print_Routine = fn;
}
+#endif
* up with a different answer to the one above)
*/
-
+#include "smbdes.h"
static int perm1[56] =
{57, 49, 41, 33, 25, 17, 9,
--- /dev/null
+/* smbdes.c */
+void E_P16(unsigned char *p14, unsigned char *p16);
+void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
+void cred_hash1(unsigned char *out, unsigned char *in, unsigned char *key);
+void cred_hash2(unsigned char *out, unsigned char *in, unsigned char *key);
#include "byteorder.h"
-char *StrnCpy(char *dest, char *src, int n);
-void strupper(char *s);
-extern void E_P16(unsigned char *, unsigned char *);
-extern void E_P24(unsigned char *, unsigned char *, unsigned char *);
-extern void mdfour(unsigned char *, unsigned char *, int);
+#include "md4.h"
+#include "smbdes.h"
+#include "smbencrypt.h"
+static void E_md4hash(unsigned char *passwd, unsigned char *p16);
+static char *StrnCpy(char *dest, char *src, int n);
+static void strupper(char *s);
/*
* This implements the X/Open SMB password encryption
--- /dev/null
+/* smbencrypt.c */
+void SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
+void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24);
+void nt_lm_owf_gen(char *pwd, char *nt_p16, char *p16);
/* We must make it possible for callers to specify these ... */
-extern char *SMB_Prots[];
+extern const char *SMB_Prots[];
extern int SMB_Types[];
typedef struct SMB_Status {
*/
#include "smblib-priv.h"
+#include "smblib.h"
#include "rfcnb.h"
#include "rfcnb-priv.h"
#include <string.h>
#include <unistd.h>
-char *SMB_Prots[] =
+const char *SMB_Prots[] =
{"PC NETWORK PROGRAM 1.0",
"MICROSOFT NETWORKS 1.03",
"MICROSOFT NETWORKS 3.0",
SMB_P_NT1,
-1};
-/* Print out an SMB pkt in all its gory detail ... */
-
-void
-SMB_Print_Pkt(FILE fd, RFCNB_Pkt * pkt, BOOL command, int Offset, int Len)
-{
-
- /* Well, just how do we do this ... print it I suppose */
-
- /* Print out the SMB header ... */
-
- /* Print the command */
-
- /* Print the other bits in the header */
-
-
- /* etc */
-
-}
-
-/* Convert a DOS Date_Time to a local host type date time for printing */
-
-char *
-SMB_DOSTimToStr(int DOS_time)
-{
- static char SMB_Time_Temp[48];
- int DOS_sec, DOS_min, DOS_hour, DOS_day, DOS_month, DOS_year;
-
- SMB_Time_Temp[0] = 0;
-
- DOS_sec = (DOS_time & 0x001F) * 2;
- DOS_min = (DOS_time & 0x07E0) >> 5;
- DOS_hour = ((DOS_time & 0xF800) >> 11);
-
- DOS_day = (DOS_time & 0x001F0000) >> 16;
- DOS_month = (DOS_time & 0x01E00000) >> 21;
- DOS_year = ((DOS_time & 0xFE000000) >> 25) + 80;
-
- sprintf(SMB_Time_Temp, "%2d/%02d/%2d %2d:%02d:%02d", DOS_day, DOS_month,
- DOS_year, DOS_hour, DOS_min, DOS_sec);
-
- return (SMB_Time_Temp);
-
-}
-
-/* Convert an attribute byte/word etc to a string ... We return a pointer
- * to a static string which we guarantee is long enough. If verbose is
- * true, we print out long form of strings ... */
-
-char *
-SMB_AtrToStr(int attribs, BOOL verbose)
-{
- static char SMB_Attrib_Temp[128];
-
- SMB_Attrib_Temp[0] = 0;
-
- if (attribs & SMB_FA_ROF)
- strcat(SMB_Attrib_Temp, (verbose ? "Read Only " : "R"));
-
- if (attribs & SMB_FA_HID)
- strcat(SMB_Attrib_Temp, (verbose ? "Hidden " : "H"));
-
- if (attribs & SMB_FA_SYS)
- strcat(SMB_Attrib_Temp, (verbose ? "System " : "S"));
-
- if (attribs & SMB_FA_VOL)
- strcat(SMB_Attrib_Temp, (verbose ? "Volume " : "V"));
-
- if (attribs & SMB_FA_DIR)
- strcat(SMB_Attrib_Temp, (verbose ? "Directory " : "D"));
-
- if (attribs & SMB_FA_ARC)
- strcat(SMB_Attrib_Temp, (verbose ? "Archive " : "A"));
-
- return (SMB_Attrib_Temp);
-
-}
-
-/* Pick up the Max Buffer Size from the Tree Structure ... */
-
-int
-SMB_Get_Tree_MBS(SMB_Tree_Handle tree)
-{
- if (tree != NULL) {
- return (tree->mbs);
- } else {
- return (SMBlibE_BAD);
- }
-}
-
-/* Pick up the Max buffer size */
-
-int
-SMB_Get_Max_Buf_Siz(SMB_Handle_Type Con_Handle)
-{
- if (Con_Handle != NULL) {
- return (Con_Handle->max_xmit);
- } else {
- return (SMBlibE_BAD);
- }
-
-}
-/* Pickup the protocol index from the connection structure */
-
-int
-SMB_Get_Protocol_IDX(SMB_Handle_Type Con_Handle)
-{
- if (Con_Handle != NULL) {
- return (Con_Handle->prot_IDX);
- } else {
- return (0xFFFF); /* Invalid protocol */
- }
-
-}
-
-/* Pick up the protocol from the connection structure */
-
-int
-SMB_Get_Protocol(SMB_Handle_Type Con_Handle)
-{
- if (Con_Handle != NULL) {
- return (Con_Handle->protocol);
- } else {
- return (0xFFFF); /* Invalid protocol */
- }
-
-}
-
/* Figure out what protocol was accepted, given the list of dialect strings */
/* We offered, and the index back from the server. We allow for a user */
/* supplied list, and assume that it is a subset of our list */
-int
-SMB_Figure_Protocol(char *dialects[], int prot_index)
+static int
+SMB_Figure_Protocol(const char *dialects[], int prot_index)
{
int i;
/* none acceptible, and our return value is 0 if ok, <0 if problems */
int
-SMB_Negotiate(SMB_Handle_Type Con_Handle, char *Prots[])
+SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[])
{
struct RFCNB_Pkt *pkt;
int prots_len, i, pkt_len, prot, alloc_len;
SMB_Tree_Handle Tree_Handle,
char *path,
char *password,
- char *device)
+ const char *device)
{
struct RFCNB_Pkt *pkt;
int param_len, pkt_len;
}
-int
-SMB_TreeDisconnect(SMB_Tree_Handle Tree_Handle, BOOL discard)
-{
- struct RFCNB_Pkt *pkt;
- int pkt_len;
-
- pkt_len = SMB_tdis_len;
-
- pkt = (struct RFCNB_Pkt *) RFCNB_Alloc_Pkt(pkt_len);
-
- if (pkt == NULL) {
-
- SMBlib_errno = SMBlibE_NoSpace;
- return (SMBlibE_BAD); /* Should handle the error */
-
- }
- /* Now plug in the values ... */
-
- bzero(SMB_Hdr(pkt), SMB_tdis_len);
- SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
- *(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBtdis;
- SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Tree_Handle->con->pid);
- SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Tree_Handle->con->mid);
- SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Tree_Handle->con->uid);
- *(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 0;
-
- SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, Tree_Handle->tid);
- SSVAL(SMB_Hdr(pkt), SMB_tcon_bcc_offset, 0);
-
- /* Now send the packet and sit back ... */
-
- if (RFCNB_Send(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) {
-
-#ifdef DEBUG
- fprintf(stderr, "Error sending TDis request\n");
-#endif
-
- RFCNB_Free_Pkt(pkt);
- SMBlib_errno = -SMBlibE_SendFailed;
- return (SMBlibE_BAD);
-
- }
- /* Now get the response ... */
-
- if (RFCNB_Recv(Tree_Handle->con->Trans_Connect, pkt, pkt_len) < 0) {
-
-#ifdef DEBUG
- fprintf(stderr, "Error receiving response to TCon\n");
-#endif
-
- RFCNB_Free_Pkt(pkt);
- SMBlib_errno = -SMBlibE_RecvFailed;
- return (SMBlibE_BAD);
-
- }
- /* Check out the response type ... */
-
- if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS) { /* Process error */
-
-#ifdef DEBUG
- fprintf(stderr, "SMB_TDis failed with errorclass = %i, Error Code = %i\n",
- CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset),
- SVAL(SMB_Hdr(pkt), SMB_hdr_err_offset));
-#endif
-
- SMBlib_SMB_Error = IVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset);
- RFCNB_Free_Pkt(pkt);
- SMBlib_errno = SMBlibE_Remote;
- return (SMBlibE_BAD);
-
- }
- Tree_Handle->tid = 0xFFFF; /* Invalid TID */
- Tree_Handle->mbs = 0; /* Invalid */
-
-#ifdef DEBUG
-
- fprintf(stderr, "Tree disconnect successful ...\n");
-
-#endif
-
- /* What about the tree handle ? */
-
- if (discard == TRUE) { /* Unlink it and free it ... */
-
- if (Tree_Handle->next == NULL)
- Tree_Handle->con->first_tree = Tree_Handle->prev;
- else
- Tree_Handle->next->prev = Tree_Handle->prev;
-
- if (Tree_Handle->prev == NULL)
- Tree_Handle->con->last_tree = Tree_Handle->next;
- else
- Tree_Handle->prev->next = Tree_Handle->next;
-
- }
- RFCNB_Free_Pkt(pkt);
- return (0);
-
-}
-
/* Pick up the last LMBlib error ... */
int
/* Keep this table in sync with the message codes in smblib-common.h */
-static char *SMBlib_Error_Messages[] =
+static const char *SMBlib_Error_Messages[] =
{
"Request completed sucessfully.",
#include "rfcnb-priv.h"
#include "rfcnb.h"
#include "rfcnb-util.h"
+#include "smbencrypt.h"
#include <stdlib.h>
#include <unistd.h>
SMB_State_Types SMBlib_State;
-extern int RFCNB_Set_Sock_NoDelay(RFCNB_Con *, BOOL);
-extern void SMB_Get_My_Name(char *, int);
-
/* Initialize the SMBlib package */
int
-SMB_Init()
+SMB_Init(void)
{
SMBlib_State = SMB_State_Started;
}
-int
-SMB_Term()
-{
-
-#ifdef SMBLIB_INSTRUMENT
-
- SMBlib_Instrument_Term(); /* Clean up and print results */
-
-#endif
-
- return 0;
-
-}
-
/* SMB_Create: Create a connection structure and return for later use */
/* We have other helper routines to set variables */
}
-int
-SMBlib_Set_Sock_NoDelay(SMB_Handle_Type Con_Handle, BOOL yn)
-{
-
-
- if (RFCNB_Set_Sock_NoDelay(Con_Handle->Trans_Connect, yn) < 0) {
-
-#ifdef DEBUG
-#endif
-
- fprintf(stderr, "Setting no-delay on TCP socket failed ...\n");
-
- }
- return (0);
-
-}
-
/* SMB_Connect_Server: Connect to a server, but don't negotiate protocol */
/* or anything else ... */
/* If Con_Handle == NULL then create a handle and connect, otherwise */
/* use the handle passed */
-char *SMB_Prots_Restrict[] =
+const char *SMB_Prots_Restrict[] =
{"PC NETWORK PROGRAM 1.0",
NULL};
/* Create a handle to allow us to set/override some parameters ... */
-SMB_Handle_Type SMB_Create_Con_Handle();
+SMB_Handle_Type SMB_Create_Con_Handle(void);
/* Connect to a server, but do not do a tree con etc ... */
/* Negotiate a protocol */
-int SMB_Negotiate(void *Con_Handle, char *Prots[]);
+int SMB_Negotiate(SMB_Handle_Type Con_Handle, const char *Prots[]);
/* Connect to a tree ... */
-void *SMB_TreeConnect(void *con_handle, void *tree_handle,
- char *path, char *password, char *dev);
+SMB_Tree_Handle SMB_TreeConnect(SMB_Handle_Type con_handle, SMB_Tree_Handle tree_handle,
+ char *path, char *password, const char *dev);
/* Disconnect a tree ... */
int SMB_Check_Dir(void *tree, char *dir_name);
-int SMB_Get_Last_Error();
+int SMB_Get_Last_Error(void);
-int SMB_Get_Last_SMB_Err();
+int SMB_Get_Last_SMB_Err(void);
-int SMB_Get_Error_Msg(int msg, char *msgbuf, int len);
+void SMB_Get_Error_Msg(int msg, char *msgbuf, int len);
void *SMB_Logon_And_TCon(void *con, void *tree, char *user, char *pass,
char *service, char *st);
+
+void SMB_Get_My_Name(char *, int);
+
+int SMB_Init(void);
+
+extern int SMB_Logon_Server(SMB_Handle_Type, char *, char *);
+
#include "smblib.h"
#include "valid.h"
-extern int SMB_Init(void);
-extern int SMB_Logon_Server(SMB_Handle_Type, char *, char *);
-
-
int
Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP, char *DOMAIN)
{
- char *SMB_Prots[] =
+ const char *SMB_Prots[] =
{"PC NETWORK PROGRAM 1.0",
"MICROSOFT NETWORKS 1.03",
"MICROSOFT NETWORKS 3.0",