Ejemplo n.º 1
0
static int cmd_node_set_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
                             struct cmdl *cmdl, void *data)
{
    char *str;
    uint32_t addr;
    struct nlattr *nest;
    char buf[MNL_SOCKET_BUFFER_SIZE];

    if (cmdl->argc != cmdl->optind + 1) {
        fprintf(stderr, "Usage: %s node set address ADDRESS\n",
                cmdl->argv[0]);
        return -EINVAL;
    }

    str = shift_cmdl(cmdl);
    addr = str2addr(str);
    if (!addr)
        return -1;

    if (!(nlh = msg_init(buf, TIPC_NL_NET_SET))) {
        fprintf(stderr, "error, message initialisation failed\n");
        return -1;
    }

    nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
    mnl_attr_put_u32(nlh, TIPC_NLA_NET_ADDR, addr);
    mnl_attr_nest_end(nlh, nest);

    return msg_doit(nlh, NULL, NULL);
}
Ejemplo n.º 2
0
static void cmd_dest(Stream *chp, int argc, char *argv[]) 
{
  addr_t x;
  if (argc > 0) {
    str2addr(&x, argv[0], false);
    SET_PARAM(DEST, &x);
    chprintf(chp, "Ok\r\n");
  }
  else {
    GET_PARAM(DEST, &x);
    chprintf(chp, "DEST %s\r\n", addr2str(buf, &x));
  } 
}
Ejemplo n.º 3
0
static void cmd_mycall(Stream *chp, int argc, char *argv[]) 
{
   addr_t x;
   if (argc > 0) {
      str2addr(&x, argv[0], false);
      SET_PARAM(MYCALL, &x);
      chprintf(chp, "Ok\r\n");
   }
   else {
      GET_PARAM(MYCALL, &x);
      chprintf(chp, "MYCALL %s\r\n", addr2str(buf, &x));
   } 
}
Ejemplo n.º 4
0
	/// Sets the address by extracting it from a string in the format 11:22:33:44:55:66.
	MacAddress& operator = (const std::string& addrStr) {
		str2addr(addrStr, _address);
		return *this;
	}
Ejemplo n.º 5
0
static void
do_client(const char *server, short port, char *filename, afs_int32 command,
	  afs_int32 times, afs_int32 bytes, afs_int32 sendbytes, afs_int32 readbytes,
          int dumpstats, int nojumbo, int maxmtu, int maxwsize, int minpeertimeout,
          int udpbufsz, int nostats, int hotthread, int threads)
{
    struct rx_connection *conn;
    afs_uint32 addr;
    struct rx_securityClass *secureobj;
    int secureindex;
    int ret;
    char stamp[2048];
    struct client_data *params;

#ifdef AFS_PTHREAD_ENV
    int i;
    pthread_t thread[MAX_THREADS];
    pthread_attr_t tattr;
    void *status;
#endif

    params = calloc(1, sizeof(struct client_data));

#ifdef AFS_NT40_ENV
    if (afs_winsockInit() < 0) {
	printf("Can't initialize winsock.\n");
	exit(1);
    }
#endif

    if (hotthread)
        rx_EnableHotThread();

    if (nostats)
        rx_enable_stats = 0;

    addr = str2addr(server);

    rx_SetUdpBufSize(udpbufsz);

    ret = rx_Init(0);
    if (ret)
	errx(1, "rx_Init failed");

    if (nojumbo)
      rx_SetNoJumbo();

    if (maxmtu)
      rx_SetMaxMTU(maxmtu);

    if (maxwsize) {
        rx_SetMaxReceiveWindow(maxwsize);
        rx_SetMaxSendWindow(maxwsize);
    }

    if (minpeertimeout)
        rx_SetMinPeerTimeout(minpeertimeout);


    get_sec(0, &secureobj, &secureindex);

    switch (command) {
    case RX_PERF_RPC:
        sprintf(stamp, "RPC: threads\t%d, times\t%d, write bytes\t%d, read bytes\t%d",
                 threads, times, sendbytes, readbytes);
        break;
    case RX_PERF_RECV:
        sprintf(stamp, "RECV: threads\t%d, times\t%d, bytes\t%d",
                 threads, times, bytes);
        break;
    case RX_PERF_SEND:
        sprintf(stamp, "SEND: threads\t%d, times\t%d, bytes\t%d",
                 threads, times, bytes);
        break;
    case RX_PERF_FILE:
        sprintf(stamp, "FILE %s: threads\t%d, times\t%d, bytes\t%d",
                 filename, threads, times, bytes);
        break;
    }

    conn = rx_NewConnection(addr, htons(port), RX_SERVER_ID, secureobj, secureindex);
    if (conn == NULL)
	errx(1, "failed to contact server");

#ifdef AFS_PTHREAD_ENV
    pthread_attr_init(&tattr);
    pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE);
