Exemplo n.º 1
0
const void setExecCommandFile(const uchar command, const char *args)
{
  char args2[256], check[256];


  strcpy(args2, args);
  strcpy(check, args);

  if (command != SETCMD_SET) remTrailingSpaces(args2);
  else
  {
   // don't process SET MAINZONENAME command, cuz it screws up paths while
   // loading

    upstrn(check);
    if (strleft(check, VAR_MAINZONENAME_NAME)) return;
  }

  switch (command)
  {
    case SETCMD_SET     : setVarArgs(args2, FALSE, FALSE); break;
    case SETCMD_ALIAS   : addAliasArgs(args2, FALSE, FALSE, &aliasHead); break;
    case SETCMD_LIMIT   : setLimitArgsStartup(args2); break;
    case SETCMD_SETTEMP : setTemplateArgs(args2, FALSE, FALSE); break;
//    case SETCMD_RANDOM : setRandomArgs(args2); break;

    default : _outtext(
"\nsetExecCommand() - internal error (no match found for command in list)\n\n");
  }
}
Exemplo n.º 2
0
void parse_badchains(int badchains[MAXREM][MAXREM], char *file, char *startindicator, REMAILER *remailer, int maxrem) {
  int i,j;
  FILE *list;
  char line[LINELEN];

  if (!badchains)
    return;

  for (i = 0; i < maxrem; i++ )
    for (j = 0; j < maxrem; j++ )
      badchains[i][j] = 0;
  list = mix_openfile(TYPE2REL, "r");
  if (list != NULL) {
    while (fgets(line, sizeof(line), list) != NULL &&
      !strleft(line, startindicator)) ;
    while (fgets(line, sizeof(line), list) != NULL &&
      strleft(line, "(")) {
      char *left, *right, *tmp;
      int lefti, righti;

      left = line + 1;
      while (*left == ' ')
	left ++;

      tmp = left + 1;
      while (*tmp != ' ' && *tmp != '\0' && *tmp != ')')
	tmp ++;
      if (*tmp == '\0' || *tmp == ')')
	/* parsing this line failed */
	continue;
      *tmp = '\0';

      right = tmp+1;
      while (*right == ' ')
	right ++;
      tmp = right + 1;
      while (*tmp != ' ' && *tmp != '\0' && *tmp != ')')
	tmp ++;
      if (*tmp == '\0')
	/* parsing this line failed */
	continue;
      *tmp = '\0';

      lefti = -1;
      righti = -1;
      for (i = 1; i < maxrem; i++) {
	if (strcmp(remailer[i].name, left) == 0)
	  lefti = i;
	if (strcmp(remailer[i].name, right) == 0)
	  righti = i;
      }
      if (strcmp(left, "*") == 0)
	lefti = 0;
      if (strcmp(right, "*") == 0)
	righti = 0;

      if (lefti == -1 || righti == -1)
	/* we don't know about one or both remailers */
	continue;
      badchains[lefti][righti] = 1;
    }
    fclose(list);
    /* If some broken chain includes all remailers (*) mark it broken for
     * every single remailer - this simplifies handling in other places */
    for (i=1; i < maxrem; i++ ) {
      if (badchains[0][i])
	for (j=1; j < maxrem; j++ )
	  badchains[j][i] = 1;
      if (badchains[i][0])
	for (j=1; j < maxrem; j++ )
	  badchains[i][j] = 1;
    }
  }
}
Exemplo n.º 3
0
int
chain_2 (int argc, char *argv[])
{
  FILE *in;
  char line[256], filename[80] = "", *destination[NUMDEST], outfile[80] = "";
  char *subject[NUMSUB], *t;
  int chain[HOPMAX];
  byte numdest = 0, numsub = 0;
  int i, num_remailers, outfileflag = 0;
  REMAILER remailer_list[256];
  int filter = 0, rfcmsg = 0, dummy = 0;

  num_remailers = read_remailer_list (remailer_list);

  chain[0] = 0;

  /* what is in those arguments */
  /* Here is the expected format */
  /* mixmaster [-c][-f][filename][-[o,O] outfile][-to who@where][-s "subject"][-l 1 2 3 4] */
  /* if no outfile given, then pipe to sendmail. outfile = stdout send to stdout */
  for (i = 1; i < argc; i++)
    {
      if (streq (argv[i], "-c"))
	{
	  /* nop */
	}
      else if (strleft (argv[i], "-h") || streq (argv[i], "--help"))
	{
	  /* Print help and exit */
	  printf ("Mixmaster %s (C) Copyright Lance M. Cottrell 1995, 1996\n",
		  VERSION);
	  printf ("Released under the GNU public license. No warranty!\n\n");
	  printf ("Client Mode command line arguments:\n");
	  printf ("mixmaster [-c] [infile] [-f] [-m] [-s subject] [-v 'Header: text' [-v ...]]\n[-n numcopies] [-[o,O] outfile] [-to who@where] [-l 1 2 3 ...]\n");
	  exit (-1);
	}
      else if (streq (argv[i], "-f"))
	{
	  /* set filter mode */
	  filter = 1;
	}
      else if (streq (argv[i], "-m"))
	{
	  filter = 1;
	  rfcmsg = 1;
	}
      else if (streq (argv[i], "-d"))
	{
	  filter = 1;
	  destination[0] = (char *) calloc (1, DESTSIZE);
	  strcpy (destination[0], "null:");
	  numdest = 1;
	  REQUIRE[0] = '\0';
	  REJECT[0] = '\0';
	  dummy = 5 + random_number (11);
	}
      else if (streq (argv[i], "-s"))
	{
	  if (i < argc - 1)
	    i++;
	  subject[numsub] = (char *) calloc (1, SUBSIZE);
	  strcpy (subject[numsub], "Subject: ");
	  strncat (subject[numsub], argv[i], SUBSIZE - sizeof ("Subject: "));
	  numsub++;
	}
      else if (streq (argv[i], "-v"))
	{
	  if (i < argc - 1)
	    i++;
	  subject[numsub] = (char *) calloc (1, SUBSIZE);
	  subject[numsub][0] = 0;
	  strncat (subject[numsub], argv[i], SUBSIZE - 1);
	  numsub++;
	}
      else if (streq (argv[i], "-o") || streq (argv[i], "-O"))
	{
	  if (streq (argv[i], "-O"))
	    outfileflag = 1;	/* add To: line */
	  if (i < argc - 1)
	    i++;
	  if (streq (argv[i], "stdout"))
	    strcpy (outfile, "-");
	  else
	    parse_filename (outfile, argv[i]);
	}
      else if (streq (argv[i], "-n"))
	{
	  if (i < argc - 1)
	    i++;
	  sscanf (argv[i], "%d", &NUMCOPIES);
	}
      else if (streq (argv[i], "-to") && numdest < NUMDEST)
	{
	  if (i < argc - 1)
	    i++;
	  destination[numdest] = (char *) calloc (1, DESTSIZE);
	  strncpy (destination[numdest], argv[i], DESTSIZE - 1);
	  destination[numdest][DESTSIZE - 1] = '\0';
	  chop (destination[numdest]);
	  numdest++;
	}
      else if (streq (argv[i], "-l"))
	{
	  for (i++; i < argc && chain[0] < HOPMAX; i++)
	    if ((chain[++chain[0]] =
		 select_remailer (remailer_list,
				  num_remailers, argv[i])) < 0)
	      exit (-1);	/* Invalid remailer */
	}
      else
	{
	  if (strlen (filename) != 0)
	    {
	      fprintf (errlog, "problem with the command line\n");
	      return (-1);
	    }
	  strncpy (filename, argv[i], sizeof (filename));
	}
    }

  if (numdest == 0 && !rfcmsg)
    {
      if (!filter)
	fprintf (errlog, "Enter final destinations (one per line return when done).\n");
      do
	{
	  if (!filter)
	    fprintf (errlog, "Enter destination :");
	  getline (line, sizeof (line), stdin);
	  if (strlen (line) >= 2 && numdest < NUMDEST)
	    {
	      destination[numdest] = (char *) calloc (1, DESTSIZE);
	      strncpy (destination[numdest], line, DESTSIZE - 1);
	      destination[numdest][DESTSIZE - 1] = '\0';
	      numdest++;
	    }
	}
      while (strlen (line) > 0 || numdest == 0);
    }
  if (numdest == 0 && filter && !rfcmsg)
    exit (-1);			/* no destination and in filter mode */

  if (numsub == 0 && !dummy)
    {
      if (!filter)
	{
	  fprintf (errlog, "Enter message headers (one per line, return when done).\n");
	  fprintf (errlog, "You must include the header name, e.g. 'Subject: foo'\n");
	}
      do
	{
	  if (!filter)
	    fprintf (errlog, "Enter header :");
	  getline (line, sizeof (line), stdin);
	  if (rfcmsg && (strileft (line, "To:") || strileft (line, "Newsgroups:")) && numdest < NUMDEST)
	    {
	      destination[numdest] = (char *) calloc (1, DESTSIZE);
	      if (strileft (line, "To:"))
		{
		  t = line + sizeof ("To:") - 1;
		  while (*t == ' ' || *t == '\t')
		    t++;
		  strncpy (destination[numdest], t, DESTSIZE - 1);
		}
	      else
		{
		  t = line + sizeof ("Newsgroups:") - 1;
		  while (*t == ' ' || *t == '\t')
		    t++;
		  strcpy (destination[numdest], "post: ");
		  strncat (destination[numdest], t, DESTSIZE - sizeof ("post: "));
		}
	      destination[numdest][DESTSIZE - 1] = '\0';
	      numdest++;
	    }
	  else if (strlen (line) > 0 && numsub < NUMSUB)
	    {
	      subject[numsub] = (char *) calloc (1, SUBSIZE);
	      strncpy (subject[numsub], line, SUBSIZE - 1);
	      subject[numsub][SUBSIZE - 1] = '\0';
	      numsub++;
	    }
	}
      while (strlen (line) > 0);
    }

  if (!strchr (REQUIRE, 'N'))
    for (i = 0; i < numdest; i++)
      if (strileft (destination[i], "post:"))
	{
	  strcat (REQUIRE, "N");
	  break;
	}

  if (chain[0] == 0 && strlen (CHAIN))
    if (scan_remailer_list (CHAIN, chain, remailer_list, num_remailers) < 0)
      return (-1);
  if (chain[0] == 0 && dummy)
    {
      while (chain[0] < dummy)
	chain[++chain[0]] = 0;
    }
  if (chain[0] == 0 && !filter)
    {
      get_chain (remailer_list, num_remailers, chain);
    }
  if (chain[0] == 0)
    {
      return (-1);
    }
#if 1
  if ((chain[chain[0]] > 0)
      && check_abilities (remailer_list[chain[chain[0]]].abilities,
			  REQUIRE, REJECT) == 0)
    {
      fprintf (errlog, "Warning: Remailer %s has insufficient capabilities!\n",
	       remailer_list[chain[chain[0]]].shortname);
    }
#else
  while ((chain[chain[0]] > 0)
	 && check_abilities (remailer_list[chain[chain[0]]].abilities,
			     REQUIRE, REJECT) == 0)
    {
      fprintf (errlog, "Remailer %s has insufficient capabilities!\n",
	       remailer_list[chain[chain[0]]].shortname);
      if (!filter)
	{
	  chain[0]--;
	  get_chain (remailer_list, num_remailers, chain);
	}
      else
	exit (-1);
    }
#endif

  /* if file = stdin then I will take stdin */
  if (strlen (filename) == 0 && !filter)
    {
      fprintf (errlog, "Please enter the name of the file to chain: ");
      getline (filename, sizeof (filename), stdin);
    }
  if (streq (filename, "stdin"))
    strcpy (filename, "-");
  parse_filename (line, filename);
  if (dummy)
    in = NULL;
  else if (streq (filename, "-") || strlen (filename) == 0)
    {
      if (!filter)
	fprintf (errlog, "Please enter the message.\n");
      in = stdin;
    }
  else
    in = open_user_file (line, "r");
  /* ok, that should be everything we need to know */

#ifdef DEBUG
  printf ("filtermode %d\n", filter);	/*debug */
  printf ("source file %s\n", filename);	/*debug */
  printf ("#destinations %d\n", numdest);	/*debug */
  for (i = 0; i < numdest; i++)
    printf ("destination %d  %s\n", i, destination[i]);	/*debug */
  for (i = 1; i <= chain[0]; i++)
    printf ("remailer %d\n", chain[i]);	/*debug */
  for (i = 0; i < numsub; i++)
    printf ("header %d  %s\n", i, subject[i]);	/*debug */
#endif

  return (build_message (in, numdest, destination, chain,
			 numsub, subject, outfile, outfileflag,
			 remailer_list, num_remailers, 1));
}
Exemplo n.º 4
0
int parseURL(char *url, struct urlparts **returnpart) {
        register i;
        int seplen;
        char * remainder;
        char * regall = ":/;?#";
        char * regpath = ":;?#";
        char * regx;
        if(!*url)
        {
                strcpy(parseError, "nothing to do!\n");
                return 0;
        }
        if((remainder = malloc(strlen(url) + 1)) == NULL)
        {
                printf("cannot allocate memory\n");
                exit(-1);
        }
        strcpy(remainder, url);
        if(firstpunc(remainder) == ':')
        {
                strcpy(returnpart[scheme]->value, strsplit(remainder, returnpart[scheme]->separator));
                strleft(remainder, 1);
        }
        if (!strcmp(returnpart[scheme]->value, "mailto"))
        *(returnpart[host]->separator) = 0;
        for(i = 0; i < NUMPARTS; i++)
        {
                if(!*remainder)
                break;
                if(i == scheme || i == userid || i == password)
                continue;
                if(i == host && strchr(remainder, '@'))
                {
                        if(!strncmp(remainder, "//", 2))
                        strleft(remainder, 2);
                        strcpy(returnpart[userid]->value, strsplit(remainder, ":@"));
                        strleft(remainder, 1);
                        if(strchr(remainder, '@'))
                        {
                                strcpy(returnpart[password]->value, strsplit(remainder, "@"));
                                strleft(remainder, 1);
                        }
                        *(returnpart[host]->separator) = 0;
                }
                if(i == path && (! *(returnpart[scheme]->value)))
                {
                        *(returnpart[path]->separator) = 0;
                        strcpy(returnpart[scheme]->value, "http");
                }
                regx = (i == path) ? regpath : regall ;
                seplen = strlen(returnpart[i]->separator);
                if(strncmp(remainder, returnpart[i]->separator, seplen))
                continue;
                else
                strleft(remainder, seplen);
                strcpy(returnpart[i]->value, strsplit(remainder, regx));
        }
        if(*remainder)
        sprintf(parseError, "I don't understand '%s'", remainder);
        free(remainder);
        return 0;
}
Exemplo n.º 5
0
int t1_rlist(REMAILER remailer[], int badchains[MAXREM][MAXREM])
{
  FILE *list, *excl;
  int i, listed = 0;
  int n = 0;
  char line[2 * LINELEN], l2[LINELEN], name[LINELEN], *flags;
  BUFFER *starex;

  starex = buf_new();
  excl = mix_openfile(STAREX, "r");
  if (excl != NULL) {
    buf_read(starex, excl);
    fclose(excl);
  }

  list = mix_openfile(TYPE1LIST, "r");
  if (list == NULL) {
    buf_free(starex);
    return (-1);
  }

  while (fgets(line, sizeof(line), list) != NULL && n < MAXREM) {
    if (strleft(line, "$remailer") &&
	strchr(line, '<') && strchr(line, '>') &&
	strchr(line, '{') && strchr(line, '{') + 4 < strchr(line, '}')) {
      if (line[strlen(line) - 1] == '\n')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] == '\r')
	line[strlen(line) - 1] = '\0';
      while (line[strlen(line) - 1] == ' ')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] != ';'
	  && fgets(l2, sizeof(l2), list) != NULL)
	strcatn(line, l2, LINELEN);
      flags = strchr(line, '>');
      strncpy(name, strchr(line, '{') + 2,
	      strchr(line, '}') - strchr(line, '{') - 3);
      name[strchr(line, '}') - strchr(line, '{') - 3] = '\0';
      name[20] = '\0';

      for (i = 1; i <= n; i++)
	if (streq(name, remailer[i].name))
	  break;
      if (i > n) {
	/* not in mix list */
	n++;
	strcpy(remailer[i].name, name);
	strncpy(remailer[i].addr, strchr(line, '<') + 1,
		strchr(line, '>') - strchr(line, '<'));
	remailer[i].addr[strchr(line, '>') - strchr(line, '<') - 1]
	  = '\0';
	remailer[i].flags.mix = 0;
	remailer[i].flags.post = strifind(flags, " post");
      }
      remailer[i].flags.cpunk = strfind(flags, " cpunk");
      remailer[i].flags.pgp = strfind(flags, " pgp");
      remailer[i].flags.pgponly = strfind(flags, " pgponly");
      remailer[i].flags.latent = strfind(flags, " latent");
      remailer[i].flags.middle = strfind(flags, " middle");
      remailer[i].flags.ek = strfind(flags, " ek");
      remailer[i].flags.esub = strfind(flags, " esub");
      remailer[i].flags.hsub = strfind(flags, " hsub");
      remailer[i].flags.newnym = strfind(flags, " newnym");
      remailer[i].flags.nym = strfind(flags, " nym");
      remailer[i].info[1].reliability = 0;
      remailer[i].info[1].latency = 0;
      remailer[i].info[1].history[0] = '\0';
      remailer[i].flags.star_ex = bufifind(starex, name);
   }
    if (strleft(line,
		"-----------------------------------------------------------------------"))
      break;
  }
  n++;				/* ?? */
  while (fgets(line, sizeof(line), list) != NULL) {
    if (strlen(line) >= 72 && strlen(line) <= 73)
      for (i = 1; i < n; i++)
	if (strleft(line, remailer[i].name) &&
	    line[strlen(remailer[i].name)] == ' ') {
	  strncpy(remailer[i].info[1].history, line + 42, 12);
	  remailer[i].info[1].history[12] = '\0';
	  remailer[i].info[1].reliability = 10000 * N(line[64])
	    + 1000 * N(line[65]) + 100 * N(line[66])
	    + 10 * N(line[68]) + N(line[69]);
	  remailer[i].info[1].latency = 36000 * N(line[55])
	    + 3600 * N(line[56]) + 600 * N(line[58])
	    + 60 * N(line[59]) + 10 * N(line[61])
	    + N(line[62]);
	  listed++;
	}
  }
  fclose(list);
  parse_badchains(badchains, TYPE1LIST, "Broken type-I remailer chains", remailer, n);
  if (listed < 4)		/* we have no valid reliability info */
    for (i = 1; i < n; i++)
      remailer[i].info[1].reliability = 10000;

