X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=authprogs%2Fsmbval%2Frfcnb-io.c;fp=authprogs%2Fsmbval%2Frfcnb-io.c;h=0000000000000000000000000000000000000000;hb=b7a32e2d73e3ab1add8208d3e157f7269a31ef4d;hp=3f030fa9db7275142929802b0f5f7b9f51499a24;hpb=ac902a8299ff4469b356836f431ead31c3377377;p=innduct.git diff --git a/authprogs/smbval/rfcnb-io.c b/authprogs/smbval/rfcnb-io.c deleted file mode 100644 index 3f030fa..0000000 --- a/authprogs/smbval/rfcnb-io.c +++ /dev/null @@ -1,310 +0,0 @@ -/* UNIX RFCNB (RFC1001/RFC1002) NEtBIOS implementation - - Version 1.0 - RFCNB IO Routines ... - - Copyright (C) Richard Sharpe 1996 - -*/ - -/* - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "config.h" -#include "clibrary.h" -#include -#include - -#include "rfcnb-priv.h" -#include "rfcnb-util.h" -#include "rfcnb-io.h" - -int RFCNB_Timeout = 0; /* Timeout in seconds ... */ - -/* Discard the rest of an incoming packet as we do not have space for it - in the buffer we allocated or were passed ... */ - -int RFCNB_Discard_Rest(struct RFCNB_Con *con, int len) - -{ char temp[100]; /* Read into here */ - int rest, this_read, bytes_read; - - /* len is the amount we should read */ - - rest = len; - - while (rest > 0) { - - this_read = (rest > sizeof(temp)?sizeof(temp):rest); - - bytes_read = read(con -> fd, temp, this_read); - - if (bytes_read <= 0) { /* Error so return */ - - if (bytes_read < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; - - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - - } - - rest = rest - bytes_read; - - } - - return(0); - -} - - -/* Send an RFCNB packet to the connection. - - We just send each of the blocks linked together ... - - If we can, try to send it as one iovec ... - -*/ - -int RFCNB_Put_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) - -{ int len_sent, tot_sent, this_len; - struct RFCNB_Pkt *pkt_ptr; - char *this_data; - int i; - struct iovec io_list[10]; /* We should never have more */ - /* If we do, this will blow up ...*/ - - /* Try to send the data ... We only send as many bytes as len claims */ - /* We should try to stuff it into an IOVEC and send as one write */ - - - pkt_ptr = pkt; - len_sent = tot_sent = 0; /* Nothing sent so far */ - i = 0; - - while ((pkt_ptr != NULL) & (i < 10)) { /* Watch that magic number! */ - - this_len = pkt_ptr -> len; - this_data = pkt_ptr -> data; - if ((tot_sent + this_len) > len) - this_len = len - tot_sent; /* Adjust so we don't send too much */ - - /* Now plug into the iovec ... */ - - io_list[i].iov_len = this_len; - io_list[i].iov_base = this_data; - i++; - - tot_sent += this_len; - - if (tot_sent == len) break; /* Let's not send too much */ - - pkt_ptr = pkt_ptr -> next; - - } - - /* Set up an alarm if timeouts are set ... */ - - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); - - if ((len_sent = writev(con -> fd, io_list, i)) < 0) { /* An error */ - - con -> rfc_errno = errno; - if (errno == EINTR) /* We were interrupted ... */ - RFCNB_errno = RFCNBE_Timeout; - else - RFCNB_errno = RFCNBE_BadWrite; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - - } - - if (len_sent < tot_sent) { /* Less than we wanted */ - if (errno == EINTR) /* We were interrupted */ - RFCNB_errno = RFCNBE_Timeout; - else - RFCNB_errno = RFCNBE_BadWrite; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - } - - if (RFCNB_Timeout > 0) - alarm(0); /* Reset that sucker */ - - return(len_sent); - -} - -/* Read an RFCNB packet off the connection. - - We read the first 4 bytes, that tells us the length, then read the - rest. We should implement a timeout, but we don't just yet - -*/ - - -int RFCNB_Get_Pkt(struct RFCNB_Con *con, struct RFCNB_Pkt *pkt, int len) - -{ int read_len, pkt_len; - char hdr[RFCNB_Pkt_Hdr_Len]; /* Local space for the header */ - struct RFCNB_Pkt *pkt_frag; - int more, this_time, offset, frag_len, this_len; - bool seen_keep_alive = true; - - /* Read that header straight into the buffer */ - - if (len < RFCNB_Pkt_Hdr_Len) { /* What a bozo */ - - RFCNB_errno = RFCNBE_BadParam; - return(RFCNBE_Bad); - - } - - /* We discard keep alives here ... */ - - if (RFCNB_Timeout > 0) - alarm(RFCNB_Timeout); - - while (seen_keep_alive) { - - if ((read_len = read(con -> fd, hdr, sizeof(hdr))) < 0) { /* Problems */ - if (errno == EINTR) - RFCNB_errno = RFCNBE_Timeout; - else - RFCNB_errno = RFCNBE_BadRead; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - - } - - /* Now we check out what we got */ - - if (read_len == 0) { /* Connection closed, send back eof? */ - - if (errno == EINTR) - RFCNB_errno = RFCNBE_Timeout; - else - RFCNB_errno = RFCNBE_ConGone; - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - - } - - if (RFCNB_Pkt_Type(hdr) != RFCNB_SESSION_KEEP_ALIVE) { - seen_keep_alive = false; - } - - } - - /* What if we got less than or equal to a hdr size in bytes? */ - - if (read_len < sizeof(hdr)) { /* We got a small packet */ - - /* Now we need to copy the hdr portion we got into the supplied packet */ - - memcpy(pkt -> data, hdr, read_len); /*Copy data */ - - return(read_len); - - } - - /* Now, if we got at least a hdr size, alloc space for rest, if we need it */ - - pkt_len = RFCNB_Pkt_Len(hdr); - - /* Now copy in the hdr */ - - memcpy(pkt -> data, hdr, sizeof(hdr)); - - /* Get the rest of the packet ... first figure out how big our buf is? */ - /* And make sure that we handle the fragments properly ... Sure should */ - /* use an iovec ... */ - - if (len < pkt_len) /* Only get as much as we have space for */ - more = len - RFCNB_Pkt_Hdr_Len; - else - more = pkt_len; - - this_time = 0; - - /* We read for each fragment ... */ - - if (pkt -> len == read_len){ /* If this frag was exact size */ - pkt_frag = pkt -> next; /* Stick next lot in next frag */ - offset = 0; /* then we start at 0 in next */ - } - else { - pkt_frag = pkt; /* Otherwise use rest of this frag */ - offset = RFCNB_Pkt_Hdr_Len; /* Otherwise skip the header */ - } - - frag_len = pkt_frag -> len; - - if (more <= frag_len) /* If len left to get less than frag space */ - this_len = more; /* Get the rest ... */ - else - this_len = frag_len - offset; - - while (more > 0) { - - if ((this_time = read(con -> fd, (pkt_frag -> data) + offset, this_len)) <= 0) { /* Problems */ - - if (errno == EINTR) { - - RFCNB_errno = RFCNB_Timeout; - - } - else { - if (this_time < 0) - RFCNB_errno = RFCNBE_BadRead; - else - RFCNB_errno = RFCNBE_ConGone; - } - - RFCNB_saved_errno = errno; - return(RFCNBE_Bad); - - } - - read_len = read_len + this_time; /* How much have we read ... */ - - /* Now set up the next part */ - - if (pkt_frag -> next == NULL) break; /* That's it here */ - - pkt_frag = pkt_frag -> next; - this_len = pkt_frag -> len; - offset = 0; - - more = more - this_time; - - } - - if (read_len < (pkt_len + sizeof(hdr))) { /* Discard the rest */ - - return(RFCNB_Discard_Rest(con, (pkt_len + sizeof(hdr)) - read_len)); - - } - - if (RFCNB_Timeout > 0) - alarm(0); /* Reset that sucker */ - - return(read_len + sizeof(RFCNB_Hdr)); -}