summaryrefslogtreecommitdiff
path: root/usr/src/lib/nsswitch/files/common/getservent.c
diff options
context:
space:
mode:
authordjl <none@none>2006-09-29 06:00:17 -0700
committerdjl <none@none>2006-09-29 06:00:17 -0700
commitcb5caa98562cf06753163f558cbcfe30b8f4673a (patch)
tree7a24623821583899295e29553207e69701b471ff /usr/src/lib/nsswitch/files/common/getservent.c
parent350f572a3fa518fc3690d53066c2c54fd03b5a08 (diff)
downloadillumos-joyent-cb5caa98562cf06753163f558cbcfe30b8f4673a.tar.gz
PSARC 2005/133 Sparks: Name Service Switch 2
4406529 artificial limit of 10 threads per backend 4516075 LDAP connections could be reused more 4696964 LDAP naming services should support Kerberos authentication 4740951 Need host based authentication options in Native LDAP 4952533 Some backends of gethostby* do not set h_errno correctly 4979596 getXbyY calls should have better buffer mechanism 5028908 /usr/bin/logins accesses free memory deep in nss_getent_u(). 5046881 nscd: old-data-ok parameter is not useful, should go away 6225323 NSS/nscd Enhancements (Sparks Project) --HG-- rename : usr/src/cmd/nscd/attrstr.c => deleted_files/usr/src/cmd/nscd/attrstr.c rename : usr/src/cmd/nscd/hash.c => deleted_files/usr/src/cmd/nscd/hash.c rename : usr/src/cmd/nscd/nscd_parse.c => deleted_files/usr/src/cmd/nscd/nscd_parse.c rename : usr/src/cmd/nscd/nscd.h => usr/src/cmd/nscd/cache.h
Diffstat (limited to 'usr/src/lib/nsswitch/files/common/getservent.c')
-rw-r--r--usr/src/lib/nsswitch/files/common/getservent.c146
1 files changed, 119 insertions, 27 deletions
diff --git a/usr/src/lib/nsswitch/files/common/getservent.c b/usr/src/lib/nsswitch/files/common/getservent.c
index 855b543d55..32e73ea3f6 100644
--- a/usr/src/lib/nsswitch/files/common/getservent.c
+++ b/usr/src/lib/nsswitch/files/common/getservent.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,10 +19,10 @@
* CDDL HEADER END
*/
/*
- * Copyright (c) 1988-1995 Sun Microsystems Inc
- * All Rights Reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
*
- * files/getservent.c -- "files" backend for nsswitch "services" database
+ * files/getservent.c -- "files" backend for nsswitch "services" database
*/
#pragma ident "%Z%%M% %I% %E% SMI"
@@ -32,27 +31,85 @@
#include "files_common.h"
#include <sys/types.h>
#include <netinet/in.h>
+#include <inttypes.h>
#include <strings.h>
+#include <ctype.h>
+#include <stdlib.h>
static int
-check_name(args)
- nss_XbyY_args_t *args;
+check_name(nss_XbyY_args_t *argp, const char *line, int linelen)
{
- struct servent *serv = (struct servent *) args->returnval;
- const char *name = args->key.serv.serv.name;
- const char *proto = args->key.serv.proto;
- char **aliasp;
+ const char *limit, *linep, *keyp;
+ int name_match = 0;
- if (proto != 0 && strcmp(serv->s_proto, proto) != 0) {
- return (0);
+ linep = line;
+ limit = line + linelen;
+ keyp = argp->key.serv.serv.name;
+
+ /* compare name */
+ while (*keyp && linep < limit && !isspace(*linep) && *keyp == *linep) {
+ keyp++;
+ linep++;
}
- if (strcmp(serv->s_name, name) == 0) {
- return (1);
+ if (*keyp == '\0' && linep < limit && isspace(*linep)) {
+ if (argp->key.serv.proto == NULL)
+ return (1);
+ else
+ name_match = 1;
}
- for (aliasp = serv->s_aliases; *aliasp != 0; aliasp++) {
- if (strcmp(*aliasp, name) == 0) {
+
+ /* skip remainder of the name, if any */
+ while (linep < limit && !isspace(*linep))
+ linep++;
+ /* skip the delimiting spaces */
+ while (linep < limit && isspace(*linep))
+ linep++;
+ /* skip port number */
+ while (linep < limit && !isspace(*linep) && *linep != '/')
+ linep++;
+ if (linep == limit || *linep != '/')
+ return (0);
+
+ linep++;
+ if ((keyp = argp->key.serv.proto) == NULL) {
+ /* skip protocol */
+ while (linep < limit && !isspace(*linep))
+ linep++;
+ } else {
+ /* compare protocol */
+ while (*keyp && linep < limit && !isspace(*linep) &&
+ *keyp == *linep) {
+ keyp++;
+ linep++;
+ }
+ /* no protocol match */
+ if (*keyp || (linep < limit && !isspace(*linep)))
+ return (0);
+ /* protocol and name match, return */
+ if (name_match)
return (1);
+ /* protocol match but name yet to be matched, so continue */
+ }
+
+ /* compare with the aliases */
+ while (linep < limit) {
+ /* skip the delimiting spaces */
+ while (linep < limit && isspace(*linep))
+ linep++;
+
+ /* compare with the alias name */
+ keyp = argp->key.serv.serv.name;
+ while (*keyp && linep < limit && !isspace(*linep) &&
+ *keyp == *linep) {
+ keyp++;
+ linep++;
}
+ if (*keyp == '\0' && (linep == limit || isspace(*linep)))
+ return (1);
+
+ /* skip remainder of the alias name, if any */
+ while (linep < limit && !isspace(*linep))
+ linep++;
}
return (0);
}
@@ -62,21 +119,56 @@ getbyname(be, a)
files_backend_ptr_t be;
void *a;
{
- nss_XbyY_args_t *argp = (nss_XbyY_args_t *) a;
+ nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
return (_nss_files_XY_all(be, argp, 1,
argp->key.serv.serv.name, check_name));
}
static int
-check_port(args)
- nss_XbyY_args_t *args;
+check_port(nss_XbyY_args_t *argp, const char *line, int linelen)
{
- struct servent *serv = (struct servent *) args->returnval;
- const char *proto = args->key.serv.proto;
+ const char *limit, *linep, *keyp, *numstart;
+ int numlen, s_port;
+ char numbuf[12], *numend;
+
+ linep = line;
+ limit = line + linelen;
+
+ /* skip name */
+ while (linep < limit && !isspace(*linep))
+ linep++;
+ /* skip the delimiting spaces */
+ while (linep < limit && isspace(*linep))
+ linep++;
+
+ /* compare port num */
+ numstart = linep;
+ while (linep < limit && !isspace(*linep) && *linep != '/')
+ linep++;
+ if (linep == limit || *linep != '/')
+ return (0);
+ numlen = linep - numstart;
+ if (numlen == 0 || numlen >= sizeof (numbuf))
+ return (0);
+ (void) memcpy(numbuf, numstart, numlen);
+ numbuf[numlen] = '\0';
+ s_port = htons((int)strtol(numbuf, &numend, 10));
+ if (*numend != '\0')
+ return (0);
+ if (s_port == argp->key.serv.serv.port) {
+ if ((keyp = argp->key.serv.proto) == NULL)
+ return (1);
+ } else
+ return (0);
- return (serv->s_port == args->key.serv.serv.port &&
- (proto == 0 || strcmp(serv->s_proto, proto) == 0));
+ /* compare protocol */
+ linep++;
+ while (*keyp && linep < limit && !isspace(*linep) && *keyp == *linep) {
+ keyp++;
+ linep++;
+ }
+ return (*keyp == '\0' && (linep == limit || isspace(*linep)));
}
static nss_status_t
@@ -84,10 +176,10 @@ getbyport(be, a)
files_backend_ptr_t be;
void *a;
{
- nss_XbyY_args_t *argp = (nss_XbyY_args_t *) a;
+ nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
char portstr[12];
- sprintf(portstr, "%d", ntohs(argp->key.serv.serv.port));
+ (void) snprintf(portstr, 12, "%d", ntohs(argp->key.serv.serv.port));
return (_nss_files_XY_all(be, argp, 1, portstr, check_port));
}