"Jordan Brown (Sun)" wrote:
> Roland Mainz wrote:
> > Ok... two questions:
> > 1. How can a Bourne[1] shell script get the number of values in a
> > property ?
> > 2. How can I get value number <n> from a Bourne[1] shell script ?
> 
> I love sh puzzles...
> 
> Ignoring the possibility of feeding it through awk or something like
> that, how about...
> 
> set -- `svccfg -s svc:/application/mydaemon listprop my/prop`
> shift 2
> echo $#
> echo $1
> echo $2
> ...
> ?

Yes... I did something similar with "read -A myarrayvar" in ksh93... but
it's still a bit scary since it relies on field splitting via IFS (e.g.
either set to the default value or IFS=' ') which itself is tricky when
the script explicitly set IFS='' as security measure against code
injection attacks (see link to David Korn's recommendations "how to
write secure scripts").

> Processing the quoting right is left as an exercise for the reader (but,
> hint:  I suspect that "eval" is your friend).

Except that "eval" is a _SERIOUS_ security risk (short: attributary code
execution) and should be avoided at all costs (you can find David Korn's
recommendation for "eval" in
http://mail.opensolaris.org/pipermail/shell-discuss/2007-June/000993.html
; also note that almost every mordern shell added other ways to replace
the most common consumers for "eval", e.g. ksh93's original design added
the "nameref" datatype to replace things like $ foo="abc" ; eval
"${foo}=\"${value}\"" # by $ nameref foo="abc" ; abc="${value}" #) ...
and it should even more avoided in the case of SMF and setuid/setgid
scripts to avoid things like "priviledge escalation" ...

... one question is still open: How do I know when a property is
_supposed_ to have only exactly one value or when it _may_ have multiple
values by design ? The XML file can define this via "astring_list" to
indicate that multiple values may follow... but I don't see a way to
seperate between both cases on the consumer side via /usr/bin/svcprop
... ;-(

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)

Reply via email to