LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2007, 10:22 PM   #1
Keshav V
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Rep: Reputation: 0
Login through program


Hi,

I have a GTK+ program which needs special privilege to perform certain to do few file copying.

So only users with special privilege can do it.

One option is to recommend the user to login with special privileges and then execute the program.

Other option is to build a logic inside the program to detect whether the current user is having enough privileges, if not provide a GUI interface to him to login, Just like any other administrative application (e.g. network configuration applet) works.

Please tell me how to do this in a program.

thank you
Keshav
 
Old 07-11-2007, 08:32 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
This is a common Unix programming issue. I would create a separate group and user account with the program's name. Disable the user account (set the password to expired, etc.,) change the restricted file ownership to program:program, set the permissions to something like 770, 660, or 440, and add the group to the appropriate real user accounts. libc should take care of the rest.

If you don't want to use the built-in UID/GID system, you'll have to come up with your own which maintains a list of users, hashed passwords, and activity permissions. That's a lot of work when Unix already comes with this functionality specifically for these purposes.
ta0kira

Last edited by ta0kira; 07-11-2007 at 08:40 AM.
 
Old 07-11-2007, 11:30 AM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
What I would have tried to say, but much better phrased.

This is the way to do it inside the normal *nix framework, any reason you think this won't work for you?
 
Old 07-11-2007, 10:30 PM   #4
Keshav V
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Re : Login through program

Quote:
Originally Posted by archtoad6
What I would have tried to say, but much better phrased.

This is the way to do it inside the normal *nix framework, any reason you think this won't work for you?
To ta0kira and archtoad6,

Thank for your reply..

I really did not understood much from your reply.. I am pretty new to programming and it may take a while for me to understand.

To give more info on my work, this will be distributed via CD and user is expected to run the program from CD only once. Hence it looks difficult for me to alter user groups and file permissions.

I am thinking of suggesting the user to login with special privileges i.e. as root. But debian and ubuntu are problematic, because of the sudo thing..

Thank you
Keshav
 
Old 07-12-2007, 04:37 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
A number of distros don't allow graphical root login by default. So I guess that that option is totally out.

You can have a look at setuid() which will eleveate the permissions of the program to that of the owner regardless of the user that executes the program. It however needs a special bit set in the permissions 'field' and I'm not sure if that possible on a CD.
And it implies that every user that gets hold of the CD will be able to run the program with these privileges.
 
Old 07-12-2007, 05:32 AM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Wouldn't the suggested permissions & file ownership be associated w/ the program file on the CD?

BTW, man chown & man chmod might get you started.
 
Old 07-12-2007, 09:48 AM   #7
Keshav V
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by archtoad6
Wouldn't the suggested permissions & file ownership be associated w/ the program file on the CD?

BTW, man chown & man chmod might get you started.
I will try out the new suggestions you have give and setuid() and comeback..

thank you
Keshav
 
Old 07-23-2007, 12:52 PM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
What happened?
 
Old 10-11-2007, 06:25 AM   #9
Keshav V
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

I was caught up with some busy work. so couldn't take up this.

Meantime, I read some online documents saying that, usage of setuid() is not safe?? Any thoughts on this?

-Keshav

Quote:
Originally Posted by archtoad6 View Post
What happened?
 
Old 10-11-2007, 11:08 PM   #10
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
I don't know in what context it was said. The problem with setuid is that it elevates the privileges to those of the user who owns the file (which is usually root). Hence a setuid program can do damage, but that fully depends on what the program does. If it's properly written, I don't see problems using setuid.

As you're writing your own program, only elevate when you have to and fall back once done. I have a program that needs to configure a PCI card and requires root privileges for that. During the startup of the program, I elevate the permissions, configure the card, and go back to normal permissions. Next I don't have a need to elevate so I don't.

An example of a program that requires setuid is ping.

Code:
wim@btd-techweb01:~/tacinc/web$ ls -l /bin/ping
-rws--x--x  1 root bin 29232 2004-11-04 06:55 /bin/ping*
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
execute program only once during login tcma Linux - General 6 11-03-2004 08:55 AM
i don't want the login program alaios Linux - General 6 08-10-2004 02:09 PM
How to start program on X login donbellioni Linux - General 11 07-28-2004 04:45 PM
A program not working in one login Sharko Red Hat 2 03-19-2004 09:26 AM
Autostarting a program upon login... Thymox Linux - General 3 02-07-2002 11:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration