mounting floppy as a non-root user in C.
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > mounting floppy as a non-root user in C.




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    mounting floppy as a non-root user in C.  
dalbosco


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

Hi,


I am currently writing a Unix software ( Unix means "Unix portable") and
i'm facing a problem with writing data on a floppy as a simple user.


I'v given below a working example of what my problem is.
As a user the program answers :
# ./main
mount failed : Operation not permitted.
umount failed : Invalid argument.


Though as root it succeeds and replies:
# su -c ./main
Password:
mount succeeded.
umount succeeded.


What embarasses me, is that in /etc/fstab i can add the option "user" to
the floppy entry:

/dev/fd0  /mnt/floppy             auto    noauto,user,kudzu 0 0



and then in a shell as a user I can succesfully do "mount /mnt/floppy".

So I was wondering how to do the same in a C program WITHOUT making a
system("mount /mnt/floppy") call as far as i wan't to check the return
value of the mounting operation to be able to detect if there is a
floppy in the drive or not, not being able to write the file if the user
retrieves the floppy too fast...
Does anyone know how to do that?
Thanks by advance.
--
Dalbosco
Jean-François


#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <errno.h>


static void
check_error_ret(int ret, const char* szCmd)
{
if( -1 == ret )
{
printf("%s failed : %s.\n", szCmd, strerror(errno));
}
else
{
printf("%s succeeded.\n", szCmd);
}
}


int
main(int argc, char** argv)
{
int ret = 0;


ret = mount("/dev/fd0", "/mnt/floppy", "vfat", MS_MGC_VAL, "");
check_error_ret(ret, "mount");


ret = umount("/mnt/floppy");
check_error_ret(ret, "umount");
}





[ Post a follow-up to this message ]



    Re: mounting floppy as a non-root user in C.  
Daniel Rakel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-28-04 11:19 PM

dalbosco wrote:

> I'v given below a working example of what my problem is.
> As a user the program answers :
> # ./main
> mount failed : Operation not permitted.
> umount failed : Invalid argument.
>
> Though as root it succeeds and replies:
> # su -c ./main
> Password:
> mount succeeded.
> umount succeeded.
>
> What embarasses me, is that in /etc/fstab i can add the option "user" to
> the floppy entry:
>
> /dev/fd0  /mnt/floppy             auto    noauto,user,kudzu 0 0
>
> and then in a shell as a user I can succesfully do "mount /mnt/floppy".

To mount you need root privileges in either case. mount(1) as a
setuid-root program has these privileges and checks the user option in
/etc/fstab when called by an unprivileged user.

Regards,
Daniel





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:25 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register