Exemplo n.º 1
1
Arquivo: cpu-bl.c Projeto: npe9/harvey
/*
 *  user level challenge/response
 */
static int
netkeyauth(int fd)
{
	char chall[32];
	char resp[32];

	strecpy(chall, chall+sizeof chall, getuser());
	print("user[%s]: ", chall);
	if(readln(resp, sizeof(resp)) < 0)
		return -1;
	if(*resp != 0)
		strcpy(chall, resp);
	writestr(fd, chall, "challenge/response", 1);

	for(;;){
		if(readstr(fd, chall, sizeof chall) < 0)
			break;
		if(*chall == 0)
			return fd;
		print("challenge: %s\nresponse: ", chall);
		if(readln(resp, sizeof(resp)) < 0)
			break;
		writestr(fd, resp, "challenge/response", 1);
	}
	return -1;
}
Exemplo n.º 2
0
static int
select_mechanism (char **mechlist)
{
  char *in;

  if (args_info.imap_flag)
    return imap_select_mechanism (mechlist);
  if (args_info.smtp_flag)
    return smtp_select_mechanism (mechlist);

  if (args_info.mechanism_arg)
    *mechlist = args_info.mechanism_arg;
  else if (args_info.server_flag)
    {
      if (!args_info.quiet_given)
	fprintf (stderr, _("Choose SASL mechanism:\n"));
      if (!readln (&in))
	return 0;
      *mechlist = in;
    }
  else				/* if (args_info.client_flag) */
    {
      if (!args_info.quiet_given)
	fprintf (stderr,
		 _("Input list of SASL mechanisms supported by server:\n"));
      if (!readln (&in))
	return 0;

      *mechlist = in;
    }

  return 1;
}
Exemplo n.º 3
0
void readlnwithstringconsumestoeol() {
	std::istringstream in { "1 some rest 123\n2the rest\n" };
	std::string rest { };
	int first { };
	readln(in, first, rest);
	ASSERT_EQUAL(1, first);
	ASSERT_EQUAL(" some rest 123", rest);
	readln(in, first, rest);
	ASSERT_EQUAL(2, first);
	ASSERT_EQUAL("the rest", rest);

}
Exemplo n.º 4
0
int main() {
  char input[2][MAX_INPUT_SIZE];
  readln(input[0]);
  readln(input[1]);

  if (areAnagrams(input[0], input[1]))
    printf("String are anagrams\n");
  else
    printf("Strings are not anagrams\n");

  return 0;
}
Exemplo n.º 5
0
void
NetDCC::dcc_chat (void)
{
    int i = readln ();
    if (i == -1)
    {
        dcc_stop ();		// probably the client closed the dcc
        return;
    }
    if (i)
    {
        // fake a privmsg
        char buf2[20];		// should do to keep dcc chat's index
        snprintf (s->bufread, MSG_SIZE, ":%s PRIVMSG %s :%s", (c_char)mask,
                  itoa (index, buf2, 19), bufread);
        s->irc_parse ();
        s->script.irc_event ();
        last_time = s->time_now;
    }
    if (difftime (s->time_now, last_time) > 600)	// timeout in ten minutes
    {
        dcc_chat_write ("Closing idle DCC Chat.");
        dcc_stop ();
    }
}
Exemplo n.º 6
0
void pausa() {
  fprintf(stdout, "\n\n");
  fprintf(stdout, "     *****   Press <RETURN> to continue   *****");
  readln();
  clear_screen();
  return;
}
Exemplo n.º 7
0
short read_bool(char *prompt, short def) {
  int answer;
  for (int timeout = 0; timeout <= 5; timeout++) {
    if (def == false)
      fprintf(FPTR, "%s (y/n) [NO] > ", prompt);
    else
      fprintf(FPTR, "%s (y/n) [YES] > ", prompt);
    answer = readln();
    switch (answer) {
      case '\n':
        return (def);
      case 'y':
      case 'Y':
        return (true);
      case 'n':
      case 'N':
        return (false);
      default:
        beep();
        break;
    }
  }
  fprintf(FPTR, "\n FATAL ERROR: too many wrong attempts ");
  fprintf(FPTR, "in read_bool() \n");
  exit(-1);
  return (false);        // not used: just to be nice with the compiler
}
Exemplo n.º 8
0
static int read_monitor_keys(uint64_t *valuev)
{
        char *key_line = NULL;
        size_t key_line_size;
        int retval = -1;

        if (readln(&key_line, &key_line_size,
                   PATH_MONITOR_CAPABILITIES_KEY) == -1)
                return -1;

        switch (strtovaluev(valuev, KEY_VALUEC, key_line)) {
        case 0:
                break;
        case -1:
                goto out;
        case -2:
                retval = SETTINGS_ERROR_DIRTY_MONITOR_KEY;
                goto out;
        case -3:
                retval = SETTINGS_ERROR_DIRTY_MONITOR_KEY;
                goto out;
        default:
                retval = SETTINGS_ERROR_UNKNOWN;
                goto out;
        }
        retval = 0;
out:
        free(key_line);
        return retval;
}
Exemplo n.º 9
0
int upper_echo(int fd, struct timeval *to, void *data)
{
	int		n, i;
	char	line[80];

	n = readln(fd, line, 80);
	if ( n < 0 )
	{
		perror("read() message");
		return n;
	}
	else if ( n == 0 )
		return ENOTCONN;

	for ( i = 0; i < n; i++ )
		line[i] = toupper(line[i]);

	if ( writen(fd, line, n) != n )
	{
		perror("write() message back");
		return -1;
	}

	return 0;
}
Exemplo n.º 10
0
void testNonStringAtEnd() {
	std::istringstream in { "1 2 3\n" };
	int a { }, b { }, c { }, d { };
	readln(in, a, b, c, d);
	ASSERT_EQUAL(1, a);
	ASSERT_EQUAL(0, d);
}
/*
../../build/Source/pin/pin-windows-intel64/pin.exe -slow_asserts  C:\Users\tevi\Documents\work\pin\pin_mc_malloc_2_9\build\Source\pin\pin-W-X-Y-ia32_intel64-windows\/Tests/obj-intel64/cp-pin.exe makefile makefile.winapp_ru
*/
int main (int argc, char *argv[])
{
    char correctCmdLine[1024];
    int i, j, k, correctCmdLineChar;
    int argvNum;

    memset (correctCmdLine, 0, 1024);
    FILE *fp = fopen ("pin_invoke.txt", "r");
    readln (fp, correctCmdLine);
    correctCmdLineChar = strlen (correctCmdLine);
    correctCmdLine[correctCmdLineChar] = ' ';
    
    for (i=1; i<argc; i++)
    {
        strcat (correctCmdLine, " ");
        strcat (correctCmdLine, (argv[i]));
    }
    correctCmdLineChar = 0;
    
    while (correctCmdLine[correctCmdLineChar] != 0)
    {
        if (correctCmdLine[correctCmdLineChar] == '/')
        {
            correctCmdLine[correctCmdLineChar] = '\\';
        }
        else if (correctCmdLine[correctCmdLineChar] == '-' && correctCmdLine[correctCmdLineChar+1] == '-')
        {
            correctCmdLine[correctCmdLineChar-1] = ' ';
        }
        correctCmdLineChar++;
    }
    
    printf ("%s\n", correctCmdLine);
}
Exemplo n.º 12
0
void successfulreadlntestwithoutlineend() {
	std::istringstream in { "42" };
	int var { };
	readln(in, var);
	ASSERT_EQUAL(42, var);
	ASSERT(!in.fail());
}
Exemplo n.º 13
0
static int read_filter_name(struct settings *settings)
{
        if (readln(&settings->filter_name, &settings->filter_name_size,
                   PATH_FILTER_NAME) == -1)
                return -1;
        return 0;
}
Exemplo n.º 14
0
static int read_filter_rels(uint64_t *valuev)
{
        char *rel_line = NULL;
        size_t rel_line_size;
        int retval = -1;

        if (readln(&rel_line, &rel_line_size,
                   PATH_FILTER_CAPABILITIES_REL) == -1)
                return -1;

        switch (strtovaluev(valuev, REL_VALUEC, rel_line)) {
        case 0:
                break;
        case -1:
                goto out;
        case -2:
                retval = SETTINGS_ERROR_DIRTY_FILTER_REL;
                goto out;
        case -3:
                retval = SETTINGS_ERROR_DIRTY_FILTER_REL;
                goto out;
        default:
                retval = SETTINGS_ERROR_UNKNOWN;
                goto out;
        }
        retval = 0;
out:
        free(rel_line);
        return retval;
}
Exemplo n.º 15
0
/* Returns

   0 : Everything went just ok and settings were updated.

   -1 : Syscall failed and errno is set: no changes were made.

   >0 : One of the SETTINGS_ERROR_-prefixed values defined in settings.h.
*/
static int read_filter_duration(struct settings *settings)
{
        char *filter_duration_line = NULL;
        size_t filter_duration_line_size;
        char *strtod_endptr = NULL;
        double duration;
        int retval = -1;

        if (readln(&filter_duration_line, &filter_duration_line_size,
                   PATH_FILTER_DURATION) == -1)
                return -1;

        errno = 0; /* Needed to distinguish errors from real return values. */
        duration = strtod(filter_duration_line, &strtod_endptr);
        if (errno != 0)
                goto out;

        /* No conversion was made because the file was empty or dirty. */
        if (duration == 0 && filter_duration_line == strtod_endptr) {
                retval = SETTINGS_ERROR_FILTER_DURATION;
                goto out;
        }

        settings->filter_duration = duration;
        retval = 0;
out:
        free(filter_duration_line);
        filter_duration_line = NULL;
        return retval;
}
Exemplo n.º 16
0
static int read_clone_id_member(uint16_t *valuep, const char *path,
                                int errretval)
{
        char *line = NULL;
        size_t line_size;
        char *strtoul_endptr = NULL;
        unsigned long int value;
        int retval = -1;

        if (readln(&line, &line_size, path) == -1)
                return -1;

        errno = 0; /* Needed to distinguish errors from real return values. */
        value = strtoul(line, &strtoul_endptr, 10);
        if (errno != 0)
                goto out;

        /* No conversion was made because the file was empty or dirty. */
        if (value == 0 && line == strtoul_endptr) {
                retval = errretval;
                goto out;
        }

        if (value > USHRT_MAX) {
                errno = ERANGE;
                goto out;
        }

        *valuep = (uint16_t) value;
        retval = 0;
out:
        free(line);
        line = NULL;
        return retval;
}
Exemplo n.º 17
0
int scanstring(char *parm) {
  int c;
  char buf[EASYIO_MAX_STR_LEN];
  int buf_len = 0;

  for (buf_len = 0; ((c = getchar()) != '\n') && (c != '#') &&
                    (buf_len < EASYIO_MAX_STR_LEN); buf_len++) {
    buf[buf_len] = c;
    if ((c != '.') && (c < '0') && (c > '9') &&
        (c < 'a') && (c > 'z') && (c < 'A') &&
        (c > 'Z'))
      return (EASYIO_ERROR);
  }
  if (c == '#') c = readln();    /* empty buffer for next line */

  switch (buf_len) {
    case 0:
      return (EASYIO_DEFAULT);
    case EASYIO_MAX_STR_LEN:
      return (EASYIO_ERROR);
    default:
      buf[buf_len] = '\0';
      strcpy(parm, buf);
      return (EASYIO_OKAY);
  }
}
Exemplo n.º 18
0
static char*
defreadln(char *prompt, char *def, int must, int *changed)
{
	char pr[512];
	char reply[256];

	do {
		if(def && *def){
			if(must)
				snprint(pr, sizeof pr, "%s[return = %s]: ", prompt, def);
			else
				snprint(pr, sizeof pr, "%s[return = %s, space = none]: ", prompt, def);
		} else
			snprint(pr, sizeof pr, "%s: ", prompt);
		readln(pr, reply, sizeof(reply), 0);
		switch(*reply){
		case ' ':
			break;
		case 0:
			return def;
		default:
			*changed = 1;
			if(def)
				free(def);
			return strdup(reply);
		}
	} while(must);

	if(def){
		*changed = 1;
		free(def);
	}
	return 0;
}
Exemplo n.º 19
0
int main(int argc, char *argv[])
{
    char* line;
    g_progname = argv[0];

    switch (argc) {
    case 2:
        break;
    case 1:
        die("too few arguments (need regexp pattern)");
    default:
        die("too many arguments (only one pattern accepted)");
    }

    while ((line = readln()) != NULL) grep(line, argv[1]);

    switch (errno) { /* find out why readln() couldn't get another line */
    case 0:
        break;
    case EIO:
        die("couldn't read from standard input");
    case ENOMEM:
        die("out of memory (can't store input)");
    }

    freeln(line);
    /* "TODO": More code here, that justifies bothering to call freeln()  *
     *         before program termination (which frees all heap memory).  */
    return EXIT_SUCCESS;
}
Exemplo n.º 20
0
void
main(int argc, char *argv[])
{
	char buf[32], pass[32], key[DESKEYLEN];
	char *s;
	int n;

	ARGBEGIN{
	default:
		usage();
	}ARGEND
	if(argc)
		usage();

	s = getenv("service");
	if(s && strcmp(s, "cpu") == 0){
		fprint(2, "netkey must not be run on the cpu server\n");
		exits("boofhead");
	}

	readln("Password: "******"challenge: ");
		n = read(0, buf, sizeof buf - 1);
		if(n <= 0)
			exits(0);
		buf[n] = '\0';
		n = strtol(buf, 0, 10);
		snprint(buf, sizeof buf, "%d", n);
		netcrypt(key, buf);
		print("response: %s\n", buf);
	}
}
Exemplo n.º 21
0
/*
 * getwebpage
 *
 * this function returns the URL and Description for the line if it is in the format
 *   PATCHFILE url description
 */
int getwebpage(int sockfd, int isnet, char *url, char *description)
{
    static char buffer[MAX], hdr[MAX] ;
    int len ;

    // Get Next Entry

    len=readln(sockfd, isnet, buffer, MAX-1) ;

    if (len<0) return (1==0) ;

    // Extract URL
    sscanf(buffer, "%s %s", hdr, url) ;

    if (strcmp(hdr, "PATCHFILE")!=0) {
        url[0]='\0' ;
        description[0]='\0' ;
    } else {
        // Skip White Spaces Extract Description
        len=strlen(url)+strlen("PATCHFILE ") ;
        while (buffer[len]==' ' || buffer[len]=='\t') len++ ;
        strcpy(description, &buffer[len]) ;
    }

    return (1==1) ;
}
Exemplo n.º 22
0
static int read_monitor_name(struct settings *settings)
{
        if (readln(&settings->monitor_name, &settings->monitor_name_size,
                   PATH_MONITOR_NAME) == -1)
                return -1;
        return 0;
}
Exemplo n.º 23
0
void testDisk(){
    clr();
    printf("Ingrese el nombre del disco\n");
    printf("raid-manager> ");
    char *path = readln(256);
    readDisk(path);
    readchar();
}
Exemplo n.º 24
0
int menuMontarRaid(){
    clr();
    printf("\n\tMontar Unidad RAID\n\n");
    printf("Ingrese la ruta de la unidad (drive.dat)\n");
    printf("raid-manager> ");
    char *manager = readln(256);
    loadraid(manager);
    readchar();
}
Exemplo n.º 25
0
int scandouble(double *parm) {

  int c;
  int buf_len;
  int buf[EASYIO_MAX_BUF_LEN];


  for (buf_len = 0; ((c = getchar()) != '\n') && (c != '#') &&
                    (buf_len < EASYIO_MAX_BUF_LEN); buf_len++)
    buf[buf_len] = c;
  if (c == '#') c = readln();        /* empty buffer for next line */

  switch (buf_len) {
    case 0:
      return (EASYIO_DEFAULT);
    case EASYIO_MAX_BUF_LEN:
      return (EASYIO_ERROR);
    default:
      break;
  }

  double mantissa = 0.0;
  int count = 0;
  int pot = 0;
  double potenza = 1.0;
  short neg = 1;

  for (int i = 0; i < buf_len; i++) {
    c = buf[i];
    if ((c != ' ') && (c != '\t')) {
      if (count == -1) return (EASYIO_ERROR);
      else count++;
    }
    if (count > EASYIO_MAX_FLOAT_LEN)
      return (EASYIO_ERROR);
    if (c == '-')
      neg = -1;
    else if ((c >= '0') && (c <= '9')) {
      mantissa = (mantissa * 10) + buf[i] - '0';
      if (pot) potenza *= 10;
    }
    else if (c == '.') {
      if ((buf[i + 1] < '0') || (buf[i + 1] > '9'))
        return (EASYIO_ERROR);
      if (pot != 0)
        return (EASYIO_ERROR);
      pot = 1;
    }
    else if ((c == ' ') || (c == '\t')) {
      if (count != 0) count = -1;
    }
    else return (EASYIO_ERROR);
  }

  *parm = neg * mantissa / potenza;
  return (EASYIO_OKAY);
}
Exemplo n.º 26
0
void cargaMasiva(){
    clr();
    printf("Ingresa la ruta del archivo de texto\n");
    printf("raid-manager> ");
    char *path = readln(256);
    writeFileOnDisk(path);
    readchar();
    
}
Exemplo n.º 27
0
int32_t Adafruit_BLE::readln_parseInt(void)
{
  char buffer[BLE_BUFSIZE+1];
  buffer[BLE_BUFSIZE] = 0;

  size_t len = readln(buffer, BLE_BUFSIZE);
  if (len == 0) return 0;

  int32_t val = strtol(buffer, NULL, 0);

  // discard the rest of the line
  while( len == BLE_BUFSIZE )
  {
    len = readln(buffer, BLE_BUFSIZE);
  }

  return val;
}
Exemplo n.º 28
0
void longreadlntest() {
	std::istringstream in { "one 1 two \02 three 3.0\nthe rest\n" };
	std::string one { };
	std::string two { };
	std::string three { };
	int ione { };
	char ctwo { };
	double dthree { };

	readln(in, one, ione, two, ctwo, three, dthree);
	std::string rest;
	readln(in, rest);
	ASSERT_EQUAL("one", one);
	ASSERT_EQUAL("two", two);
	ASSERT_EQUAL("three", three);
	ASSERT_EQUAL(1, ione);
	ASSERT_EQUAL('\02', ctwo);
	ASSERT_EQUAL(3.0, dthree);
	ASSERT_EQUAL("the rest", rest);
}
Exemplo n.º 29
0
/*-----------------------------------------------------------------------
 *
 * Program: chatclient
 * Purpose: contact a chatserver and allow users to chat
 * Usage:   chatclient <compname> <appnum>
 *
 *-----------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
	computer	comp;
	connection	conn;
	char		buff[BUFFSIZE];
	int		len;

	if (argc != 3) {
		(void) fprintf(stderr, "usage: %s <compname> <appnum>\n",
			       argv[0]);
		exit(1);
	}

	/* convert the compname to binary form comp */

	comp = cname_to_comp(argv[1]);
	if (comp == -1)
		exit(1);

	/* make a connection to the chatserver */

	conn = make_contact(comp, (appnum) atoi(argv[2]));
	if (conn < 0) 
		exit(1);

	(void) printf("Chat Connection Established.\n");
	(void) printf(INPUT_PROMPT);
	(void) fflush(stdout);

	/* iterate, reading from local user and then from chatserver */

	while((len = readln(buff, BUFFSIZE)) > 0) {
		buff[len - 1] = '\n';
		(void) send(conn, buff, len, 0);
		
		/* receive and print a line from the chatserver */
		if ((len = recvln(conn, buff, BUFFSIZE)) < 1)
			break;
		(void) printf(RECEIVED_PROMPT);
		(void) fflush(stdout);
		(void) write(STDOUT_FILENO, buff, len);

		(void) printf(INPUT_PROMPT);
		(void) fflush(stdout);
	}

	/* iteration ends when stdin or the connection indicates EOF */

	(void) printf("\nChat Connection Closed.\n");
	(void) send_eof(conn);
	exit(0);
}
Exemplo n.º 30
0
/* Return 1 on token, 2 on protocol success, 3 on protocol fail, 0 on
   errors. */
static int
step_recv (char **data)
{
  if (args_info.imap_flag)
    return imap_step_recv (data);
  if (args_info.smtp_flag)
    return smtp_step_recv (data);

  if (!readln (data))
    return 0;

  return 1;
}