示例#1
0
文件: edit.c 项目: jff/mathspad
static void remove_auto_save(EDITINFO *einf)
{
    buffer[0] = '\0';
    Ustrcat(buffer, userdir);
    Ustrcat(buffer, translate("/#"));
    Ustrcat(buffer, strip_name(einf->filename));
    Ustrcat(buffer, translate("#" EXTENSION));
    remove_file(buffer);
}
示例#2
0
void
version_init(void)
{
int i = 0;
uschar today[20];

version_string = US"2.06";

Ustrcpy(today, __DATE__);
if (today[4] == ' ') i = 1;
today[3] = today[6] = '-';

version_date = (uschar *)malloc(32);
version_date[0] = 0;
Ustrncat(version_date, today+4+i, 3-i);
Ustrncat(version_date, today, 4);
Ustrncat(version_date, today+7, 4);
Ustrcat(version_date, " ");
Ustrcat(version_date, __TIME__);
}
示例#3
0
文件: edit.c 项目: jff/mathspad
static void edit_auto_save(void *data, int dump)
{
    EDITINFO *einf = (EDITINFO *) data;
    FILE *f;
    /* Using dump%s to keep a possible #%s# as extra backup */

    if (!einf->auto_saved && !einf->empty) {
      if (dump) {
	buffer[0]=0;
	Ustrcat(buffer, translate("dump"));
	Ustrcat(buffer, strip_name(einf->filename));
	Ustrcat(buffer, translate(EXTENSION));
      } else {
	buffer[0]=0;
	Ustrcat(buffer, translate("#"));
	Ustrcat(buffer, strip_name(einf->filename));
	Ustrcat(buffer, translate("#" EXTENSION));
      }
	f = open_dirfile(userdir, buffer, "wb");
	if (f) {
	    set_file(f);
	    put_filecode(DOCUMENTFILE);
	    save_editwindow(einf->info);
	    unset_file();
	    cleanup_stencilstack();
	    fclose(f);
	    einf->auto_saved = MP_True;
	} else failure=MP_True;
    }
    /* 
    ** In case of a failure, the document should be saved
    ** in another file, to make sure nothing gets lost.
    **
    */
}
示例#4
0
文件: edit.c 项目: jff/mathspad
static void set_output_name(EDITINFO *einf)
{
    int i=0,l;
    if (einf->outputname) free(einf->outputname);
    i= Ustrlen(latexdir);
    l = i+Ustrlen(einf->filename)+15;
    einf->outputname = (Char*) malloc(sizeof(Char)*l);
    if (latexdir[i-1]=='/')
      concat_in(einf->outputname,latexdir,einf->filename);
    else {
      Ustrcpy(einf->outputname,latexdir);
      einf->outputname[i]='/';
      einf->outputname[i+1]=0;
      Ustrcat(einf->outputname, einf->filename);
    }
    if (output_mode==ASCII)
      Ustrncat(einf->outputname, translate(".asc"),l);
    else
      Ustrncat(einf->outputname, translate(".tex"),l);
}
示例#5
0
文件: pvs.c 项目: jff/mathspad
int pvs_parse_prove(unsigned char *buffer, unsigned int *len)
{
  char *pos, *startat;
  if (!toproof || !curstep) {
    /* end of proof, expect a 'really want to quit?' prompt */
    if (strstr(buffer,"want to quit?")) {
      edit_string_to_proces(translate("y\n"), translate("PVS-shell"));
    }
    return 0;
  }
  startat=(char*)buffer;
  while (startat && *startat) {
    switch (prove_pos) {
    case InRubbish:
      pos = strstr(startat, "Q.E.D.");
      if (pos) {
	Char *pvsres;
	Char txt[10240];
	pvsres = translate("PVS Results");
	string_to_window(pvsres, LocaletoUstr((unsigned char*)toproof->lemma));
	string_to_window(pvsres, translate(" is correct according to PVS.\n"));
	curstep = curstep->next;
	txt[0]=0;
	while (curstep) {
	  if (curstep->steptype == KeywordStep) {
	    string_to_window(pvsres, translate("Warning: keyword \""));
	    string_to_window(pvsres, curstep->keyword->str);
	    string_to_window(pvsres, translate("\" is not needed\n"));
	    Ustrcat(txt, translate("Warning: keyword \""));
	    Ustrcat(txt, curstep->keyword->str);
	    Ustrcat(txt, translate("\" is not needed.\n"));
	  }
	  curstep=curstep->next;
	}
	if (txt[0]) {
	  int i=Ustrlen(txt);
	  make_node(MP_Text, txt, i, 0,0);
	  txt[0]=PhNum2Char(MP_Text,1);
	  make_node(MP_Op, txt, 1, warning_template,0);
	} else {
	  make_node(MP_Op, txt, 0, good_template,0);
	}
	finish_current_proof(0);
	startat=0;
	break;
      }
      pos = strstr(startat, "this yields ");
      if (pos && strstr(pos, "subgoals")) {
	Char *pvsres;
	Char *split_error;
	Char txt[1024];
	pvsres = translate("PVS Results");
	split_error =
	  translate(": PVS split the proof into subgoals. Unable to proceed.");
	string_to_window(pvsres, LocaletoUstr((unsigned char*)toproof->lemma));
	string_to_window(pvsres, split_error);
	string_to_window(pvsres, LocaletoUstr("\n"));
	message2(MP_ERROR, LocaletoUstr(toproof->lemma), split_error);
	Ustrcpy(txt, split_error);
	make_node(MP_Text, txt, Ustrlen(txt),0,0);
	txt[0]=PhNum2Char(MP_Text,1);
	make_node(MP_Op, txt, 1, wrong_template, 0);
	finish_current_proof(1);
	startat=0;
	break;
      }
      pos = strstr(startat, "want to quit?");
      if (pos) {
	edit_string_to_proces(translate("y\n"), translate("PVS-shell"));
	startat=0;
	/* no matter what happened, the proof is finished */
	break;
      }
      pos = strstr(startat, toproof->lemma);
      if (pos) {
	pos=pos+strlen(toproof->lemma);
	if (*pos!='.') {
	  /* perhaps could use strchr(pos,'\n') here. */
	  while (*pos && *pos!=':') pos++;
	  if (*pos==':') pos++;
	  while (*pos==' ' || *pos=='\t') pos++;
	  while (*pos=='\n') pos++;
	  step_clear_result(curstep);
	  prove_pos = InExpr;
	  startat = pos;
	  break;
	}
      }
      pos = strstr(startat, "Rule? ");
      if (pos) {
	if (!pos[6]) {
	  /* !pos[6] indicates that there is no more input yet. */
	  if (curstep->next) {
	    ProofStep *h=curstep;
	    /* send next step */
	    curstep=curstep->next;
	    if (curstep->pvsinput) {
	      edit_string_to_proces(LocaletoUstr(curstep->pvsinput),
				    translate("PVS-shell"));
	    }
	    if (curstep->keyword) {
	      edit_string_to_proces(LocaletoUstr(curstep->keyword->step),
				    translate("PVS-shell"));
	    }
	    if (curstep->use_result) {
	      PVSProof *prf;
	      pvs_use_result(h->result, curstep->use_result-1);
	      curstep=0;
	      prf=toproof;
	      toproof=toproof->next;
	      destruct_selection(prf->selection);
	      /* free prf */
	    }
	  } else {
	    Char *pvsres;
	    Char *insuf_error;
	    pvsres= translate("PVS Results");
	    insuf_error= translate(": Insufficient information to prove the selected hint.");
	    message2(MP_ERROR, LocaletoUstr(toproof->lemma), insuf_error);
	    string_to_window(pvsres, LocaletoUstr(toproof->lemma));
	    string_to_window(pvsres, insuf_error);
	    string_to_window(pvsres, LocaletoUstr("\n"));
	    string_to_window(pvsres, translate("The proof attempt ends with the following PVS expression:\n"));
	    /* add parse - diff - analyse routine here */
	    if (1)
	    {
	      Char txt[2];
	      pvs_parse_result(curstep->result);
	      txt[0]=PhNum2Char(MP_Text,1);
	      make_node(MP_Op, txt, 1, wrong_template,0);
	      /* structure_to_window(pvsres); */
	    } else {
	      string_to_window(pvsres, LocaletoUstr(curstep->result));
	    }
	    string_to_window(pvsres, LocaletoUstr("\n"));
	    finish_current_proof(1);
	  }
	}
	startat=pos+6;
	break;
      }
      pos = strstr(startat, ";;; GC:");
      if (pos) {
	message(MP_MESSAGE, translate("PVS collects garbage. One moment please."));
	startat = pos+7;
	break;
      }
      pos = strstr(startat, ";;; Finished GC");
      if (pos) {
	message(MP_MESSAGE, translate("PVS finished collecting garbage. Sorry for the inconvenience."));
	startat = pos+15;
	break;
      }
      /* nothing usefull found. Just skip everything. */
      startat=0;
      break;
    case InExpr:
      /* search for the PVS prompt */
      if (after_newline && startat[0]=='\n') {
	int stepreslen;
	stepreslen = strlen(curstep->result);
	curstep->result[stepreslen-1]=0;
	startat++;
	after_newline=0;
	prove_pos=InRubbish;
      } else {
	pos = strstr(startat, "\n\n");
	if (pos) {
	  *pos=0;
	  step_add_to_result(curstep,startat);
	  after_newline=0;
	  startat=pos+2;
	  prove_pos=InRubbish;
	} else {
	  step_add_to_result(curstep,startat);
	  if (startat[strlen(startat)-1]=='\n') {
	    after_newline=1;
	  }
	  startat = 0;
	}
      }
      break;
    default:
      fprintf(stderr, "Bad case in pvs_parse_prove.\n");
      startat=0;
      break;
    }
  }
  *len=0;
  return 0;
}
示例#6
0
文件: dcc.c 项目: mosqutip/EECS395-27
int dcc_process(uschar **listptr) {
  int sep = 0;
  uschar *list = *listptr;
  FILE *data_file;
  uschar *dcc_daemon_ip = US"";
  uschar *dcc_default_ip_option = US"127.0.0.1";
  uschar *dcc_ip_option = US"";
  uschar *dcc_helo_option = US"localhost";
  uschar *dcc_reject_message = US"Rejected by DCC";
  uschar *xtra_hdrs = NULL;

  /* from local_scan */
  int i, j, k, c, retval, sockfd, resp, line;
  unsigned int portnr;
  struct sockaddr_un  serv_addr;
  struct sockaddr_in  serv_addr_in;
  struct hostent *ipaddress;
  uschar sockpath[128];
  uschar sockip[40], client_ip[40];
  uschar opts[128];
  uschar rcpt[128], from[128];
  uschar sendbuf[4096];
  uschar recvbuf[4096];
  uschar dcc_return_text[1024];
  uschar mbox_path[1024];
  uschar message_subdir[2];
  struct header_line *dcchdr;
  uschar *dcc_acl_options;
  uschar dcc_acl_options_buffer[10];
  uschar dcc_xtra_hdrs[1024];

  /* grep 1st option */
  if ((dcc_acl_options = string_nextinlist(&list, &sep,
                                           dcc_acl_options_buffer,
                                           sizeof(dcc_acl_options_buffer))) != NULL)
  {
    /* parse 1st option */
    if ( (strcmpic(dcc_acl_options,US"false") == 0) ||
         (Ustrcmp(dcc_acl_options,"0") == 0) ) {
      /* explicitly no matching */
      return FAIL;
    };

    /* special cases (match anything except empty) */
    if ( (strcmpic(dcc_acl_options,US"true") == 0) ||
         (Ustrcmp(dcc_acl_options,"*") == 0) ||
         (Ustrcmp(dcc_acl_options,"1") == 0) ) {
      dcc_acl_options = dcc_acl_options;
    };
  }
  else {
    /* empty means "don't match anything" */
    return FAIL;
  };

  sep = 0;

  /* if we scanned this message last time, just return */
  if ( dcc_ok )
      return dcc_rc;

  /* open the spooled body */
  message_subdir[1] = '\0';
  for (i = 0; i < 2; i++) {
    message_subdir[0] = (split_spool_directory == (i == 0))? message_id[5] : 0;
    sprintf(CS mbox_path, "%s/input/%s/%s-D", spool_directory, message_subdir, message_id);
    data_file = Ufopen(mbox_path,"rb");
    if (data_file != NULL)
      break;
  };

  if (data_file == NULL) {
    /* error while spooling */
    log_write(0, LOG_MAIN|LOG_PANIC,
           "dcc acl condition: error while opening spool file");
    return DEFER;
  };

  /* Initialize the variables */

  bzero(sockip,sizeof(sockip));
  if (dccifd_address) {
    if (dccifd_address[0] == '/')
      Ustrncpy(sockpath, dccifd_address, sizeof(sockpath));
    else
      if( sscanf(CS dccifd_address, "%s %u", sockip, &portnr) != 2) {
        log_write(0, LOG_MAIN,
          "dcc acl condition: warning - invalid dccifd address: '%s'", dccifd_address);
        (void)fclose(data_file);
        return DEFER;
      }
  }

  /* opts is what we send as dccifd options - see man dccifd */
  /* We don't support any other option than 'header' so just copy that */
  bzero(opts,sizeof(opts));
  Ustrncpy(opts, "header", sizeof(opts)-1);
  Ustrncpy(client_ip, dcc_ip_option, sizeof(client_ip)-1);
  /* If the dcc_client_ip is not provided use the
   * sender_host_address or 127.0.0.1 if it is NULL */
  DEBUG(D_acl)
    debug_printf("my_ip_option = %s - client_ip = %s - sender_host_address = %s\n", dcc_ip_option, client_ip, sender_host_address);
  if(!(Ustrcmp(client_ip, ""))){
    /* Do we have a sender_host_address or is it NULL? */
    if(sender_host_address){
      Ustrncpy(client_ip, sender_host_address, sizeof(client_ip)-1);
    } else {
      /* sender_host_address is NULL which means it comes from localhost */
      Ustrncpy(client_ip, dcc_default_ip_option, sizeof(client_ip)-1);
    }
  }
  DEBUG(D_acl)
    debug_printf("Client IP: %s\n", client_ip);
  Ustrncpy(sockip, dcc_daemon_ip, sizeof(sockip)-1);
  /* strncat(opts, my_request, strlen(my_request)); */
  Ustrcat(opts, "\n");
  Ustrncat(opts, client_ip, sizeof(opts)-Ustrlen(opts)-1);
  Ustrncat(opts, "\nHELO ", sizeof(opts)-Ustrlen(opts)-1);
  Ustrncat(opts, dcc_helo_option, sizeof(opts)-Ustrlen(opts)-2);
  Ustrcat(opts, "\n");

  /* initialize the other variables */
  dcchdr = header_list;
  /* we set the default return value to DEFER */
  retval = DEFER;

  bzero(sendbuf,sizeof(sendbuf));
  bzero(dcc_header_str,sizeof(dcc_header_str));
  bzero(rcpt,sizeof(rcpt));
  bzero(from,sizeof(from));

  /* send a null return path as "<>". */
  if (Ustrlen(sender_address) > 0)
    Ustrncpy(from, sender_address, sizeof(from));
  else
    Ustrncpy(from, "<>", sizeof(from));
  Ustrncat(from, "\n", sizeof(from)-Ustrlen(from)-1);

  /**************************************
   * Now creating the socket connection *
   **************************************/

  /* If there is a dcc_daemon_ip, we use a tcp socket, otherwise a UNIX socket */
  if(Ustrcmp(sockip, "")){
    ipaddress = gethostbyname((char *)sockip);
    bzero((char *) &serv_addr_in, sizeof(serv_addr_in));
    serv_addr_in.sin_family = AF_INET;
    bcopy((char *)ipaddress->h_addr, (char *)&serv_addr_in.sin_addr.s_addr, ipaddress->h_length);
    serv_addr_in.sin_port = htons(portnr);
    if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) < 0){
      DEBUG(D_acl)
        debug_printf("Creating socket failed: %s\n", strerror(errno));
      log_write(0,LOG_REJECT,"Creating socket failed: %s\n", strerror(errno));
      /* if we cannot create the socket, defer the mail */
      (void)fclose(data_file);
      return retval;
    }
    /* Now connecting the socket (INET) */
    if (connect(sockfd, (struct sockaddr *)&serv_addr_in, sizeof(serv_addr_in)) < 0){
      DEBUG(D_acl)
        debug_printf("Connecting socket failed: %s\n", strerror(errno));
      log_write(0,LOG_REJECT,"Connecting socket failed: %s\n", strerror(errno));
      /* if we cannot contact the socket, defer the mail */
      (void)fclose(data_file);
      return retval;
    }
  } else {
    /* connecting to the dccifd UNIX socket */
    bzero((char *)&serv_addr,sizeof(serv_addr));
    serv_addr.sun_family = AF_UNIX;
    Ustrcpy(serv_addr.sun_path, sockpath);
    if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0){
      DEBUG(D_acl)
        debug_printf("Creating socket failed: %s\n", strerror(errno));
      log_write(0,LOG_REJECT,"Creating socket failed: %s\n", strerror(errno));
      /* if we cannot create the socket, defer the mail */
      (void)fclose(data_file);
      return retval;
    }
    /* Now connecting the socket (UNIX) */
    if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0){
      DEBUG(D_acl)
                            debug_printf("Connecting socket failed: %s\n", strerror(errno));
      log_write(0,LOG_REJECT,"Connecting socket failed: %s\n", strerror(errno));
      /* if we cannot contact the socket, defer the mail */
      (void)fclose(data_file);
      return retval;
    }
  }
  /* the socket is open, now send the options to dccifd*/
  DEBUG(D_acl)
    debug_printf("\n---------------------------\nSocket opened; now sending input\n-----------------\n");
  /* First, fill in the input buffer */
  Ustrncpy(sendbuf, opts, sizeof(sendbuf));
  Ustrncat(sendbuf, from, sizeof(sendbuf)-Ustrlen(sendbuf)-1);

  DEBUG(D_acl)
  {
    debug_printf("opts = %s\nsender = %s\nrcpt count = %d\n", opts, from, recipients_count);
    debug_printf("Sending options:\n****************************\n");
  }

  /* let's send each of the recipients to dccifd */
  for (i = 0; i < recipients_count; i++){
    DEBUG(D_acl)
      debug_printf("recipient = %s\n",recipients_list[i].address);
    if(Ustrlen(sendbuf) + Ustrlen(recipients_list[i].address) > sizeof(sendbuf))
    {
      DEBUG(D_acl)
        debug_printf("Writing buffer: %s\n", sendbuf);
      flushbuffer(sockfd, sendbuf);
      bzero(sendbuf, sizeof(sendbuf));
    }
    Ustrncat(sendbuf, recipients_list[i].address, sizeof(sendbuf)-Ustrlen(sendbuf)-1);
    Ustrncat(sendbuf, "\r\n", sizeof(sendbuf)-Ustrlen(sendbuf)-1);
  }
  /* send a blank line between options and message */
  Ustrncat(sendbuf, "\n", sizeof(sendbuf)-Ustrlen(sendbuf)-1);
  /* Now we send the input buffer */
  DEBUG(D_acl)
    debug_printf("%s\n****************************\n", sendbuf);
  flushbuffer(sockfd, sendbuf);

  /* now send the message */
  /* Clear the input buffer */
  bzero(sendbuf, sizeof(sendbuf));
  /* First send the headers */
  /* Now send the headers */
  DEBUG(D_acl)
    debug_printf("Sending headers:\n****************************\n");
  Ustrncpy(sendbuf, dcchdr->text, sizeof(sendbuf)-2);
  while((dcchdr=dcchdr->next)) {
    if(dcchdr->slen > sizeof(sendbuf)-2) {
      /* The size of the header is bigger than the size of
       * the input buffer, so split it up in smaller parts. */
       flushbuffer(sockfd, sendbuf);
       bzero(sendbuf, sizeof(sendbuf));
       j = 0;
       while(j < dcchdr->slen)
       {
        for(i = 0; i < sizeof(sendbuf)-2; i++) {
          sendbuf[i] = dcchdr->text[j];
          j++;
        }
        flushbuffer(sockfd, sendbuf);
        bzero(sendbuf, sizeof(sendbuf));
       }
    } else if(Ustrlen(sendbuf) + dcchdr->slen > sizeof(sendbuf)-2) {
      flushbuffer(sockfd, sendbuf);
      bzero(sendbuf, sizeof(sendbuf));
      Ustrncpy(sendbuf, dcchdr->text, sizeof(sendbuf)-2);
    } else {
      Ustrncat(sendbuf, dcchdr->text, sizeof(sendbuf)-Ustrlen(sendbuf)-2);
    }
  }

  /* a blank line seperates header from body */
  Ustrncat(sendbuf, "\n", sizeof(sendbuf)-Ustrlen(sendbuf)-1);
  flushbuffer(sockfd, sendbuf);
  DEBUG(D_acl)
    debug_printf("\n****************************\n%s", sendbuf);

  /* Clear the input buffer */
  bzero(sendbuf, sizeof(sendbuf));

  /* now send the body */
  DEBUG(D_acl)
    debug_printf("Writing body:\n****************************\n");
  (void)fseek(data_file, SPOOL_DATA_START_OFFSET, SEEK_SET);
  while((fread(sendbuf, 1, sizeof(sendbuf)-1, data_file)) > 0) {
    flushbuffer(sockfd, sendbuf);
    bzero(sendbuf, sizeof(sendbuf));
  }
  DEBUG(D_acl)
    debug_printf("\n****************************\n");

  /* shutdown() the socket */
  if(shutdown(sockfd, 1) < 0){
    DEBUG(D_acl)
      debug_printf("Couldn't shutdown socket: %s\n", strerror(errno));
    log_write(0,LOG_MAIN,"Couldn't shutdown socket: %s\n", strerror(errno));
    /* If there is a problem with the shutdown()
     * defer the mail. */
    (void)fclose(data_file);
    return retval;
  }
  DEBUG(D_acl)
    debug_printf("\n-------------------------\nInput sent.\n-------------------------\n");

    /********************************
   * receiving output from dccifd *
   ********************************/
  DEBUG(D_acl)
    debug_printf("\n-------------------------------------\nNow receiving output from server\n-----------------------------------\n");

  /******************************************************************
   * We should get 3 lines:                                         *
   * 1/ First line is overall result: either 'A' for Accept,        *
   *    'R' for Reject, 'S' for accept Some recipients or           *
   *    'T' for a Temporary error.                                  *
   * 2/ Second line contains the list of Accepted/Rejected          *
   *    recipients in the form AARRA (A = accepted, R = rejected).  *
   * 3/ Third line contains the X-DCC header.                       *
   ******************************************************************/

  line = 1;    /* we start at the first line of the output */
  j = 0;       /* will be used as index for the recipients list */
  k = 0;       /* initializing the index of the X-DCC header: dcc_header_str[k] */

  /* Let's read from the socket until there's nothing left to read */
  bzero(recvbuf, sizeof(recvbuf));
  while((resp = read(sockfd, recvbuf, sizeof(recvbuf)-1)) > 0) {
    /* How much did we get from the socket */
    c = Ustrlen(recvbuf) + 1;
    DEBUG(D_acl)
      debug_printf("Length of the output buffer is: %d\nOutput buffer is:\n------------\n%s\n-----------\n", c, recvbuf);

    /* Now let's read each character and see what we've got */
    for(i = 0; i < c; i++) {
      /* First check if we reached the end of the line and
       * then increment the line counter */
      if(recvbuf[i] == '\n') {
        line++;
      }
      else {
        /* The first character of the first line is the
         * overall response. If there's another character
         * on that line it is not correct. */
        if(line == 1) {
          if(i == 0) {
            /* Now get the value and set the
             * return value accordingly */
            if(recvbuf[i] == 'A') {
              DEBUG(D_acl)
                debug_printf("Overall result = A\treturning OK\n");
              Ustrcpy(dcc_return_text, "Mail accepted by DCC");
              dcc_result = US"A";
              retval = OK;
            }
            else if(recvbuf[i] == 'R') {
              DEBUG(D_acl)
                debug_printf("Overall result = R\treturning FAIL\n");
              dcc_result = US"R";
              retval = FAIL;
              if(sender_host_name) {
                log_write(0, LOG_MAIN, "H=%s [%s] F=<%s>: rejected by DCC", sender_host_name, sender_host_address, sender_address);
              }
              else {
                log_write(0, LOG_MAIN, "H=[%s] F=<%s>: rejected by DCC", sender_host_address, sender_address);
              }
              Ustrncpy(dcc_return_text, dcc_reject_message, Ustrlen(dcc_reject_message) + 1);
            }
            else if(recvbuf[i] == 'S') {
              DEBUG(D_acl)
                debug_printf("Overall result  = S\treturning OK\n");
              Ustrcpy(dcc_return_text, "Not all recipients accepted by DCC");
              /* Since we're in an ACL we want a global result
               * so we accept for all */
              dcc_result = US"A";
              retval = OK;
            }
            else if(recvbuf[i] == 'G') {
              DEBUG(D_acl)
                debug_printf("Overall result  = G\treturning FAIL\n");
              Ustrcpy(dcc_return_text, "Greylisted by DCC");
              dcc_result = US"G";
              retval = FAIL;
            }
            else if(recvbuf[i] == 'T') {
              DEBUG(D_acl)
                debug_printf("Overall result = T\treturning DEFER\n");
              retval = DEFER;
              log_write(0,LOG_MAIN,"Temporary error with DCC: %s\n", recvbuf);
              Ustrcpy(dcc_return_text, "Temporary error with DCC");
              dcc_result = US"T";
            }
            else {
              DEBUG(D_acl)
                debug_printf("Overall result = something else\treturning DEFER\n");
              retval = DEFER;
              log_write(0,LOG_MAIN,"Unknown DCC response: %s\n", recvbuf);
              Ustrcpy(dcc_return_text, "Unknown DCC response");
              dcc_result = US"T";
            }
          }
          else {
          /* We're on the first line but not on the first character,
           * there must be something wrong. */
            DEBUG(D_acl)
              debug_printf("Line = %d but i = %d != 0  character is %c - This is wrong!\n", line, i, recvbuf[i]);
              log_write(0,LOG_MAIN,"Wrong header from DCC, output is %s\n", recvbuf);
          }
        }
        else if(line == 2) {
          /* On the second line we get a list of
           * answers for each recipient. We don't care about
           * it because we're in an acl and take the
           * global result. */
        }
        else if(line > 2) {
          /* The third and following lines are the X-DCC header,
           * so we store it in dcc_header_str. */
          /* check if we don't get more than we can handle */
          if(k < sizeof(dcc_header_str)) { 
            dcc_header_str[k] = recvbuf[i];
            k++;
          }
          else {
            DEBUG(D_acl)
              debug_printf("We got more output than we can store in the X-DCC header. Truncating at 120 characters.\n");
          }
        }
        else {
          /* Wrong line number. There must be a problem with the output. */
          DEBUG(D_acl)
            debug_printf("Wrong line number in output. Line number is %d\n", line);
        }
      }
    }
    /* we reinitialize the output buffer before we read again */
    bzero(recvbuf,sizeof(recvbuf));
  }
  /* We have read everything from the socket */

  /* We need to terminate the X-DCC header with a '\n' character. This needs to be k-1
   * since dcc_header_str[k] contains '\0'. */
  dcc_header_str[k-1] = '\n';

  /* Now let's sum up what we've got. */
  DEBUG(D_acl)
    debug_printf("\n--------------------------\nOverall result = %d\nX-DCC header: %sReturn message: %s\ndcc_result: %s\n", retval, dcc_header_str, dcc_return_text, dcc_result);

  /* We only add the X-DCC header if it starts with X-DCC */
  if(!(Ustrncmp(dcc_header_str, "X-DCC", 5))){
    dcc_header = dcc_header_str;
    if(dcc_direct_add_header) {
      header_add(' ' , "%s", dcc_header_str);
  /* since the MIME ACL already writes the .eml file to disk without DCC Header we've to erase it */
      unspool_mbox();
    }
  }
  else {
    DEBUG(D_acl)
      debug_printf("Wrong format of the X-DCC header: %s\n", dcc_header_str);
  }

  /* check if we should add additional headers passed in acl_m_dcc_add_header */
  if(dcc_direct_add_header) {
    if (((xtra_hdrs = expand_string(US"$acl_m_dcc_add_header")) != NULL) && (xtra_hdrs[0] != '\0')) {
      Ustrncpy(dcc_xtra_hdrs, xtra_hdrs, sizeof(dcc_xtra_hdrs) - 2);
      if (dcc_xtra_hdrs[Ustrlen(dcc_xtra_hdrs)-1] != '\n')
        Ustrcat(dcc_xtra_hdrs, "\n");
      header_add(' ', "%s", dcc_xtra_hdrs);
      DEBUG(D_acl)
        debug_printf("adding additional headers in $acl_m_dcc_add_header: %s", dcc_xtra_hdrs);
    }
  }

  dcc_ok = 1;
  /* Now return to exim main process */
  DEBUG(D_acl)
    debug_printf("Before returning to exim main process:\nreturn_text = %s - retval = %d\ndcc_result = %s\n", dcc_return_text, retval, dcc_result);

  (void)fclose(data_file);
  dcc_rc = retval;
  return dcc_rc;
}
示例#7
0
文件: bmi_spam.c 项目: fanf2/exim
uschar *bmi_process_message(header_line *header_list, int data_fd) {
  BmiSystem *system = NULL;
  BmiMessage *message = NULL;
  BmiError err;
  BmiErrorLocation err_loc;
  BmiErrorType err_type;
  const BmiVerdict *verdict = NULL;
  FILE *data_file;
  uschar data_buffer[4096];
  uschar localhost[] = "127.0.0.1";
  uschar *host_address;
  uschar *verdicts = NULL;
  int i,j;

  err = bmiInitSystem(BMI_VERSION, (char *)bmi_config_file, &system);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: could not initialize Brightmail system.", (int)err_loc, (int)err_type);
    return NULL;
  }

  err = bmiInitMessage(system, &message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: could not initialize Brightmail message.", (int)err_loc, (int)err_type);
    bmiFreeSystem(system);
    return NULL;
  }

  /* Send IP address of sending host */
  if (sender_host_address == NULL)
    host_address = localhost;
  else
    host_address = sender_host_address;
  err = bmiProcessConnection((char *)host_address, message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiProcessConnection() failed (IP %s).", (int)err_loc, (int)err_type, (char *)host_address);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };

  /* Send envelope sender address */
  err = bmiProcessFROM((char *)sender_address, message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiProcessFROM() failed (address %s).", (int)err_loc, (int)err_type, (char *)sender_address);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };

  /* Send envelope recipients */
  for(i=0;i<recipients_count;i++) {
    recipient_item *r = recipients_list + i;
    BmiOptin *optin = NULL;

    /* create optin object if optin string is given */
    if ((r->bmi_optin != NULL) && (Ustrlen(r->bmi_optin) > 1)) {
      debug_printf("passing bmiOptin string: %s\n", r->bmi_optin);
      bmiOptinInit(&optin);
      err = bmiOptinMset(optin, r->bmi_optin, ':');
      if (bmiErrorIsFatal(err) == BMI_TRUE) {
        log_write(0, LOG_PANIC|LOG_MAIN,
                   "bmi warning: [loc %d type %d]: bmiOptinMSet() failed (address '%s', string '%s').", (int)err_loc, (int)err_type, (char *)r->address, (char *)r->bmi_optin);
        if (optin != NULL)
          bmiOptinFree(optin);
        optin = NULL;
      };
    };

    err = bmiAccumulateTO((char *)r->address, optin, message);

    if (optin != NULL)
      bmiOptinFree(optin);

    if (bmiErrorIsFatal(err) == BMI_TRUE) {
      err_loc = bmiErrorGetLocation(err);
      err_type = bmiErrorGetType(err);
      log_write(0, LOG_PANIC,
                 "bmi error [loc %d type %d]: bmiAccumulateTO() failed (address %s).", (int)err_loc, (int)err_type, (char *)r->address);
      bmiFreeMessage(message);
      bmiFreeSystem(system);
      return NULL;
    };
  };
  err = bmiEndTO(message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiEndTO() failed.", (int)err_loc, (int)err_type);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };

  /* Send message headers */
  while (header_list != NULL) {
    /* skip deleted headers */
    if (header_list->type == '*') {
      header_list = header_list->next;
      continue;
    };
    err = bmiAccumulateHeaders((const char *)header_list->text, header_list->slen, message);
    if (bmiErrorIsFatal(err) == BMI_TRUE) {
      err_loc = bmiErrorGetLocation(err);
      err_type = bmiErrorGetType(err);
      log_write(0, LOG_PANIC,
                 "bmi error [loc %d type %d]: bmiAccumulateHeaders() failed.", (int)err_loc, (int)err_type);
      bmiFreeMessage(message);
      bmiFreeSystem(system);
      return NULL;
    };
    header_list = header_list->next;
  };
  err = bmiEndHeaders(message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiEndHeaders() failed.", (int)err_loc, (int)err_type);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };

  /* Send body */
  data_file = fdopen(data_fd,"r");
  do {
    j = fread(data_buffer, 1, sizeof(data_buffer), data_file);
    if (j > 0) {
      err = bmiAccumulateBody((const char *)data_buffer, j, message);
      if (bmiErrorIsFatal(err) == BMI_TRUE) {
        err_loc = bmiErrorGetLocation(err);
        err_type = bmiErrorGetType(err);
        log_write(0, LOG_PANIC,
                   "bmi error [loc %d type %d]: bmiAccumulateBody() failed.", (int)err_loc, (int)err_type);
        bmiFreeMessage(message);
        bmiFreeSystem(system);
        return NULL;
      };
    };
  } while (j > 0);
  err = bmiEndBody(message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiEndBody() failed.", (int)err_loc, (int)err_type);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };


  /* End message */
  err = bmiEndMessage(message);
  if (bmiErrorIsFatal(err) == BMI_TRUE) {
    err_loc = bmiErrorGetLocation(err);
    err_type = bmiErrorGetType(err);
    log_write(0, LOG_PANIC,
               "bmi error [loc %d type %d]: bmiEndMessage() failed.", (int)err_loc, (int)err_type);
    bmiFreeMessage(message);
    bmiFreeSystem(system);
    return NULL;
  };

  /* get store for the verdict string */
  verdicts = store_get(1);
  *verdicts = '\0';

  for ( err = bmiAccessFirstVerdict(message, &verdict);
        verdict != NULL;
        err = bmiAccessNextVerdict(message, verdict, &verdict) ) {
    char *verdict_str;

    err = bmiCreateStrFromVerdict(verdict,&verdict_str);
    if (!store_extend(verdicts, Ustrlen(verdicts)+1, Ustrlen(verdicts)+1+strlen(verdict_str)+1)) {
      /* can't allocate more store */
      return NULL;
    };
    if (*verdicts != '\0')
      Ustrcat(verdicts, US ":");
    Ustrcat(verdicts, US verdict_str);
    bmiFreeStr(verdict_str);
  };

  DEBUG(D_receive) debug_printf("bmi verdicts: %s\n", verdicts);

  if (Ustrlen(verdicts) == 0)
    return NULL;
  else
    return verdicts;
}
示例#8
0
文件: edit.c 项目: jff/mathspad
static int set_name(void *data, Char *pathname)
{
    EDITINFO *einf = (EDITINFO *) data;
    XTextProperty prop_name;
    Char *name;
    int namesize;
    Char *stripname, *nname;

    if (pathname == NULL) {
	EDITINFO *tinf;
	FlexArray istck;
	int i=0,j;
	int_init(istck);
	while (aig(tinf=(EDITINFO*)next_data_with_type(MAINEDITWINDOW, &i))) {
	  if (!Ustrncmp(translate(EMPTYFILE),tinf->filename, Ustrlen(translate(EMPTYFILE)))) {
	    j = Ustrtol(tinf->filename+Ustrlen(translate(EMPTYFILE)), NULL, 10);
	    int_add(istck, j);
	  }
	  i++;
	}
	i=1;
	while (int_contains(istck,i)) i++;
	int_clear(istck);
	nname = (Char *) malloc(sizeof(Char)*(Ustrlen(userdir) +
					      Ustrlen(translate("/" EMPTYFILE))
					      + 5 +Ustrlen(translate(EXTENSION))));
	concat_in(nname, userdir, translate("/" EMPTYFILE));
	stripname = nname + Ustrlen(nname);
	{ Char sb[40];
	  Char *s;
	  sb[39]=0;
	  s=Ultostr(i,sb+39);
	  Ustrcat(stripname,s);
	}
	Ustrcat(stripname, translate(EXTENSION));
    } else
        nname = pathname;
    stripname = concat(strip_name(nname),NULL);
    if (!Ustrcmp(stripname+Ustrlen(stripname)-Ustrlen(translate(EXTENSION)),
		 translate(EXTENSION)))
	stripname[Ustrlen(stripname)-Ustrlen(translate(EXTENSION))] = 0;
    namesize = Ustrlen(translate(EDITNAME)) + Ustrlen(stripname) + 1 +
	(einf->saved ? 0 : Ustrlen(translate(CHANGED))) +
	(einf->view_mode && !einf->shell ? Ustrlen(translate(VIEWCOM)) : 0) +
	(einf->shell && !einf->fini ? Ustrlen(translate(RUNCOM)) : 0) +
	(einf->shell && einf->fini ? Ustrlen(translate(DONECOM)) : 0);
    name = (Char *) malloc((size_t) namesize*sizeof(Char) );
    if (name) {
	name[0]= '\0';
	Ustrcat(name, translate(EDITNAME));
	Ustrcat(name, stripname);
	if (!einf->saved && !einf->shell) Ustrcat(name, translate(CHANGED));
	if (einf->view_mode && !einf->shell) Ustrcat(name, translate(VIEWCOM));
	if (einf->shell && !einf->fini) Ustrcat(name, translate(RUNCOM));
	if (einf->shell && einf->fini) Ustrcat(name, translate(DONECOM));
    }
    {
      char *n;
      n= (char*)UstrtoLocale(name);
      if (!name || !XStringListToTextProperty(&n, 1, &prop_name)) {
	message(MP_ERROR, translate("No location for editname."));
	return 0;
      }
    }
    XSetWMName(display, einf->win_id, &prop_name);
    free(einf->headername);
    if (einf->pathname!=nname) free(einf->pathname);
    free(einf->filename);
    einf->headername = name;
    einf->filename = stripname;
    einf->pathname = nname;
    {
      char *icn;
      icn = (char*)UstrtoLocale(stripname);
      if (!XStringListToTextProperty(&icn, 1, &prop_name)) {
	message(MP_ERROR, translate("No location for editicon."));
	return 0;
      }
    }
    XSetWMIconName(display, einf->win_id, &prop_name);
    return 1;
}