Creating a samba share programatically in Mac OS

Discussion in 'Mac Programming' started by GoGades, Jan 18, 2011.

  1. GoGades macrumors newbie

    Joined:
    Mar 1, 2008
    #1
    Hello folks,

    I'm building a simple app which needs to create and remove a samba share programaticly.

    I was hoping I would just be able to stuff (or remove) the required directives in /etc/smb.conf but I see that Mac OS has a pretty sophisticated configuration system.

    I've done a bunch of googling and didn't find a satisfactory answer. I would consider using AppleScript, although that seems pretty brittle.

    Suggestions and/or links to relevant docs much appreciated. Thanks!
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    No offense, but sounds scary, as in the kind of thing a trojan might want to do.

    Is this really the best way to achieve your goal? Whatever that may be.

    AppleScript using the System Preferences seems to be the way to go though.

    EDIT: However you do it, if you end up doing it, make it visible to the user what you are doing.

    B
     
  3. GoGades thread starter macrumors newbie

    Joined:
    Mar 1, 2008
    #3
    Of course - this is a commercial application...

    "AppleScript using the System Preferences seems to be the way to go though. "

    You say this based on what - that there are no API or command line tools to manipulate the sharing configurations, or is that just a guess?
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    Exactly. The only exposed way to do this is via System Preferences -> Sharing -> File Sharing.

    Doing it any other way you run the risk of stomping on the user's settings which would be a bad thing. (Unless of course this is an internal application in which case stomp away).

    I've run into similar issues in Linux where making changes to the smb.conf file directly has confused the GUI admin tools so much that they become useless.

    (BTW Just because it's a commercial app, doesn't mean this is the right way to achieve your goal.)

    B
     
  5. GoGades thread starter macrumors newbie

    Joined:
    Mar 1, 2008
    #5
    Uh, so much that...

    net usershare add <sharename> <dirpath> does the trick from the CLI

    man net provides oodles more info. Thanks for the help and advice.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    Sorry, my adventures in samba configuration predate version 3 and net, so I (obviously) didn't think of it.

    Clearly someone else had a need similar to yours. :p I like the fact that it doesn't require root which alleviates my concerns.

    Out of curiosity, does the share you create that way show up in System Preferences?

    EDIT: Per the fine man page, you're still going to have to edit smb.conf to enable this (usershare is not enabled by default) and there is still a risk that you and the GUI will cross swords.

    B
     

Share This Page