Date: Wed, 25 Apr 2012 21:03:48 GMT From: markham breitbach <markham@ssimicro.com> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/167302: mfiutil doesn't allow RO access to RO attributes for device Message-ID: <201204252103.q3PL3mK9051859@red.freebsd.org> Resent-Message-ID: <201204252110.q3PLAAsV052972@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 167302 >Category: misc >Synopsis: mfiutil doesn't allow RO access to RO attributes for device >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Apr 25 21:10:10 UTC 2012 >Closed-Date: >Last-Modified: >Originator: markham breitbach >Release: 8.1-RELEASE >Organization: SSi Micro >Environment: FreeBSD jellybean.ssimicro.com 8.1-RELEASE-p5 FreeBSD 8.1-RELEASE-p5 #0: Tue Sep 27 16:18:26 UTC 2011 root@i386-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386 >Description: Currently mfiutil is only really useful to run as root beacuse all access to the device is RDWR. This patch allows users with RO privilege to the device to read the RO attributes (mostly SHOW commands). This is useful, for example for a nagios or other monitoring system. >How-To-Repeat: >Fix: created patch for usr.src/mfiutil. Patch attached with submission follows: diff -rupN /tmp/mfiutil/mfi_cmd.c ./mfi_cmd.c --- /tmp/mfiutil/mfi_cmd.c 2012-04-25 20:50:18.000000000 +0000 +++ ./mfi_cmd.c 2012-04-25 20:22:10.000000000 +0000 @@ -301,12 +301,12 @@ mfi_ctrl_get_info(int fd, struct mfi_ctr } int -mfi_open(int unit) +mfi_open(int unit,int access) { char path[MAXPATHLEN]; snprintf(path, sizeof(path), "/dev/mfi%d", unit); - return (open(path, O_RDWR)); + return (open(path, access)); } void diff -rupN /tmp/mfiutil/mfi_config.c ./mfi_config.c --- /tmp/mfiutil/mfi_config.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_config.c 2012-04-25 20:33:15.000000000 +0000 @@ -43,6 +43,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> #include "mfiutil.h" #ifdef DEBUG @@ -154,7 +155,7 @@ clear_config(int ac, char **av) int ch, fd; u_int i; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -546,7 +547,7 @@ create_volume(int ac, char **av) } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -797,7 +798,7 @@ delete_volume(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -856,7 +857,7 @@ add_spare(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -962,7 +963,7 @@ remove_spare(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -1100,7 +1101,7 @@ debug_config(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -1134,7 +1135,7 @@ dump(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_drive.c ./mfi_drive.c --- /tmp/mfiutil/mfi_drive.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_drive.c 2012-04-25 20:33:38.000000000 +0000 @@ -40,6 +40,7 @@ #include <string.h> #include <strings.h> #include <unistd.h> +#include <fcntl.h> #include <cam/scsi/scsi_all.h> #include "mfiutil.h" @@ -296,7 +297,7 @@ drive_set_state(char *drive, uint16_t ne uint8_t mbox[6]; int error, fd; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -389,7 +390,7 @@ start_rebuild(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -438,7 +439,7 @@ abort_rebuild(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -486,7 +487,7 @@ drive_progress(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -545,7 +546,7 @@ drive_clear(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -598,7 +599,7 @@ drive_locate(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_evt.c ./mfi_evt.c --- /tmp/mfiutil/mfi_evt.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_evt.c 2012-04-25 20:34:08.000000000 +0000 @@ -38,6 +38,7 @@ #include <strings.h> #include <time.h> #include <unistd.h> +#include <fcntl.h> #include "mfiutil.h" static int @@ -74,7 +75,7 @@ show_logstate(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -539,7 +540,7 @@ show_events(int ac, char **av) int ch, fd, num_events, verbose; u_int i; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_flash.c ./mfi_flash.c --- /tmp/mfiutil/mfi_flash.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_flash.c 2012-04-25 20:34:53.000000000 +0000 @@ -38,6 +38,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> #include "mfiutil.h" #define FLASH_BUF_SIZE (64 * 1024) @@ -140,7 +141,7 @@ flash_adapter(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_patrol.c ./mfi_patrol.c --- /tmp/mfiutil/mfi_patrol.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_patrol.c 2012-04-25 20:35:16.000000000 +0000 @@ -37,6 +37,7 @@ #include <string.h> #include <time.h> #include <unistd.h> +#include <fcntl.h> #include "mfiutil.h" static char * @@ -84,7 +85,7 @@ show_patrol(int ac, char **av) int fd; u_int i; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -180,7 +181,7 @@ start_patrol(int ac, char **av) { int fd; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -203,7 +204,7 @@ stop_patrol(int ac, char **av) { int fd; - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -270,7 +271,7 @@ patrol_config(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_show.c ./mfi_show.c --- /tmp/mfiutil/mfi_show.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_show.c 2012-04-25 20:30:29.000000000 +0000 @@ -37,6 +37,9 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> +#include <sys/ioctl.h> + #include "mfiutil.h" MFI_TABLE(top, show); @@ -61,7 +64,7 @@ show_adapter(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); @@ -144,7 +147,7 @@ show_battery(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); @@ -249,7 +252,7 @@ show_config(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); @@ -345,7 +348,7 @@ show_volumes(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); @@ -423,7 +426,7 @@ show_drives(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); @@ -519,7 +522,7 @@ show_firmware(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfi_volume.c ./mfi_volume.c --- /tmp/mfiutil/mfi_volume.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfi_volume.c 2012-04-25 20:39:28.000000000 +0000 @@ -37,6 +37,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <fcntl.h> #include "mfiutil.h" MFI_TABLE(top, volume); @@ -158,7 +159,7 @@ volume_cache(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -330,7 +331,7 @@ volume_name(int ac, char **av) return (ENOSPC); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDWR); if (fd < 0) { warn("mfi_open"); return (errno); @@ -374,7 +375,7 @@ volume_progress(int ac, char **av) return (EINVAL); } - fd = mfi_open(mfi_unit); + fd = mfi_open(mfi_unit,O_RDONLY); if (fd < 0) { warn("mfi_open"); return (errno); diff -rupN /tmp/mfiutil/mfiutil.c ./mfiutil.c --- /tmp/mfiutil/mfiutil.c 2010-06-14 02:09:06.000000000 +0000 +++ ./mfiutil.c 2012-04-25 20:41:16.000000000 +0000 @@ -91,7 +91,7 @@ static int version(int ac, char **av) { - printf("mfiutil version 1.0.13"); + printf("mfiutil version 1.0.13b"); #ifdef DEBUG printf(" (DEBUG)"); #endif diff -rupN /tmp/mfiutil/mfiutil.h ./mfiutil.h --- /tmp/mfiutil/mfiutil.h 2010-06-14 02:09:06.000000000 +0000 +++ ./mfiutil.h 2012-04-25 20:21:30.000000000 +0000 @@ -133,7 +133,7 @@ int mfi_lookup_drive(int fd, char *drive int mfi_lookup_volume(int fd, const char *name, uint8_t *target_id); int mfi_dcmd_command(int fd, uint32_t opcode, void *buf, size_t bufsize, uint8_t *mbox, size_t mboxlen, uint8_t *statusp); -int mfi_open(int unit); +int mfi_open(int unit,int access); int mfi_ctrl_get_info(int fd, struct mfi_ctrl_info *info, uint8_t *statusp); int mfi_ld_get_info(int fd, uint8_t target_id, struct mfi_ld_info *info, uint8_t *statusp); >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204252103.q3PL3mK9051859>