Esempio n. 1
0
File: mknod.c Progetto: 8l/FUZIX
int do_mknod(char *path, char *modes, char *devs)
{
	int mode;
	int dev;

	mode = parse_number(modes, 8);
	if (mode < 0) {
		writes("mknod: bad mode\n");
		return 1;
	}

	if (!S_ISFIFO(mode) && !S_ISDEV(mode)) {
		writes("mknod: mode is not device/fifo\n");
		return 1;
	}

	dev = parse_number(devs, 10);
	if (dev < 0) {
		writes("mknod: bad device\n");
		return 1;
	}

	if (mknod(path, mode, dev) != 0) {
		perror("mknod");
		return 1;
	}
	return (0);
}
Esempio n. 2
0
static void internaldate(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
struct	stat	stat_buf;
char	buf[256];
char	*p, *q;

	writes("INTERNALDATE ");
	if (fstat(fileno(fp), &stat_buf) == 0)
	{
		rfc822_mkdate_buf(stat_buf.st_mtime, buf);

		/* Convert RFC822 date to imap date */

		p=strchr(buf, ',');
		if (p)	++p;
		else	p=buf;
		while (*p == ' ')	++p;
		if ((q=strchr(p, ' ')) != 0)	*q++='-';
		if ((q=strchr(p, ' ')) != 0)	*q++='-';
		writes("\"");
		writes(p);
		writes("\"");
	}
	else
		writes("NIL");
}
Esempio n. 3
0
void fetchflags(unsigned long n)
{
#if SMAP
	if (smapflag)
	{
		writes("* FETCH ");
		writen(n+1);
	}
	else
#endif
	{
		writes("* ");
		writen(n+1);
		writes(" FETCH (");
	}

	doflags(0, 0, &current_maildir_info, n, 0);

#if SMAP
	if (smapflag)
	{
		writes("\n");
	}
	else
#endif
		writes(")\r\n");
}
Esempio n. 4
0
void prsize(uint16_t blocks)
{
	writes(1, _itoa(blocks));
	writes(1, "\t");
	writes(1, fname);
	write(1, "\n", 1);
}
Esempio n. 5
0
static void rfc822(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *info, unsigned long msgnum,
	struct rfc2045 *rfcp)
{
unsigned long n=0;
int	c;
char	buf[BUFSIZ];
unsigned long i;

	writes("RFC822 ");

	if (fseek(fp, 0L, SEEK_SET) == -1)
	{
		fetcherror("fseek", fi, info, msgnum);
		writes("{0}\r\n");
		return;
	}
	while ((c=getc(fp)) != EOF)
	{
		++n;
		if (c == '\n')	++n;
	}

	if (fseek(fp, 0L, SEEK_SET) == -1)
	{
		fetcherror("fseek", fi, info, msgnum);
		writes("{0}\r\n");
		return;
	}
	writes("{");
	writen(n);
	writes("}\r\n");

	i=0;
	while (n)
	{
		c=getc(fp);
		if (c == '\n')
		{
			if (i >= sizeof(buf))
			{
				writemem(buf, i);
				i=0;
			}
			buf[i++]='\r';
			if (--n == 0)	break;
		}

		if (i >= sizeof(buf))
		{
			writemem(buf, i);
			i=0;
		}
		buf[i++]=c;
		--n;
		++body_count;
	}
	writemem(buf, i);
}
Esempio n. 6
0
static void rfc822text(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *info, unsigned long msgnum,
	struct rfc2045 *rfcp)
{
off_t start_pos, end_pos, start_body;
off_t nlines, nbodylines;
unsigned long i;
int	c;
char	buf[BUFSIZ];
unsigned long l;

	writes("RFC822.TEXT {");

	rfc2045_mimepos(rfcp, &start_pos, &end_pos, &start_body,
		&nlines, &nbodylines);

	if (fseek(fp, start_body, SEEK_SET) == -1)
	{
		fetcherror("fseek", fi, info, msgnum);
		writes("0}\r\n");
		return;
	}

	i=end_pos - start_body + nbodylines;

	writen(i);
	writes("}\r\n");

	l=0;
	while (i)
	{
		c=getc(fp);
		if (c == EOF)
		{
			fetcherror("unexpected EOF", fi, info, msgnum);
			_exit(1);
		}
		--i;
		if (l >= sizeof(BUFSIZ))
		{
			writemem(buf, l);
			l=0;
		}
		if (c == '\n' && i)
		{
			--i;
			buf[l++]='\r';
			if (l >= sizeof(BUFSIZ))
			{
				writemem(buf, l);
				l=0;
			}
		}
		buf[l++]=c;
		++body_count;
	}
	writemem(buf, l);
}
Esempio n. 7
0
static void fetchmsgbody(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
	writes("BODY");
	print_bodysection_partial(fi, &print_bodysection_output);
	writes(" ");
	dofetchmsgbody(fp, fi, i, msgnum, mimep);
}
Esempio n. 8
0
void fetchflags_byuid(unsigned long n)
{
	writes("* ");
	writen(n+1);
	writes(" FETCH (");
	uid(0, 0, &current_maildir_info, n, 0);
	writes(" ");
	doflags(0, 0, &current_maildir_info, n, 0);
	writes(")\r\n");
}
Esempio n. 9
0
void dumsg(const char *x, const char *p)
{
	writes(2, x);
	if (p) {
		write(2, " `", 2);
		writes(2, p);
		write(2, "'\n", 2);
	} else
		write(2, "\n", 1);
}
Esempio n. 10
0
static void fast(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
	doflags(fp, fi, i, msgnum, mimep);
	writes(" ");
	internaldate(fp, fi, i, msgnum, mimep);
	writes(" ");
	rfc822size(fp, fi, i, msgnum, mimep);
}
Esempio n. 11
0
static char *send_auth_reply(const char *q, void *dummy)
{
	struct imaptoken *tok;
	char	*p;

#if SMAP
	const char *cp=getenv("PROTOCOL");

	if (cp && strcmp(cp, "SMAP1") == 0)
		writes("> ");
	else
#endif

	{
		writes("+ ");
	}
	writes(q);
	writes("\r\n");
	writeflush();
	read_timeout(SOCKET_TIMEOUT);
	tok=nexttoken_nouc();

	switch (tok->tokentype)	{
	case IT_ATOM:
	case IT_NUMBER:
		p=my_strdup(tok->tokenbuf);
		break;
	case IT_EOL:
		p=my_strdup("");
		break;
	default:
		return (0);
	}
	if (!p)
	{
		perror("malloc");
		return (0);
	}

	if (nexttoken()->tokentype != IT_EOL)
	{
		free(p);
		fprintf(stderr, "Invalid SASL response\n");
		return (0);
	}
	read_eol();
	return (p);
}
Esempio n. 12
0
static void envelope(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
	writes("ENVELOPE ");
	msgenvelope( &writemem, fp, mimep);
}
Esempio n. 13
0
static void body(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
	writes("BODY ");
	msgbodystructure(writemem, 0, fp, mimep);
}
Esempio n. 14
0
void Node::write2Blk(Block &blk, int typeId, int strLen, BufferManager* bufferManager) {
    char* mem = blk.data;
    
    mem[0] = isleaf; mem[1] = isroot;
    mem += 2*sizeof(char);
    writei(getPSize(), mem), writei(getKSize(), mem), writei(typeId, mem), writei(strLen, mem);
    
    std::cout << "getPSize()" << getPSize() <<std::endl;
    std::cout << "getKSize()" << getKSize() <<std::endl;
    
    for( int i = 0; i < getPSize(); i++ ) {
        std::cout << "P[i]" << P[i] << std::endl;
        writei(P[i], mem);
    }
    
    for( int i = 0; i < getKSize(); i++ ) {
        std::cout << "K[i]" << K[i].datai << std::endl;
        if( typeId == 0 ) {
            writei(K[i].datai, mem);
        }
        else if( typeId == 1 ) {
            writef(K[i].dataf, mem);
        }
        else if( typeId == 2 ) {
            writes(K[i].datas, strLen, mem);
        }
    }
    
    std::cout << "Node::write2Blk " << blk.pos/BLOCK_SIZE << std::endl;
    
    //BufferManager bufferManager;
    bufferManager->writeBlock(blk);
}
Esempio n. 15
0
static void uid(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
	writes("UID ");
	writen(i->msgs[msgnum].uid);
}
Esempio n. 16
0
static void disconnected_timeout(void)
{
	writes("* BYE Disconnected for inactivity.\r\n");
	writeflush();
	bye_msg("INFO: TIMEOUT");
	bye();
}
Esempio n. 17
0
void Fib(int argc, char **argv) {
    int x,y,z;

    if (argc < 2) {
        usage(stderr);
        exit();
    }

    int N = strtou32(argv[1]);
    
    x = 1;           //MOV R1, #1
    y = 0;           //MOV R2, #0
    if (N < 2)       //CMP R0, #2
        x = N;       //MOVMI R1, R0; BMI #5
    else {
        N -= 2;
        do {
            z = y;       //MOV R3, R2
            y = x;       //MOV R2, R1
            x = y + z;   //ADD R1, R2, R3
            N--;         //SUBS R0, R0, 1
        } while (N >= 0);//BPL #-6
    }

    writei(stdout, x);
    writes(stdout, "\n");
    exit();
}
Esempio n. 18
0
TEST(MeterFile, format3) {
	char tempfilename[L_tmpnam+1];
	ASSERT_NE(tmpnam_r(tempfilename), (char*)0);
	std::list<Option> options;
	options.push_back(Option("path", tempfilename));
	options.push_back(Option("format", (char*)"$t;$i : $v"));
	
	MeterFile m(options);
	ASSERT_STREQ(m.path(), tempfilename) << "devicename not eq " << tempfilename;
	ASSERT_EQ(0, mkfifo(tempfilename, S_IRUSR|S_IWUSR));
	int fd = open(tempfilename, O_RDWR);
	ASSERT_NE(fd, -1);
	ASSERT_EQ(SUCCESS, m.open());

	// now we can simulate some input by simply writing into fd
	std::vector<Reading> rds;
	rds.resize(2);

	// write two good data set
	writes(fd, "1001.2;id1 : 32552\r\n");
	writes(fd, "1002.5;id2 : 32552.5\r\n");

	// now read two readings:
	EXPECT_EQ(2, m.read(rds, 2));
	// check obis data:
	ReadingIdentifier *p = rds[0].identifier().get();
	double value = rds[0].value();
	EXPECT_EQ(32552, value);
	EXPECT_EQ(1001200ll, rds[0].time_ms()) << rds[0].time_ms();

	StringIdentifier *o = dynamic_cast<StringIdentifier*>(p);
	ASSERT_NE((StringIdentifier*)0, o);
	EXPECT_EQ(StringIdentifier("id1"), *o);

	value = rds[1].value();
	p = rds[1].identifier().get();
	o = dynamic_cast<StringIdentifier*>(p);
	EXPECT_EQ(32552.5, value);
	EXPECT_EQ(1002500ll, rds[1].time_ms());
	ASSERT_NE((StringIdentifier*)0, o);
	EXPECT_EQ(StringIdentifier("id2"), *o);

	EXPECT_EQ(0, m.close());

	EXPECT_EQ(0, close(fd));
	EXPECT_EQ(0, unlink(tempfilename));
}
Esempio n. 19
0
static dsk_err_t compress(SQ_COMPRESS_DATA *self)
{
	char *s = self->sq_truename;
	dsk_err_t e;
	unsigned short dictbase;
	unsigned short dictlen;
	unsigned short dn;

	e = writes(self, MAGIC); if (e) return e;     /* Magic */
	e = writes(self, self->ck_sum);
				 if (e) return e;     /* Source file checksum */	
	do		/* Filename */
	{
		e = writec(self, *s); if (e) return e;
	} while ( *(s++) );	

	dictbase = self->huf_curnode + 1;
	/* Dictionary length = MAXNODE - dictbase */
	dictlen = MAXNODE - dictbase;
	e = writes(self, dictlen); if (e) return e;
	for (dn = dictbase; dn < MAXNODE; dn++)
	{
		short l = self->huf_node[dn].left;
		short r = self->huf_node[dn].right;

		if (l >= 0) l -= dictbase;
		if (r >= 0) r -= dictbase;

		e = writes(self, l);
		e = writes(self, r);
	}	
	/* Dictionary written. Start spitting bytes. */ 
	self->huf_nout = 0;
	self->huf_out  = 0;	
	rle_reset(self);
	e = rle_stream(self, huf_encode); if (e) return e;

	/* Write any pending bits */
	if (self->huf_nout)
	{
		if (fputc(self->huf_out, self->fp_out) == EOF) 
				return DSK_ERR_SYSERR;
	}
	fseek(self->fp_out, 2, SEEK_SET);
	
	return DSK_ERR_OK;
}
Esempio n. 20
0
void writeqs(const char *s)
{
size_t	i=strlen(s), j;

	while (i)
	{
		for (j=0; j<i; j++)
		{
			if ( s[j] == '"' || s[j] == '\\')
			{
				writemem(s, j);
				writemem("\\", 1);
				writemem(s+j, 1);
				++j;
				s += j;
				i -= j;
				j=0;
				break;
			}
#if 0
			if (s[j] == '&')
			{
				writemem(s, j);
				writemem("&-", 2);
				++j;
				s += j;
				i -= j;
				j=0;
				break;
			}

			if (s[j] < ' ' || s[j] >= 0x7F)
			{
			char	*q;

				writemem(s, j);
				++j;
				s += j;
				i -= j;
				for (j=0; j<i; j++)
					if (s[j] >= ' ' && s[j] < 0x7F)
						break;
				q=imap_utf7_encode(s, j);
				if (!q)	write_error_exit(0);
				writemem("&", 1);
				writes(q);
				writemem("-", 1);
				s += j;
				i -= j;
				j=0;
				break;
			}
#endif
		}
		writemem(s, j);
		s += j;
		i -= j;
	}
}
Esempio n. 21
0
void read_and_print(int *fd, const char *colour)
{
	writes(1, colour);

	char buf[4096];
	ssize_t n = read(*fd, buf, sizeof buf);
	check(n, "read");
	if(n == 0){
		close(*fd);
		*fd = -1;
		return;
	}

	write(1, buf, n);

	writes(1, "\x1b[m");
}
Esempio n. 22
0
File: mknod.c Progetto: 8l/FUZIX
int main(int argc, char *argv[])
{
	if (argc != 4) {
		writes("usage: mknod path modes devs\n");
		return 1;
	}
	return do_mknod(argv[1], argv[2], argv[3]);
}
Esempio n. 23
0
TEST(MeterFile, basic) {
	char tempfilename[L_tmpnam+1];
	ASSERT_NE(tmpnam_r(tempfilename), (char*)0);
	std::list<Option> options;
	options.push_back(Option("path", tempfilename));
	
	// test without format option
	MeterFile m(options);
	ASSERT_STREQ(m.path(), tempfilename) << "devicename not eq " << tempfilename;
	ASSERT_EQ(0, mkfifo(tempfilename, S_IRUSR|S_IWUSR));
	int fd = open(tempfilename, O_RDWR);
	ASSERT_NE(fd, -1);
	ASSERT_EQ(SUCCESS, m.open());

	// now we can simulate some input by simply writing into fd
	std::vector<Reading> rds;
	rds.resize(10);

	// write two good data set
	writes(fd, "32552\r\n");
	writes(fd, "32552.5\r\n");
	//	writes(fd, "32552.6\r\n"); // bug: with 2 only it hangs! Fixed with changing order in while (i<n...) in MeterFile.cpp

	// now read two readings:
	EXPECT_EQ(2, m.read(rds, 2));
	// check obis data:
	ReadingIdentifier *p = rds[0].identifier().get();
	double value = rds[0].value();
	EXPECT_EQ(32552, value);
	StringIdentifier *o = dynamic_cast<StringIdentifier*>(p);
	ASSERT_NE((StringIdentifier*)0, o);
	EXPECT_EQ(StringIdentifier(""), *o);

	value = rds[1].value();
	p = rds[1].identifier().get();
	o = dynamic_cast<StringIdentifier*>(p);
	EXPECT_EQ(32552.5, value);
	ASSERT_NE((StringIdentifier*)0, o);
	EXPECT_EQ(StringIdentifier(""), *o);

	EXPECT_EQ(0, m.close());

	EXPECT_EQ(0, close(fd));
	EXPECT_EQ(0, unlink(tempfilename));
}
Esempio n. 24
0
File: chgrp.c Progetto: 8l/FUZIX
int main(int argc, char *argv[])
{
    char *cp;
    int gid;
    struct group *grp;
    struct stat statbuf;

    cp = argv[1];
    if (!cp) {
	writes("chgrp: too few arguments\n");
	return 1;
    }
    if (isdigit(*cp)) {
	gid = 0;
	while (isdigit(*cp))
	    gid = gid * 10 + (*cp++ - '0');

	if (*cp) {
	    writes("chgrp: bad gid value\n");
	    return 1;
	}
    } else {
	grp = getgrnam(cp);
	if (grp == NULL) {
	    writes("chgrp: unknown group name\n");
	    return 1;
	}
	gid = grp->gr_gid;
    }

    argc--;
    argv++;

    while (argc-- > 1) {
	argv++;
	if ((stat(*argv, &statbuf) < 0) ||
	    (chown(*argv, statbuf.st_uid, gid) < 0)) {
	    perror(*argv);
	    return 1;
	}
    }

    return 0;
}
Esempio n. 25
0
File: ulock.c Progetto: jwilk/ulock
void check_password(void)
{
  static struct pam_conv conv =
  {
    ulock_conv,
    NULL
  };
  pam_handle_t *pamh;
  char username[1 << 8];
  username[0] = '\0';
  strncat(username, getpwuid(getuid())->pw_name, (sizeof username) - 1);
  pam_start("ulock", username, &conv, &pamh);
  writes(STDOUT_FILENO, "The terminal is now locked. Please enter the password to unlock it.\n");
  char *username2 = username;
  for (int i = 0; ; i++)
  {
    int pam_error;
    writes(STDOUT_FILENO, username2);
    writes(STDOUT_FILENO, "'s password: "******"Erm, one minute penalty...\n");
      sleep(60);
    }
    username2 = (username2 == username) ? "root" : username;
  }
  pam_end(pamh, PAM_SUCCESS);
  fatal("Something went *SERIOUSLY* wrong\n");
}
Esempio n. 26
0
File: ulock.c Progetto: jwilk/ulock
static int ulock_conv(int num_msg, const struct pam_message **msgm, struct pam_response **response, void *appdata_ptr)
{
  appdata_ptr = appdata_ptr;

  if (num_msg <= 0)
    return PAM_CONV_ERR;

  struct pam_response *reply = calloc(num_msg, sizeof(struct pam_response));
  if (reply == NULL)
    return PAM_CONV_ERR;

  for (int i = 0; i < num_msg; i++)
  {
    char *string = NULL;
    switch (msgm[i]->msg_style)
    {
    case PAM_PROMPT_ECHO_OFF:
    case PAM_PROMPT_ECHO_ON:
      string = calloc(1 << 8, 1);
      if (string == NULL)
        goto fail;
      ssize_t size = read(STDIN_FILENO, string, 1 << 8);
      if (size < 0)
      {
        free(string);
        goto fail;
      }
      else if (size > 0)
        string[size - 1] = '\0';
      writes(STDOUT_FILENO, "\n");
      break;
    case PAM_ERROR_MSG:
    case PAM_TEXT_INFO:
      continue;
    default:
      goto fail;
    }
    if (string != NULL)
    {
      reply[i].resp_retcode = 0;
      reply[i].resp = string;
      string = NULL;
    }
  }
  *response = reply;
  reply = NULL;
  return PAM_SUCCESS;
fail:
  if (reply != NULL)
  for (int i = 0; i < num_msg; i++)
    if (reply[i].resp != NULL)
      free(reply[i].resp);
  free(reply);
  return PAM_CONV_ERR;
}
Esempio n. 27
0
int main(int argc, const char *argv[])
{
    if(argc < 3) {
	writes(2, "usage: mount device path\n");
	return 0;
    }

    mount(argv[1], argv[2], 0);

    return 0;
}
Esempio n. 28
0
static void rfc822size(FILE *fp, struct fetchinfo *fi,
	struct imapscaninfo *i, unsigned long msgnum,
	struct rfc2045 *mimep)
{
off_t start_pos, end_pos, start_body;
off_t nlines, nbodylines;

	writes("RFC822.SIZE ");

	rfc2045_mimepos(mimep, &start_pos, &end_pos, &start_body,
		&nlines, &nbodylines);

	writen(end_pos - start_pos + nlines);
}
Esempio n. 29
0
void write_error_exit(const char *funcname)
{
	outbuf_cnt=0;
	writes("* BYE [ALERT] Fatal error: ");
	if (funcname && *funcname)
	{
		writes(funcname);
		writes(": ");
	}

	if (errno)
	{
#if	HAVE_STRERROR
	const	char *p;

		p=strerror(errno);
#else
	char	p[40];

		sprintf(p, "Error %d", (int)errno);
#endif


		writes(p);
	}
	writes("\r\n");
	writeflush();

	if (funcname && *funcname)
	{
		fprintf(stderr, "ERR: %s: %s\n", getenv("AUTHENTICATED"),
			funcname);
		fflush(stderr);
	}
	_exit(1);
}
Esempio n. 30
0
File: rmdir.c Progetto: 8l/FUZIX
int main(int argc, char **argv)
{
    int i, parent = 0, er = 0;

    if ((argv[1][0] == '-') && (argv[1][1] == 'p'))
	parent = 1;

    newmode = 0666 & ~umask(0);

    for (i = parent + 1; i < argc; i++) {
	if (argv[i][0] != '-') {
	    if (remove_dir(argv[i], parent)) {
	        writes("rmdir: cannot remove directory '");
	        writes(argv[i]);
	        perror("'");
		er = 1;
	    }
	} else {
	    writes("rmdir: usage error\n");
	    exit(1);
	}
    }
    return er;
}