示例#1
0
文件: network.c 项目: fiorix/linvpn
/* save pidfile */
void save_pidfile(const char *suffix)
{
    FILE *fp;
    char pidfile[1024];
    
    memset(pidfile, 0, sizeof(pidfile));
    snprintf(pidfile, sizeof(pidfile), "/var/run/linvpn-%s.pid", suffix);

    setperm(VPN_ROOT);
    if((fp = fopen(pidfile, "w")) == NULL) {
        xmsg(0, VPN_DEBUG|VPN_INFO, 
                "unable to create pidfile %s: %s\n", pidfile, errstr);
    } else {
        fprintf(fp, "%d", getpid());
        fclose(fp);
    }

    setperm(VPN_USER);
}
示例#2
0
static int ftpdl(char *list, char *loog)
{
	FILE *listh;
	FILE *logh;

	char buf[1024];
	char buf2[1024];

	snprintf(buf2, sizeof buf2, "%s/users/%d/ftp",
		origdir, user.user_account_id);
	mkdir(buf2, 0777);
	setperm(buf2, 0777);
	snprintf(buf2, sizeof buf2, "%s/users/%d/ftp/dl",
		origdir, user.user_account_id);
	mkdir(buf2, 0777);
	setperm(buf2, 0777);

	if (!(listh = fopen(list, "r")))
		return 0;

	logh = fopen(loog, "w");

	while (fgetsnolf(buf, 1024, listh)) {
		snprintf(buf2, sizeof buf2, "%s/users/%d/ftp/dl/%s",
			origdir, user.user_account_id, filepart(buf));
		//symlink(buf, buf2);
		link(buf, buf2);
		if (logh) {
			struct stat st;
			stat(buf, &st);
			fprintf(logh,
				"s %6d     0 bps    0 cps   0 errors     0 1024 %s 0\n",
				(int) st.st_size, filepart(buf));

		}
	}
	fclose(listh);
	if (logh)
		fclose(logh);
	return 1;
}
示例#3
0
文件: lfb.c 项目: Snake2k/OS-Zero
void *
deckmaplfb(struct deck *deck, long depth, long width, long height)
{
    void             *lfb;
    struct sysmemreg  memreg;
    long              pixsize;

    switch (depth) {
        case 8:
            pixsize = 1;

            break;
        case 15:
        case 16:
            pixsize = 2;

            break;
        case 24:
            pixsize = 3;

            break;
        case 32:
            pixsize = 4;

            break;
        default:
            fprintf(stderr, "DECK: unknown framebuffer depth\n");

            exit(1);
    }

    /* FIXME: fix the stuff below */
#if (_ZERO_SOURCE) && 0
    setperm(&memreg.perm, getuid(), getgid(), PERM_UW);
    memreg.adr = NULL;
    memreg.ofs = 0;
    memreg.len = pixsize * width * height;
    lfb = _syscall(SYS_MAP, SYS_NODESC, 0, &memreg);
#endif

    return lfb;
}
示例#4
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;
}