I'm writing a program and I need it to goto root. The user knows the password but I'm using QT and do not know how-to get the password to su.
I'm writing a program and I need it to goto root. The user knows the password but I'm using QT and do not know how-to get the password to su.
I doubt you could use setuid(RootID) unless you ran the program as root, in which case, it could do what you wanted anyway. You can get it from man getpwnam
One thing though, which I prefer the manual pages on FreeBSD, it uses the library -lc (which isn't mentioned here), but I don't think you need to use it, bceause it's just the standard C library
Hope this helps
- Daniel Wallace
Hi,
even I wanted an answer to a similar question, How do I trap the return value (well, not exactly value as I can use exec to do that).
Suppose i write..
then how can I collect the return string "Password: " and then pass the value (password) to that program(command) again?Code:system("su");
Also, another question I wanted an answer to is the #defines' in the header files. What is the significance of two underscores before the word.
Eg: __NULL__ etc. which is most commonly seen in standard headerfiles like stdio etc. Why cannot they simply use
Also, if such a statement is not defined, how does the compiler know when we use...Code:#define NULL 0
Regards,Code:if(xxx == NULL) ... ...
Harsha.
Help everyone you can
But "su" isn't going to help you, no matter how you roll it. It will always be a child process of your program, so only the child process (that's su) will have root access. Your program will remain with the access which it started with.
See the manual page for setuid(). There are all sorts of side issues regarding security etc. Be sure about why you want to goto root in the first place, and be specific about what you want to achieve when you get there. If you fudge the issue, your program will be insecure.
> What is the significance of two underscores before the word.
It means you shouldn't be using them.
Anything beginning with an underscore is reserved for use by the system. It may appear / disappear / change meaning at any time.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hi Salem,
Thanks for the "its-not-your-business" answer. But I was wondering if I can have some more details about it? Those answers ("Its reserver for use by system" etc etc)... keep my brain racked until I find more. I need answers in detail (Or even a LINK to anyplace that explains them in detail). I couldnt find them in the Tutorials or Advanced Tutorials and have never come across them in the standard C Books.
1. Can only the compiler designers use them in their standard libraries (which they ship along with their packages). If so, how do they use them and for what purposes?
2. Can I not use those variables for any benificial purposes in my header files?
Please give me a link to an appropriate explanation.
Thank you and
Kind Regards,
Harsha.
Help everyone you can
If they have an underscore, the compiler will use them. The compiler could use them for any purpose, to see what chip you are using to if you have a local APIC or not, etc., stuff we usually don't have to deal with unless we are writing compilers or kernels.
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
> But I was wondering if I can have some more details about it?
Read the standard then.
This is the last draft of C99, which is available for free. Proper copies cost money
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/
Then pay attention to
7.1.3 Reserved identifiers
> 2. Can I not use those variables for any benificial purposes in my header files?
Sure you can - but the risk is enormous in doing so.
You risk having to change your code every time you upgrade your compiler (in any way), or change to a new compiler.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.