Fix possible buffer overflow: buflen (a size_t*) was being used
[hcoop/debian/libnss-afs.git] / nss_afs_test.c
1 /*****************************************************************************
2 * libnss-afs (nss_afs_test.c)
3 *
4 * Copyright 2008, licensed under GNU Library General Public License (LGPL)
5 * see COPYING file for details
6 *
7 * by Adam Megacz <megacz@hcoop.net>
8 * derived from Frank Burkhardt's libnss_ptdb,
9 * which was derived from Todd M. Lewis' libnss_pts
10 *****************************************************************************/
11
12 #include <nss.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <sys/types.h>
16 #include <stdio.h>
17 #include <sys/time.h>
18 #include <sys/select.h>
19 #include <unistd.h>
20 #include <errno.h>
21 #include <stdlib.h>
22
23 int main(int argc,char **argv,char **envp) {
24 int buflen=1000;
25 char buffer[buflen];
26 char *buf, *arg, *name;
27 int uid;
28 int res;
29
30 buf=buffer;
31 if ( argc != 2 ) {
32 printf("Usage: %s [name or id]\n\n",argv[0]);
33 printf("Attempts lookup of a username or userid.\n");
34 printf("Statically linked against nss_afs.c.\n");
35 exit(1);
36 }
37 arg=argv[1];
38 if ( ( arg[0] > '0' ) && ( arg[0] < '9' ) ) {
39 uid=atoi(arg);
40 name = buf;
41 res=ptsid2name(uid,&buf,&buflen);
42 } else {
43 name = arg;
44 res=ptsname2id(arg,&uid);
45 }
46 switch(res) {
47 case NSS_STATUS_SUCCESS:
48 printf("uid=%i name=%s\n",uid,name);
49 break;
50 case NSS_STATUS_NOTFOUND:
51 printf("not found.\n");
52 break;
53 case NSS_STATUS_UNAVAIL:
54 printf("unable to contact ptserver or library internal error.\n");
55 break;
56 }
57 }