From: Iain Patterson Date: Tue, 4 Aug 2009 13:41:53 +0000 (+0100) Subject: Netgroups. X-Git-Url: http://git.iain.cx/?p=profile.git;a=commitdiff_plain;h=80a28ca55ac0e9a9743b561ff3a0ac9ccc62d4ce Netgroups. Added netgroups.c since the netgroups binary is needed by sshcolourterm. Be quiet checking netgroups in sshcolourterm. This allows, for example, hacking sshcolourterm for an SGE terminal viz: env SSHTERM_SSH=qrsh sshterm --- diff --git a/opt/bin/sshcolourterm b/opt/bin/sshcolourterm index 4a5f302..8bae4b0 100755 --- a/opt/bin/sshcolourterm +++ b/opt/bin/sshcolourterm @@ -18,7 +18,7 @@ fi # Get colour by netgroup. if [ -z "$colour" ]; then for netgroup in $(ls "$SSHCOLOURS" | grep ^\@); do - if netgroups $netgroup ${fqdn%%.*} 2>/dev/null; then + if netgroups $netgroup ${fqdn%%.*} &>/dev/null; then colour=$(readlink "$SSHCOLOURS/$netgroup") break fi diff --git a/src/netgroups.c b/src/netgroups.c new file mode 100644 index 0000000..0a3dd77 --- /dev/null +++ b/src/netgroups.c @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char **argv) { + char *group, *host, *hostp, *userp, *domainp; + + if (argc == 1) { + fprintf(stderr, "Usage: netgroups []\n"); + exit(1); + } + + /* What group do we want? */ + group = argv[1]; + if (*group == '@') group++; + + /* Do we want to match a host? */ + host = argv[2]; + + if (host) exit(! innetgr(group, host, 0, 0)); + + setnetgrent(group); + while (getnetgrent(&hostp, &userp, &domainp)) printf("%s\n", hostp); + endnetgrent(); + + exit(0); +}