#endif

    params->conn = conn;
    params->filename = filename;
    params->command = command;
    params->times = times;
    params->bytes = bytes;
    params->sendbytes = sendbytes;
    params->readbytes = readbytes;

    start_timer();

#ifdef AFS_PTHREAD_ENV
    for ( i=0; i<threads; i++) {
        pthread_create(&thread[i], &tattr, client_thread, params);
        if ( (i + 1) % RX_MAXCALLS == 0 ) {
            conn = rx_NewConnection(addr, htons(port), RX_SERVER_ID, secureobj, secureindex);
            if (conn != NULL) {
                struct client_data *new_params = malloc(sizeof(struct client_data));
                memcpy(new_params, params, sizeof(struct client_data));
                new_params->conn = conn;
                params = new_params;
            }
        }
    }
#else
        client_thread(params);
#endif

#ifdef AFS_PTHREAD_ENV
    for ( i=0; i<threads; i++)
        pthread_join(thread[i], &status);
#endif

    switch (command) {
    case RX_PERF_RPC:
        end_and_print_timer(stamp, (long long)threads*times*(sendbytes+readbytes));
        break;
    case RX_PERF_RECV:
    case RX_PERF_SEND:
    case RX_PERF_FILE:
        end_and_print_timer(stamp, (long long)threads*times*bytes);
        break;
    }

    DBFPRINT(("done for good\n"));

    if (dumpstats) {
	rx_PrintStats(stdout);
	rx_PrintPeerStats(stdout, rx_PeerOf(conn));
    }
    rx_Finalize();

#ifdef AFS_PTHREAD_ENV
    pthread_attr_destroy(&tattr);
