Example #1
0
File: port.c Project: aunali1/exopc
unsigned int read_port_w(unsigned short port)
{
    unsigned int r;
    int i = find_port(port, IO_READ);
    int j = find_port(port + 1, IO_READ);

#ifdef GUSPNP
    if (port == 0x324)
	i = j = 0;
#endif

    /* FIXME:  shoudl already be checked.  ASSERT if i, j == -1 */
    if (i == -1) {
	i_printf("can't read low-byte of 16 bit port 0x%04x:trying to read high\n",
		 port);
	return ((read_port(port + 1) << 8) | 0xff);
    }
    if (j == -1) {
	i_printf("can't read hi-byte of 16 bit port 0x%04x:trying to read low\n",
		 port);
	return (read_port(port) | 0xff00);
    }
    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3fe) {
	set_ioperm(port, 2, 1);
    } else
	priv_iopl(3);
    if (!video_port_io)
	leave_priv_setting();

    r = port_in_w(port);
    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3fe)
	set_ioperm(port, 2, 0);
    else
	priv_iopl(0);
    if (!video_port_io)
	leave_priv_setting();

    if (
#ifdef GUSPNP
	   i && j &&
#endif
	   !video_port_io) {
	r &= (ports[i].andmask | 0xff00);
	r &= ((ports[j].andmask << 8) | 0xff);
	r |= (ports[i].ormask & 0xff);
	r |= ((ports[j].ormask << 8) & 0xff00);
    } else
	video_port_io = 0;

    LOG_IO(port, r, '}', 0xffff);

    i_printf("read 16 bit port 0x%x gave %04x at %04x:%04x\n",
	     port, r, LWORD(cs), LWORD(eip));
    return (r);
}
Example #2
0
File: port.c Project: aunali1/exopc
int write_port_w(unsigned int value, unsigned short port)
{
    int i = find_port(port, IO_WRITE);
    int j = find_port(port + 1, IO_WRITE);

#ifdef GUSPNP
    if (port == 0x324)
	i = j = 0;
#endif
    if ((i == -1) || (j == -1)) {
	i_printf("can't write to 16 bit port 0x%04x\n", port);
	return 0;
    }
    if (
#ifdef GUSPNP
	   i && j &&
#endif
	   !video_port_io) {
	value &= (ports[i].andmask | 0xff00);
	value &= ((ports[j].andmask << 8) | 0xff);
	value |= (ports[i].ormask & 0xff);
	value |= ((ports[j].ormask << 8) & 0xff00);
    }
    i_printf("write 16 bit port 0x%x value %04x at %04x:%04x\n",
	     port, (value & 0xffff), LWORD(cs), LWORD(eip));

    LOG_IO(port, value, '{', 0xffff);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3fe)
	set_ioperm(port, 2, 1);
    else
	priv_iopl(3);
    if (!video_port_io)
	leave_priv_setting();

    port_out_w(value, port);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3fe)
	set_ioperm(port, 2, 0);
    else
	priv_iopl(0);
    if (!video_port_io)
	leave_priv_setting();
    video_port_io = 0;

    return (1);
}
Example #3
0
static void writeAttachment(struct MHINFO *w)
{
	const char *atname;
	if ((ismc | ignoreImages) && w->atimage)
		return;		/* image ignored */
	if (w->pgp)
		return;		/* Ignore PGP signatures. */
	if (w->error64 == BAD_BASE64_DECODE)
		i_printf(MSG_Abbreviated);
	if (w->start == w->end) {
		i_printf(MSG_AttEmpty);
		if (w->cfn[0])
			printf(" %s", w->cfn);
		nl();
		atname = "x";
	} else {
		i_printf(MSG_Att);
		atname = getFileName(MSG_FileName, (w->cfn[0] ? w->cfn : 0),
				     true, false);
/* X is like x, but deletes all future images */
		if (stringEqual(atname, "X")) {
			atname = "x";
			ignoreImages = true;
		}
	}
	if (!ismc && stringEqual(atname, "e")) {
		int cx, svcx = context;
		for (cx = 1; cx < MAXSESSION; ++cx)
			if (!sessionList[cx].lw)
				break;
		if (cx == MAXSESSION) {
			i_printf(MSG_AttNoBuffer);
		} else {
			cxSwitch(cx, false);
			i_printf(MSG_SessionX, cx);
			if (!addTextToBuffer
			    ((pst) w->start, w->end - w->start, 0, false))
				i_printf(MSG_AttNoCopy, cx);
			else if (w->cfn[0])
				cw->fileName = cloneString(w->cfn);
			cxSwitch(svcx, false);	/* back to where we were */
		}
	} else if (!stringEqual(atname, "x")) {
		int fh =
		    open(atname, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0666);
		if (fh < 0) {
			i_printf(MSG_AttNoSave, atname);
			if (ismc)
				exit(1);
		} else {
			int nb = w->end - w->start;
			if (write(fh, w->start, nb) < nb) {
				i_printf(MSG_AttNoWrite, atname);
				if (ismc)
					exit(1);
			}
			close(fh);
		}
	}
}				/* writeAttachment */
Example #4
0
File: port.c Project: aunali1/exopc
/* release registered ports or blocked devices */
void release_ports()
{
/* FIXME */
#if 0
    unsigned int i;

    for (i = 0; i < num_ports; i++)
	if (ports[i].fp == -1) {
	    i_printf("PORT Syscall to release ports not yet implemented\n");
	    i_printf("PORT releasing registered ports 0x%04x-0x%04x \n",
		     ports[i].start, ports[i].start + ports[i].size - 1);
	} else if (close(ports[i].fp) == -1) {
	    i_printf("PORT Closeing device-filedescriptor %d failed with %s\n",
		     ports[i].fp, strerror(errno));
	} else {
	    i_printf("PORT Closeing device succeeded\n");
	}
#endif
}
Example #5
0
char *o_printf(const char *fmt, ...) {

    va_list inargs;
    char *str;

    va_start(inargs, fmt);
    str = i_printf(fmt, inargs);
    va_end(inargs);

    return str;
}
Example #6
0
File: port.c Project: aunali1/exopc
void safe_port_out_byte(const unsigned short port, const unsigned char byte)
{
    if (i_am_root) {
	int result;

	result = set_ioperm(port, 1, 1);
	if (result) {
	    dprintf("failed to enable port %x\n", port);
	    leaveemu(ERR_IO);
	}
	port_out(byte, port);
	result = set_ioperm(port, 1, 0);
	if (result) {
	    dprintf("failed to disable port %x\n", port);
	    leaveemu(ERR_IO);
	}

    } else
	i_printf("want to ");
    i_printf("out(%x, 0x%x)\n", port, byte);
}
Example #7
0
void o_concatf(char **mainStr, const char *fmt, ...) {

    va_list inargs;
    char *str;

    va_start(inargs, fmt);
    str = i_printf(fmt, inargs);
    va_end(inargs);

    conCat(mainStr, str);
    free(str);

}
Example #8
0
File: port.c Project: aunali1/exopc
char safe_port_in_byte(const unsigned short port)
{
    unsigned char value = 0;

    if (i_am_root) {
	int result;

	result = set_ioperm(port, 1, 1);
	if (result)
	    error("failed to enable port %x\n", port);
	value = port_in(port);
	result = set_ioperm(port, 1, 0);
	if (result)
	    error("failed to disable port %x\n", port);
    } else
	i_printf("want to ");
    i_printf("in(%x)", port);
    if (i_am_root)
	i_printf(" = 0x%x", value);
    i_printf("\n");
    return value;
}
Example #9
0
bool
showTables(void)
{
    char tabname[40];
    char tabtype[40];
    char tabowner[40];
    SQLLEN tabnameOut, tabtypeOut, tabownerOut;
    char *buf;
    int buflen, cx;
    int truevalue = SQL_TRUE;

/*
SQLSetConnectAttr(hdbc, SQL_ATTR_METADATA_ID,
&truevalue, SQL_IS_INTEGER);
*/

    newStatement();
    stmt_text = "get tables";
    debugStatement();
    rc = SQLTables(hstmt,
       NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS, NULL, SQL_NTS);
    if(rc)
	goto abort;

    SQLBindCol(hstmt, 2, SQL_CHAR, (SQLPOINTER) tabowner, sizeof (tabowner),
       &tabownerOut);
    SQLBindCol(hstmt, 3, SQL_CHAR, (SQLPOINTER) tabname, sizeof (tabname),
       &tabnameOut);
    SQLBindCol(hstmt, 4, SQL_CHAR, (SQLPOINTER) tabtype, sizeof (tabtype),
       &tabtypeOut);

    buf = initString(&buflen);
    while(SQLFetch(hstmt) == SQL_SUCCESS) {
	char tabline[140];
	sprintf(tabline, "%s.%s|%s\n", tabowner, tabname, tabtype);
	stringAndString(&buf, &buflen, tabline);
    }

    cx = sideBuffer(0, buf, buflen, 0, false);
    nzFree(buf);
    i_printf(MSG_ShowTables, cx);
    SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    return true;

  abort:
    SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
    return false;
}				/* showTables */
Example #10
0
void scanMail(void)
{
	int nmsgs, m;

	if (!isInteractive)
		i_printfExit(MSG_FetchNotBackgnd);
	if (!mailDir)
		i_printfExit(MSG_NoMailDir);
	if (chdir(mailDir))
		i_printfExit(MSG_NoDirChange, mailDir);

	if (!umf) {
		umf = allocMem(strlen(mailUnread) + 12);
		sprintf(umf, "%s/", mailUnread);
		umf_end = umf + strlen(umf);
	}

/* How many mail messages? */
	unreadBase = 0;
	unreadStats();
	nmsgs = unreadCount;
	if (!nmsgs) {
		i_puts(MSG_NoMail);
		exit(0);
	}
	i_printf(MSG_MessagesX, nmsgs);

	loadAddressBook();

	for (m = 1; m <= nmsgs; ++m) {
		nzFree(lastMailText);
		lastMailText = 0;
/* Now grab the entire message */
		unreadStats();
		sprintf(umf_end, "%d", unreadMin);
		if (!fileIntoMemory(umf, &mailstring, &mailstring_l))
			showErrorAbort();
		unreadBase = unreadMin;

		if (presentMail() == 1)
			unlink(umf);
	}			/* loop over mail messages */

	exit(0);
}				/* scanMail */
Example #11
0
File: port.c Project: aunali1/exopc
unsigned char read_port(unsigned short port)
{
    unsigned char r;
    int i = find_port(port, IO_READ);

    /* FIXME:  stuff does/should check find_port first, so don't waste
       time checking again!  ASSERT!! */

    if (i == -1)
	return (0xff);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3ff)
	set_ioperm(port, 1, 1);
    else
	priv_iopl(3);
    if (!video_port_io)
	leave_priv_setting();

    r = port_in(port);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3ff)
	set_ioperm(port, 1, 0);
    else
	priv_iopl(0);
    if (!video_port_io)
	leave_priv_setting();

    if (!video_port_io) {
	r &= ports[i].andmask;
	r |= ports[i].ormask;
    } else
	video_port_io = 0;

    LOG_IO(port, r, '>', 0xff);

    i_printf("read port 0x%x gave %02x at %04x:%04x\n",
	     port, r, LWORD(cs), LWORD(eip));
    return (r);
}
Example #12
0
File: port.c Project: aunali1/exopc
int write_port(unsigned int value, unsigned short port)
{
    int i = find_port(port, IO_WRITE);

    if (i == -1)
	return (0);

    if (!video_port_io) {
	value &= ports[i].andmask;
	value |= ports[i].ormask;
    }
    i_printf("write port 0x%x value %02x at %04x:%04x\n",
	     port, (value & 0xff), LWORD(cs), LWORD(eip));

    LOG_IO(port, value, '<', 0xff);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3ff)
	set_ioperm(port, 1, 1);
    else
	priv_iopl(3);
    if (!video_port_io)
	leave_priv_setting();

    port_out(value, port);

    if (!video_port_io)
	enter_priv_on();
    if (port <= 0x3ff)
	set_ioperm(port, 1, 0);
    else
	priv_iopl(0);
    if (!video_port_io)
	leave_priv_setting();
    video_port_io = 0;

    return (1);
}
/****************************************************************************************************
 * @fn      DoProfiling
 *          Calculates and prints CPU/Stack profiling information
 *
 ***************************************************************************************************/
