Finbarr O'Kane (finbarro@netsoc.ucd.ie)
Thu, 30 Sep 1999 23:15:56 +0100 (BST)
Hi (again)
I couldnt find anything that did exactly what I wanted so I hacked
together a really quick program.
its called, suprisingly enough 'finger_wrapper'
when called with either:
1. no args, it figures out what the local hostname is, and does finger
@<hostname>
if it cant figure that out it just does finger @localhost
if its called with 2 args... then, like the regular finger program
usage: finger [-lmps] [login ...]
it checks the 2nd arg for the existance of a @ in the word, and if so,
just passes the whole lot to a local finger program
if it only has 1 arg, it does the same @ check, if there is none, then it
appends @<local host name> onto the end and does a finger...
i just have /usr/local/bin/finger pointing to
/usr/local/bin/finger_wrapper
and it calls /usr/bin/finger once it has massaged the input a little :)
so now, 'finger' polls the information cfingerd gathers , not what
/usr/bin/finger gathers
fin
#include <stdio.h>
#include <string.h>
/*
* simple wrapper to see if a hostname arg has been passed through,
* if not.. .add this host...
*/
int main (int argc, char *argv[]) {
int user_arg=0;
int maxuser=8;
int maxhost=16;
char newuser[maxuser+maxhost+1];
char host[maxhost+1];
char thost[maxhost+1];
char *ptr;
/* find where the username portion is... */
if(argc==0 || argc > 3) {
printf("Too many args for finger, exiting\n");
exit(-1);
} else {
user_arg = (argc - 1);
};
/* get hostname */
strcpy(host,"@");
if ( gethostname(thost,maxhost) != 0) {
strcat(host,"localhost");
} else {
strncat(host,thost,maxhost);
};
/* check that the args are valid and process appropriately */
if(user_arg==0) {
/* just exec finger @host */
execl("/usr/bin/finger", "/usr/bin/finger" ,host, NULL);
} else {
if((ptr = strchr(argv[user_arg],'@')) != (char *)NULL) {
execvp("/usr/bin/finger", argv);
} else {
/* want to append '@host' to the end of the string */
if(strlen(argv[user_arg]) > maxuser) {
/* username too long, lets reject its ass :) */
printf("username too long, exiting..\n");
exit(-1);
} else {
strncpy(newuser,argv[user_arg],maxuser+1);
if(strlen(host)> (maxuser+maxhost)- strlen(newuser)) {
/* hostname too long would cause problems otherwise, exit */
printf("hostname too long, exiting..\n");
exit(-1);
} else {
strncat(newuser,host,((maxuser+maxhost)-strlen(newuser)));
if(user_arg==1) {
execl("/usr/bin/finger","/usr/bin/finger",newuser,NULL);
} else {
execl("/usr/bin/finger","/usr/bin/finger",argv[1],newuser,NULL);
};
};
};
};
};
}
#
# Simple finger wrapper to be used in conjunction with
# cfingerd-1.4.x
#
Version 0.1
Does simple bounds checking :
- username: 8 characters
- hostname: 64 characters
Exits without calling finger if either is violated
IF gethostname(char *name) fails, or returns a hostname longer than 64
then 'localhost' is set as a placeholder
Simple C code, so its relatively transparent to users.
known to work on:
SPARC/x86 Solaris
Linux x86 Redhat 5.2/6
Compile flags: none needed
Compile command:
gcc -o finger_wrapper finger_wrapper.c
This archive was generated by hypermail 2.0b3 on Fri Oct 01 1999 - 00:16:18 CEST