#endif

    free(params);
}
Ejemplo n.º 6
0
static int enable(struct cmd_struct *cmd, struct arg_struct *arg)
{
	int cnt;
	int err;
	char *bearer;
	struct tipc_nl_msg msg;
	struct cmd_option *opt;
	struct nlattr *attrs;
	__u32 domain = 0;
	__u32 priority = 0;

	/* One mandatory argument (bearer) */
	if (arg->argc < arg->loc + 1)
		return -EINVAL;

	bearer = arg->argv[arg->loc];
	(arg->loc)++;

	cnt = opt_parse(cmd, arg);
	if (cnt < 0)
		return -EINVAL;

	msg.nl_flags =  NLM_F_REQUEST;
	msg.nl_cmd = TIPC_NL_BEARER_ENABLE;
	err = msg_init(&msg);
	if (err)
		return err;

	attrs = nla_nest_start(msg.nl_msg, TIPC_NLA_BEARER);
	NLA_PUT_STRING(msg.nl_msg, TIPC_NLA_BEARER_NAME, bearer);

	opt = get_opt(cmd, "priority");
	if (opt) {
		struct nlattr *prop;

		priority = atoi(opt->val);
		prop = nla_nest_start(msg.nl_msg, TIPC_NLA_BEARER_PROP);
		NLA_PUT_U32(msg.nl_msg, TIPC_NLA_PROP_PRIO, priority);
		nla_nest_end(msg.nl_msg, prop);
	}

	opt = get_opt(cmd, "domain");
	if (opt) {
		domain = str2addr(opt->val);
		if (!domain) {
			msg_abort(&msg);
			return -1;
		}

		NLA_PUT_U32(msg.nl_msg, TIPC_NLA_BEARER_DOMAIN, domain);
	}

	nla_nest_end(msg.nl_msg, attrs);

	err = msg_send(&msg);
	if (err)
		return err;

	err = msg_recv(&msg, NULL);
	if (err)
		return err;

	log_info("Bearer %s enabled\n", bearer);

	return 0;

nla_put_failure:
	msg_abort(&msg);

	return -ENOBUFS;
}
Ejemplo n.º 7
0
void
main(int argc, char *argv[])
{
	uchar buf[8*1024], *p;
	char addr[128], dir[40], ldir[40], *s;
	int cmd, fd, cfd, n;
	NetConnInfo *nc;

	fmtinstall('I', eipfmt);

	setnetmtpt(inside, sizeof(inside), 0);
	setnetmtpt(outside, sizeof(outside), 0);
	ARGBEGIN {
	case 'x':
		setnetmtpt(inside, sizeof(inside), ARGF());
		break;
	case 'o':
		setnetmtpt(outside, sizeof(outside), ARGF());
		break;
	} ARGEND;

	/* ver+cmd or ver+nmethod */
	if(readn(0, buf, 2) != 2)
		return;
	socksver = buf[0];
	if(socksver < 4)
		return;
	if(socksver > 5)
		socksver = 5;

	if(socksver == 4){
		/* port+ip4 */
		if(readn(0, buf+2, 2+4) != 2+4)
			return;
		/* +user\0 */
		for(p = buf+2+2+4;; p++){
			if(p >= buf+sizeof(buf))
				return;
			if(read(0, p, 1) != 1)
				return;
			if(*p == 0)
				break;
		}
		/* socks 4a dom hack */
		if((buf[4] | buf[5] | buf[6]) == 0 && buf[7]){
			/* +dom\0 */
			for(++p;; p++){
				if(p >= buf+sizeof(buf))
					return;
				if(read(0, p, 1) != 1)
					return;
				if(*p == 0)
					break;
			}
		}
	} else {
		/* nmethod */
		if((n = buf[1]) > 0)
			if(readn(0, buf+2, n) != n)
				return;

		/* ver+method */
		buf[0] = socksver;
		buf[1] = 0x00;	/* no authentication required */
		if(write(1, buf, 2) != 2)
			return;

		/* ver+cmd+res+atyp */
		if(readn(0, buf, 4) != 4)
			return;
		switch(buf[3]){
		default:
			return;
		case 0x01:	/* +ipv4 */
			if(readn(0, buf+4, 4+2) != 4+2)
				return;
			break;
		case 0x03:	/* +len+dom[len] */
			if(readn(0, buf+4, 1) != 1)
				return;
			if((n = buf[4]) == 0)
				return;
			if(readn(0, buf+5, n+2) != n+2)
				return;
			break;
		case 0x04:	/* +ipv6 */
			if(readn(0, buf+4, 16+2) != 16+2)
				return;
			break;
		}
	}

	dir[0] = 0;
	fd = cfd = -1;
	cmd = buf[1];
	switch(cmd){
	case 0x01:	/* CONNECT */
		snprint(addr, sizeof(addr), "%s/tcp", outside);
		if((s = addr2str(addr, buf)) == nil)
			break;
		alarm(30000);
		fd = dial(s, 0, dir, &cfd);
		alarm(0);
		break;
	case 0x02:	/* BIND */
		if(myipaddr(buf, outside) < 0)
			break;
		snprint(addr, sizeof(addr), "%s/tcp!%I!0", outside, buf);
		fd = announce(addr, dir);
		break;
	case 0x03:	/* UDP */
		if(myipaddr(buf, inside) < 0)
			break;
		snprint(addr, sizeof(addr), "%s/udp!%I!0", inside, buf);
		fd = announce(addr, dir);
		break;
	}

Reply:
	/* reply */
	buf[1] = sockerr(fd < 0);			/* status */
	if(socksver == 4){
		buf[0] = 0x00;				/* vc */
		if(fd < 0){
			memset(buf+2, 0, 2+4);
			write(1, buf, 2+2+4);
			return;
		}
	} else {
		buf[0] = socksver;			/* ver */
		buf[2] = 0x00;				/* res */
		if(fd < 0){
			buf[3] = 0x01;			/* atyp */
			memset(buf+4, 0, 4+2);
			write(1, buf, 4+4+2);
			return;
		}
	}
	if((nc = getnetconninfo(dir, cfd)) == nil)
		return;
	if((n = str2addr((cmd & 0x100) ? nc->raddr : nc->laddr, buf)) <= 0)
		return;
	if(write(1, buf, n) != n)
		return;

	switch(cmd){
	default:
		return;
	case 0x01:	/* CONNECT */
		break;
	case 0x02:	/* BIND */
		cfd = listen(dir, ldir);
		close(fd);
		fd = -1;
		if(cfd >= 0){
			strcpy(dir, ldir);
			fd = accept(cfd, dir);
		}
		cmd |= 0x100;
		goto Reply;
	case 0x102:
		break;		
	case 0x03:	/* UDP */
		if(udprelay(fd, dir) == 0)
			while(read(0, buf, sizeof(buf)) > 0)
				;
		goto Hangup;
	}
	
	/* relay data */
	switch(rfork(RFMEM|RFPROC|RFFDG|RFNOWAIT)){
	case -1:
		return;
	case 0:
		dup(fd, 0);
		break;
	default:
		dup(fd, 1);
	}
	while((n = read(0, buf, sizeof(buf))) > 0)
		if(write(1, buf, n) != n)
			break;
Hangup:
	if(cfd >= 0)
		hangup(cfd);
	postnote(PNGROUP, getpid(), "kill");
}
Ejemplo n.º 8
0
int entermsg(struct DayDream_Message *msg, int reply, char *params)
{
    char ebuf[1024];
    int hola;
    int msgfd;
    char *s;
    struct DayDream_Message header;
    char *lineedmem;

    int recoff;

    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'E' && ((access1 & (1L << SECB_FIDOMESSAGE)) == 0)) {
        DDPut(sd[emnofidomsgstr]);
        return 0;
    }
    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'N' && ((access2 & (1L << SECB_SENDNETMAIL)) == 0)) {
        DDPut(sd[emnonetmsgstr]);
        return 0;
    }
    changenodestatus("Entering a message");
    if (msg) {
        memcpy(&header, msg, sizeof(struct DayDream_Message));
    } else {
        s = (char *) &header;
        memset(&header, 0, sizeof(struct DayDream_Message));
        if (params)
            strncpy(header.MSG_RECEIVER, params, 25);
    }

    if (current_msgbase->MSGBASE_FLAGS & (1L << 0) && current_msgbase->MSGBASE_FLAGS & (1L << 1)) {
        DDPut(sd[emnomsgsstr]);
        return 0;
    }
    DDPut(sd[emhead1str]);
    DDPut(current_msgbase->MSGBASE_NAME);
    ebuf[0] = 0;
    strlcat(ebuf, sd[emhead2str], sizeof ebuf);
    hola = 61 - strlen(current_msgbase->MSGBASE_NAME);
    while (hola) {
        strlcat(ebuf, "-", sizeof ebuf);
        hola--;
    }
    DDPut(ebuf);
    ddprintf(sd[emhead3str], highest);
    DDPut(sd[emhead4str]);

    if ((current_msgbase->MSGBASE_FLAGS & (1L << 0)) || (header.MSG_FLAGS & (1L << 0))) {
        DDPut(sd[emprvstr]);
        header.MSG_FLAGS |= (1L << 0);
    } else {
        DDPut(sd[empubstr]);
    }
    header.MSG_CREATION = time(0);
    DDPut(sd[emhead5str]);
    DDPut(ctime(&header.MSG_CREATION));

    DDPut(sd[emhead6str]);
    if (current_msgbase->MSGBASE_FLAGS & (1L << 2)) {
        strlcpy(header.MSG_AUTHOR, user.user_handle, sizeof header.MSG_AUTHOR);
    } else {
        strlcpy(header.MSG_AUTHOR, user.user_realname, sizeof header.MSG_AUTHOR);
    }
    DDPut(header.MSG_AUTHOR);
    for (;;) {
askrec:
        DDPut(sd[emhead7str]);
        if (!(Prompt(header.MSG_RECEIVER, 25, 0)))
            return 0;
        if (header.MSG_RECEIVER[0] == 0 || (!strcasecmp(header.MSG_RECEIVER, "all")) || (!strcasecmp(header.MSG_RECEIVER, "all users"))) {
            if (current_msgbase->MSGBASE_FLAGS & (1L << 0)) {
                DDPut(sd[emhead8str]);
                HotKey(0);
                header.MSG_RECEIVER[0] = 0;
            } else {
                DDPut(sd[emhead9str]);
                header.MSG_RECEIVER[0] = 0;
                break;
            }
        } else if (!strcasecmp(header.MSG_RECEIVER, "eall")) {
            if (current_msgbase->MSGBASE_FLAGS & (1L << 0)) {
                DDPut(sd[emhead8str]);
                HotKey(0);
                header.MSG_RECEIVER[0] = 0;
            } else if (access1 & (1L << SECB_EALLMESSAGE)) {
                header.MSG_RECEIVER[0] = -1;
                DDPut(sd[emhead10str]);
                break;
            } else {
                DDPut(sd[emnopoststr]);
                HotKey(0);
                header.MSG_RECEIVER[0] = 0;
            }
        } else {
            if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'L') {
                struct userbase user;

                if (!strcasecmp(header.MSG_RECEIVER, "sysop")) {
                    recoff = 0;
                } else {
                    recoff = findusername(header.MSG_RECEIVER);
                }
                if (recoff == -1 ||
                        getubentbyid(recoff, &user) == -1) {
                    DDPut(sd[emnouserstr]);
                    HotKey(0);
                    goto askrec;
                }

                if (!checkconfaccess(conference()->conf.CONF_NUMBER, &user)) {
                    DDPut(sd[emnoaccessstr]);
                    HotKey(0);
                }
                DDPut("                     ");
                if (current_msgbase->MSGBASE_FLAGS & (1L << 2)) {
                    strlcpy(header.MSG_RECEIVER,
                            user.user_handle,
                            sizeof header.MSG_RECEIVER);
                } else {
                    strlcpy(header.MSG_RECEIVER,
                            user.user_realname,
                            sizeof header.MSG_RECEIVER);
                }
                DDPut(header.MSG_RECEIVER);
                break;
            } else
                break;
        }
    }
    DDPut(sd[emsubjectstr]);
    if (!(Prompt(header.MSG_SUBJECT, 67, 0)))
        return 0;
    if (header.MSG_SUBJECT[0] == 0) {
        DDPut(sd[emabortedstr]);
        return 0;
    }
    DDPut("                                                                       ");
    if (header.MSG_RECEIVER[0] == 0 || header.MSG_RECEIVER[0] == -1 || header.MSG_FLAGS & (1L << 0) || current_msgbase->MSGBASE_FLAGS & (1L << 1)) {

    } else {
        DDPut(sd[emisprivatestr]);
        hola = HotKey(HOT_NOYES);
        if (hola == 0)
            return 0;
        if (hola == 1)
            header.MSG_FLAGS |= MSG_FLAGS_PRIVATE;
    }

    if ((header.MSG_FLAGS & (1L << 0)) == 0 && (access1 & (1L << SECB_PUBLICMESSAGE)) == 0) {
        DDPut(sd[emnopubstr]);
        return 0;
    }
    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'N') {
        if (header.MSG_FN_DEST_NET) {
            snprintf(ebuf, sizeof ebuf, "%d:%d/%d.%d",
                     header.MSG_FN_DEST_ZONE,
                     header.MSG_FN_DEST_NET,
                     header.MSG_FN_DEST_NODE,
                     header.MSG_FN_DEST_POINT);
        } else {
            *ebuf = 0;
        }
        DDPut(sd[emnetaddstr]);
        if (!(Prompt(ebuf, 30, 0)))
            return 0;
        if (!str2addr(ebuf, &header.MSG_FN_DEST_ZONE, &header.MSG_FN_DEST_NET,
                      &header.MSG_FN_DEST_NODE, &header.MSG_FN_DEST_POINT))
            return 0;
        if(access2 & (1L << SECB_CRASH)) {
            DDPut(sd[emnetcrashstr]);
            if(HotKey(HOT_NOYES) == 1) {
                header.MSG_FLAGS |= MSG_FLAGS_CRASH;
            }
        }
        DDPut(sd[emnetkillstr]);
        if(HotKey(HOT_YESNO) == 1) {
            header.MSG_FLAGS |= MSG_FLAGS_KILL_SENT;
        }
    }
    *header.MSG_ATTACH = 0;

    if (current_msgbase->MSGBASE_FLAGS & (1L << 5)) {
        if ((header.MSG_FLAGS & (1L << 0)) && (access2 & (1L << SECB_PVTATTACH))) {
            *header.MSG_ATTACH = 1;
        } else if (((header.MSG_FLAGS & (1L << 0)) == 0) && (access2 & (1L << SECB_PUBATTACH))) {
            *header.MSG_ATTACH = 1;
        }
    }
    if (reply) {
        if (!askqlines()) {
            snprintf(ebuf, sizeof ebuf, "%s/daydream%d.msg",
                     DDTMP, node);
            unlink(ebuf);
        }
        DDPut("\n\n");
    }
    /* XXX: size should be replaced by a constant! */
    lineedmem = (char *) xmalloc(80 * 500);
    hola = edfile(lineedmem, 80 * 500, reply, &header);
    if (hola == 0) {
        char fabuf[1024];

        DDPut(sd[emaborted2str]);
        free(lineedmem);
        if (cleantemp() == -1) {
            DDPut(sd[tempcleanerrstr]);
            return 0;
        }
        snprintf(fabuf, sizeof fabuf, "%s/attachs.%d", DDTMP, node);
        unlink(fabuf);

        return 0;
    }
    DDPut(sd[emsavingstr]);

    getmsgptrs();
    highest++;
    header.MSG_NUMBER = highest;
    if (setmsgptrs() == 0) {
        free(lineedmem);
        return 0;
    }
    if (*header.MSG_ATTACH) {
        char fabuf[1024];
        FILE *fd;

        snprintf(fabuf, sizeof fabuf, "%s/attachs.%d", DDTMP, node);
        if ((fd = fopen(fabuf, "r"))) {
            char hoobab[1024];

            snprintf(hoobab, sizeof hoobab, "%s/messages/base%3.3d/fa%5.5d", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER);
            mkdir(hoobab, 0777);
            setperm(hoobab, 0777);

            while (fgetsnolf(hoobab, 1024, fd)) {
                char sr[1024];
                char de[1024];
                snprintf(sr, sizeof sr, "%s/%s", currnode->MULTI_TEMPORARY, hoobab);
                snprintf(de, sizeof de, "%s/messages/base%3.3d/fa%5.5d/%s", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER, hoobab);
                newrename(sr, de);
            }
            fclose(fd);
            snprintf(hoobab, sizeof hoobab, "%s/messages/base%3.3d/msf%5.5d", conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER);
            newrename(fabuf, hoobab);
        } else {
            *header.MSG_ATTACH = 0;
        }
    }

    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) != 'L') {
        header.MSG_FN_ORIG_ZONE = current_msgbase->MSGBASE_FN_ZONE;
        header.MSG_FN_ORIG_NET = current_msgbase->MSGBASE_FN_NET;
        header.MSG_FN_ORIG_NODE = current_msgbase->MSGBASE_FN_NODE;
        header.MSG_FN_ORIG_POINT = current_msgbase->MSGBASE_FN_POINT;
        header.MSG_FLAGS |= (1L << 2);
    }
    if ((msgfd = ddmsg_open_base(conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, O_RDWR | O_CREAT, 0666)) == -1) {
        DDPut(sd[emwriteerrstr]);
        free(lineedmem);
        return 0;
    }
    fsetperm(msgfd, 0666);
    lseek(msgfd, 0, SEEK_END);
    safe_write(msgfd, &header, sizeof(struct DayDream_Message));
    ddmsg_close_base(msgfd);

    if ((msgfd = ddmsg_open_msg(conference()->conf.CONF_PATH, current_msgbase->MSGBASE_NUMBER, header.MSG_NUMBER, O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) {
        DDPut(sd[emwriteerrstr]);
        free(lineedmem);
        return 0;
    }
    fsetperm(msgfd, 0666);
    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'E') {
        char ub[128];
        int uq;

        strlcpy(ub, current_msgbase->MSGBASE_FN_TAG, sizeof ub);
        strupr(ub);
        snprintf(ebuf, sizeof ebuf, "AREA:%s\n", ub);
        safe_write(msgfd, ebuf, strlen(ebuf));
        if ((uq = getfidounique())) {
            snprintf(ebuf, sizeof ebuf, "\001MSGID: %d:%d/%d.%d %8.8x\n", current_msgbase->MSGBASE_FN_ZONE, current_msgbase->MSGBASE_FN_NET, current_msgbase->MSGBASE_FN_NODE, current_msgbase->MSGBASE_FN_POINT, uq);
            safe_write(msgfd, ebuf, strlen(ebuf));
            if (header.MSG_ORIGINAL) {
                if (getreplyid(header.MSG_ORIGINAL, ebuf, sizeof ebuf))
                    safe_write(msgfd, ebuf, strlen(ebuf));
            }
        }
    } else if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'N') {
        snprintf(ebuf, sizeof ebuf, "\001INTL %d:%d/%d %d:%d/%d\n",
                 header.MSG_FN_DEST_ZONE, header.MSG_FN_DEST_NET,
                 header.MSG_FN_DEST_NODE, header.MSG_FN_ORIG_ZONE,
                 header.MSG_FN_ORIG_NET, header.MSG_FN_ORIG_NODE);
        safe_write(msgfd, ebuf, strlen(ebuf));

        if (header.MSG_FN_DEST_POINT) {
            snprintf(ebuf, sizeof ebuf, "\001TOPT %d\n", header.MSG_FN_DEST_POINT);
            safe_write(msgfd, ebuf, strlen(ebuf));
        }
        if (header.MSG_FN_ORIG_POINT) {
            snprintf(ebuf, sizeof ebuf, "\001FMPT %d\n", header.MSG_FN_ORIG_POINT);
            safe_write(msgfd, ebuf, strlen(ebuf));
        }
    }
    s = lineedmem;
    while (hola) {
        snprintf(ebuf, sizeof ebuf, "%s\n", s);
        safe_write(msgfd, ebuf, strlen(ebuf));
        hola--;
        s = &s[80];
    }

