Changeset 251 for trunk


Ignore:
Timestamp:
Oct 1, 2009, 9:42:28 PM (15 years ago)
Author:
katerina
Message:

Improved logic for interpreting /proc/net/udp,tcp

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r248 r251  
    1212dnl start
    1313dnl
    14 AM_INIT_AUTOMAKE(samhain, 2.5.9b)
     14AM_INIT_AUTOMAKE(samhain, 2.5.9c)
    1515AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1616AC_CANONICAL_HOST
  • trunk/docs/Changelog

    r250 r251  
     12.5.9c:
     2        * move stale file record error message closer to problem zone
     3        * sh_port2proc.c: fix flawed logic for interpreting /proc/net/udp,tcp
     4       
    152.5.9b:
    26        * remove stale file record when creating handle, and raise diagnostic
  • trunk/src/sh_port2proc.c

    r250 r251  
    4646#if defined(SH_USE_PORTCHECK) && (defined (SH_WITH_CLIENT) || defined (SH_STANDALONE))
    4747
     48/* #define DEBUG_P2P 1 */
     49
    4850/****************************************************************************
    4951 *
     
    329331  *pid = 0;
    330332
     333#ifdef DEBUG_P2P
     334  {
     335    char errmsg[256];
     336    sl_snprintf(errmsg, sizeof(errmsg),
     337                "query, file=%s, proto=%d, port=%d, iface=%s\n",
     338                file, proto, sport, inet_ntoa(*saddr));
     339    fprintf(stderr, "%s", errmsg);
     340  }
     341#endif
     342
    331343  if (fd)
    332344    {
    333       int n, iface, port, inode;
     345      unsigned int n, iface, port, inode, istatus;
    334346      char line[512];
    335347
     
    337349        {
    338350       
    339           if (4 == sscanf(line,
    340                           "%d: %X:%X %*X:%*X %*X %*X:%*X %*X:%*X %*X %*d %*d %d %*s",
    341                           &n, &iface, &port, &inode))
     351#ifdef DEBUG_P2P
     352          {
     353            fprintf(stderr, "%s", line);
     354          }
     355#endif
     356
     357          if (5 == sscanf(line,
     358                          "%u: %X:%X %*X:%*X %X %*X:%*X %*X:%*X %*X %*d %*d %u %*s",
     359                          &n, &iface, &port, &istatus, &inode))
    342360            {
    343361              struct in_addr haddr;
     362
    344363              haddr.s_addr = (unsigned long)iface;
    345364
    346               if ((proto == IPPROTO_UDP || haddr.s_addr == saddr->s_addr) && port == sport)
     365#ifdef DEBUG_P2P
     366              {
     367                char a[32];
     368                char b[32];
     369
     370                sl_strlcpy(a, inet_ntoa(haddr), sizeof(a));
     371                sl_strlcpy(b, inet_ntoa(*saddr), sizeof(b));
     372
     373                fprintf(stderr, " -> inode %u, iface/port %s,%u, status %u, searching %s,%u, %u\n",
     374                        inode, a, port, istatus, b, sport,
     375                        proto == IPPROTO_TCP ? 0x0a : 0x07);
     376              }
     377#endif
     378
     379              if (proto == IPPROTO_TCP && istatus != 0x0a)
     380                continue;
     381              if (proto == IPPROTO_UDP && istatus == 0x01)
     382                continue;
     383
     384#ifdef DEBUG_P2P
     385              {
     386                fprintf(stderr, "check iface %u..\n", iface);
     387              }
     388#endif
     389
     390              if ((proto == IPPROTO_UDP || iface == 0 || haddr.s_addr == saddr->s_addr) && port == (unsigned int)sport)
    347391                {
    348392                  struct sock_store * new = socklist;
    349393
     394#ifdef DEBUG_P2P
     395                  {
     396                    fprintf(stderr, "found it\n");
     397                  }
     398#endif
     399
    350400                  while (new)
    351401                    {
    352                       if ((unsigned int)inode == new->sock)
     402#ifdef DEBUG_P2P
     403                      {
     404                        fprintf(stderr, "searching inode %u: %lu\n",
     405                                inode, new->sock);
     406                      }
     407#endif
     408                      if (inode == new->sock)
    353409                        {
     410#ifdef DEBUG_P2P
     411                          {
     412                            fprintf(stderr, "found it: path=(%s), user=(%s)\n",
     413                                    new->path == NULL ? "NULL" : new->path,
     414                                    new->user == NULL ? "NULL" : new->user);
     415                          }
     416#endif
    354417                          fclose(fd);
    355418                          *pid = (unsigned long) new->pid;
  • trunk/src/sh_unix.c

    r248 r251  
    34773477        err_open = errno;
    34783478
     3479      {
     3480        char * stale = sl_check_stale();
     3481
     3482        if (stale)
     3483          {
     3484            sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, err_open, MSG_E_SUBGEN,
     3485                            stale, _("sh_unix_getinfo_open"));
     3486          }
     3487      }
     3488
    34793489      alert_timeout = 120; /* this is per 8K block now ! */
    34803490
     
    35053515    {
    35063516      fstat_return = retry_fstat (FIL__, __LINE__, fd, &fbuf);
     3517
    35073518      if (fstat_return)
    3508         fstat_errno = errno;
     3519        {
     3520          char * stale;
     3521
     3522          fstat_errno = errno;
     3523
     3524          stale = sl_check_stale();
     3525
     3526          if (stale)
     3527            {
     3528              sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, fstat_errno,
     3529                              MSG_E_SUBGEN,
     3530                              stale, _("sh_unix_getinfo_fstat"));
     3531            }
     3532        }
    35093533    }
    35103534  else
Note: See TracChangeset for help on using the changeset viewer.