Re: Setting Network Preferences Programatically
Re: Setting Network Preferences Programatically
- Subject: Re: Setting Network Preferences Programatically
- From: Quinn <email@hidden>
- Date: Tue, 21 Oct 2003 13:49:07 -0700
At 14:09 -0700 20/10/03, James Masasaki wrote:
I know there must be a way to do it because I can set the Network
settings in System Preferences without the authorization dialog
without being logged in as root or su.
So my questions are:
1) Can this be accomplished programatically at all in OS X 10.1 and 10.2?
Yes. The same code should work on 10.1 and later.
2) Can it be accomplished without needing to write a priviledged user tool?
No.
3) Can it be accomplished programatically at all without prompting
the user for the authentication dialog?
No. Changing this setting is a privileged operation, so there is no
way to do it without *any* authorization dialogs. However, you can
do it with just one, at install time (or at first launch time). The
first authorization will allow you to create a setuid root helper
tool, which you can then use for all subsequent operations.
If so, can someone point me to the precise sample of code that shows
how to do this?
There is no sample code that shows exactly what you want to do.
That's why you get paid the big bucks (-: However, there are a
number of samples that show all of the pieces. You just have to
assemble them in a way that meets your specific requirements.
Let's look at each of the pieces in turn.
1. MoreSCF -- This provides a high-level API on top of the basic
System Configuration framework API. There is no specific MoreSCF
function for setting proxies, but you can combine the existing
functions to do what you need. I'll talk about this more below.
<
http://developer.apple.com/samplecode/Sample_Code/Networking/MoreSCF.htm>
2. MoreAuthSample -- This shows the standard "setuid root helper
tool" technique for doing privileged operations. This involves using
a setuid root helper tool to do the privileged operation that can't
be done directly by your application. You use Authorization Services
to prompt the user to enter their password to execute the tool the
first time. It's possible to bypass the authorization dialog if you
have an installer that installs the setuid root helper tool, but the
installer will probably want to display a dialog of its own.
<
http://developer.apple.com/samplecode/Sample_Code/Security/MoreAuthSample.htm>
3. QISA -- This high-level sample that shows how to integrate MoreSCF
and MoreAuthSample.
<
http://developer.apple.com/samplecode/Sample_Code/Networking/QISA.htm>
* * *
The MoreSCF functions that you want to use are:
o MoreSCCreateProxiesEntity -- This creates a proxy entity dictionary
from a parameter block.
o MoreSCSetEntity -- You can use this to store the proxy entity
dictionary into a particular service of a particular set. You can
pass NULL to the setID parameter, because you want to affect the
current set. The protocol parameter should be kSCEntNetProxies. The
serviceID parameter should be the service ID of the active service
within the set. This is somewhat complicated because the active
service is the first service whose link is active. To work this out
you really need to go digging in the SCF dynamic store. However, you
can probably use the expedient solution of iterating through all of
the services in the set, and setting the proxy entity in each service.
o MoreSCCopyEntity -- Use this to get the old value of the proxy
entity before you overwrite it.
o MoreSCCopyServiceIDs -- Will return a list of service IDs for a
set. Pass NULL to the setID parameter to work with the current set.
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.