The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 07:44 AM
asking about return code naamas03 Shell Programming and Scripting 3 08-28-2007 05:53 AM
return value of a function prez Shell Programming and Scripting 3 08-22-2007 06:08 PM
What is wrapper script and how to write chiru UNIX for Dummies Questions & Answers 1 06-12-2006 06:23 AM
Return Code of tar in AIX dupeng AIX 3 02-23-2004 12:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2008
pwd pwd is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 5
how to write a wrapper c code to return uid using getuid() function

And how to use setuid() ?
thanks
  #2 (permalink)  
Old 05-12-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807

Code:
#include <unistd.h>
uid_t myuid(void)
{
    return getuid();
}

No offense meant, but setuid is a major security risk. Don't go implementing your code on your system unless it is a home desktop that can be trashed.

setuid requires either root or the so-called sticky bit set to allow the program to change it's username.

It may seem simple but there is a lot to writing a setuid program:

http://nob.cs.ucdavis.edu/bishop/sec...sproglogin.pdf
  #3 (permalink)  
Old 05-12-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
setuid() is pretty integral to a safe unix process.
One basic mode is for a root privileged parent to acquire
resources only it can handle (ports < 1024) and then delegate service to setuid(> 0) children/threads, ala OpenSSH and many other pieces of software via IPC.

Given it's not easy to do securely and does pose a considerable security issue: mostly races and various abuses of unsafe programing practices in the privileged process.
  #4 (permalink)  
Old 05-13-2008
pwd pwd is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 5
thanks jim mcnamara,
i want catch value of getuid() to put into a logfile. How to do it?
  #5 (permalink)  
Old 05-13-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,807
one way:

Code:
id >> logfile

c code

Code:
/* myid.c */
#include <unistd.h>
uid_t myuid(void)
{
    return getuid();
}

int main()
{
     printf("%d\n", myuid() );
     return 0;
}

cc myid.c -o myid

in your script

Code:
myid >> logfile

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0