Apr 282009
 

Biasanya From: header akan di isi oleh nilai dari settingan client masing2 user.

contoh: di thunderbird From: header akan di isi settingan dari Your Name:.

untuk email2 official From header bisa di paksakan supaya menggunakan nama user yg ada di database postfix user.
dengan bantuan altermime dan sedikit coding(c dan bash script).

altermime dapat di download disini:

www.pldaniels.com/altermime/

Coding c (access mysql db):

fungsinya untuk query field “name” (nama lengkap email user) di database postfix

paste code ini di console editor.(vi atau pico)

#include 
#include 
#include 
#include 

main(int argc,char *argv[]) {
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;

   char *server = "localhost";
   char *user = "user";
   char *password = "password";
   char *database = "db";
   char strsql[512];

   if(argc != 2)
   {
       printf("Usage: %s ’string query’\n", argv[0]);
       exit(EXIT_FAILURE);
   }

   snprintf(strsql, 512, "SELECT REPLACE(TRIM(name),’\n’,”) FROM mailbox WHERE username=TRIM(’%s’)", argv[1]);

   conn = mysql_init(NULL);

   /* Connect to database */
   if (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 0)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(EXIT_FAILURE);
   }

   /* send SQL query */
   if (mysql_query(conn, strsql)) {
      fprintf(stderr, "%s\n", mysql_error(conn));
      exit(EXIT_FAILURE);
   }

   res = mysql_use_result(conn);

     while ( (row = mysql_fetch_row(res))  !=  NULL )
      printf("%s\n", row[0]);
   return(0);

   /* Release memory used to store results and close connection */
   mysql_free_result(res);
   mysql_close(conn);
}

Continue reading »

Jun 272008
 

quoted from http://liw.iki.fi/liw/texts/longest-living-bug.html

In the spring and summer of 1991, my friend Linus was playing around with this OS-like program, which later became Linux. He wanted a printf like service inside the kernel, but didn’t know how to implement it, though (he didn’t know C thoroughly back then). So I wrote him an sprintf clone, and he used that, after some modifications.

In September of 1994, Friedemann Baitinger at IBM, who was developing a device driver for another operating system, used my sprintf clone as a debugging aid (but not in the final product). The bug lived for three or three and a half years before anyone found it. Worse, the bug was immediately obvious as soon as one tried to use the function in a certain, common way. No-one had done that, ever, not even I when I wrote it. Don’t ever hire me to write code that is expected to work.

The bug was in the handling of a field width given via the argument list. With sprintf, to print a string, for example, you would write

sprintf(buf, "%s", str);

This would put the str' string intobuf’. sprintf allows formatting of the output:

sprintf(buf, "%10s", str);

This would make the output string at least 10 characters wide (wider, if `str’ is wider). The field width can be a constant, or it can be given as a separate argument:

sprintf(buf, "%*s", 10, str);

This gives the same output as before, but triggered my bug.

My sprintf was implemented with a loop that walked through the format string and incremented an index when it processed various parts of the format string. Except that when it processed the `*’, it didn’t increment. Oops.

So why do I explain this so thoroughly? My weird sense of humor made me put “Author of the longest-living Linux bug” in the CREDITS file in the kernel sources, and people sometimes ask me about it. I figured I’d answer it once, and point people at this web page.