DCCoolBreeze
Programmer
I am having trouble progammically loging into an account.
I get an account status of 103. This is on UNIX but I assume that the same error code is returned regardless of the system. Any help or does anyone know where I can get more information on this type of coding???
The code is
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#define SIZE sizeof(struct sockaddr_in)
typedef struct
{
int ui32RequestType;
char padding_1[28];
char achUserName[32];
char achPassword[32];
char achNewPassword[32];
char achDomain[32];
} AuthenticationRequest;
typedef struct
{
unsigned int ui32AccountStatus;
char padding_1[28];
unsigned int ui32MinPasswordLength;
char padding_2[28];
unsigned int ui32MaxPasswdAge;
char padding_3[28];
unsigned int ui32ExpirationDays;
char padding_4[28];
} AuthenticationResponse;
main(int argc, char *argv[])
{
int sockfd;
in_port_t port;
int bytesSent=0;
int totalBytesSent=0;
int bytesReceived=0;
int totalBytesReceived=0;
struct sockaddr_in server;
AuthenticationRequest hRequest;
AuthenticationResponse hResponse;
if (argc < 5)
{
printf("Invalid number of Arguments passed\n"
;
printf("prompt>chkcon UserID Password Domain IP\n"
;
exit(-1);
}
port = 12000;
printf("\nPreparing to validate connection using...\n"
;
printf("...User ID %s\n",argv[1]);
printf("...Password %s\n",argv[2]);
printf("...Domain %s\n",argv[3]);
printf("...Host %s\n",argv[4]);
printf("...Port %d\n\n",port);
printf("Getting socket...\n"
;
if ((sockfd = socket(PF_INET, SOCK_STREAM,0)) == -1)
{
printf("socket call failed:\n"
;
printf("...Error: %d->%s\n",errno,strerror(errno));
exit(1);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(argv[4]);
server.sin_port = htons( port );
printf("Attempting to connect...\n"
;
if (connect(sockfd,(struct sockaddr *)&server, SIZE) == -1)
{
printf("...connect call failed:\n"
;
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("Closing connection...\n"
;
close(sockfd);
exit(1);
}
else
printf("Connected to Server %s...\n",argv[4]);
memset( &hRequest, 0x00, sizeof( AuthenticationRequest ) );
memcpy( hRequest.achUserName, argv[1], strlen(argv[1]) );
memcpy( hRequest.achPassword, argv[2], strlen(argv[2]) );
memcpy( hRequest.achDomain, argv[3], strlen(argv[3]) );
hRequest.ui32RequestType = 0;
printf("Attempting to Authenticate...\n"
;
printf("...Sending request to server\n"
;
while( totalBytesSent < sizeof(AuthenticationRequest))
{
bytesSent = send(sockfd,&hRequest,sizeof(AuthenticationRequest),0);
switch(bytesSent)
{
case 0:
printf("...send call failed:\n"
;
printf("...Error: No data sent to Server\n"
;
printf("...Closing connection...\n"
;
close(sockfd);
exit(1);
case -1:
printf("...send call failed:\n"
;
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("...Closing connection...\n"
;
close(sockfd);
exit(1);
default:
totalBytesSent += bytesSent;
}
}
printf("...Message sent\n"
;
printf("...Retreiving response from the server\n"
;
memset( &hResponse, 0x00, sizeof( AuthenticationResponse ) );
while( totalBytesReceived < sizeof(AuthenticationResponse))
{
bytesReceived = recv(sockfd,&hResponse,sizeof(AuthenticationResponse),0);
printf("...bytesReceived=%d\n",bytesReceived);
switch(bytesReceived)
{
case 0:
printf("...recv call failed:\n"
;
printf("...Error: No data received from Server\n"
;
printf("...Closing connection...\n"
;
close(sockfd);
exit(1);
case -1:
printf("...recv call failed:\n"
;
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("...Closing connection...\n"
;
close(sockfd);
exit(1);
default:
totalBytesReceived += bytesReceived;
}
}
printf("Authentication was successful...\n"
;
printf("...Bytes Sent were %d\n", totalBytesSent);
printf("...Bytes Received were %d\n", totalBytesReceived);
printf("Closing connection...\n"
;
close(sockfd);
printf("Account Status: %d\n",ntohl(hResponse.ui32AccountStatus));
printf("Password attributes:\n"
;
printf("...Minimum length: %d\n",ntohl(hResponse.ui32MinPasswordLength));
printf("...Maximum age: %d\n",ntohl(hResponse.ui32MaxPasswdAge));
printf("...Expiration Days: %d\n",ntohl(hResponse.ui32ExpirationDays));
I get an account status of 103. This is on UNIX but I assume that the same error code is returned regardless of the system. Any help or does anyone know where I can get more information on this type of coding???
The code is
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#define SIZE sizeof(struct sockaddr_in)
typedef struct
{
int ui32RequestType;
char padding_1[28];
char achUserName[32];
char achPassword[32];
char achNewPassword[32];
char achDomain[32];
} AuthenticationRequest;
typedef struct
{
unsigned int ui32AccountStatus;
char padding_1[28];
unsigned int ui32MinPasswordLength;
char padding_2[28];
unsigned int ui32MaxPasswdAge;
char padding_3[28];
unsigned int ui32ExpirationDays;
char padding_4[28];
} AuthenticationResponse;
main(int argc, char *argv[])
{
int sockfd;
in_port_t port;
int bytesSent=0;
int totalBytesSent=0;
int bytesReceived=0;
int totalBytesReceived=0;
struct sockaddr_in server;
AuthenticationRequest hRequest;
AuthenticationResponse hResponse;
if (argc < 5)
{
printf("Invalid number of Arguments passed\n"
printf("prompt>chkcon UserID Password Domain IP\n"
exit(-1);
}
port = 12000;
printf("\nPreparing to validate connection using...\n"
printf("...User ID %s\n",argv[1]);
printf("...Password %s\n",argv[2]);
printf("...Domain %s\n",argv[3]);
printf("...Host %s\n",argv[4]);
printf("...Port %d\n\n",port);
printf("Getting socket...\n"
if ((sockfd = socket(PF_INET, SOCK_STREAM,0)) == -1)
{
printf("socket call failed:\n"
printf("...Error: %d->%s\n",errno,strerror(errno));
exit(1);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(argv[4]);
server.sin_port = htons( port );
printf("Attempting to connect...\n"
if (connect(sockfd,(struct sockaddr *)&server, SIZE) == -1)
{
printf("...connect call failed:\n"
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("Closing connection...\n"
close(sockfd);
exit(1);
}
else
printf("Connected to Server %s...\n",argv[4]);
memset( &hRequest, 0x00, sizeof( AuthenticationRequest ) );
memcpy( hRequest.achUserName, argv[1], strlen(argv[1]) );
memcpy( hRequest.achPassword, argv[2], strlen(argv[2]) );
memcpy( hRequest.achDomain, argv[3], strlen(argv[3]) );
hRequest.ui32RequestType = 0;
printf("Attempting to Authenticate...\n"
printf("...Sending request to server\n"
while( totalBytesSent < sizeof(AuthenticationRequest))
{
bytesSent = send(sockfd,&hRequest,sizeof(AuthenticationRequest),0);
switch(bytesSent)
{
case 0:
printf("...send call failed:\n"
printf("...Error: No data sent to Server\n"
printf("...Closing connection...\n"
close(sockfd);
exit(1);
case -1:
printf("...send call failed:\n"
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("...Closing connection...\n"
close(sockfd);
exit(1);
default:
totalBytesSent += bytesSent;
}
}
printf("...Message sent\n"
printf("...Retreiving response from the server\n"
memset( &hResponse, 0x00, sizeof( AuthenticationResponse ) );
while( totalBytesReceived < sizeof(AuthenticationResponse))
{
bytesReceived = recv(sockfd,&hResponse,sizeof(AuthenticationResponse),0);
printf("...bytesReceived=%d\n",bytesReceived);
switch(bytesReceived)
{
case 0:
printf("...recv call failed:\n"
printf("...Error: No data received from Server\n"
printf("...Closing connection...\n"
close(sockfd);
exit(1);
case -1:
printf("...recv call failed:\n"
printf("...Error: %d->%s\n",errno,strerror(errno));
printf("...Closing connection...\n"
close(sockfd);
exit(1);
default:
totalBytesReceived += bytesReceived;
}
}
printf("Authentication was successful...\n"
printf("...Bytes Sent were %d\n", totalBytesSent);
printf("...Bytes Received were %d\n", totalBytesReceived);
printf("Closing connection...\n"
close(sockfd);
printf("Account Status: %d\n",ntohl(hResponse.ui32AccountStatus));
printf("Password attributes:\n"
printf("...Minimum length: %d\n",ntohl(hResponse.ui32MinPasswordLength));
printf("...Maximum age: %d\n",ntohl(hResponse.ui32MaxPasswdAge));
printf("...Expiration Days: %d\n",ntohl(hResponse.ui32ExpirationDays));