forked from osmocom/wireshark
As mentioned on the users-mailinglist[1], it could be useful to have groups read access to the ringbuffer that dumpcap creates. That way, a group of people can access the capture files without having to use root access.
[1] http://www.wireshark.org/lists/wireshark-users/201008/msg00235.html svn path=/trunk/; revision=33978
This commit is contained in:
parent
42a0f16cef
commit
f17c5ac01f
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue