Apache2-AuthenNTLM
view release on metacpan or search on metacpan
smb/smbval/smblib.c view on Meta::CPAN
SMB_State_Types SMBlib_State;
/* Initialize the SMBlib package */
int SMB_Init()
{
SMBlib_State = SMB_State_Started;
signal(SIGPIPE, SIG_IGN); /* Ignore these ... */
/* If SMBLIB_Instrument is defines, turn on the instrumentation stuff */
#ifdef SMBLIB_INSTRUMENT
SMBlib_Instrument_Init();
#endif
return 0;
}
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 */
SMB_Handle_Type SMB_Create_Con_Handle()
{
SMBlib_errno = SMBlibE_NotImpl;
return(NULL);
}
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 ... */
SMB_Handle_Type SMB_Connect_Server(SMB_Handle_Type Con_Handle,
char *server, char *NTdomain)
{ SMB_Handle_Type con;
char temp[80], called[80], calling[100], *address, buf [20];
int i;
/* Get a connection structure if one does not exist */
con = Con_Handle;
if (Con_Handle == NULL) {
if ((con = (struct SMB_Connect_Def *)malloc(sizeof(struct SMB_Connect_Def))) == NULL) {
SMBlib_errno = SMBlibE_NoSpace;
return NULL;
}
}
/* Init some things ... */
strcpy(con -> service, "");
strcpy(con -> username, "");
strcpy(con -> password, "");
strcpy(con -> sock_options, "");
strcpy(con -> address, "");
strcpy(con -> desthost, server);
strcpy(con -> PDomain, NTdomain);
strcpy(con -> OSName, SMBLIB_DEFAULT_OSNAME);
strcpy(con -> LMType, SMBLIB_DEFAULT_LMTYPE);
con -> first_tree = con -> last_tree = NULL;
SMB_Get_My_Name(con -> myname, sizeof(con -> myname));
con -> port = 0; /* No port selected */
/* Get some things we need for the SMB Header */
con -> pid = getpid();
con -> mid = con -> pid; /* This will do for now ... */
con -> uid = 0; /* Until we have done a logon, no uid */
con -> gid = getgid();
/* Now connect to the remote end, but first upper case the name of the
service we are going to call, sine some servers want it in uppercase */
smb/smbval/smblib.c view on Meta::CPAN
}
bzero(SMB_Hdr(pkt), SMB_ssetpNTLM_len);
SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
*(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBsesssetupX;
SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid);
*(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13;
*(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */
SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mbs_offset, SMBLIB_MAX_XMIT);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_mmc_offset, 2);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_vcn_offset, 1); /* must be one, otherwise server will close all other connections!!! */
SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_snk_offset, 0);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cipl_offset, pass_len);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cspl_offset, 0);
SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_res_offset, 0);
SIVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_cap_offset, 0);
SSVAL(SMB_Hdr(pkt), SMB_ssetpNTLM_bcc_offset, param_len);
/* Now copy the param strings in with the right stuff */
p = (char *)(SMB_Hdr(pkt) + SMB_ssetpNTLM_buf_offset);
/* Copy in password, then the rest. Password has no null at end */
memcpy(p, pword, pass_len);
p = p + pass_len;
strcpy(p, UserName);
p = p + strlen(UserName);
*p = 0;
p = p + 1;
strcpy(p, pdomain);
p = p + strlen(pdomain);
*p = 0;
p = p + 1;
strcpy(p, Con_Handle -> OSName);
p = p + strlen(Con_Handle -> OSName);
*p = 0;
p = p + 1;
strcpy(p, Con_Handle -> LMType);
p = p + strlen(Con_Handle -> LMType);
*p = 0;
}
/* Now send it and get a response */
if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0){
#ifdef DEBUG
fprintf(stderr, "Error sending SessSetupX request\n");
#endif
RFCNB_Free_Pkt(pkt);
SMBlib_errno = SMBlibE_SendFailed;
return(SMBlibE_BAD);
}
/* Now get the response ... */
if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0) {
#ifdef DEBUG
fprintf(stderr, "Error receiving response to SessSetupAndX\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_SessSetupAndX 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);
}
if (SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset) & 0x1)
{
/* do we allow guest login? NO! */
RFCNB_Free_Pkt(pkt);
SMBlib_errno = SMBlibE_GuestOnly ;
return(SMBlibE_BAD);
}
#ifdef DEBUG
fprintf(stderr, "SessSetupAndX response. Action = %i\n",
SVAL(SMB_Hdr(pkt), SMB_ssetpr_act_offset));
#endif
/* Now pick up the UID for future reference ... */
Con_Handle -> uid = SVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset);
RFCNB_Free_Pkt(pkt);
return(0);
}
int SMB_Logoff_Server(SMB_Handle_Type Con_Handle)
{
struct RFCNB_Pkt *pkt;
int pkt_len;
pkt_len = SMB_ssetpLM_len;
pkt = (struct RFCNB_Pkt *)RFCNB_Alloc_Pkt(pkt_len);
if (pkt == NULL) {
SMBlib_errno = SMBlibE_NoSpace;
return(SMBlibE_BAD); /* Should handle the error */
}
bzero(SMB_Hdr(pkt), SMB_ssetpNTLM_len);
SIVAL(SMB_Hdr(pkt), SMB_hdr_idf_offset, SMB_DEF_IDF); /* Plunk in IDF */
*(SMB_Hdr(pkt) + SMB_hdr_com_offset) = SMBulogoffX;
SSVAL(SMB_Hdr(pkt), SMB_hdr_pid_offset, Con_Handle -> pid);
SSVAL(SMB_Hdr(pkt), SMB_hdr_tid_offset, 0);
SSVAL(SMB_Hdr(pkt), SMB_hdr_mid_offset, Con_Handle -> mid);
SSVAL(SMB_Hdr(pkt), SMB_hdr_uid_offset, Con_Handle -> uid);
*(SMB_Hdr(pkt) + SMB_hdr_wct_offset) = 13;
*(SMB_Hdr(pkt) + SMB_hdr_axc_offset) = 0xFF; /* No extra command */
SSVAL(SMB_Hdr(pkt), SMB_hdr_axo_offset, 0);
if (RFCNB_Send(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0)
{
#ifdef DEBUG
fprintf(stderr, "Error sending UlogOffX request\n");
#endif
RFCNB_Free_Pkt(pkt);
SMBlib_errno = SMBlibE_SendFailed;
return(SMBlibE_BAD);
}
if (RFCNB_Recv(Con_Handle -> Trans_Connect, pkt, pkt_len) < 0)
{
#ifdef DEBUG
fprintf(stderr, "Error receiving response uLogoffAndX\n");
#endif
RFCNB_Free_Pkt(pkt);
SMBlib_errno = SMBlibE_RecvFailed;
return(SMBlibE_BAD);
}
if (CVAL(SMB_Hdr(pkt), SMB_hdr_rcls_offset) != SMBC_SUCCESS)
{ /* Process error */
#ifdef DEBUG
fprintf(stderr, "SMB_UlogoffAndX 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);
}
return 0;
}
/* Disconnect from the server, and disconnect all tree connects */
int SMB_Discon(SMB_Handle_Type Con_Handle, BOOL KeepHandle)
{
/* We just disconnect the connection for now ... */
RFCNB_Hangup(Con_Handle -> Trans_Connect);
if (!KeepHandle)
free(Con_Handle);
return(0);
}
( run in 1.937 second using v1.01-cache-2.11-cpan-d8267643d1d )