As mentioned on the users-mailinglist[1], it could be useful to have groups read...
authorsake <sake@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 28 Aug 2010 11:05:51 +0000 (11:05 +0000)
committersake <sake@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 28 Aug 2010 11:05:51 +0000 (11:05 +0000)
[1]  http://www.wireshark.org/lists/wireshark-users/201008/msg00235.html

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@33978 f5534014-38df-0310-8fa8-9805f1628bb7

capture_opts.c
capture_opts.h
dumpcap.c
ringbuffer.c
ringbuffer.h

index e24ec8fed190cd6db7c95dbc79700715a6f695df..a736037bfbaff5a35b53e3509115caa8a01119d4 100644 (file)
@@ -85,6 +85,7 @@ capture_opts_init(capture_options *capture_opts, void *cf)
   capture_opts->linktype                = -1;               /* the default linktype */
   capture_opts->saving_to_file          = FALSE;
   capture_opts->save_file               = NULL;
+  capture_opts->group_read_access       = FALSE;
   capture_opts->use_pcapng              = FALSE;            /* the default is pcap */
   capture_opts->real_time_mode          = TRUE;
   capture_opts->show_info               = TRUE;
@@ -159,6 +160,7 @@ capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_optio
     g_log(log_domain, log_level, "LinkType           : %d", capture_opts->linktype);
     g_log(log_domain, log_level, "SavingToFile       : %u", capture_opts->saving_to_file);
     g_log(log_domain, log_level, "SaveFile           : %s", (capture_opts->save_file) ? capture_opts->save_file : "");
+    g_log(log_domain, log_level, "GroupReadAccess    : %u", capture_opts->group_read_access);
     g_log(log_domain, log_level, "Fileformat         : %s", (capture_opts->use_pcapng) ? "PCAPNG" : "PCAP");
     g_log(log_domain, log_level, "RealTimeMode       : %u", capture_opts->real_time_mode);
     g_log(log_domain, log_level, "ShowInfo           : %u", capture_opts->show_info);
@@ -530,6 +532,9 @@ capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg_
 #endif
         status = capture_opts_output_to_pipe(capture_opts->save_file, &capture_opts->output_to_pipe);
         return status;
