Professional Web Applications Themes

How to get the user and group ID? - Mac Programming

Dear All How do you get the user ID and the group ID? I have a function to get the IDs from a file, but when I not the owner I can't change the permissions of this file. I will test the current user/group ID but I can't find functions to get this information. Thanks Rene ------------------------------------- de is never read I'm grenenewsgroup at web dot de...

  1. #1

    Default How to get the user and group ID?

    Dear All

    How do you get the user ID and the group ID? I have a function to get the
    IDs from a file, but when I not the owner I can't change the permissions of
    this file. I will test the current user/group ID but I can't find functions
    to get this information.


    Thanks
    Rene


    -------------------------------------
    de is never read
    I'm grenenewsgroup at web dot de

    Rene Guest

  2. #2

    Default Re: How to get the user and group ID?

    On Mon, 8 Dec 2003, Rene Gutschmidt wrote:
     

    getuid/geteuid/getgid

    Fred
     

    Frederick Guest

  3. #3

    Default Re: How to get the user and group ID?

    >> How do you get the user ID and the group ID? I have a function to get the 
    >
    > getuid/geteuid/getgid
    >[/ref]

    Dear Fred

    I think this function are not correct for me, because this function are
    defined and implement in the "unistd.h" and the implementation of this
    functions are:

    int getuid(void) {return 200 ;}
    int geteuid(void) {return 200 ;}
    int getgid(void) {return 100 ;}

    This are global values, but I need the user ID of the current user. E.g.
    When I logged in my system, then I have user ID 501. (In the terminal
    command 'id').

    Or I used the false header file? Give it not a mac specify function?

    Environment:
    CodeWarrior 9.1
    MacOS X 10.3.1



    Rene


    -------------------------------------
    de is never read
    I'm grenenewsgroup at web dot de

    Rene Guest

  4. #4

    Default Re: How to get the user and group ID?

    Hi Rene,


    Rene Gutschmidt <de> writes: 

    You are probably looking at a Mac OS Classic header where the concept
    of user and groups is different altogether and those functions don't
    make sense.
     

    For that OS you want to look at /usr/include/unistd.h, which only has
    prototypes but no implementation.
     

    Users and groups (in this sense) are a Unix feature, not Mac specific
    stuff. There are probably convenience wrappers in Cocoa, though.


    benny
    Benjamin Guest

  5. #5

    Default Re: How to get the user and group ID?

    In article <BBFBA126.288%de>,
    Rene Gutschmidt <de> wrote:
     

    On the "Access Paths" panel, "System" list, of your projects
    "Settings..." on the Edit menu, the first path should be:

    {OS X Volume}/usr/include

    (so it is searched before MSL.) After you have made this change, use the
    menu command: "Re-Search for Files".

    and you should have the System framework in your Frameworks panel.
    David Guest

  6. #6

    Default Re: How to get the user and group ID?

    Thanks for the '/usr/include/unistd.h'.

     

    I think this is my next problem. - With the new file and correct access
    paths opened my editor the right header file, but I compile/link with the
    'MSL_All_Carbon.Lib' (from CW9.1) and the call of 'getuid()' goes to the
    getuid from the MSL 'unistd.h', also the false function.

    What library must I link in my project? - I think you mean this with system
    framework or?

    Can I link both libraries? I think a link warning pops off with the message:
    found two e.g. getuid()-function and one wasn't used. And what getuid were
    use?


    Thanks
    Rene


    -------------------------------------
    de is never read
    I'm grenenewsgroup at web dot de

    Rene Guest

  7. #7

    Default Re: How to get the user and group ID?

    Hi Rene,

    Rene Gutschmidt <de> writes: 

    Have you already tried a CW group? This seem to be a question about
    CW project setup. While there are probably a lot of CW users here,
    too, you want to ask the real CW experts, I think.

    benny
    Benjamin Guest

  8. #8

    Default Re: How to get the user and group ID?

    In article <BBFC98E1.2D4%de>,
    Rene Gutschmidt <de> wrote:
     
    >
    > I think this is my next problem. - With the new file and correct access
    > paths opened my editor the right header file, but I compile/link with the
    > 'MSL_All_Carbon.Lib' (from CW9.1) and the call of 'getuid()' goes to the
    > getuid from the MSL 'unistd.h', also the false function.
    >
    > What library must I link in my project? - I think you mean this with system
    > framework or?
    >
    > Can I link both libraries? I think a link warning pops off with the message:
    > found two e.g. getuid()-function and one wasn't used. And what getuid were
    > use?[/ref]

    Are you writing a CFM program or a Mach-O one? i.e., Which linker are you
    using? (look at the Target Settings panel of your project's Settings.
    The "Macintosh PowerPC" one is the CFM one, the "Mac OS X PowerPC Mach-O"
    is the Mach-O one.

    In a Mach-O project, I'd expect you to be linking with MSL_ALL_Mach-O.lib ,
    and I'd not expect any linking conflicts with the System framework.

    In a CFM project, you can't link to any Mach-O library directly, but
    you can load them into your address space at run time, and extract
    function pointers that you can call. (you'll need some glue code if
    you want to pass one of your function pointers to a Mach-O routine
    for it to call back.) Search in groups.google.com and google.com for info.

    Here is some sample code to show you how you might to it.

    typedef int (*ErrnoProc)(void);
    typedef int (*OpenProc)(const char *path, int flags);
    typedef int (*CloseProc)(int);
    typedef int (*FcntlProc)(int fd, int cmd, int arg);
    typedef int (*ReadProc)(int d, void *buf, size_t nbytes);
    typedef int (*WriteProc)(int d, const void *buf, size_t nbytes);

    static ErrnoProc errnop;
    static OpenProc openp;
    static CloseProc closep;
    static FcntlProc fcntlp;
    static ReadProc readp;
    static WriteProc writep;

    OSStatus WriteCarbonSerialPortX(CarbonSerialPortX* inP, long *ioLen, const void *inBuffer){
    int val;
    if(-1 == (val = (*writep)(inP->refNum, inBuffer, *ioLen))){
    if ( (*errnop)() ) return (*errnop)();
    else return val;
    }
    *ioLen = val;
    return noErr;
    }


    if(noErr == err){
    err = LoadFrameworkBundle(CFSTR("System.framework"), &sysBundle);
    }
    if(noErr == err){
    // see: errno.h in the System framework for the reasoning behind the next line
    errnop = reinterpret_cast_(ErrnoProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("__error")));
    openp = reinterpret_cast_(OpenProc)(CFBundleGetFunctionPoi nterForName(sysBundle, CFSTR("open")));
    closep = reinterpret_cast_(CloseProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("close")));
    fcntlp = reinterpret_cast_(FcntlProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("fcntl")));
    readp = reinterpret_cast_(ReadProc)(CFBundleGetFunctionPoi nterForName(sysBundle, CFSTR("read")));
    writep = reinterpret_cast_(WriteProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("write")));
    ....
    note: leave the framework bundle loaded for the life of the program.

    // ---------------------------------------------------------------------------------
    // LoadFrameworkBundle
    // ---------------------------------------------------------------------------------
    OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
    // This routine finds a the named framework and creates a CFBundle
    // object for it. It looks for the framework in the frameworks folder,
    // as defined by the Folder Manager. Currently this is
    // "/System/Library/Frameworks", but we recommend that you avoid hard coded
    // paths to ensure future compatibility.
    //
    // You might think that you could use CFBundleGetBundleWithIdentifier but
    // that only finds bundles that are already loaded into your context.
    // That would work in the case of the System framework but it wouldn't
    // work if you're using some other, less-obvious, framework.
    {
    #if PP_Target_Classic
    #pragma unused(framework, bundlePtr)
    return paramErr;
    #else
    OSStatus err;
    FSRef frameworksFolderRef;
    CFURLRef baseURL;
    CFURLRef bundleURL;

    *bundlePtr = NULL;

    baseURL = NULL;
    bundleURL = NULL;

    // Find the frameworks folder and create a URL for it.

    err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
    if (err == noErr) {
    baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
    if (baseURL == NULL) {
    err = coreFoundationUnknownErr;
    }
    }

    // Append the name of the framework to the URL.

    if (err == noErr) {
    bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocator SystemDefault, baseURL, framework, false);
    if (bundleURL == NULL) {
    err = coreFoundationUnknownErr;
    }
    }

    // Create a bundle based on that URL and load the bundle into memory.
    // We never unload the bundle, which is reasonable in this case because
    // the sample assumes that you'll be calling functions from this
    // framework throughout the life of your application.

    if (err == noErr) {
    *bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
    if (*bundlePtr == NULL) {
    err = coreFoundationUnknownErr;
    }
    }
    if (err == noErr) {
    if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
    err = coreFoundationUnknownErr;
    }
    }

    // Clean up.

    if (err != noErr && *bundlePtr != NULL) {
    CFRelease(*bundlePtr);
    *bundlePtr = NULL;
    }
    if (bundleURL != NULL) {
    CFRelease(bundleURL);
    }
    if (baseURL != NULL) {
    CFRelease(baseURL);
    }

    return err;
    #endif
    }
    David Guest

  9. #9

    Default Re: How to get the user and group ID?

    >> I compile/link with the 'MSL_All_Carbon.Lib' (from CW9.1) and the 
    >
    > Have you already tried a CW group? This seem to be a question about
    > CW project setup. While there are probably a lot of CW users here,
    > too, you want to ask the real CW experts, I think.[/ref]


    Okay thanks for helping - I ask my problem in an CW group.


    Rene

    Rene Guest

Similar Threads

  1. What to do to add a secondary user group?
    By qazmlp in forum Linux / Unix Administration
    Replies: 2
    Last Post: August 19th, 12:23 PM
  2. IIUG94UC2-ifx user group
    By Xavier in forum Informix
    Replies: 9
    Last Post: December 29th, 11:19 PM
  3. group limit per user
    By Barry in forum Sun Solaris
    Replies: 4
    Last Post: August 15th, 09:54 AM
  4. how to add user group member
    By Kristianto in forum Sun Solaris
    Replies: 1
    Last Post: June 26th, 11:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139