Granting privileges to a group of users(list.964)
Posted in 1992
Chris writes:
>> I would like to know if it is possible to grant privileges to a group
>> of users ala UNIX's /etc/group.
Well I think I have an answer to your query. It may not be the best or
most efficient but it works. Below find a script that I wrote today to
satisfy your question. We use Informix version 2.10.00B here on what
would be considered a regular Unix machine running BSD4.3. Simply put
a mainframe if you will. I am sure that the script below will work basically
on your machine though it may need some minor modifications to compliment
what you have. Here it is as I have it written it with a couple of notes
that would need to be changed by you:
----------------------------------------------------------------------------
#! /bin/csh -f
setenv INFORMIXDIR /usr/informixsetenv DIR /database/dir
cd $DIR
echo -n \\
"Enter group that you want to grant access to(ex: amex): "
set grp = $<
set ingrp = `grep $grp /etc/group | awk -F: '{print $4}'`
echo -n \\
"Will this be a (t)ab or (d)bs privilege or (b)oth being granted? "
set priv = $<
if ($priv == t) goto get_tab
endif
if ($priv == d) goto get_dbs
endif
if ($priv == b) goto get_both
endif
get_tab:
echo -n \\
"Which tab privileges do you want to grant to $grp? "
set tabs = $<
goto grant_tabs
end
get_dbs:
echo -n \\
"Which dbs privileges do you want to grant to $grp? "
set dbss = $<
goto grant_dbs
end
get_both:
echo -n \\
"Which tab privileges do you want to grant to $grp? "
set tabs = $<
echo -n
"Which dbs privileges do you want to grant to $grp? "
set dbss = $<
goto grant_both
end
grant_tabs:
echo "Granting tab-privileges for $grp."
cat > /tmp/isqlgrantt.sql <<DONE
grant $tabs on phone_list to $ingrp
DONE
isql phone /tmp/isqlgrantt.sql
goto exit
end
grant_dbs:
echo "Granting dbs-privileges for $grp."
cat > /tmp/isqlgrantd.sql <<DONE
grant $dbss to $ingrp
DONE
isql phone /tmp/isqlgrantd.sql
goto exit
end
grant_both:
echo "Granting privileges for group."
cat > /tmp/isqlgrantt.sql <<DONE
grant $tabs on phone_list to $ingrp
DONE
isql phone /tmp/isqlgrantt.sql
echo "Granting dbs-privileges for $grp."
cat > /tmp/isqlgrantd.sql <<DONE
grant $dbss to $ingrp
DONE
isql phone /tmp/isqlgrantd.sql
goto exit
end
exit:
exit
----------------------------------------------------------------------------
The main thing for you to modify is the DIR of where you have the
database located. I have tested it here with another userid and
it works just fine. I also put together a script to possibly accompany
this one with the intent that the user would be running it. Here it
is:
---------------------------------------------------------------------------
#! /bin/csh -f
setenv INFORMIXDIR /usr/informixsetenv DIR /database/dir
cd $DIR
echo -n \\
"Enter group that you should belong to(ex: amex): "
set grp = $<
set userid = `whoami`
set usrgrp = `grep $grp /etc/group | awk -F: '{print $4}'`
set ingrp = `grep $grp /etc/group | awk -F: '{print $4}' | grep $userid`
echo "Verifying privileges for user."
if ($ingrp == "$usrgrp") goto doit
endif
if ($ingrp == "") then
echo "You do not belong to this group."
goto dblchk
end
endif
doit:
/usr/informix/bin/isql phone
goto exit
end
dblchk:
echo -n \\
"Please reenter group name or another group name(ex:esm) "
set nxtgrp = $<
set grp2 = `grep $nxtgrp /etc/group | awk -F: '{print $4}'`
set ingrp2 = `grep $nxtgrp /etc/group | awk -F: '{print $4}' | grep $userid`
echo "Checking privileges for user again."
if ($ingrp2 == "$nxtgrp") goto doit
endif
if ($ingrp2 == "") then
echo "You do not belong to this group either."
echo "Check with you database administrator to"
echo "see which group(s) you belong to."
goto exit
end
endif
exit:
exit
--------------------------------------------------------------------------
Once again with this one you will make to make appropiate modifications to
the database directory, name and whatever else would fit your scheme of
things. Hope this helps. Send me e-mail directly if you have any questions
or comments.....
--------------------------------------------------------------------------
--------------------------------------------------------------------------
Michael Fischer Voice Mail 1 510 704 3111
TRW Financial Systems
2118 Milvia
Berkeley, CA 94704 E-mail: mikey@tfs.com