+    case 'g':        /* enable group read access on the capture file(s) */
+        capture_opts->group_read_access = TRUE;
+        break;
     case 'y':        /* Set the pcap data link type */
         capture_opts->linktype = linktype_name_to_val(optarg_str_p);
         if (capture_opts->linktype == -1) {
index ed287df9a123cb90f7b76f2be7c1a66c995ef8b1..478d41be54c64cc3137e3ece2b6b3c3aeebb753f 100644 (file)
@@ -118,6 +118,7 @@ typedef struct capture_options_tag {
     gboolean monitor_mode;          /**< Capture in monitor mode, if available */
     gboolean saving_to_file;        /**< TRUE if capture is writing to a file */
     gchar    *save_file;            /**< the capture file name */
+    gboolean group_read_access;     /**< TRUE is group read permission needs to be set */
     gboolean use_pcapng;            /**< TRUE if file format is pcapng */
 
     /* GUI related */
index 15c55c188ca2a56eee483f33f48673f18f90fb78..e89094d8a54a08c1097ecabde070404833d52ae1 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -378,6 +378,7 @@ print_usage(gboolean print_ver) {
   /*fprintf(output, "\n");*/
   fprintf(output, "Output (files):\n");
   fprintf(output, "  -w <filename>            name of file to save (def: tempfile)\n");
+  fprintf(output, "  -g                       enable group read access on the output file(s)\n");
   fprintf(output, "  -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs\n");
   fprintf(output, "                           filesize:NUM - switch to next file after NUM KB\n");
   fprintf(output, "                              files:NUM - ringbuffer: replace after NUM files\n");
@@ -2668,7 +2669,8 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
       if (capture_opts->multi_files_on) {
         /* ringbuffer is enabled */
         *save_file_fd = ringbuf_init(capfile_name,
-            (capture_opts->has_ring_num_files) ? capture_opts->ring_num_files : 0);
+            (capture_opts->has_ring_num_files) ? capture_opts->ring_num_files : 0,
+            capture_opts->group_read_access);
 
         /* we need the ringbuf name */
         if(*save_file_fd != -1) {
@@ -2678,7 +2680,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
       } else {
         /* Try to open/create the specified file for use as a capture buffer. */
         *save_file_fd = ws_open(capfile_name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT,
-                             0600);
+                             (capture_opts->group_read_access) ? 0640 : 0600);
       }
     }
     is_tempfile = FALSE;
@@ -3343,7 +3345,7 @@ main(int argc, char *argv[])
 #define OPTSTRING_d ""
 #endif
 
-#define OPTSTRING "a:" OPTSTRING_A "b:" OPTSTRING_B "c:" OPTSTRING_d "Df:hi:" OPTSTRING_I "L" OPTSTRING_m "Mnpq" OPTSTRING_r "Ss:" OPTSTRING_u "vw:y:Z:"
+#define OPTSTRING "a:" OPTSTRING_A "b:" OPTSTRING_B "c:" OPTSTRING_d "Df:ghi:" OPTSTRING_I "L" OPTSTRING_m "Mnpq" OPTSTRING_r "Ss:" OPTSTRING_u "vw:y:Z:"
 
 #ifdef DEBUG_CHILD_DUMPCAP
   if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) {
@@ -3622,6 +3624,7 @@ main(int argc, char *argv[])
       case 'p':        /* Don't capture in promiscuous mode */
       case 's':        /* Set the snapshot (capture) length */
       case 'w':        /* Write to capture file x */
+      case 'g':        /* enable group read accesson file(s) */
       case 'y':        /* Set the pcap data link type */
 #ifdef HAVE_PCAP_REMOTE
       case 'u':        /* Use UDP for data transfer */
index ca946554381fe99319b4989c870c3031d059e762..541f009469602fd9ed7fb6dd86aee32baf6d7d26 100644 (file)
@@ -86,6 +86,7 @@ typedef struct _ringbuf_data {
 
   int           fd;                 /* Current ringbuffer file descriptor */
   FILE         *pdh;
+  gboolean      group_read_access;   /* TRUE if files need to be opened with group read access */
 } ringbuf_data;
 
 static ringbuf_data rb_data;
@@ -123,7 +124,8 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
     return -1;
   }
 
-  rb_data.fd = ws_open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 0600);
+  rb_data.fd = ws_open(rfile->name, O_RDWR|O_BINARY|O_TRUNC|O_CREAT, 
+                            rb_data.group_read_access ? 0640 : 0600);
 
   if (rb_data.fd == -1 && err != NULL) {
     *err = errno;
@@ -136,7 +138,7 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
  * Initialize the ringbuffer data structures
  */
 int
-ringbuf_init(const char *capfile_name, guint num_files)
+ringbuf_init(const char *capfile_name, guint num_files, gboolean group_read_access)
 {
   unsigned int i;
   char        *pfx, *last_pathsep;
@@ -149,6 +151,7 @@ ringbuf_init(const char *capfile_name, guint num_files)
   rb_data.unlimited = FALSE;
   rb_data.fd = -1;
   rb_data.pdh = NULL;
+  rb_data.group_read_access = group_read_access;
 
   /* just to be sure ... */
   if (num_files <= RINGBUFFER_MAX_NUM_FILES) {
index 497c9827d2863a6c7261e7c3f3db05e56fdf4560..02e1ccb8c542c3be3b847b1977d8dd492b9e34dd 100644 (file)
@@ -38,7 +38,7 @@
 /* Maximum number for FAT filesystems */
 #define RINGBUFFER_WARN_NUM_FILES 65535
 
-int ringbuf_init(const char *capture_name, guint num_files);
+int ringbuf_init(const char *capture_name, guint num_files, gboolean group_read_access);
 const gchar *ringbuf_current_filename(void);
 FILE *ringbuf_init_libpcap_fdopen(int *err);
 gboolean ringbuf_switch_file(FILE **pdh, gchar **save_file, int *save_file_fd,