Esempio n. 1
0
int main(int argc, char **argv)
{
      while (*++argv != 0)
      {
            XFILE *f = xopen(*argv);

            if (f == 0)
                  fprintf(stderr, "ERROR: can't open file %s\n", *argv);
            else
            {
#if 0
                  char *s;

                  fprintf(stdout, "--- %s ---\n", *argv);
                  while ((s = xgetline(f)) != NULL)
                        fputs(s, stdout);
                  xclose(f);
#else
                  unsigned int nLines = 0;
                  char *s;

                  while (xgetline(f) != NULL)
                        ++nLines;
                  printf("%5u lines in %s\n", nLines, *argv);
                  xclose(f);
#endif
            }
      }

      return 0;
}
Esempio n. 2
0
static void
newuser_getpasswd( user_id_t user_id)
{
    char pwread[20], pwtest[20];	/* for password validation */
    int done = FALSE;

    more(BBSDIR "/share/newuser/password", 1);

    while (!done) {
	cprintf("\1f\1gPlease enter a password: "******"\1f\1gPlease enter it again: ");
	    xgetline(pwtest, -19, 1);

	    if (strcmp(pwtest, pwread) != 0)
		cprintf("\1rThe passwords you typed didn't match.  Please try again.\n");
	    else
		done = TRUE;
	}
    }

    mono_sql_u_set_passwd( user_id, pwread );
    cprintf("\n");
    return;
}
Esempio n. 3
0
static void
wacky_email_stuff()
{

    size_t accepted;

    char subject[50];
    char recipient[60];
    char work[150];

    cprintf(_("\01g\01f\nWould you like to remove the color codes? \01w(\01gy/n\01w)\01g "));
    if (yesno() == YES) {
	if (de_colorize(CLIPFILE) != 0)
	    cprintf(_("\01f\01rWarning\01w:\01g Couldn't remove colours."));
    }
    cprintf("\01f\01g\nEnter a recipient:\01c ");
    xgetline(recipient, sizeof(recipient), 1);
    accepted = strspn(recipient, ACCEPTED);

    if (accepted < strlen(recipient)) {
	cprintf("\01r\01f\nInvalid email address, can't send message!\01a\n");
    } else {
	cprintf("\01f\01gSubject for the email: \01c");
	xgetline(subject, sizeof(subject), 1);
	if (strspn(subject, ACCEPTED) < strlen(subject)) {
	    cprintf("\01r\01fSubject contains invalid characters, can't send message!\01a\n");
	    return;
	}
	if (strlen(subject) == 0)
	    strcpy(subject, "Clipboard-Contents");
	log_it("email", "%s sent clipboard to %s", usersupp->username, recipient);
	(void) sprintf(work, "/bin/mail -s '%s' %s < %s", subject, recipient, CLIPFILE);
	(void) system(work);
	cprintf(_("\01g\01fMail was sent to \01c%s\01a\n"), recipient);
    }
}
Esempio n. 4
0
/* Read a complete line and return it (without trailing newline),
 * or NULL at end of file. */
static char *get_line (FILE *stream)
{
	char *result;

	result = xgetline (stream);
	if (result) {
		int length;

		length = strlen (result);
		if (result[length - 1] == '\n')
			result[length - 1] = '\0';
	}

	return result;
}
void aln_read(alignment *a, FILE *stream) {
  char *line = NULL;
  size_t line_size = 0;
  int state = 0;
  a->seq_num = 0;
  a->seqs = NULL;
  a->key_positions = NULL;

  while (xgetline(&line, &line_size, stream)) {
    if (state == 0) {
      char *beg = skipws(line);
      char *end = skipnw(beg);
      if (*beg == '*' && *(end-1) == '*') {
        *end = 0;
        a->key_positions = xstrdup(beg);
        state = 1;
      }
    } else {
      char *name = line;
      char *start = next_word(name);
      char *seq = next_word(start);
      if (*seq == 0)
        break;
      *skipnw(name) = 0;
      *skipnw(start) = 0;
      *skipnw(seq) = 0;
      ++a->seq_num;
      /* slow but simple linear reallocation for now: */
      a->seqs = XREALLOC(a->seqs, a->seq_num);
      a->seqs[a->seq_num-1].name = xstrdup(name);
      a->seqs[a->seq_num-1].seq = xstrdup(seq);
      a->seqs[a->seq_num-1].start = xstrdup(start);
    }
  }

  free(line);
}
Esempio n. 6
0
extern parse_ini_t
parse_ini_open(const char *fname)
{
	parse_ini_t     dummy    = NULL;
	local_section_t sec      = NULL;
	local_key_t     key      = NULL;
	char            *line    = NULL;
	size_t          n        = 0;
	size_t          line_len = 0;
	int             i;

	/* Get memory */
	dummy = xmalloc(sizeof(parse_ini_struct_t));

	/* Try to open the file */
	dummy->f = fopen(fname, "r");
	if (dummy->f == NULL) {
		xfree(dummy);
		return NULL;
	}

	/* Copy the filename over */
	dummy->fname = xstrdup(fname);

	/* Some init stuff */
	dummy->sections     = NULL;
	dummy->num_sections = 0;
	dummy->cursec       = -1;

	/* Parse the file */
	while (xgetline(&line, &n, dummy->f) > 0) {
		/* Check for empty (only blanks) line, wipe it */
		i        = 0;
		line_len = strlen(line);
		while ((line[i] != '\0') && (isblank(line[i])))
			i++;
		if ((size_t)i == line_len - 1) {
			line[0] = '\0';
		}

		switch (line[0]) {
		case '\0':
		/* This is an empty line, we do nothing. */
		case '#':
			/* Ignore comment lines */
			break;
		case '[':
			/* This is a new section */
			dummy->num_sections++;
			/* Get memory for it  */
			dummy->sections = xrealloc(dummy->sections,
			                           dummy->num_sections
			                           * sizeof(local_section_struct_t));
			/* Use a shortcut to access the current section */
			sec           = dummy->sections + dummy->num_sections - 1;
			/* Initialize the section structure correctly */
			sec->name     = local_parse_secname(line);
			sec->num_keys = 0;
			sec->keys     = NULL;
			/* Verify the section structure */
			if (sec->name == NULL) {
				/* Wrong file format. We die. */
				fprintf(stderr, "Could not parse '%s'\n", line);
				xfree(line);
				parse_ini_close(&dummy);
				return NULL;
			}
			break;
		default:
			/* This is potentially a key */
			if (sec == NULL) {
				/* Huh.. we haven't had a section yet, so lets
				 * ignore this gibberish.
				 */
			} else {
				/* Okay, it is a new key */
				sec->num_keys++;
				/* Get memory for it */
				sec->keys = xrealloc(sec->keys,
				                     sec->num_keys
				                     * sizeof(local_key_struct_t));
				/* Use a shortcut */
				key = sec->keys + (sec->num_keys - 1);
				/* Initialize the key correctly */
				local_parse_key(line, &(key->key_name), &(key->value));
				/* Check that it worked */
				if ((key->key_name == NULL) || (key->value == NULL)) {
					/* Wrong file format. We die. */
					fprintf(stderr, "Could not parse '%s'\n", line);
					xfree(line);
					parse_ini_close(&dummy);
					return NULL;
				}
				/* This key has not yet been requested */
				key->requested = false;
			}
			break;
		} /* switch */
	} /* while */

	/* Clean */
	fclose(dummy->f);
	dummy->f = NULL;
	xfree(line);

	/* And done */
	return dummy;
} /* parse_ini_open */
Esempio n. 7
0
int
mail_clipboard(const char *file)
{

#ifdef HAVE_SENDMAIL
    FILE *sendmail = NULL;
    char *message = NULL;
#else
    char work[L_USERNAME + RGemailLEN + 85];
#endif
    char subject[50];
    size_t accepted;

    accepted = strspn(usersupp->RGemail, ACCEPTED);

    if (accepted < strlen(usersupp->RGemail)) {
        cprintf(_("\1r\1fInvalid email address, can't send message!\1a\n"));
        return -1;
    }

    IFSYSOP {
        cprintf(_("\1f\1g\nDo you wish to send it to yourself? \1c"));
        if (yesno() == NO) {
            nox = 1;
            wacky_email_stuff();
            return 0;
        }
    }
    cprintf(_("\1f\1gE-Mail yourself the ClipBoard.\n"));

    cprintf(_("\1g\1fAre you sure you want to email your clipboard? \1w(\1gy\1w/\1gN\1w) \1c"));

    if (yesno_default(NO) == NO)
        return 0;

    cprintf(_("\1g\1f\nWould you like to remove the color codes? \1w(\1gY/n\1w)\1g \1c"));
    if (yesno_default(YES) == YES)
        if (de_colorize(file) != 0)
            cprintf(_("\1f\1r\nWarning\1w:\1g Couldn't remove colours.\1a"));

    cprintf("\1f\1gSubject for the email: \1c");
    xgetline(subject, sizeof(subject), 1);

#ifndef HAVE_SENDMAIL
    if (strspn(subject, ACCEPTED) < strlen(subject)) {
        log_it("email", "Email to %s failed.\n%s tried to send clipboard with subject %s", usersupp->RGemail, usersupp->username, subject);
        cprintf(_("\1r\1fSubject contains invalid characters, can't send message!\1a\n"));
        return 1;
    }
#endif

    if (strlen(subject) == 0)
        sprintf(subject, "%s@%s BBS: Clipboard-Contents", usersupp->username, BBSNAME);

#ifdef HAVE_SENDMAIL
    if( (sendmail = popen( SENDMAIL " -t", "w" )) == NULL ) {
	log_it("email", "Error trying to send clipboard to %s.\nCan't popen(%s)", usersupp->RGemail, SENDMAIL);
        cprintf(_("\1f\1rError trying to send clipboard to %s.\nCan't popen(%s)\n"), usersupp->RGemail, SENDMAIL );
	return 2;
    }
    if ((message = map_file(file)) == NULL) {
        xfree(message);
	log_it("email", "Error trying to send clipboard to %s.\nCan't mmap(%s)", usersupp->RGemail, file);
	cprintf(_("\1f\1rError trying to send clipboard to %s.\nCan't mmap(%s)\n"), usersupp->RGemail, file);
	return 2;
    }

    fprintf(sendmail, "To: %s <%s>\n", usersupp->RGname, usersupp->RGemail);
    fprintf(sendmail, "Subject: %s\n", subject);
    fprintf(sendmail, "%s\n", message);
    xfree(message);

    if( pclose(sendmail) == -1 ) {
	log_it("email", "Error trying to send clipboard to %s.\nCan't pclose(%X)", usersupp->RGemail, sendmail);
	cprintf(_("\1f\1rError trying to send clipboard to %s.\nCan't pclose(%X)\n"), usersupp->RGemail, sendmail);
	return 2;
    }
#else
    sprintf(work, "/bin/mail -s '%s' %s < %s", subject, usersupp->RGemail, file);
    if (system(work) == -1) {
        log_it("email", "Error trying to send clipboard to %s.", usersupp->RGemail );
        cprintf(_("\1f\1rError trying to send clipboard to %s."), usersupp->RGemail );
        return 2;
    }
#endif

    log_it("email", "%s sent clipboard to %s", usersupp->username, usersupp->RGemail);
    cprintf(_("\1g\1fMail was sent to \1c%s\1a\n"), usersupp->RGemail);

    return 0;
}
Esempio n. 8
0
static void
newuser_registration(user_t * user)
{
    char p[RGurlLEN];
    int ret;

    cprintf("\1f\1g");
    more(BBSDIR "/share/newuser/registration", 0);

    cprintf("Please enter your real name.\n");
    do {
	cprintf("\n* FULL REAL name: ");
	xgetline(user->RGname, RGnameLEN, 1);
    }
    while (strlen(user->RGname) <= 6);

    cprintf("\nNext, enter your address (street name, and number).\n\n");
    do {
	cprintf("* Address:        ");
	xgetline(user->RGaddr, RGaddrLEN, 1);
    } while (strlen(user->RGaddr) < 3);

    do {
	cprintf("* City/Suburb:    ");
	xgetline(user->RGcity, RGcityLEN, 1);
    } while (strlen(user->RGcity) < 2);

    do {
	cprintf("* Zip code:       ");
	xgetline(user->RGzip, RGzipLEN, 1);
    } while (strlen(user->RGzip) < 3);

	cprintf("  State/Province: ");
	strcpy( user->RGstate, "" ); /* initialise, or get garbage */
	xgetline(user->RGstate, RGstateLEN, 1);

    do {
	cprintf("* Country:        ");
	xgetline(user->RGcountry, RGcountryLEN, 1);
    } while (strlen(user->RGcountry) < 3);

	cprintf("  Phone number:   ");
	strcpy( user->RGphone, "" ); /* initialise or get garbage! */
	xgetline(user->RGphone, RGphoneLEN, 1);

    more(BBSDIR "/share/newuser/email", 0);

    cprintf("\n\1f\1gPlease enter your e-mail address in the form: \[email protected]\n");
    fflush(stdout);
    sleep(3);

    do {
	cprintf("\n\n* Email address:  ");
	xgetline(user->RGemail, RGemailLEN, 1);
    }
    while ((strlen(user->RGemail) < 7)
	   || (is_allowed_email(user->RGemail) == FALSE));

    cprintf("\nYou can enter a homepage address (URL) if you wish.\n");
    cprintf("Enter it in the form: host.machine.edu/directory\n");
    cprintf("If you don't have a homepage, or don't understand this ");
    cprintf("just press return.\n\n");

    fflush(stdout);

    cprintf("\n\nURL:              http://");
    xgetline(p, RGurlLEN - 7, 1);
    if (strlen(p) < 5) {
	strcpy(user->RGurl, "");
	cprintf("URL left blank.\n");
    } else {
        strremcol( p );
	sprintf(user->RGurl, "http://%s", p);
    }

    ret = mono_sql_u_update_registration( usersupp->usernum,
        usersupp->RGname, usersupp->RGaddr, usersupp->RGzip, usersupp->RGcity,
        usersupp->RGstate, usersupp->RGcountry, usersupp->RGphone );
    if ( ret == -1 ) fprintf( stderr, "Problems saving registration info.\n" );
    ret = mono_sql_u_update_email( usersupp->usernum, usersupp->RGemail );
    if ( ret == -1 ) fprintf( stderr, "Problems saving email.\n" );
    ret = mono_sql_u_update_url( usersupp->usernum, usersupp->RGurl );
    if ( ret == -1 ) fprintf( stderr, "Problems saving URL.\n" );

    cprintf("\n\1f\1gYou have entered the following information:\n\n");
    dis_regis(user, TRUE);

    cprintf("\n\1wPlease check that it is correct!\n");
    fflush(stdout);
    sleep(3);

    cprintf("\1f\1g\n\nIs the information correct so far? \1w(\1ry\1w/\1rn\1w) ");
    if (yesno() == NO)
	change_info(user, TRUE);	/* so they can edit their name */
    return;
}