//	place holder, user auto-sig goes here
//	snprintf(ebuf, sizeof ebuf, "signature here");
//	safe_write(msgfd, ebuf, strlen(ebuf));

    if (toupper(current_msgbase->MSGBASE_FN_FLAGS) == 'E') {
        snprintf(ebuf, sizeof ebuf, "\n--- DayDream BBS/UNIX (" UNAME ") %s\n * Origin: %s (%d:%d/%d)\nSEEN-BY: %d/%d\n", versionstring, current_msgbase->MSGBASE_FN_ORIGIN, current_msgbase->MSGBASE_FN_ZONE, current_msgbase->MSGBASE_FN_NET, current_msgbase->MSGBASE_FN_NODE, current_msgbase->MSGBASE_FN_NET, current_msgbase->MSGBASE_FN_NODE);
        safe_write(msgfd, ebuf, strlen(ebuf));
    } else if (toupper(current_msgbase->MSGBASE_FN_FLAGS) != 'L') {
        snprintf(ebuf, sizeof ebuf, "\n--- DayDream BBS/UNIX (" UNAME ") %s\n", versionstring);
        safe_write(msgfd, ebuf, strlen(ebuf));
    }
    ddmsg_close_msg(msgfd);

    DDPut(sd[emdonestr]);
    free(lineedmem);

    if (header.MSG_FLAGS & (1L << 0)) {
        user.user_pvtmessages++;
        clog.cl_pvtmessages++;
    } else {
        user.user_pubmessages++;
        clog.cl_pubmessages++;
    }
    return 1;
}