#ifdef USE_PGP
  pgp_rlist(remailer, n);
#endif /* USE_PGP */
  buf_free(starex);
  return (n);
}
Exemplo n.º 6
0
int
pretty_print (VALUE *result,
              RESULT_NODE *pretty,
              char *example,
              int space,
              char **error_text)
{
    char
        *tokens,
        *token,
        *c,
        *newstring,
        *oldpos,
        *newpos;
    Bool
        use_example,
        new_word;

    if (error_text)
        *error_text = NULL;             /*  No errors yet  */

    string_value (result);

    use_example = (example != NULL);

    if (pretty) {
        if (strlen (string_value (& pretty-> value)) == 0)
            use_example = FALSE;

        tokens = mem_strdup (pretty-> value. s);
        token = strtok (tokens, ", ");
        while (token) {
            strlwc (token);
            if (streq (token, "lower")) {
                use_example = FALSE;
                strlwc (result-> s);
            }
            else
            if (streq (token, "upper")) {
                use_example = FALSE;
                strupc (result-> s);
            }
            else
            if (streq (token, "camel") || streq (token, "pascal")) {
                use_example = FALSE;
                oldpos = result->s;
                newpos = result->s;
                new_word = streq (token, "pascal") ? TRUE: FALSE;
                while (*oldpos) {
                    if (!isalnum (*oldpos))
                        new_word = TRUE;
                    else
                    if (new_word) {
                        *newpos = toupper (*oldpos);
                        newpos++;
                        new_word = FALSE;
                    }
                    else {
                        *newpos = *oldpos;
                        newpos++;
                    }
                    oldpos++;
                }
                *newpos = 0;
            }
            else
            if (streq (token, "no"))
                use_example = FALSE;
            else
            if (streq (token, "neat")) {
                use_example = FALSE;
                strneat (result-> s);
            }
            else
            if (streq (token, "c")) {
                c = result-> s;
                if (*c && !isalpha (*c))
                    *c = '_';

                while (*c) {
                    if (!(isalpha (*c) || isdigit (*c)))
                        *c = '_';
                    c++;
                }
            }
            else
            if (streq (token, "cobol")) {
                c = result-> s;
                if (*c && !isalpha (*c))
                    *c = '-';

                while (*c) {
                    if (!(isalpha (*c) || isdigit (*c)))
                        *c = '-';
                    c++;
                }
            }
            else
            if (streq (token, "justify")) {
                newstring = strjustify (result-> s, space);
                mem_free (result-> s);
                result-> s = newstring;
            }
            else
            if (streq (token, "left")) {
                newstring = strleft (result-> s);
                mem_free (result-> s);
                result-> s = newstring;
            }
            else
            if (streq (token, "block"))
                result-> type = TYPE_BLOCK;
            else
            if (error_text) {
                snprintf (error_buffer, LINE_MAX,
                          "Unknown pretty-print modifier: %s", token);
                mem_free (tokens);
                *error_text = error_buffer;
                return -1;
            }
            token = strtok (NULL, ", ");
        }
        mem_free (tokens);
    }

    if ((use_example)
    &&  (strlen (example) > 1))
      {
        c = example;

        if (isupper (*c))
            while ((isupper (*c) || !isalpha (*c)) && (*c))
                c++;

        if (*c == 0)
            strupc (result-> s);
        else
        if (c == example + 1)
          {
            if (islower (*c))
              {
                while ((islower (*c) || !isalpha (*c)) && (*c))
                    c++;
                if (!isupper (*c))
                    strneat (result-> s);
              }
          }
        else
            if (c == example)
              {
                if (islower (*c))
                    while ((islower (*c) || !isalpha (*c)) && (*c))
                        c++;

                if (*c == 0)
                    strlwc (result-> s);
              }
      }
    return 0;
}