10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2830Sdjl * Common Development and Distribution License (the "License"). 6*2830Sdjl * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2830Sdjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*2830Sdjl * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <project.h> 300Sstevel@tonic-gate #include <string.h> 31*2830Sdjl #include <stdlib.h> 320Sstevel@tonic-gate #include "files_common.h" 330Sstevel@tonic-gate 340Sstevel@tonic-gate static uint_t 35*2830Sdjl hash_projname(nss_XbyY_args_t *argp, int keyhash, const char *line, 36*2830Sdjl int linelen) { 37*2830Sdjl 38*2830Sdjl const char *name; 39*2830Sdjl int namelen, i; 40*2830Sdjl uint_t hash = 0; 410Sstevel@tonic-gate 42*2830Sdjl if (keyhash) { 43*2830Sdjl name = argp->key.name; 44*2830Sdjl namelen = strlen(name); 45*2830Sdjl } else { 46*2830Sdjl name = line; 47*2830Sdjl namelen = 0; 48*2830Sdjl while (linelen-- && *line++ != ':') 49*2830Sdjl namelen++; 50*2830Sdjl } 510Sstevel@tonic-gate 52*2830Sdjl for (i = 0; i < namelen; i++) 53*2830Sdjl hash = hash * 15 + name[i]; 540Sstevel@tonic-gate return (hash); 550Sstevel@tonic-gate } 560Sstevel@tonic-gate 570Sstevel@tonic-gate static uint_t 58*2830Sdjl hash_projid(nss_XbyY_args_t *argp, int keyhash, const char *line, 59*2830Sdjl int linelen) { 60*2830Sdjl 61*2830Sdjl uint_t id; 62*2830Sdjl const char *linep, *limit, *end; 63*2830Sdjl 64*2830Sdjl linep = line; 65*2830Sdjl limit = line + linelen; 66*2830Sdjl 67*2830Sdjl if (keyhash) 68*2830Sdjl return ((uint_t)argp->key.projid); 69*2830Sdjl 70*2830Sdjl /* skip projname */ 71*2830Sdjl while (linep < limit && *linep++ != ':'); 72*2830Sdjl if (linep == limit) 73*2830Sdjl return (0); 74*2830Sdjl 75*2830Sdjl /* projid */ 76*2830Sdjl end = linep; 77*2830Sdjl id = (uint_t)strtol(linep, (char **)&end, 10); 78*2830Sdjl if (linep == end) 79*2830Sdjl return (0); 80*2830Sdjl 81*2830Sdjl return (id); 820Sstevel@tonic-gate } 830Sstevel@tonic-gate 840Sstevel@tonic-gate static files_hash_func hash_proj[2] = { 850Sstevel@tonic-gate hash_projname, 860Sstevel@tonic-gate hash_projid 870Sstevel@tonic-gate }; 880Sstevel@tonic-gate 890Sstevel@tonic-gate static files_hash_t hashinfo = { 900Sstevel@tonic-gate DEFAULTMUTEX, 910Sstevel@tonic-gate sizeof (struct project), 920Sstevel@tonic-gate NSS_BUFLEN_PROJECT, 930Sstevel@tonic-gate 2, 940Sstevel@tonic-gate hash_proj 950Sstevel@tonic-gate }; 960Sstevel@tonic-gate 970Sstevel@tonic-gate static int 98*2830Sdjl check_projid(nss_XbyY_args_t *argp, const char *line, int linelen) { 99*2830Sdjl projid_t projid; 100*2830Sdjl const char *linep, *limit, *end; 1010Sstevel@tonic-gate 102*2830Sdjl linep = line; 103*2830Sdjl limit = line + linelen; 104*2830Sdjl 105*2830Sdjl /* skip projname */ 106*2830Sdjl while (linep < limit && *linep++ != ':'); 1070Sstevel@tonic-gate 108*2830Sdjl /* empty projname not allowed */ 109*2830Sdjl if (linep == limit || linep == line + 1) 110*2830Sdjl return (0); 1110Sstevel@tonic-gate 112*2830Sdjl /* projid */ 113*2830Sdjl end = linep; 114*2830Sdjl projid = (projid_t)strtol(linep, (char **)&end, 10); 115*2830Sdjl 116*2830Sdjl /* empty projid is not valid */ 117*2830Sdjl if (linep == end) 1180Sstevel@tonic-gate return (0); 119*2830Sdjl 120*2830Sdjl return (projid == argp->key.projid); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate static nss_status_t 1240Sstevel@tonic-gate getbyname(files_backend_ptr_t be, void *a) { 125*2830Sdjl return (_nss_files_XY_hash(be, a, 0, &hashinfo, 0, 126*2830Sdjl _nss_files_check_name_colon)); 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate static nss_status_t 1300Sstevel@tonic-gate getbyprojid(files_backend_ptr_t be, void *a) { 1310Sstevel@tonic-gate return (_nss_files_XY_hash(be, a, 0, &hashinfo, 1, check_projid)); 1320Sstevel@tonic-gate } 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate static files_backend_op_t project_ops[] = { 1350Sstevel@tonic-gate _nss_files_destr, 1360Sstevel@tonic-gate _nss_files_endent, 1370Sstevel@tonic-gate _nss_files_setent, 1380Sstevel@tonic-gate _nss_files_getent_rigid, 1390Sstevel@tonic-gate getbyname, 1400Sstevel@tonic-gate getbyprojid 1410Sstevel@tonic-gate }; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate /*ARGSUSED*/ 1440Sstevel@tonic-gate nss_backend_t * 1450Sstevel@tonic-gate _nss_files_project_constr(dummy1, dummy2, dummy3) 1460Sstevel@tonic-gate const char *dummy1, *dummy2, *dummy3; 1470Sstevel@tonic-gate { 1480Sstevel@tonic-gate return (_nss_files_constr(project_ops, 1490Sstevel@tonic-gate sizeof (project_ops) / sizeof (project_ops[0]), 1500Sstevel@tonic-gate PROJF_PATH, 1510Sstevel@tonic-gate NSS_LINELEN_PROJECT, 1520Sstevel@tonic-gate &hashinfo)); 1530Sstevel@tonic-gate } 154