📄 check_user.c
字号:
#include "socks.h"#include <netdb.h>/* >>> K. Shackelford */#if defined(hpux) || defined(AIX) || defined(DGUX)#include <sys/types.h>#include <netinet/in.h>#endif/* <<< K. Shackelford */ #include <stdio.h>#include <ctype.h>#if (defined(sun) && !defined(SOLARIS)) || defined(sgi)#include <strings.h>#else#include <string.h>#endif#ifdef SOLARIS#include "bstring.h"#endif/* * These functions are used by both Validate (for sockd) * and socks_check_cconf (for clients). *//*** Simple 'socks_mkargs' doesn't handle \, ", or '.*/void socks_mkargs(cp, argc, argv, max)char *cp;int *argc;char *argv[];int max;{ *argc = 0; while (isspace(*cp)) cp++; while (*cp != '\0') { argv[(*argc)++] = cp; if (*argc >= max) return; while (!isspace(*cp) && (*cp != '\0')) cp++; while (isspace(*cp)) *cp++ = '\0'; }}int socks_GetQuad(dotquad, addr)char *dotquad;struct in_addr *addr;/* dotquad must be in dotted quad form. Returns -1 if not. */{ if ((addr->s_addr = inet_addr(dotquad)) != (u_int32) -1) return 0; if (strcmp(dotquad, "255.255.255.255") == 0) return 0; return -1;}/* ** Get address, must be dotted quad, or full domain name, or network name.** Returns -1 if none of the above.*/int socks_GetAddr(name, addr)char *name;struct in_addr *addr;{ struct hostent *hp; struct netent *np; if (socks_GetQuad(name, addr) != -1) return 0; if ((hp = gethostbyname(name)) != NULL) { bcopy(hp->h_addr_list[0], &(addr->s_addr), hp->h_length); return 0; } if ((np = getnetbyname(name)) != NULL) { addr->s_addr = np->n_net; return 0; } return -1;}long socks_GetPort(name)char *name;/* result is in HOST byte order */{ struct servent *sp; if ((sp = getservbyname(name, "tcp")) != NULL) { return ntohs(sp->s_port); } if (!isdigit(*name)) return -1; return atol(name);}int socks_check_user(userlist, src_user)char *userlist, *src_user;/* * Unless userlist is a null pointer, in which case all users are * allowed (return 1), otherwise * userlist is a nonempty string containing userids separated by * commas, no other separators are allowed in the string. * 94/03/02: if userlist starts with '/', it specifies a file * containing userids. * * Return 1 if src_user is in the userlist; * return 0 if not, or if userfile cannot be open. */{ char *p, *q; if (!(p = userlist)) { return 1; } do { if (q = index(p, ',')) *q = '\0'; if (*p == '/') { switch (check_userfile(p, src_user)) { case 1: return 1; case -1: return 0; default: ; } } else if (strcmp(p, src_user) == 0) { return 1; } if (q) *q++ = ','; } while ( p = q); return 0;}#include <string.h>#include <syslog.h>static int check_userfile(userfile, src_user)char *userfile, *src_user;/* return 1 if match, 0 otherwise *//* return -1 if cannot open file */{ FILE *fd;#define BUFLEN 1024 static char buf[BUFLEN]; char *bp; if ((fd = fopen(userfile, "r")) == NULL) { syslog(LOG_HIGH,"Unable to open userfile (%s)\n", userfile); return (-1); } while (fgets(buf, BUFLEN, fd) != NULL) { if ((bp = index(buf, '\n')) != NULL) *bp = '\0'; if (( bp = index(buf, '#')) != NULL) *bp = '\0'; for (bp = strtok(buf, " ,\t"); bp != NULL; bp = strtok(NULL, " ,\t")) { if (strcmp(bp, src_user) == 0) { fclose(fd); return 1; } } } fclose(fd); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -