#include #include #define DOMAINNAME "cs-snuent" #define YPMAP "passwd.byname" #pragma ident "ypall.c 10/29/06 CAM" /* * ypall.c * * `ypcat` using ypall(). * ypall has advantages because it uses a single RPC request/response * over TCP, rather than 'n' RPC request/responses over UDP. * (see 'ypcat.c') * * This way is cleaner, better, but also buggy. * Most bugs are gone, but you still get the last entry from the map twice. * */ extern struct ypall_callback; /* struct ypall_callBack *incallback { int (* foreach) (); char * data; }; */ int foreach_pair( int instatus, char *inkey, int inkey_len, char *inval, int inval_len, char *indata ); int main( int argc, char **argv ) { int yp_ret = 0; struct ypall_callback myCallback; myCallback.foreach = foreach_pair; if( ( yp_ret=yp_all(DOMAINNAME, YPMAP, &myCallback) ) != 0 ) { printf("Problem: yp_all returned nonzero. (%i=%s)\n", yp_ret, yperr_string(ypprot_err(yp_ret)) ); } return 0; } int foreach_pair( int instatus, char *inkey, int inkey_len, char *inval, int inval_len, char *indata ) { printf("%s\n", inval); /*N.B. appears both 'out' strings are terminated with '\n'.*/ /* MUST DO THIS. Otherwise you get data like: "/usr/local/bin/tcshcshtcshshasswordpasswordtcshcm/usr" on the next run. */ (void) memset((void *)inkey, 0, inkey_len); (void) memset((void *)inval, 0, inval_len); return 0; /* return of 0 means the function is ready to be called again. */ /* If you wanted to exit without reading more, return nonzero. */ }