⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 send_m~1.cpp

📁 一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   while(strlen(new_buff) > 76)   {      tmp_ptr=new_buff+76;      while(tmp_ptr > new_buff && *tmp_ptr != ' ' && *tmp_ptr != '\t')         tmp_ptr--;            if(tmp_ptr <= new_buff)      {         tmp_ptr=new_buff+76;         while(*tmp_ptr != ' ' && *tmp_ptr != '\t' && *tmp_ptr != '\0')            tmp_ptr++;      }      if(tmp_ptr != '\0')      {         new_buff=(char*)realloc(*buff,strlen(*buff)+sizeof("\n\t"));         if(new_buff == NULL)         {            syslog(LOG_MAIL | LOG_ERR,"mem allocation failed (%s)",			strerror(errno));            return(-1);         }                  *buff=new_buff;         new_buff=tmp_ptr+2;         char1=tmp_ptr[0];         char2=tmp_ptr[1];          tmp_ptr[0]='\n';         tmp_ptr[1]='\t';         tmp_ptr+=2;         while(char1 != '\0' && char2 != '\0')         {            char3=tmp_ptr[0];            tmp_ptr[0]=char1;            char1=char3;            char3=tmp_ptr[1];            tmp_ptr[1]=char2;            char2=char3;            tmp_ptr+=2;         }         tmp_ptr[0]=char1;         if(char1 != '\0')            tmp_ptr[1]='\0';      }      else         new_buff=tmp_ptr;   }   return(0);}////////////////////////////////////////////////////////////////////int send_attachment(struct send_info* info, FILE* out_pipe){   int input[3];   char output[4];   int x=0;   int boundary=0;   int char_read=0;   rewind(info->att);   fprintf(out_pipe,"\n--%s\n",info->new_boundary);   fprintf(out_pipe,"Content-Type: %s;\n"		    "\tname=\"%s\"\n",			info->att_cont_type,info->filename);   fprintf(out_pipe,"Content-Transfer-Encoding: base64\n");   fprintf(out_pipe,"Content-Disposition: attachment;\n"		    "\tfilename=\"%s\"\n\n",			info->filename);   do   {      for(x=0;x<3;x++)      {         char_read=getc(info->att);         if(char_read != EOF)            input[x]=char_read;         else            break;      }      if(x == 0)         break;      for(;x<3;x++)         input[x]=0xff00;      conv_to_base64(input,output);      for(x=0;x<4;x++)         putc(output[x],out_pipe);      boundary++;      if(boundary > 18)      {         putc('\n',out_pipe);         boundary=0;      }   }   while(char_read != EOF);   putc('\n',out_pipe);   return(0);}//////////////////////////////////////////////////////////////////////this will convert the 3 binary bytes (input) to 4 6 bit characters//      converted to base 64//   if EOF is found, remaining characters should be 0xff00int conv_to_base64(int input[3], char output[4]){   int x=0;   output[0]=(input[0] & 0x00fc) >> 2;   output[1]=((input[0] & 0x0003) << 4) | ((input[1] & 0x00f0) >> 4);   output[2]=((input[1] & 0x000f) << 2) | ( (input[2] & 0x00c0) >> 6);   output[3]=input[2] & 0x003f;   for(x=0;x<4;x++)      output[x]=base64_char_conv(output[x]);   if(input[0] == 0xff00)   {      output[0]='=';      output[1]='=';      output[2]='=';      output[3]='=';   }   if(input[1] == 0xff00)   {      output[2]='=';      output[3]='=';   }   if(input[2] == 0xff00)   {      output[3]='=';   }   return(' ');}////////////////////////////////////////////////////////////////////int base64_char_conv(int c){   if(c >= 0 && c <= 25)      return(c + 'A');   if(c >= 26 && c <= 51)      return(c - 26 + 'a');   if(c >= 52 && c <= 61)      return(c - 52 + '0');   if(c == 62)      return('+');   if(c == 63)      return('/');   return(0);}////////////////////////////////////////////////////////////////////// This initializes the send_info structureint init_send_info_struct(send_info* info){   if(info == NULL)      return(-1);   info->from=NULL;   info->to=NULL;   info->cc=NULL;   info->bcc=NULL;   info->subject=NULL;   info->body=NULL;   info->att=NULL;   info->filename=NULL;   info->att_cont_type=NULL;   info->new_boundary=NULL;   info->refw=-1;   info->refw_file=NULL;   info->mail_h=NULL;   return(0);}////////////////////////////////////////////////////////////////////// This will free any memory allocated to the send_info structure and//    set the freed variables to NULL. Also deletes any temporary//    files that may have been used to send message (attachments).int delete_send_info_struct(send_info* info){   if(info == NULL)      return(-1);   if(info->from != NULL)   {      free(info->from);      info->from=NULL;   }   if(info->to != NULL)      destroy_addr_arr(&(info->to));   if(info->cc != NULL)      destroy_addr_arr(&(info->cc));   if(info->bcc != NULL)      destroy_addr_arr(&(info->bcc));   if(info->subject != NULL)   {      free(info->subject);      info->subject=NULL;   }   if(info->body != NULL)   {      free(info->body);      info->body=NULL;   }   if(info->filename != NULL)   {      free(info->filename);      info->filename=NULL;   }   if(info->att_cont_type != NULL)   {      free(info->att_cont_type);      info->att_cont_type=NULL;   }   if(info->att != NULL)   {      /* temp file will be closed and deleted by destroy_cgi_env() function */      info->att=NULL;   }   if(info->new_boundary != NULL)   {      free(info->new_boundary);      info->new_boundary=NULL;   }   if(info->refw_file != NULL)   {      fclose(info->refw_file);      info->refw_file=NULL;   }   if(info->mail_h != NULL)   {      free_mail_headers(info->mail_h);      info->mail_h=NULL;   }   return(0);}////////////////////////////////////////////////////////////////////// This only gets called if the user replys/forwards a message//    that has attachments. Text messages are reply'd/forward'd to//    in the body of the message, only attachments happen here,//    which means the message MUST be multipart/*, although a//    multipart/* message does not necessairly need to call//    this function (message/alternative, or message/mixed that//    only has one plain/text part). The compose message file//    handles these situations and sets things up so this function//    is only called if necessaryint init_refw_msg(struct send_info* info){   setgid(egid);   info->refw_file=open_user_mailfile("r");   setgid(rgid);   if( info->refw_file == NULL)      return(-1);   if( point_to_message(info->refw_file,info->refw) != 0)      return(-1);   info->mail_h=fill_mail_h_struct(info->refw_file,info->refw);   if(info->mail_h == NULL)      return(-1);   if(info->mail_h->cont_type != ct_multipart_alternative)   {      if(info->mail_h->cont_boundary != NULL)      {         info->new_boundary=strdup(info->mail_h->cont_boundary);         if(info->new_boundary == NULL)            return(-1);      }      else      {         info->new_boundary=get_rand_string(20);         if(info->new_boundary == NULL)            return(-1);      }   }   else   {      info->new_boundary=get_rand_string(20);      if(info->new_boundary == NULL)         return(-1);   }   return(0);}////////////////////////////////////////////////////////////////////int send_refw_message(FILE* out_pipe, struct send_info* info){   char* file_buff=NULL;   size_t file_buff_size=0;   ssize_t b_read=0;   status_type status=st_nl;   long int file_ptr1=0;   long int file_ptr2=0;   mail_header* mail_h_next1=NULL;   mail_header* mail_h_next2=NULL;   if(out_pipe == NULL || info == NULL)      return(-1);   if(info->mail_h == NULL || info->refw_file == NULL)      return(-1);   fprintf(out_pipe,"\n--%s\n",info->new_boundary);   if(info->mail_h->cont_type == ct_multipart_mixed)   {      status=find_next_border(info->refw_file,info->new_boundary);      if(status == st_error || status == st_done)         return(-1);      file_ptr1=ftell(info->refw_file);      if( (mail_h_next1=fill_mail_h_struct(info->refw_file,0)) == NULL)         return(-1);      if(mail_h_next1->cont_type == ct_text_plain || 			mail_h_next1->cont_type == ct_none)      {         free_mail_headers(mail_h_next1);         status=find_next_border(info->refw_file,info->new_boundary);         if(status == st_error || status == st_done)            return(-1);      }      else if(mail_h_next1->cont_type == ct_multipart_alternative)      {         file_ptr2=ftell(info->refw_file);         if( (mail_h_next2=fill_mail_h_struct(info->refw_file,0)) == NULL)            return(-1);         if(mail_h_next2->cont_type == ct_text_plain ||			mail_h_next2->cont_type == ct_none)         {            status=find_next_border(info->refw_file,					mail_h_next1->cont_boundary);            if(status == st_error)            {               free_mail_headers(mail_h_next1);               free_mail_headers(mail_h_next2);               return(-1);            }            if(status == st_done)            {               status=find_next_border(info->refw_file,info->new_boundary);               if(status == st_error || status == st_done)               {                  free_mail_headers(mail_h_next1);                  free_mail_headers(mail_h_next2);                  return(-1);               }            }         }         else         {            fseek(info->refw_file,file_ptr2,SEEK_SET);         }         free_mail_headers(mail_h_next1);         free_mail_headers(mail_h_next2);      }      else      {         free_mail_headers(mail_h_next1);         fseek(info->refw_file,file_ptr1,SEEK_SET);      }   }      else   {      if(info->mail_h->cont_type_string != NULL)      {         fprintf(out_pipe,"Content-Type: %s",info->mail_h->cont_type_string);         if(info->mail_h->cont_boundary != NULL)            fprintf(out_pipe,";\n\tboundary=\"%s\"",			info->mail_h->cont_type_string);         if(info->mail_h->filename != NULL)            fprintf(out_pipe,";\n\tname=\"%s\"",			info->mail_h->filename);         fprintf(out_pipe,"\n");      }      else         fprintf(out_pipe,"Content-Type: text/plain\n");      if(info->mail_h->cont_type_enc == cte_base64)         fprintf(out_pipe,"Content-Transfer-Encoding: base64\n");      if(info->mail_h->cont_type_enc == cte_quoted_printable)         fprintf(out_pipe,"Content-Transfer-Encoding: quoted-printable\n");      if(info->mail_h->cont_type_enc == cte_binary)         fprintf(out_pipe,"Content-Transfer-Encoding: binary\n");      if(info->mail_h->cont_type_enc == cte_8bit)         fprintf(out_pipe,"Content-Transfer-Encoding: 8bit\n");      if(info->mail_h->cont_type_enc == cte_7bit)         fprintf(out_pipe,"Content-Transfer-Encoding: 7bit\n");      if(info->mail_h->filename != NULL)         fprintf(out_pipe,"Content-Disposition: attachment;\n"			  "\tname=\"%s\"\n",info->mail_h->filename);      fprintf(out_pipe,"\n");   }   do   {      b_read=getline(&file_buff,&file_buff_size,info->refw_file);      if(b_read <= 0 || file_buff == NULL)      {         syslog(LOG_MAIL | LOG_ERR,"getline failed (%s)",strerror(errno));         if(file_buff != NULL)            free(file_buff);         return(-1);      }      status=is_boundary(file_buff,info->mail_h->cont_boundary);      if(status == st_error && info->mail_h->cont_boundary == NULL)         status=st_done;      if(status != st_error && status != st_done)         b_read=fprintf(out_pipe,"%s",file_buff);   }   while(status != st_error && status != st_done && b_read > 0);   if(file_buff != NULL)      free(file_buff);   if(status == st_error || b_read <= 0)   {      syslog(LOG_MAIL | LOG_ERR,"send_refw_message could not find ending "			"boundary");      return(-1);   }   return(0);}////////////////////////////////////////////////////////////////////// This function generates a page that displays addresses that are//    invalid (don't appear to be full email addresses)int err_addr(send_info* info){   int x=0;   content_html();   html_header("ERROR - invalid addresses");   printf("<TABLE BORDER=\"0\" ALIGN=\"CENTER\" WIDTH=\"80%%\" "          "CELLPADDING=\"1\" CELLSPACING=\"1\">\n"          "   <TR>\n"          "      <TD BGCOLOR=\"#002266\" ALIGN=\"LEFT\">\n"          "      <FONT COLOR=\"#FFFFFF\" FACE=\"Arial, Helvetica\" "          "SIZE=\"3\">\n"          "      <B>ERROR: Invalid addresses</B>\n"          "      </FONT>\n"          "      </TD>\n"          "   </TR>\n"          "   <TR>\n"          "      <TD BGCOLOR=\"#EEEEEE\">\n"          "         <BR>\n");   if(info->to == NULL && info->cc == NULL && info->bcc == NULL)      printf("No recipients specified.<BR>");   else   {      if(info->to != NULL)         for(x=0; info->to[x].name || info->to[x].email; x++)            if(info->to[x].email == NULL)               printf("         <B>%s</B> is not in address book and does not "                      "appear to be a valid email address.<BR>\n",			info->to[x].name);      if(info->cc != NULL)         for(x=0; info->cc[x].name || info->cc[x].email; x++)            if(info->cc[x].email == NULL)               printf("         <B>%s</B> is not in address book and does not "                      "appear to be a valid email address.<BR>\n",			info->cc[x].name);      if(info->bcc != NULL)         for(x=0; info->bcc[x].name || info->bcc[x].email; x++)            if(info->bcc[x].email == NULL)               printf("         <B>%s</B> is not in address book and does not "		      "appear to be a valid email address.<BR>\n",			info->bcc[x].email);   }   printf("         <BR>\n"          "      </TD>\n"          "   </TR>\n");   html_footer();   return(0);}////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -