serveradmin settings indices

September 2, 2008

There’s one more really annoying thing with serveradmin:

mail:~ file$ sudo serveradmin settings vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:0 = \"10.64.200.200\"
vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:0 = "10.64.200.200"
mail:~ file$ sudo serveradmin settings vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:1 = \"10.64.200.254\"
Invalid index "1", must specifiy array elements in order
Index = 1, count = 0, currentArray = ()
for key: "vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:1"

And actually the manpage doesn’t say anything about how to work with numeric indices:

“When setting array values, special notation is needed. There are two types of arrays. Some arrays have special id keys that allow you to access individual array elements. These are accessed using the special key _array_id followed by the value of the id tag (eg. web:Mod-ules:_array_id:dav_module). To add a new element to such an array, you need to have a special line with a “create” value”.

I struggled a lot with this trying to bring a dead VPN service back to life (it had lost all its settings). I finally ended up exprting the settings from another 10.4 server and importing them in, but then I discovered this workaround:

mail:~ file$ cat - | sudo serveradmin settings
vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:0 = "10.64.200.200"
vpn:Servers:com.apple.ppp.pptp:IPv4:DestAddressRanges:_array_index:1 = "10.64.200.254"

and it worked. That’s right - if you want to use numeric indices, you must provide the whole array every time you make a change. So basically dump the existing settings, append your new element and then set the whole array.