- {
- if(!isalpha(id[i]) && id[i] != '_')
- {
- return 0;
- }
- }
-
- return 1;
-}
-
-/* Generic outgoing request routine - takes care of logging and error detection as well */
-
-int send_request(conn_list_t *cl, const char *format, int request, /*args*/ ...)
-{
- va_list args;
- char *buffer = NULL;
- int len;
-
-cp
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_DEBUG, _("Sending %s to %s (%s)"), request_name[request], cl->name, cl->hostname);
-
- va_start(args, request);
- len = vasprintf(&buffer, format, args);
- va_end(args);
-
- if(len < 0 || !buffer)
- {
- syslog(LOG_ERR, _("Error during vasprintf(): %m"));
- return -1;
- }
-
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Sending meta data to %s (%s): %s"),
- cl->name, cl->hostname, buffer);
-
- if(cl->status.encryptin)
- {
- /* FIXME: Do encryption */
- }
-
- if((write(cl->meta_socket, buffer, len)) < 0)
- {
- syslog(LOG_ERR, _("Sending meta data failed: %m"));
- return -1;
- }
-cp
-}
-
-/* Connection protocol:
-
- Client Server
- send_id(u)
- send_challenge(R)
- send_chal_reply(BH)
- send_id(B)
- send_challenge(BR)
- send_chal_reply(BH)
- send_ack(B)
- send_ack(B)
-
- (u) Unencrypted,
- (R) RSA,
- (H) SHA1,
- (B) Blowfish.
-
- Part of the challenge is directly used to set the blowfish key and the initial vector.
- (Twee vliegen in één klap!)
-*/
-
-int send_id(conn_list_t *cl)
-{
-cp
- return send_request(cl, "%d %s %d %s", ID,
- myself->name, myself->protocol_version, opt2str(myself->options));
-}
-
-int id_h(conn_list_t *cl)
-{
- conn_list_t *old;
- char *options;
-cp
- if(sscanf(cl->buffer, "%*d %as %d %as", &cl->name, &cl->protocol_version, &options) != 3)
- {
- syslog(LOG_ERR, _("Got bad ID from %s"), cl->hostname);
- return -1;
- }
-
- /* Check if version matches */
-
- if(cl->protocol_version != myself->protocol_version)
- {
- syslog(LOG_ERR, _("Peer %s (%s) uses incompatible version %d"),
- cl->name, cl->hostname, cl->protocol_version);