// // Send acknowledgement for message data. // DTMailError_t POP2Server::ptrans_retrieve_end(int) { if (_removeafterdelivery) return do_transaction("ACKD"); else return do_transaction("ACKS"); }
/**************************************************************************** * release_ticket * Give a ticket back to the server * Results: 0 for success, -1 for failure */ int release_ticket() { char buf[MSGLEN]; char *response; if(!have_ticket) /* don't have a ticket */ return(0); /* nothing to release */ sprintf(buf, "GBYE %s", ticket_buf); /* compose message */ if ( (response = do_transaction(buf)) == NULL ) return(-1); /* examine response * success: THNX info-string * failure: FAIL error-string */ if ( strncmp(response, "THNX", 4) == 0 ){ narrate("released ticket OK",""); return 0; } if ( strncmp(response, "FAIL", 4) == 0) narrate("release failed", response+5); else narrate("Unknown message:", response); return(-1); } /* release_ticket */
/**************************************************************************** * get_ticket * get a ticket from the license server * Results: 0 for success, -1 for failure */ int get_ticket() { char *response; char buf[MSGLEN]; if(have_ticket) /* don't be greedy */ return(0); sprintf(buf, "HELO %d", pid); /* compose request */ if ( (response = do_transaction(buf)) == NULL ) return(-1); /* parse the response and see if we got a ticket. * on success, the message is: TICK ticket-string * on failure, the message is: FAIL failure-msg */ if ( strncmp(response, "TICK", 4) == 0 ){ strcpy(ticket_buf, response + 5); /* grab ticket-id */ have_ticket = 1; /* set this flag */ narrate("got ticket", ticket_buf); return(0); } if ( strncmp(response,"FAIL",4) == 0) narrate("Could not get ticket",response); else narrate("Unknown message:", response); return(-1); } /* get_ticket */
// // Get range of messages to be fetched. // DTMailError_t POP2Server::ptrans_fldstate_read(int *countp, int *newp) { // // We should have picked up a count of messages in the user's // default inbox from the pop2_getauth() response. // if (_pound_arg == -1) return DTME_MailServerAccess_Error; // Maybe the user wanted a non-default folder. if (! is_inbox()) { DTMailError_t ok; ok = do_transaction("FOLD %s", _folder); if (DTME_NoError != ok) return ok; if (_pound_arg == -1) return DTME_MailServerAccess_Error; } *countp = _pound_arg; *newp = -1; return DTME_NoError; }
/******************************************************************* * get_ticket * get a ticket from the license server * Result: 0 for scuccess, -1 for failure */ int get_ticket() { char *response; char buf[MSGLEN]; if(have_ticket) return 0; // dont' be greedy sprintf(buf,"HELLO %d",pid); if((response = do_transaction(buf)) == NULL) { return -1; } /* parse the response and if we got a ticket. * on success,the message is: TICK ticket-string * on failure,the message is: FAIL failute-msg */ if(strncmp(response,"TICK",4) == 0) { strcpy(ticket_buf,response + 5);; // grab ticket -id have_ticket = 1; // set the flag narrate("got ticket",ticket_buf); return 0; } if(strncmp(response,"FAIL",4) == 0) narrate("Could not get ticket",response); else narrate("Unknowm message:",response); return -1; }// get_ticket
/******************************************************************* * do_validate * validate the ticket that hold on * Result: 0 for success, -1 for failure */ int do_validate() { char buf[BUFSIZ]; char *response; sprintf(buf,"VALD %s",ticket_buf); if((response = do_transaction(buf)) == NULL) return -1; /* parse the response and see if we the ticket is valid * on success, the message is: GOOD vaild-msg * on failure, the message is: FIAL failure-msg */ if(strncmp(response,"GOOD",4) == 0) { narrate("Validate success",ticket_buf); return 0; } if(strncmp(response,"FAIL",4) == 0) narrate("Invalid ticket",response); else narrate("Unknown message:",response); return -1; }
// // Apply for connection authorization. // DTMailError_t POP2Server::ptrans_authorize(char*) { DTMailError_t ok; ok = do_transaction("HELO %s %s", _username, _password); if (DTME_NoError != ok) return DTME_MailServerAccess_AuthorizationFailed; return DTME_NoError; }
/* Generic handler for GET, HEAD, and POST methods. */ static int handle_method(struct socket_buffer *client_sock, struct http_request *request) { struct socket_buffer server_sock; union sockaddr_u su; size_t sslen = sizeof(su.storage); int code; int s, rc; if (strcmp(request->uri.scheme, "http") != 0) { if (o.verbose) logdebug("Unknown scheme in URI: %s.\n", request->uri.scheme); return 400; } if (request->uri.port == -1) { if (o.verbose) logdebug("Unknown port in URI.\n"); return 400; } rc = resolve(request->uri.host, request->uri.port, &su.storage, &sslen, o.af); if (rc != 0) { if (o.debug) { logdebug("Can't resolve name %s:%d: %s.\n", request->uri.host, request->uri.port, gai_strerror(rc)); } return 504; } /* RFC 2616, section 5.1.2: "In order to avoid request loops, a proxy MUST be able to recognize all of its server names, including any aliases, local variations, and the numeric IP address. */ if (request->uri.port == o.portno && addr_is_local(&su)) { if (o.verbose) logdebug("Proxy loop detected: %s:%d\n", request->uri.host, request->uri.port); return 403; } s = Socket(su.storage.ss_family, SOCK_STREAM, IPPROTO_TCP); if (connect(s, &su.sockaddr, sslen) == -1) { if (o.debug) logdebug("Can't connect to %s.\n", inet_socktop(&su)); Close(s); return 504; } socket_buffer_init(&server_sock, s); code = do_transaction(request, client_sock, &server_sock); fdinfo_close(&server_sock.fdn); if (code != 0) return code; return 0; }
// // Request nth message. // DTMailError_t POP2Server::ptrans_retrieve_start(int msg, int *lenp) { DTMailError_t ok; *lenp = 0; ok = do_transaction("READ %d", msg); if (DTME_NoError != ok) return ok; *lenp = _equal_arg; ok = do_send("RETR"); return ok; }
bool SocketInstance::commit_transaction (Transaction &trans) { SCIM_DEBUG_IMENGINE(2) << " commit_transaction:\n"; bool ret = false; if (m_peer_id >= 0) { if (global->send_transaction (trans)) { while (1) { if (!global->receive_transaction (trans)) break; if (!do_transaction (trans, ret)) return ret; } } } if (global->create_connection ()) reset (); return ret; }
// // Apply for connection authorization. // DTMailError_t APOPServer::ptrans_authorize(char *greeting) { static const char *pname = "APOPServer::ptrans_authorize"; static char ascii_digest [33]; char *start,*end; char *msg; DTMailError_t ok; // Build MD5 digest from greeting timestamp + password. // Find start of timestamp. for (start = greeting; *start != 0 && *start != '<'; start++) continue; if (*start == 0) { _logger.logError( DTM_FALSE, "%s: APOP timestamp not found in greeting", pname); return DTME_MailServerAccess_AuthorizationFailed; } // Find end of timestamp. for (end = start; *end != 0 && *end != '>'; end++) continue; if (*end == 0 || end == start + 1) { _logger.logError( DTM_FALSE, "%s: APOP timestamp not found in greeting", pname); return DTME_MailServerAccess_AuthorizationFailed; } else *++end = '\0'; { int i; MD5_CTX context; unsigned char digest[16]; // Copy timestamp and password into digestion buffer. msg = (char*) malloc((end-start+1) + strlen(_password) + 1); strcpy(msg, start); strcat(msg, _password); MD5Init(&context); MD5Update(&context, (unsigned char*) msg, strlen(msg)); for (i = 0; i < 16; i++) sprintf(ascii_digest+2*i, "%02x", digest[i]); free(msg); } ok = do_transaction("APOP %s %s", _username, ascii_digest); if (DTME_NoError != ok) return DTME_MailServerAccess_AuthorizationFailed; return DTME_NoError; }