Change Unix file permissions from a Carbon app?

Ask a Question related to Mac Programming, Design and Development.

  1. #1

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

    In article <not.here-ya02408000R3007030100130001@news.dial.pipex.com>,
    [email]not.here@dial.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/documentation/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. Similar Questions and Discussions

    1. how do you change IUSR_machinename permissions?
      Having a nightmare with the old DW bug when using an Access database and ASP pages that produces this error: "Could not open "unknown"; file...
    2. filesystem permissions change by themselves...
      permissions on my /opt filesystem are changing daily, seeming by themselves. i.e. I tried to run a scipt and noticed that the permissions on...
    3. Problem with permissions between w2k & unix
      Hi there! I've got a unix mapped drive in a w2k server using the nfs w2k services for unix. I can create and delete files in the unix drive...
    4. backup under privileged mode (unix permissions)
      I have some data which I make a backup of on daily basis. The data has many different owners/groups. I have writen some Ruby which does the job...
    5. cant change file permissions from read only on network
      Im on WindowsXP Home--I have a network setup and experience no problems, except for one. I can share drives on each computer and see all the data,...
  3. #2

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

    In article <oster-E9E4D4.17162229072003@newssvr23-ext.news.prodigy.com>,
    David Phillip Oster <oster@ieee.org> wrote:
    > In article <not.here-ya02408000R3007030100130001@news.dial.pipex.com>,
    > [email]not.here@dial.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/documentation/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. #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-ya02408000R3007030152040001@news.dial.pipex.com>,
    [email]not.here@dial.pipex.com[/email] (Phil Taylor) wrote:
    > In article <oster-E9E4D4.17162229072003@newssvr23-ext.news.prodigy.com>,
    > David Phillip Oster <oster@ieee.org> wrote:
    >
    > > In article <not.here-ya02408000R3007030100130001@news.dial.pipex.com>,
    > > [email]not.here@dial.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/documentation/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

  5. #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

  6. #5

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

    In article <3f27d3df$1@news.inet.com.pl>,
    "Patryk 'Silver Dream !' ?ogiewa" <silverdr@inet.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.Stadelmann@unine.ch>
    Patrick Stadelmann Guest

  7. #6

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

    In article <MPG.1991e9c88c84325f989683@News.Individual.NET> ,
    James Weatherley <news@weatherley.net> wrote:
    > In article <Patrick.Stadelmann-1AA30D.16315930072003@news.fu-berlin.de>,
    > [email]Patrick.Stadelmann@unine.ch[/email] says...
    > > In article <3f27d3df$1@news.inet.com.pl>,
    > > "Patryk 'Silver Dream !' ?ogiewa" <silverdr@inet.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

  8. #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

  9. #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

Posting Permissions

  • You may not post new threads
  • You may 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