Professional Web Applications Themes

Change Unix file permissions from a Carbon app? - Mac Programming

In article <not.here-ya02408000R3007030100130001news.dial.pipex.com>, [email]not.heredial.pipex.com[/email] (Phil Taylor) wrote: > I'm trying to invoke a Unix tool from within my CFM-Carbon app. > To do this I can create a file containing the command line input, > save it in the user's home directory and send an Apple event > to the Finder to launch Terminal with the file as input. > > This all works fine provided that the command file is marked > as executable by the user, but I need to do this programmatically. > How can I perform the equivalent of chmod from within my app? 1.) Look ...

  1. #1

    Default Re: Change Unix file permissions from a Carbon app?

    In article <not.here-ya02408000R3007030100130001news.dial.pipex.com>,
    [email]not.heredial.pipex.com[/email] (Phil Taylor) wrote:
    > I'm trying to invoke a Unix tool from within my CFM-Carbon app.
    > To do this I can create a file containing the command line input,
    > save it in the user's home directory and send an Apple event
    > to the Finder to launch Terminal with the file as input.
    >
    > This all works fine provided that the command file is marked
    > as executable by the user, but I need to do this programmatically.
    > How can I perform the equivalent of chmod from within my app?
    1.)
    Look in <Files.h> at FSSetCatalogInfo(), and struct FSPermissionInfo


    2.)
    chmod is a system call. You can just call it, but you will need
    to dynamicly link to Mach-O from CFM. See:


    Calling Quartz Functions From a CFM Application


    <[url]http://developer.apple.com/doentation/GraphicsImaging/Conceptual/Quar[/url]
    tzPrimer/qprimer_main/chapter_1_section_6.html#//apple_ref/doc/uid/DontLi
    nkBookID_99-DontLinkChapterID_1-TPXREF21>

    for an example of doing this.

    Look in the System framework for chmod().

    From Terminal, do:

    ---------
    man 2 chmod
    ---------

    for more information.
    David Phillip Oster Guest

  2. #2

    Default Re: Change Unix file permissions from a Carbon app?

    In article <oster-E9E4D4.17162229072003newssvr23-ext.news.prodigy.com>,
    David Phillip Oster <osterieee.org> wrote:
    > In article <not.here-ya02408000R3007030100130001news.dial.pipex.com>,
    > [email]not.heredial.pipex.com[/email] (Phil Taylor) wrote:
    >
    > > I'm trying to invoke a Unix tool from within my CFM-Carbon app.
    > > To do this I can create a file containing the command line input,
    > > save it in the user's home directory and send an Apple event
    > > to the Finder to launch Terminal with the file as input.
    > >
    > > This all works fine provided that the command file is marked
    > > as executable by the user, but I need to do this programmatically.
    > > How can I perform the equivalent of chmod from within my app?
    >
    > 1.)
    > Look in <Files.h> at FSSetCatalogInfo(), and struct FSPermissionInfo
    >
    >
    > 2.)
    > chmod is a system call. You can just call it, but you will need
    > to dynamicly link to Mach-O from CFM. See:
    >
    >
    > Calling Quartz Functions From a CFM Application
    >
    >
    > <[url]http://developer.apple.com/doentation/GraphicsImaging/Conceptual/Quar[/url]
    > tzPrimer/qprimer_main/chapter_1_section_6.html#//apple_ref/doc/uid/DontLi
    > nkBookID_99-DontLinkChapterID_1-TPXREF21>
    >
    > for an example of doing this.
    >
    > Look in the System framework for chmod().
    >
    > From Terminal, do:
    >
    > ---------
    > man 2 chmod
    > ---------
    >
    > for more information.
    Many thanks! That looks like just what I need.

    Phil Taylor
    Phil Taylor Guest

  3. #3

    Default Re: Change Unix file permissions from a Carbon app?


    Hmm, still having trouble with this.

    man 2 chmod

    tells me that I need the value 700 to set user permissions to rwx,
    and doing that manually in terminal works OK.

    So I try getting the existing permissions using FSGetCatalogInfo,
    with kFSCatInfoPermissions as the FSCatalogInfoBitmap parameter,
    change permissions and use FSSetCatalogInfo to set the new value.

    However, the permissions field of FSCatalogInfo is an array of
    four UINT32s. So which do I change? The online docs say:

    "permissions
    User and group permission information. The Mac OS 8 and 9 File Manager does
    not use or enforce this permission information. It could be used by a file
    server program or other operating system (primarily Mac OS X)."

    Which is not much use to me.

    Experimentally, I find that setting permissions[2] to 0x700, or ORing
    it with 0x700 causes FSSetCatalogInfo to return a -36 OSErr, while
    changing any (or all) of the other three has no effect, leaving the
    file's permissions unchanged.

    Any idea what I'm doing wrong here?

    I'd rather not mess with Mach-O at the moment, since that's a whole
    new world.



    In article <not.here-ya02408000R3007030152040001news.dial.pipex.com>,
    [email]not.heredial.pipex.com[/email] (Phil Taylor) wrote:
    > In article <oster-E9E4D4.17162229072003newssvr23-ext.news.prodigy.com>,
    > David Phillip Oster <osterieee.org> wrote:
    >
    > > In article <not.here-ya02408000R3007030100130001news.dial.pipex.com>,
    > > [email]not.heredial.pipex.com[/email] (Phil Taylor) wrote:
    > >
    > > > I'm trying to invoke a Unix tool from within my CFM-Carbon app.
    > > > To do this I can create a file containing the command line input,
    > > > save it in the user's home directory and send an Apple event
    > > > to the Finder to launch Terminal with the file as input.
    > > >
    > > > This all works fine provided that the command file is marked
    > > > as executable by the user, but I need to do this programmatically.
    > > > How can I perform the equivalent of chmod from within my app?
    > >
    > > 1.)
    > > Look in <Files.h> at FSSetCatalogInfo(), and struct FSPermissionInfo
    > >
    > >
    > > 2.)
    > > chmod is a system call. You can just call it, but you will need
    > > to dynamicly link to Mach-O from CFM. See:
    > >
    > >
    > > Calling Quartz Functions From a CFM Application
    > >
    > >
    > > <[url]http://developer.apple.com/doentation/GraphicsImaging/Conceptual/Quar[/url]
    > > tzPrimer/qprimer_main/chapter_1_section_6.html#//apple_ref/doc/uid/DontLi
    > > nkBookID_99-DontLinkChapterID_1-TPXREF21>
    > >
    > > for an example of doing this.
    > >
    > > Look in the System framework for chmod().
    > >
    > > From Terminal, do:
    > >
    > > ---------
    > > man 2 chmod
    > > ---------
    > >
    > > for more information.
    >
    > Many thanks! That looks like just what I need.
    Phil Taylor
    Phil Taylor Guest

  4. #4

    Default Re: Change Unix file permissions from a Carbon app?

    Phil Taylor wrote:
    > Hmm, still having trouble with this.
    >
    > man 2 chmod
    >
    > tells me that I need the value 700 to set user permissions to rwx,
    > and doing that manually in terminal works OK.
    >
    [...]
    >
    > Experimentally, I find that setting permissions[2] to 0x700, or ORing
    > it with 0x700 causes FSSetCatalogInfo to return a -36 OSErr, while
    > changing any (or all) of the other three has no effect, leaving the
    > file's permissions unchanged.
    >
    > Any idea what I'm doing wrong here?
    I don't know if this helps in that particular situation but this number
    is supposed to be octal, not hex, and I remember when passing e.g. 750
    to mkdir(), I needed to pass 0750. Yes. The leading zero was significant.

    Patryk 'Silver Dream !' Łogiewa Guest

  5. #5

    Default Re: Change Unix file permissions from a Carbon app?

    In article <3f27d3df$1news.inet.com.pl>,
    "Patryk 'Silver Dream !' ?ogiewa" <silverdrinet.remove.it.pl> wrote:
    > I don't know if this helps in that particular situation but this number
    > is supposed to be octal, not hex, and I remember when passing e.g. 750
    > to mkdir(), I needed to pass 0750. Yes. The leading zero was significant.
    Sure. In C, 750 is interpreted as a decimal number and 0750 as an octal
    number. The leading 0 is the equivalent of the leading 0x for
    hexadecimal numbers.

    Patrick
    --
    Patrick Stadelmann <Patrick.Stadelmannunine.ch>
    Patrick Stadelmann Guest

  6. #6

    Default Re: Change Unix file permissions from a Carbon app?

    In article <MPG.1991e9c88c84325f989683News.Individual.NET> ,
    James Weatherley <newsweatherley.net> wrote:
    > In article <Patrick.Stadelmann-1AA30D.16315930072003news.fu-berlin.de>,
    > [email]Patrick.Stadelmannunine.ch[/email] says...
    > > In article <3f27d3df$1news.inet.com.pl>,
    > > "Patryk 'Silver Dream !' ?ogiewa" <silverdrinet.remove.it.pl> wrote:
    > >
    > > > I don't know if this helps in that particular situation but this number
    > > > is supposed to be octal, not hex, and I remember when passing e.g. 750
    > > > to mkdir(), I needed to pass 0750. Yes. The leading zero was significant.
    > >
    > > Sure. In C, 750 is interpreted as a decimal number and 0750 as an octal
    > > number. The leading 0 is the equivalent of the leading 0x for
    > > hexadecimal numbers.
    > >
    > > Patrick
    > >
    >
    > And this leads to great obfuscation possiblities:
    I talked to a Navy man once, who claimed that he'd worked in an
    assembler that implemented the rule:

    "Leading zero means base 8."

    even for floating point numbers. So,

    .5 was one half (five tenths)

    but

    0.5 was five eighths.

    This created many subtle errors in the navigation software.
    David Phillip Oster Guest

  7. #7

    Default Re: Change Unix file permissions from a Carbon app?

    David Phillip Oster wrote:
    [...]
    >
    > I talked to a Navy man once, who claimed that he'd worked in an
    > assembler that implemented the rule:
    >
    > "Leading zero means base 8."
    >
    > even for floating point numbers. So,
    >
    > .5 was one half (five tenths)
    >
    > but
    >
    > 0.5 was five eighths.
    >
    > This created many subtle errors in the navigation software.
    .... and the Bermuda Triangle legend began. ;-)

    Patryk 'Silver Dream !' Łogiewa Guest

  8. #8

    Default Re: Change Unix file permissions from a Carbon app?

    OK, I figured it out (I think).

    permissions[2] contains the usual set of permissions in the
    low order ten bits, i.e. drwxrwxrwx, so the value I need to
    OR with it to set the user permission to execute is 0x40.
    700 octal would have worked too, as you pointed out. I've
    still no idea what the rest of the permissions array is for
    so I'll just leave it alone.

    Thanks again for pointing me in the right direction.

    Phil Taylor
    Phil Taylor Guest

Similar Threads

  1. how do you change IUSR_machinename permissions?
    By Nathon Jones in forum Dreamweaver AppDev
    Replies: 3
    Last Post: April 7th, 08:41 PM
  2. Problem with permissions between w2k & unix
    By Julian in forum Linux / Unix Administration
    Replies: 0
    Last Post: February 19th, 12:15 PM
  3. backup under privileged mode (unix permissions)
    By Simon Strandgaard in forum Ruby
    Replies: 5
    Last Post: September 12th, 02:24 PM
  4. cant change file permissions from read only on network
    By craig in forum Windows Setup, Administration & Security
    Replies: 1
    Last Post: July 20th, 07:19 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