00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libnuclient.h"
00024 #include <sasl/saslutil.h>
00025 #include <proto.h>
00026 #include <nussl.h>
00027
00028 #include "sending.h"
00029 #include "proc.h"
00030
00036 #if DEBUG_ENABLE
00037 int count;
00038 #endif
00039
00040 int send_hello_pckt(nuauth_session_t * session)
00041 {
00042 struct nu_header header;
00043
00044
00045 header.proto = PROTO_VERSION;
00046 header.msg_type = USER_HELLO;
00047 header.option = 0;
00048 header.length = htons(sizeof(struct nu_header));
00049
00050 #if XXX
00051
00052 if (session->tls) {
00053 if (gnutls_record_send
00054 (session->tls, &header,
00055 sizeof(struct nu_header)) <= 0) {
00056 #if DEBUG_ENABLE
00057 printf("write failed at %s:%d\n", __FILE__,
00058 __LINE__);
00059 #endif
00060 return 0;
00061 }
00062 }
00063 #else
00064 if (nussl_write(session->nussl, (char*)&header, sizeof(struct nu_header)) < 0)
00065 {
00066 #if DEBUG_ENABLE
00067 printf("write failed at %s:%d\n", __FILE__,
00068 __LINE__);
00069 #endif
00070 return 0;
00071 }
00072 #endif
00073
00074 return 1;
00075 }
00076
00077
00083 int send_user_pckt(nuauth_session_t * session, conn_t * carray[CONN_MAX])
00084 {
00085 char datas[PACKET_SIZE];
00086 char *pointer;
00087 unsigned int item;
00088 struct nu_header *header;
00089 struct nu_authreq *authreq;
00090 struct nu_authfield_ipv6 *authfield;
00091 struct nu_authfield_app *appfield;
00092 unsigned len;
00093 const char *appname;
00094 char *app_ptr;
00095
00096 session->timestamp_last_sent = time(NULL);
00097 memset(datas, 0, sizeof datas);
00098
00099 header = (struct nu_header *) datas;
00100 header->proto = PROTO_VERSION;
00101 header->msg_type = USER_REQUEST;
00102 header->option = 0;
00103 header->length = sizeof(struct nu_header);
00104 pointer = (char *) (header + 1);
00105
00106 for (item = 0; ((item < CONN_MAX) && carray[item] != NULL); item++) {
00107 #if DEBUG
00108 printf("adding one authreq\n");
00109 #endif
00110 #ifdef LINUX
00111
00112 appname = prg_cache_get(carray[item]->inode);
00113 #else
00114 appname = "UNKNOWN";
00115 #endif
00116 header->length +=
00117 sizeof(struct nu_authreq) +
00118 sizeof(struct nu_authfield_ipv6);
00119
00120 authreq = (struct nu_authreq *) pointer;
00121 authreq->packet_seq = session->packet_seq++;
00122 authreq->packet_length =
00123 sizeof(struct nu_authreq) +
00124 sizeof(struct nu_authfield_ipv6);
00125
00126 authfield = (struct nu_authfield_ipv6 *) (authreq + 1);
00127 authfield->type = IPV6_FIELD;
00128 authfield->option = 0;
00129 authfield->src = carray[item]->ip_src;
00130 authfield->dst = carray[item]->ip_dst;
00131 authfield->proto = carray[item]->protocol;
00132 authfield->flags = 0;
00133 authfield->FUSE = 0;
00134 #ifdef _I386__ENDIAN_H_
00135 #ifdef __DARWIN_LITTLE_ENDIAN
00136 authfield->sport = carray[item]->port_src;
00137 authfield->dport = carray[item]->port_dst;
00138 #else
00139 authfield->sport = htons(carray[item]->port_src);
00140 authfield->dport = htons(carray[item]->port_dst);
00141 #endif
00142 #else
00143 authfield->sport = htons(carray[item]->port_src);
00144 authfield->dport = htons(carray[item]->port_dst);
00145 #endif
00146
00147
00148 appfield = (struct nu_authfield_app *) (authfield + 1);
00149 appfield->type = APP_FIELD;
00150 appfield->option = APP_TYPE_NAME;
00151 app_ptr = (char *) (appfield + 1);
00152 sasl_encode64(appname, strlen(appname), app_ptr,
00153 PROGNAME_BASE64_WIDTH, &len);
00154 appfield->length = sizeof(struct nu_authfield_app) + len;
00155 authreq->packet_length += appfield->length;
00156
00157
00158 header->length += appfield->length;
00159
00160 assert(header->length < PACKET_SIZE);
00161
00162 pointer += authreq->packet_length;
00163
00164 appfield->length = htons(appfield->length);
00165 authreq->packet_length = htons(authreq->packet_length);
00166 authfield->length =
00167 htons(sizeof(struct nu_authfield_ipv6));
00168 }
00169 header->length = htons(header->length);
00170 if (session->debug_mode) {
00171 printf("[+] Send %u new connection(s) to nuauth\n", item);
00172 }
00173
00174
00175 #if XXX
00176 if (session->tls) {
00177 if (gnutls_record_send
00178 (session->tls, datas, pointer - datas) <= 0) {
00179 printf("write failed\n");
00180 return 0;
00181 }
00182 }
00183 #else
00184 if (nussl_write(session->nussl, (char*)datas, pointer - datas) < 0)
00185 {
00186 printf("write failed\n");
00187 return 0;
00188 }
00189 #endif
00190 return 1;
00191 }
00192