Changeset 212 for trunk/src


Ignore:
Timestamp:
Feb 17, 2009, 10:37:42 PM (16 years ago)
Author:
katerina
Message:

Lock baseline database (ticket #139) and allow list as input for PortCheckInterface (ticket #140).

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/samhain_setpwd.c

    r171 r212  
    252252  if (argc < 4)
    253253    {
    254       fprintf (stderr, _("\nUsage: samhain_setpwd <filename> <suffix> "\
     254      fprintf (stderr, "%s", _("\nUsage: samhain_setpwd <filename> <suffix> "\
    255255               "<new_password>\n\n"));
    256       fprintf (stderr, _("   This program is a utility that will:\n"));
    257       fprintf (stderr, _("    - search in the binary executable <filename> "\
    258                "for samhain's\n"));
    259       fprintf (stderr, _("      compiled-in default password,\n"));
    260       fprintf (stderr, _("    - change it to <new_password>,\n"));
    261       fprintf (stderr, _("    - and output the modified binary to "\
     256      fprintf (stderr, "%s", _("   This program is a utility that will:\n"));
     257      fprintf (stderr, "%s", _("    - search in the binary executable "\
     258               "<filename> for samhain's\n"));
     259      fprintf (stderr, "%s", _("      compiled-in default password,\n"));
     260      fprintf (stderr, "%s", _("    - change it to <new_password>,\n"));
     261      fprintf (stderr, "%s", _("    - and output the modified binary to "\
    262262               "<filename>.<suffix>\n\n"));
    263       fprintf (stderr, _("   To allow for non-printable chars, "\
     263      fprintf (stderr, "%s", _("   To allow for non-printable chars, "\
    264264                         "<new_password> must be\n"));
    265       fprintf (stderr, _("   a 16-digit hexadecimal "\
     265      fprintf (stderr, "%s", _("   a 16-digit hexadecimal "\
    266266               "number (only 0-9,A-F allowed in input),\n"));
    267       fprintf (stderr, _("   thus corresponding"\
     267      fprintf (stderr, "%s", _("   thus corresponding"\
    268268                         "   to an 8-byte password.\n\n"));
    269       fprintf (stderr, _("   Example: 'samhain_setpwd samhain new "\
     269      fprintf (stderr, "%s", _("   Example: 'samhain_setpwd samhain new "\
    270270               "4142434445464748'\n"));
    271       fprintf (stderr, _("   takes the file 'samhain', sets the password to "\
    272                "'ABCDEFGH'\n"));
    273       fprintf (stderr, _("   ('A' = 41 hex, 'B' = 42 hex, ...) "\
     271      fprintf (stderr, "%s", _("   takes the file 'samhain', sets the "\
     272               "password to 'ABCDEFGH'\n"));
     273      fprintf (stderr, "%s", _("   ('A' = 41 hex, 'B' = 42 hex, ...) "\
    274274               "and outputs the result\n"));
    275       fprintf (stderr, _("   to 'samhain.new'.\n"));
     275      fprintf (stderr, "%s", _("   to 'samhain.new'.\n"));
    276276      return  EXIT_FAILURE;
    277277    }
     
    360360        {
    361361          suc = 1;
    362           fprintf (stdout, _("INFO   old password found\n"));
     362          fprintf (stdout, "%s", _("INFO   old password found\n"));
    363363          fflush(stdout);
    364364          for (i = 0; i < 8; ++i)
     
    409409  if (suc == 1 && badcnt == 7)
    410410    {
    411       fprintf (stdout, _("INFO   finished\n"));
     411      fprintf (stdout, "%s", _("INFO   finished\n"));
    412412      close (newf);
    413413      close (oldf);
     
    419419  lseek (newf, 0, SEEK_SET);
    420420
    421   fprintf (stdout, _("INFO   Not found in first pass.\n"));
    422   fprintf (stdout, _("INFO   Second pass ..\n"));
     421  fprintf (stdout, "%s", _("INFO   Not found in first pass.\n"));
     422  fprintf (stdout, "%s", _("INFO   Second pass ..\n"));
    423423
    424424  /* offset the start point
     
    449449        {
    450450          suc = 1;
    451           fprintf (stdout, _("INFO   old password found\n"));
     451          fprintf (stdout, "%s", _("INFO   old password found\n"));
    452452          for (i = 0; i < 8; ++i)
    453453            {
     
    497497  if (suc == 1 && badcnt == 7)
    498498    {
    499       fprintf (stdout, _("INFO   finished\n"));
     499      fprintf (stdout, "%s", _("INFO   finished\n"));
    500500      fflush(stdout);
    501501      return 0;
     
    504504  if (suc == 0 || badcnt < 7)
    505505    {
    506       fprintf (stdout, _("ERROR incomplete replacement\n"));
     506      fprintf (stdout, "%s", _("ERROR incomplete replacement\n"));
    507507    }
    508508  else
    509509    {
    510       fprintf (stdout, _("ERROR bad replacement\n"));
     510      fprintf (stdout, "%s", _("ERROR bad replacement\n"));
    511511    }
    512512  fflush(stdout);
  • trunk/src/samhain_stealth.c

    r205 r212  
    270270static void usage ()
    271271{
    272       fprintf(stdout, _("\nUsage:  samhain_stealth -i|s|g|o <where> "\
    273                         "[what]\n\n"));
    274 
    275       fprintf(stdout, _("   -i info on PS image 'where'\n"));
    276       fprintf(stdout, _("      (how much bytes can be hidden in it).\n"));
    277       fprintf(stdout, _("   -s hide file 'what' in PS image 'where'\n"));
    278       fprintf(stdout, _("   -g get hidden data from PS image 'where'\n"));
    279       fprintf(stdout, _("      (output to stdout)\n"));
    280       fprintf(stdout, _("   -o size of file 'where' = offset to "\
    281                         "end-of-file\n"));
    282       fprintf(stdout, _("      (same as wc -c).\n\n"));
    283       fprintf(stdout, _(" Example: let bar.ps be the ps file, and foo the config file\n"));
    284       fprintf(stdout, _("   1) extract with: samhain_stealth -g bar.ps >foo\n"));
    285       fprintf(stdout, _("   2) hide with:    samhain_stealth -s bar.ps foo\n\n"));
    286 
    287       fprintf(stdout, _(" This program hides a file in an UNCOMPRESSED "\
    288               "postscript\n"));
    289       fprintf(stdout, _(" image. To generate such an image, you may "\
    290               "use e.g.:\n"));
    291       fprintf(stdout, _("   'convert +compress foo.jpg bar.ps'.\n"));
    292       fprintf(stdout, _("   'gimp' apparently saves postscript uncompressed "\
    293                         "by default\n"));
    294       fprintf(stdout, _("          (V 1.06 of the postscript plugin).\n"));
    295       fprintf(stdout, _("   'xv' seems to save with run-length compression, "\
    296               "which is unsuitable.\n"));
    297       fprintf(stdout, _(" The program does not check the compression type of "\
    298               "the PS file.\n"));
    299       fprintf(stdout, _(" Just have a look at the result to check.\n"));
     272      fprintf(stdout, "%s", _("\nUsage:  samhain_stealth -i|s|g|o <where> "\
     273                              "[what]\n\n"));
     274
     275      fprintf(stdout, "%s", _("   -i info on PS image 'where'\n"));
     276      fprintf(stdout, "%s", _("      (how much bytes can be hidden in it).\n"));
     277      fprintf(stdout, "%s", _("   -s hide file 'what' in PS image 'where'\n"));
     278      fprintf(stdout, "%s", _("   -g get hidden data from PS image 'where'\n"));
     279      fprintf(stdout, "%s", _("      (output to stdout)\n"));
     280      fprintf(stdout, "%s", _("   -o size of file 'where' = offset to "\
     281                              "end-of-file\n"));
     282      fprintf(stdout, "%s", _("      (same as wc -c).\n\n"));
     283      fprintf(stdout, "%s", _(" Example: let bar.ps be the ps file, and"\
     284                              "foo the config file\n"));
     285      fprintf(stdout, "%s", _("   1) extract with: samhain_stealth "\
     286                              "-g bar.ps >foo\n"));
     287      fprintf(stdout, "%s", _("   2) hide with:    samhain_stealth "\
     288                              "-s bar.ps foo\n\n"));
     289
     290      fprintf(stdout, "%s", _(" This program hides a file in an UNCOMPRESSED "\
     291                              "postscript\n"));
     292      fprintf(stdout, "%s", _(" image. To generate such an image, you may " \
     293                              "use e.g.:\n"));
     294      fprintf(stdout, "%s", _("   'convert +compress foo.jpg bar.ps'.\n"));
     295      fprintf(stdout, "%s", _("   'gimp' apparently saves postscript "\
     296                              "uncompressed by default\n"));
     297      fprintf(stdout, "%s", _("         (V 1.06 of the postscript plugin).\n"));
     298      fprintf(stdout, "%s", _("   'xv' seems to save with run-length "\
     299                              "compression, which is unsuitable.\n"));
     300      fprintf(stdout, "%s", _(" The program does not check the "\
     301                              "compression type of the PS file.\n"));
     302      fprintf(stdout, "%s", _(" Just have a look at the result to check.\n"));
    300303      return;
    301304}
     
    338341      if (fd == -1)
    339342        {
    340           fprintf(stderr, _("Error: could not open() %s for reading\n"), argv[2]);
     343          fprintf(stderr, _("Error: could not open() %s for reading\n"),
     344                  argv[2]);
    341345          return (1);
    342346        }
     
    417421          return (1);
    418422        }
    419       fprintf(stdout, _(" .. finished\n"));
     423      fprintf(stdout, "%s", _(" .. finished\n"));
    420424      return (0);
    421425    }
     
    458462  return (1);
    459463}
    460  
    461      
     464
  • trunk/src/sh_err_log.c

    r210 r212  
    665665          /* don't write second EOF mark
    666666           */
    667           if (current->log_start != S_TRUE)
     667          if (current->log_start != S_TRUE && sh.flag.islocked == GOOD)
    668668            {
    669669              /* Don't use inet_peer == NULL, userwise a lock file will
  • trunk/src/sh_extern.c

    r211 r212  
    3131 * for debugging
    3232 */
    33 #if 1
    34 #define PDGBFILE "/home/rainer/PROJECTS/samhain/devel/pdbg."
     33#if 0
     34#define PDGBFILE "/pdbg."
    3535#endif
    3636
     
    781781  struct  sigaction  new_act;
    782782  struct  sigaction  old_act;
    783   char  dir[SH_PATHBUF];
    784   char * p;
    785783  char * out = NULL;
    786784  int    status;
     
    14691467  while (listval != NULL)
    14701468    {
     1469      PDBG_OPEN;
    14711470      PDBG(-2);
    14721471      if (t1 == listval->type[0] &&
  • trunk/src/sh_hash.c

    r210 r212  
    15521552              sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS,
    15531553                              geteuid(), file_path('D', 'W'));
    1554               SL_RET0(_("sh_hash_pushdata_int"));
     1554              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
    15551555            }
     1556
     1557          if (SL_ISERROR(status = sl_lock (pushdata_fd)))
     1558            {
     1559              SH_FREE(fullpath);
     1560              SH_FREE(linkpath);
     1561              sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH,
     1562                              _("Failed to lock baseline database"), _("sh_hash_pushdata_int"),
     1563                              file_path('D', 'W'));
     1564              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
     1565            }
     1566
    15561567          if ( SL_ISERROR(status = sl_forward(pushdata_fd)))
    15571568            {
     
    15591570              SH_FREE(linkpath);
    15601571              sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH,
    1561                               _("Fast forward failed"), _("sh_hash_pushdata_int"),
     1572                              _("Failed to seek to end of baseline database"), _("sh_hash_pushdata_int"),
    15621573                              file_path('D', 'W'));
    1563               SL_RET0(_("sh_hash_pushdata_int"));
     1574              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
    15641575            }
    15651576        }
     
    15701581        {
    15711582          TPT((0, FIL__, __LINE__, _("msg=<Update.>\n")))
    1572           if ( SL_ISERROR(pushdata_fd = sl_open_rdwr(file_path('D', 'W'), SL_YESPRIV))){
    1573             SH_FREE(fullpath);
    1574             SH_FREE(linkpath);
    1575             sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS,
    1576                             geteuid(), file_path('D', 'W'));
    1577             SL_RET0(_("sh_hash_pushdata_int"));
    1578           }
     1583            if ( SL_ISERROR(pushdata_fd = sl_open_rdwr(file_path('D', 'W'), SL_YESPRIV))){
     1584              SH_FREE(fullpath);
     1585              SH_FREE(linkpath);
     1586              sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS,
     1587                              geteuid(), file_path('D', 'W'));
     1588              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
     1589            }
     1590
     1591          if (SL_ISERROR(status = sl_lock (pushdata_fd)))
     1592            {
     1593              SH_FREE(fullpath);
     1594              SH_FREE(linkpath);
     1595              sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH,
     1596                              _("Failed to lock baseline database"), _("sh_hash_pushdata_int"),
     1597                              file_path('D', 'W'));
     1598              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
     1599            }
     1600
    15791601          line = SH_ALLOC(MAX_PATH_STORE+1);
    15801602          if (SL_ISERROR(sh_hash_setdataent_old (pushdata_fd, line,
     
    15851607              SH_FREE(linkpath);
    15861608              SH_FREE(line);
    1587               SL_RET0(_("sh_hash_pushdata_int"));
     1609              aud_exit(FIL__, __LINE__, EXIT_FAILURE);
    15881610            }
    15891611          SH_FREE(line);
  • trunk/src/sh_portcheck.c

    r210 r212  
    12181218/* Subroutine to add an interface
    12191219 */
     1220static void * sh_dummy_str    = NULL; /* fix clobbered by.. warning */
     1221
    12201222static int sh_portchk_add_interface (const char * str)
    12211223{
    12221224  struct in_addr   haddr;
    12231225  char errbuf[256];
     1226  char buf[64];
     1227
     1228  sh_dummy_str    = (void*) &str;
    12241229
    12251230  if (iface_initialized == 0)
     
    12291234    }
    12301235
    1231   if (0 == inet_aton(str, &haddr))
    1232     return -1;
    1233 
    1234   if (iface_list.used == SH_IFACE_MAX)
    1235     return -1;
    1236 
    1237   sl_snprintf(errbuf, sizeof(errbuf), _("interface: %s"), inet_ntoa(haddr));
    1238   SH_MUTEX_LOCK(mutex_thread_nolog);
    1239   sh_error_handle(SH_ERR_INFO, FIL__, __LINE__, 0, MSG_E_SUBGEN,
    1240                   errbuf, _("sh_portchk_add_interface"));
    1241   SH_MUTEX_UNLOCK(mutex_thread_nolog);
    1242 
    1243   memcpy (&(iface_list.iface[iface_list.used].s_addr), &(haddr.s_addr), sizeof(in_addr_t));
    1244   ++iface_list.used;
     1236  do {
     1237
     1238    while (*str == ',' || *str == ' ' || *str == '\t') ++str;
     1239
     1240    if (*str)
     1241      {
     1242        unsigned int i = 0;
     1243        while (*str && i < (sizeof(buf)-1) && *str != ',' && *str != ' ' && *str != '\t')
     1244          {
     1245            buf[i] = *str; ++str; ++i;
     1246          }
     1247        buf[i] = '\0';
     1248
     1249        if (0 == inet_aton(buf, &haddr))
     1250          return -1;
     1251
     1252        if (iface_list.used == SH_IFACE_MAX)
     1253          return -1;
     1254
     1255        sl_snprintf(errbuf, sizeof(errbuf), _("interface: %s"), inet_ntoa(haddr));
     1256        SH_MUTEX_LOCK(mutex_thread_nolog);
     1257        sh_error_handle(SH_ERR_INFO, FIL__, __LINE__, 0, MSG_E_SUBGEN,
     1258                        errbuf, _("sh_portchk_add_interface"));
     1259        SH_MUTEX_UNLOCK(mutex_thread_nolog);
     1260       
     1261        memcpy (&(iface_list.iface[iface_list.used].s_addr), &(haddr.s_addr), sizeof(in_addr_t));
     1262        ++iface_list.used;
     1263      }
     1264  } while (*str);
    12451265
    12461266  return 0;
  • trunk/src/slib.c

    r203 r212  
    21522152}
    21532153
     2154int sl_lock (SL_TICKET ticket)
     2155{
     2156  int fd;
     2157  struct flock lock;
     2158  int retval;
     2159 
     2160  SL_ENTER(_("sl_lock"));
     2161
     2162  if (SL_ISERROR(fd = get_the_fd (ticket)))
     2163    SL_IRETURN(fd, _("sl_lock"));
     2164
     2165  lock.l_type   = F_WRLCK;
     2166  lock.l_whence = SEEK_SET;
     2167  lock.l_start  = 0;
     2168  lock.l_len    = 0;
     2169
     2170  /* F_SETLK returns if the lock cannot be obtained */
     2171  do {
     2172    retval = fcntl(fd, F_SETLK, &lock);
     2173  } while (retval < 0 && errno == EINTR);
     2174
     2175  if (retval < 0 && errno == EBADF)
     2176    SL_IRETURN(SL_ETICKET, _("sl_lock"));
     2177  else if (retval < 0)
     2178    SL_IRETURN(SL_EBADFILE, _("sl_lock"));
     2179  else
     2180    SL_IRETURN(SL_ENONE, _("sl_lock"));
     2181 }
     2182 
    21542183int sl_close (SL_TICKET ticket)
    21552184{
Note: See TracChangeset for help on using the changeset viewer.