static void DoProfiling( osp_bool_t withStartEnd )
{
    uint8_t  taskCounter, numTasks;
    uint32_t start, end, highWater;
    uint32_t totalElapsedTime;
    osp_float_t taskLoad;
    P_TCB tskPtr;
    uint8_t *pTaskList;
    TaskId tid;


    numTasks = GetTaskList( &pTaskList );
# ifdef STACK_INFO_ONLY
    /* Stack check */
    i_printf("\r\n\t\t\t*** ");
    for (taskCounter = 0; taskCounter < numTasks; taskCounter++)
    {
        tid = (TaskId)pTaskList[taskCounter];
        start = (uint32_t)asfTaskHandleTable[tid].pStack;
        end = start + asfTaskHandleTable[tid].stkSize;
        highWater = HighWaterMarkSearch( start, end );
        i_printf("%02d ", (highWater * 100)/asfTaskHandleTable[tid].stkSize);
    }
    /* Main stack check */
    start = (uint32_t)&gStackMem;
    end = start + (uint32_t)&gStackSize;
    highWater = HighWaterMarkSearch( start, end );
    i_printf("%02d ***\r\n\n", (highWater * 100)/((uint32_t)&gStackSize));
# else
    i_printf("\r\n------------------------------------------------------\r\n");
    totalElapsedTime = RTC_GetCounter() - gSystemRTCRefTime;
    for (taskCounter = 0; taskCounter < numTasks; taskCounter++)
    {
        /* Stack check */
        tid = (TaskId)pTaskList[taskCounter];
        start = (uint32_t)asfTaskHandleTable[tid].pStack;
        end = start + asfTaskHandleTable[tid].stkSize;
        highWater = HighWaterMarkSearch( start, end );

        /* CPU Usage */
        tskPtr = os_active_TCB[asfTaskHandleTable[tid].handle - 1];
        taskLoad = ((osp_float_t)tskPtr->cumulativeRunTime * 100.0f)/(osp_float_t)totalElapsedTime;
        if (withStartEnd) {
            i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", C_gAsfTaskInitTable[tid].tskName, start, end, highWater,
                asfTaskHandleTable[tid].stkSize,
                (highWater * 100)/asfTaskHandleTable[tid].stkSize, taskLoad, tskPtr->runCount);
        } else {
            i_printf("%16s: %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", C_gAsfTaskInitTable[tid].tskName, highWater,
                asfTaskHandleTable[tid].stkSize,
                (highWater * 100)/asfTaskHandleTable[tid].stkSize, taskLoad, tskPtr->runCount);
        }
#  ifdef ON_DEMAND_PROFILING
        /* Reset (only for CPU usage) runtime for next profiling period */
        tskPtr->cumulativeRunTime = 0;
#  endif
    }
    /* For IDLE task */
    /* --- Stack check */
    start = (uint32_t)os_idle_TCB.stack;
    end = start + C_gOsStkSize;
    highWater = HighWaterMarkSearch( start, end );
    /* --- CPU load */
    taskLoad = ((osp_float_t)os_idle_TCB.cumulativeRunTime * 100.0f)/(osp_float_t)totalElapsedTime;
#  ifdef ON_DEMAND_PROFILING
    /* Reset (only for CPU usage) runtime for next profiling period */
    os_idle_TCB.cumulativeRunTime = 0;
    gSystemRTCRefTime = RTC_GetCounter(); //Reset reference time
#  endif
    if (withStartEnd) {
        i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", "IDLE TASK", start, end, highWater,
            C_gOsStkSize, (highWater * 100)/C_gOsStkSize, taskLoad, os_idle_TCB.runCount);
    } else {
        i_printf("%16s: %04ld/%04ld\t%d%%\t%.2f%%\t%ld\r\n", "IDLE TASK", highWater,
            C_gOsStkSize, (highWater * 100)/C_gOsStkSize, taskLoad, os_idle_TCB.runCount);
    }
    /* Main stack check */
    start = (uint32_t)&gStackMem;
    end = start + (uint32_t)&gStackSize;
    highWater = HighWaterMarkSearch( start, end );
    if (withStartEnd) {
        i_printf("%16s: %08x/%08x %04ld/%04ld\t%d%%\t -*-\t -*-\r\n", "System Stack", start, end, highWater,
            (uint32_t)&gStackSize, (highWater * 100)/((uint32_t)&gStackSize));
    } else {
        i_printf("%16s: %04ld/%04ld\t%d%%\t -*-\t -*-\r\n", "System Stack", highWater,
            (uint32_t)&gStackSize, (highWater * 100)/((uint32_t)&gStackSize));
    }
    i_printf("------------------------------------------------------\r\n");
