- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: setuid
Operating System - HP-UX
1758620
Members
1984
Online
108874
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 06:01 PM
тАО07-14-2003 06:01 PM
I have a c program as below. the execute file owner is not root, assume is use1. I'd like to set the user id to ZERO while run the program.
But this program "setuid(0)" always run error.
Does anyone has the experience how to use the setuid() in C program?
#include
#include
main()
if(setuid(0) < 0) {
printf("setuid error ");
exit(1);
}
But this program "setuid(0)" always run error.
Does anyone has the experience how to use the setuid() in C program?
#include
#include
main()
if(setuid(0) < 0) {
printf("setuid error ");
exit(1);
}
Hero
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 06:59 PM
тАО07-14-2003 06:59 PM
Solution
With setuid() you have to have root as the owner of the file and have setuid bit set on the file. Then it will work properly.
Here is a sample program which sets the uid to root and runs some file and then exits.
#include
#include
#include
main(argc,argv)
int argc;
int *argv[];
{
int uid;
char *command=(char *)malloc(2048);
uid=getuid();
setuid(0);
strcpy(command,"/home/rshukla/scripts/killfsq");
if ( system(command) !=0 ) {
printf("1:Failed to kill the FSQ \n");
exit(1);
}
printf("0:FSQ Killed ...\n");
}
the compiled program fsqkill should have following permissions.
-r-sr-xr-x 1 root sys 20480 Sep 23 2002 fsqkill
Then it will work properly.
Thanks
Rajeev
Here is a sample program which sets the uid to root and runs some file and then exits.
#include
#include
#include
main(argc,argv)
int argc;
int *argv[];
{
int uid;
char *command=(char *)malloc(2048);
uid=getuid();
setuid(0);
strcpy(command,"/home/rshukla/scripts/killfsq");
if ( system(command) !=0 ) {
printf("1:Failed to kill the FSQ \n");
exit(1);
}
printf("0:FSQ Killed ...\n");
}
the compiled program fsqkill should have following permissions.
-r-sr-xr-x 1 root sys 20480 Sep 23 2002 fsqkill
Then it will work properly.
Thanks
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2003 08:05 PM
тАО07-14-2003 08:05 PM
Re: setuid
Yes, I have just a little bit of experience in using setuid in c. What you are trying to do is hopeless unless 1) root owns this executable and 2) the setuid bit is set on the file (e.g chmod 4755 myfile). It's a very good thing it works this way!! If your method worked then anyone could become super-user anytime they wanted to!
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 12:42 PM
тАО12-18-2003 12:42 PM
Re: setuid
I found that with the Goldbase June 2003 and Dec 2003 pathes installed, it fails all the time. Don't know if this is on your system.
Tried uninstalling and it started working again. They must have changed the library ??
Tried uninstalling and it started working again. They must have changed the library ??
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP