summaryrefslogtreecommitdiff
path: root/usr/src/lib/nsswitch/nisplus/common/getprofattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/nsswitch/nisplus/common/getprofattr.c')
-rw-r--r--usr/src/lib/nsswitch/nisplus/common/getprofattr.c135
1 files changed, 47 insertions, 88 deletions
diff --git a/usr/src/lib/nsswitch/nisplus/common/getprofattr.c b/usr/src/lib/nsswitch/nisplus/common/getprofattr.c
index 7e6dfcb04c..c1a7111f41 100644
--- a/usr/src/lib/nsswitch/nisplus/common/getprofattr.c
+++ b/usr/src/lib/nsswitch/nisplus/common/getprofattr.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,8 +19,8 @@
* CDDL HEADER END
*/
/*
- * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
- * All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
@@ -47,19 +46,18 @@ getbynam(nisplus_backend_ptr_t be, void *a)
* place the results from the nis_object structure into argp->buf.result
* Returns NSS_STR_PARSE_{SUCCESS, ERANGE, PARSE}
*/
+/*ARGSUSED*/
static int
-nis_object2profstr(int nobj, nis_object *obj, nss_XbyY_args_t *argp)
+nis_object2profstr(int nobj, nis_object *obj,
+ nisplus_backend_ptr_t be,
+ nss_XbyY_args_t *argp)
{
- int len;
- int buflen = argp->buf.buflen;
- char *buffer, *limit, *val, *endnum, *nullstring;
- char *empty = "";
- profstr_t *prof;
+ char *buffer, *name, *res1, *res2, *desc;
+ char *attr;
+ int buflen, namelen, res1len, res2len;
+ int desclen, attrlen;
struct entry_col *ecol;
- limit = argp->buf.buffer + buflen;
- prof = (profstr_t *)argp->buf.result;
- buffer = argp->buf.buffer;
/*
* If we got more than one nis_object, we just ignore object(s) except
* the first. Although it should never have happened.
@@ -74,81 +72,41 @@ nis_object2profstr(int nobj, nis_object *obj, nss_XbyY_args_t *argp)
}
ecol = obj->EN_data.en_cols.en_cols_val;
- /*
- * profstr->name: profile name
- */
- EC_SET(ecol, PROFATTR_NDX_NAME, len, val);
- if (len < 1 || (*val == '\0')) {
- val = empty;
- }
- prof->name = buffer;
- buffer += len;
- if (buffer >= limit) {
- return (NSS_STR_PARSE_ERANGE);
- }
- strcpy(prof->name, val);
- nullstring = (buffer - 1);
-
- /*
- * profstr->res1: reserved field 1
- */
- EC_SET(ecol, PROFATTR_NDX_RES1, len, val);
- if (len < 1 || (*val == '\0')) {
- val = empty;
- }
- prof->res1 = buffer;
- buffer += len;
- if (buffer >= limit) {
- return (NSS_STR_PARSE_ERANGE);
- }
- strcpy(prof->res1, val);
- nullstring = (buffer - 1);
-
- /*
- * profstr->res2: reserved field 2
- */
- EC_SET(ecol, PROFATTR_NDX_RES2, len, val);
- if (len < 1 || (*val == '\0')) {
- val = empty;
+ /* name: profile name */
+ __NISPLUS_GETCOL_OR_RETURN(ecol, PROFATTR_NDX_NAME, namelen, name);
+
+ /* res1: reserved field 1 */
+ __NISPLUS_GETCOL_OR_EMPTY(ecol, PROFATTR_NDX_RES1, res1len, res1);
+
+ /* res2: reserved field 2 */
+ __NISPLUS_GETCOL_OR_EMPTY(ecol, PROFATTR_NDX_RES2, res2len, res2);
+
+ /* desc: description */
+ __NISPLUS_GETCOL_OR_EMPTY(ecol, PROFATTR_NDX_DESC, desclen, desc);
+
+ /* attrs: key-value pairs of attributes */
+ __NISPLUS_GETCOL_OR_EMPTY(ecol, PROFATTR_NDX_ATTR, attrlen, attr);
+
+ buflen = namelen + res1len + res2len + desclen + attrlen + 5;
+ if (argp->buf.result != NULL) {
+ if ((be->buffer = calloc(1, buflen)) == NULL)
+ return (NSS_STR_PARSE_PARSE);
+ /* exclude trailing null from length */
+ be->buflen = buflen - 1;
+ buffer = be->buffer;
+ } else {
+ if (buflen > argp->buf.buflen)
+ return (NSS_STR_PARSE_ERANGE);
+ buflen = argp->buf.buflen;
+ buffer = argp->buf.buffer;
+ (void) memset(buffer, 0, buflen);
}
- prof->res2 = buffer;
- buffer += len;
- if (buffer >= limit) {
- return (NSS_STR_PARSE_ERANGE);
- }
- strcpy(prof->res2, val);
- nullstring = (buffer - 1);
-
- /*
- * profstr->desc: description
- */
- EC_SET(ecol, PROFATTR_NDX_DESC, len, val);
- if (len < 1 || (*val == '\0')) {
- val = empty;
- }
- prof->desc = buffer;
- buffer += len;
- if (buffer >= limit) {
- return (NSS_STR_PARSE_ERANGE);
- }
- strcpy(prof->desc, val);
- nullstring = (buffer - 1);
-
- /*
- * profstr->attrs: key-value pairs of attributes
- */
- EC_SET(ecol, PROFATTR_NDX_ATTR, len, val);
- if (len < 1 || (*val == '\0')) {
- val = empty;
- }
- prof->attr = buffer;
- buffer += len;
- if (buffer >= limit) {
- return (NSS_STR_PARSE_ERANGE);
- }
- strcpy(prof->attr, val);
- nullstring = (buffer - 1);
-
+ (void) snprintf(buffer, buflen, "%s:%s:%s:%s:%s",
+ name, res1, res2, desc, attr);
+#ifdef DEBUG
+ (void) fprintf(stdout, "profattr [%s]\n", buffer);
+ (void) fflush(stdout);
+#endif /* DEBUG */
return (NSS_STR_PARSE_SUCCESS);
}
@@ -160,6 +118,7 @@ static nisplus_backend_op_t profattr_ops[] = {
getbynam
};
+/*ARGSUSED*/
nss_backend_t *
_nss_nisplus_prof_attr_constr(const char *dummy1,
const char *dummy2,