# endif

}
Example #14
0
/* Return 0 for ok, 1 to delete the mail, -1 to stop.
 * stop is only meaningful for imap. */
static int presentMail(void)
{
	int j, k;
	const char *redirect = NULL;	/* send mail elsewhere */
	char key = 0;
	const char *atname = NULL;	/* name of file or attachment */
	bool delflag = false;	/* delete this mail */
	bool scanat = false;	/* scan for attachments */
	int displine;
	int stashNumber = -1;

/* clear things out from the last message */
	if (lastMailInfo)
		freeMailInfo(lastMailInfo);
	lastMailInfo = 0;

	if (sessionList[1].lw)
		cxQuit(1, 2);
	cs = 0;
	cxSwitch(1, false);

	iuReformat(mailstring, mailstring_l, &mailu8, &mailu8_l);
	if (mailu8) {
		if (!addTextToBuffer((pst) mailu8, mailu8_l, 0, false))
			showErrorAbort();
	} else {
		if (!addTextToBuffer((pst) mailstring, mailstring_l, 0, false))
			showErrorAbort();
	}

	browseCurrentBuffer();

	if (!passMail) {
		redirect = mailRedirect(lastMailInfo->to,
					lastMailInfo->from,
					lastMailInfo->reply,
					lastMailInfo->subject);
	}

	if (redirect) {
		if (!isimap) {
			delflag = true;
			key = 'w';
			if (*redirect == '-')
				++redirect, key = 'u';
			if (stringEqual(redirect, "x"))
				i_puts(MSG_Junk);
			else
				printf("> %s\n", redirect);
		} else {
			if (*redirect == '-')
				++redirect;
			if (stringEqual(redirect, "x"))
				redirect = NULL;
		}
	}

/* display the next page of mail and get a command from the keyboard */
	displine = 1;
paging:
	if (!delflag) {		/* show next page */
		if (displine <= cw->dol) {
			for (j = 0; j < 20 && displine <= cw->dol;
			     ++j, ++displine) {
				char *showline = (char *)fetchLine(displine, 1);
				k = pstLength((pst) showline);
				showline[--k] = 0;
				printf("%s\n", showline);
				nzFree(showline);
			}
		}
	}

/* get key command from user */
key_command:
	if (delflag)
		goto writeMail;

/* interactive prompt depends on whether there is more text or not */
	printf("%c ", displine > cw->dol ? '?' : '*');
	fflush(stdout);
	key = getLetter((isimap ? "q? nwWuUasd" : "q? nwud"));
	printf("\b\b\b");
	fflush(stdout);

	switch (key) {
	case 'q':
		i_puts(MSG_Quit);
		exit(0);

	case 'n':
		i_puts(MSG_Next);
		goto afterinput;

	case 's':
		i_puts(MSG_Stop);
		goto afterinput;

	case 'd':
		i_puts(MSG_Delete);
		delflag = true;
		goto afterinput;

	case ' ':
		if (displine > cw->dol)
			i_puts(MSG_EndMessage);
		goto paging;

	case '?':
		i_puts(isimap ? MSG_ImapReadHelp : MSG_MailHelp);
		goto key_command;

	case 'a':
		key = 'w';	/* this will scan attachments */
		scanat = true;

	case 'w':
	case 'W':
	case 'u':
	case 'U':
		break;

	default:
		i_puts(MSG_NYI);
		goto key_command;
	}			/* switch */

/* At this point we're saving the mail somewhere. */
writeMail:
	if (!isimap || isupper(key))
		delflag = true;
	atname = 0;
	if (!isimap)
		atname = redirect;

	if (scanat)
		goto attachOnly;

saveMail:
	if (!atname)
		atname = getFileName(MSG_FileName, redirect, false, false);
	if (stringEqual(atname, "x"))
		goto afterinput;

	char exists = fileTypeByName(atname, false);
	int fsize;		/* file size */
	int fh = open(atname, O_WRONLY | O_TEXT | O_CREAT | O_APPEND, 0666);
	if (fh < 0) {
		i_printf(MSG_NoCreate, atname);
		goto saveMail;
	}
	if (exists)
		write(fh,
		      "======================================================================\n",
		      71);
	if (key == 'u') {
		if (write(fh, mailstring, mailstring_l) < mailstring_l) {
badsave:
			i_printf(MSG_NoWrite, atname);
			close(fh);
			goto saveMail;
		}
		close(fh);
		fsize = mailstring_l;
	} else {

/* key = w, write the file - if pop then save the original unformatted */
		if (!isimap && mailStash) {
			char *rmf;	/* raw mail file */
			int rmfh;	/* file handle to same */
/* I want a fairly easy filename, in case I want to go look at the original.
* Not a 30 character message ID that I am forced to cut&paste.
* 4 or 5 digits would be nice.
* So the filename looks like /home/foo/.Trash/rawmail/36921
* I pick the digits randomly.
* Please don't accumulate 100,000 emails before you empty your trash.
* It's good to have a cron job empty the trash early Sunday morning.
*/

			k = strlen(mailStash);
			rmf = allocMem(k + 12);
/* Try 20 times, then give up. */
			for (j = 0; j < 20; ++j) {
				int rn = rand() % 100000;	/* random number */
				sprintf(rmf, "%s/%05d", mailStash, rn);
				if (fileTypeByName(rmf, false))
					continue;
/* dump the original mail into the file */
				rmfh =
				    open(rmf,
					 O_WRONLY | O_TEXT | O_CREAT | O_APPEND,
					 0666);
				if (rmfh < 0)
					break;
				if (write(rmfh, mailstring, mailstring_l) <
				    mailstring_l) {
					close(rmfh);
					unlink(rmf);
					break;
				}
				close(rmfh);
/* written successfully, remember the stash number */
				stashNumber = rn;
				break;
			}
		}

		fsize = 0;
		for (j = 1; j <= cw->dol; ++j) {
			char *showline = (char *)fetchLine(j,
							   1);
			int len = pstLength((pst)
					    showline);
			if (write(fh, showline, len) < len)
				goto badsave;
			nzFree(showline);
			fsize += len;
		}		/* loop over lines */

		if (stashNumber >= 0) {
			char addstash[60];
			sprintf(addstash, "\nUnformatted %05d\n", stashNumber);
			k = strlen(addstash);
			if (write(fh, addstash, k) < k)
				goto badsave;
			fsize += k;
		}

		close(fh);

attachOnly:

		if (nattach)
			writeAttachments(lastMailInfo);
		else if (scanat)
			i_puts(MSG_NoAttachments);
	}			/* unformat or format */

	if (scanat)
		goto afterinput;
/* print "mail saved" message */
	i_printf(MSG_MailSaved, fsize);
	if (exists)
		i_printf(MSG_Appended);
	nl();

afterinput:
	nzFree(mailstring);
	mailstring = 0;
	nzFree(mailu8);
	mailu8 = 0;

	if (delflag)
		return 1;
	if (key == 's')
		return -1;
	return 0;
}				/* presentMail */
Example #15
0
File: port.c Project: aunali1/exopc
/* control the io permissions for ports */
int allow_io(unsigned int start, int size, int permission, int ormask, int andmask,
	     unsigned int portspeed, char *device)
{
    int opendevice = -1;
    char line[100];
    char portname[50];
    unsigned int beg, end;
    FILE *fp;

    /* find out whether the port address request is available 
     * this way, try to deny uncoordinated acces
     *
     * If it is not listed in /proc/ioports, register them 
     * ( we need some syscall to do so bo 960609)
     * if it is registered, we need the name of a device to open
     * if we can open it, we disallow to that port
     */
    if ((fp = fopen("/proc/ioports", "r")) == NULL) {
	i_printf("Ports can't open /proc/ioports\n");
	return (0);
    }
    while (fgets(line, 100, fp)) {
	sscanf(line, "%x-%x : %s", &beg, &end, portname);
	if ((start >= beg) && (start + size - 1 <= end)) {
	    /* ports are occupied, try to open the according device */
	    i_printf("PORT already registered as %s 0x%04x-0x%04x\n",
		     portname, beg, end);
	    enter_priv_on();
	    opendevice = open(device, O_RDWR);
	    leave_priv_setting();
	    if (opendevice == -1)
		switch (errno) {
		case EBUSY:
		    i_printf("PORT Device %s already in use\n", device);
		    return (0);
		case EACCES:
		    i_printf("PORT Device %s , access not allowed\n", device);
		    return (0);
		case ENOENT:
		    i_printf("PORT No such Device %s\n", device);
		    return (0);
		}
	    i_printf("PORT Device %s opened successfully\n", device);
	}
    }
    if (opendevice == -1) {
	/* register it
	 */
	i_printf("PORT Syscall to register ports not yet implemented\n");
    }
#if 0
    if ((base + size) < beg || base >= end)
	continue;
    else
	return NULL;		/* overlap */
#endif



    /* first the simplest case...however, this simplest case does
     * not apply to ports above 0x3ff--the maximum ioperm()able
     * port under Linux--so we must handle some of that ourselves.
     *
     * if we want to log port access below 0x400, don't enter these 
     * ports here with set_ioperm but add them to the list of allowed
     * ports. That way we get an exception to get out of vm86(0)
     */
    if (permission == IO_RDWR && (ormask == 0 && andmask == 0xFFFF)
	&& portspeed) {
	if ((start + size - 1) <= 0x3ff) {
	    i_printf("giving fast hardware access to ports 0x%x -> 0x%x\n",
		     start, start + size - 1);
	    set_ioperm(start, size, 1);
	    /* Don't return, but enter it in the list to keep track of the file 
	     * descriptor
	     * return (1);
	     */
	}
	/* allow direct I/O to all the ports that *are* below 0x3ff
	   * and add the rest to our list
	 */
	else if (start <= 0x3ff) {
	    warn("PORT: s-s: %d %d\n", start, size);
	    i_printf("giving fast hardware access only to ports 0x%x -> 0x3ff\n",
		     start);
	    set_ioperm(start, 0x400 - start, 1);
	    size = start + size - 0x400;
	    start = 0x400;
	}
    }
    /* we'll need to add an entry */
    if (ports) {
	ASSERT(0);  /* FIXME XXX */
	/* ports = (struct port_struct *) realloc(ports, sizeof(struct port_struct) * (num_ports + 1)); */
    } else {
	ASSERT(0);  /* FIXME XXX */
	/* ports = (struct port_struct *) malloc(sizeof(struct port_struct) * (num_ports + 1)); */
    }

    num_ports++;
    if (!ports) {
	error("allocation error for ports!\n");
	num_ports = 0;
	return (0);
    }
    ports[num_ports - 1].start = start;
    ports[num_ports - 1].size = size;
    ports[num_ports - 1].permission = permission;
    ports[num_ports - 1].ormask = ormask;
    ports[num_ports - 1].andmask = andmask;
    ports[num_ports - 1].fp = opendevice;

    i_printf("added port %x size=%d permission=%d ormask=%x andmask=%x\n",
	     start, size, permission, ormask, andmask);

    return (1);
}
Example #16
0
void
sql_connect(const char *db, const char *login, const char *pw)
{
    short waste;
    char constring[200];
    char outstring[200];
    char drivername[40];
    char *s;

    if(isnullstring(db))
	errorPrint
	   ("2sql_connect receives no data source, check your edbrowse config file");
    if(debugLevel >= 1)
	i_printf(MSG_DBConnecting, db);

    /* first disconnect the old one */
    if(disconnect())
	return;

    /* initial call to sql_connect sets up ODBC */
    if(henv == SQL_NULL_HENV) {
	char verstring[6];

	/* Allocate environment and connection handles */
	/* these two handles are never freed */
	rc = SQLAllocEnv(&henv);
	if(rc)
	    errorPrint("@could not alloc ODBC environment handle");
	rc = SQLAllocConnect(henv, &hdbc);
	if(rc)
	    errorPrint("@could not alloc ODBC connection handle");

	/* Establish the ODBC major version number.
	 * Course the call to make this determination doesn't exist
	 * prior to version 2.0. */
	odbc_version = 1;
	rc = SQLGetInfo(hdbc, SQL_DRIVER_ODBC_VER, verstring, 6, &waste);
	if(!rc) {
	    verstring[2] = 0;
	    odbc_version = atoi(verstring);
	}
    }

    /* connect to the database */
    sprintf(constring, "DSN=%s", db);
    if(login) {
	s = constring + strlen(constring);
	sprintf(s, ";UID=%s", login);
    }
    if(pw) {
	s = constring + strlen(constring);
	sprintf(s, ";PWD=%s", pw);
    }

    stmt_text = constring;
    debugStatement();
    rc = SQLDriverConnect(hdbc, NULL,
       constring, SQL_NTS,
       outstring, sizeof (outstring), &waste, SQL_DRIVER_NOPROMPT);
    if(errorTrap(0))
	return;
    sql_database = db;
    exclist = 0;

    /* Set the persistent connect/statement options.
     * Note that some of these merely reassert the default,
     * but it's good documentation to spell it out here. */
    stmt_text = "noscan on";
    rc = SQLSetConnectOption(hdbc, SQL_NOSCAN, SQL_NOSCAN_ON);
    stmt_text = "repeatable read";
    rc = SQLSetConnectOption(hdbc, SQL_TXN_ISOLATION, SQL_TXN_REPEATABLE_READ);	/* fail */
    stmt_text = "rowset size";
    rc = SQLSetConnectOption(hdbc, SQL_ROWSET_SIZE, 1);
    stmt_text = "login timeout";
    rc = SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 15);	/* fail */
    stmt_text = "query timeout";
    rc = SQLSetConnectOption(hdbc, SQL_QUERY_TIMEOUT, 0);	/* fail */
    stmt_text = "async disable";
    rc = SQLSetConnectOption(hdbc, SQL_ASYNC_ENABLE, SQL_ASYNC_ENABLE_OFF);	/* fail */
    stmt_text = "autocommit";
    rc = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
    stmt_text = "cursor forward";
    rc = SQLSetConnectOption(hdbc, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY);
    stmt_text = "concurrent reads";
    rc = SQLSetConnectOption(hdbc, SQL_CONCURRENCY, SQL_CONCUR_READ_ONLY);
    stmt_text = "use driver";
    rc = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_DRIVER);	/* fail */
    stmt_text = "no bookmarks";
    rc = SQLSetConnectOption(hdbc, SQL_USE_BOOKMARKS, SQL_UB_OFF);	/* fail */

    /* this call is only necessary if SQL_NULL_HSTMT != 0 */
    clearAllCursors();

    /* set defaults, in case the GetInfo command fails */
    cursors_under_commit = cursors_under_rollback = SQL_CB_DELETE;
    SQLGetInfo(hdbc, SQL_CURSOR_COMMIT_BEHAVIOR, &cursors_under_commit, 4,
       &waste);
    SQLGetInfo(hdbc, SQL_CURSOR_ROLLBACK_BEHAVIOR, &cursors_under_rollback, 4,
       &waste);
    getdata_opts = 0;
    SQLGetInfo(hdbc, SQL_GETDATA_EXTENSIONS, &getdata_opts, 4, &waste);
    bookmarkBits = false;
    SQLGetInfo(hdbc, SQL_BOOKMARK_PERSISTENCE, &bookmarkBits, 4, &waste);

    exclist = 0;

/* Time to find out what the driver is, so we can have driver specific tweaks. */
    SQLGetInfo(hdbc, SQL_DRIVER_NAME, drivername, sizeof (drivername), &waste);
    current_driver = DRIVER_NONE;
    if(stringEqual(drivername, "libsqliteodbc.so") ||
       stringEqual(drivername, "sqlite3odbc.so"))
	current_driver = DRIVER_SQLITE;
    if(stringEqual(drivername, "libmyodbc.so"))
	current_driver = DRIVER_MYSQL;
    if(stringEqual(drivername, "libodbcpsql.so"))
	current_driver = DRIVER_POSTGRESQL;
    if(stringEqual(drivername, "iclis09b.so"))
	current_driver = DRIVER_INFORMIX;
    if(stringEqual(drivername, "libtdsodbc.so")) {
	current_driver = DRIVER_TDS;
	openfirst = true;
    }

    if(sql_debug) {
	if(current_driver)
	    appendFile(sql_debuglog, "driver is %d", current_driver);
	else
	    appendFile(sql_debuglog, "driver string is %s", drivername);
    }

    exclist = 0;
}				/* sql_connect */