#include #include #include #include #include #include #include #include #define SAMPLE_SEC_BUF_SIZE (2048) char buf[SAMPLE_SEC_BUF_SIZE]; static sasl_conn_t *conn = NULL; char *realm = "DOMAIN.COM"; char *mech = "gssapi"; char *iplocal = "127.0.0.1"; char *ipremote = "127.0.0.1"; char *searchpath = NULL; char *service = "zeekling"; int cfd; int init_sasl() { int result = sasl_client_init(NULL); if (result != SASL_OK) { printf("Initializing libsasl"); return -1; } return 0; } int connect_server() { struct sockaddr_in s_add,c_add; unsigned short portnum=2345; printf("Hello,welcome to client !\r\n"); cfd = socket(AF_INET, SOCK_STREAM, 0); if(-1 == cfd) { printf("socket fail ! \r\n"); return 1; } printf("socket ok !\r\n"); bzero(&s_add,sizeof(struct sockaddr_in)); s_add.sin_family=AF_INET; s_add.sin_addr.s_addr= inet_addr("127.0.0.1"); s_add.sin_port=htons(portnum); if(-1 == connect(cfd,(struct sockaddr *)(&s_add), sizeof(struct sockaddr))) { printf("connect fail !\r\n"); return 1; } printf("connect ok !\r\n"); return 0; } int auth_sever() { return 0; } int main() { int result; const char *data; const char *chosenmech; int serverlast = 0; unsigned len; char *fqdn = ""; char *userid = NULL; char *authid = NULL; int recbytes; int sin_size; char buffer[1024]={0}; if (connect_server() != 0) { return 1; } if (init_sasl() != 0) { return 1; } if(-1 == (recbytes = read(cfd, buffer, 1024))) { printf("read data fail !\r\n"); return -1; } if (strcmp(buffer, "need_auth") == 0 && auth_sever() != 0) { printf("auth failed"); return -1; } printf("auth ok\r\nREC:\r\n"); buffer[recbytes]='\0'; printf("%s\r\n",buffer); getchar(); close(cfd); if (init_sasl() != 0) { return 1; } return 0; }