netname.c (7c478bd9) | netname.c (61961e0f) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 4 unchanged lines hidden (view full) --- 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 4 unchanged lines hidden (view full) --- 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END |
21 * 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. | 21 */ 22 23/* 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26/* All Rights Reserved */ 27/* 28 * Portions of this source code were derived from Berkeley 29 * 4.3 BSD under license from the Regents of the University of 30 * California. --- 19 unchanged lines hidden (view full) --- 50#undef NIS 51 52#include "mt.h" 53#include "rpc_mt.h" 54#include <stdio.h> 55#include <stdlib.h> 56#include <unistd.h> 57#include <sys/types.h> | 25 * Use is subject to license terms. 26 */ 27/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29/* 30 * Portions of this source code were derived from Berkeley 31 * 4.3 BSD under license from the Regents of the University of 32 * California. --- 19 unchanged lines hidden (view full) --- 52#undef NIS 53 54#include "mt.h" 55#include "rpc_mt.h" 56#include <stdio.h> 57#include <stdlib.h> 58#include <unistd.h> 59#include <sys/types.h> |
58#include <rpc/trace.h> | |
59#include <ctype.h> 60#include <string.h> 61#include <syslog.h> 62#include <sys/param.h> 63#include <rpc/rpc.h> 64#include <rpcsvc/nis.h> 65#include <rpcsvc/nis_dhext.h> 66#include <nsswitch.h> --- 10 unchanged lines hidden (view full) --- 77 * the value for NOBODY_UID is set by the SVID. The following define also 78 * appears in netnamer.c 79 */ 80 81#define NOBODY_UID 60001 82 83extern int __nis_principal(); 84extern int getdomainname(); | 60#include <ctype.h> 61#include <string.h> 62#include <syslog.h> 63#include <sys/param.h> 64#include <rpc/rpc.h> 65#include <rpcsvc/nis.h> 66#include <rpcsvc/nis_dhext.h> 67#include <nsswitch.h> --- 10 unchanged lines hidden (view full) --- 78 * the value for NOBODY_UID is set by the SVID. The following define also 79 * appears in netnamer.c 80 */ 81 82#define NOBODY_UID 60001 83 84extern int __nis_principal(); 85extern int getdomainname(); |
85extern char *strncpy(); | |
86extern int key_call(); 87#define OPSYS_LEN 4 88#define PKTABLE_LEN 12 89static const char *OPSYS = "unix"; 90static const char *PKTABLE = "cred.org_dir"; 91 92 93/* --- 25 unchanged lines hidden (view full) --- 119 * 0. If domain is NULL (indicating local domain), first try to get 120 * netname from keyserv (keylogin sets this). 121 * 1. Get the nisplus principal name from the LOCAL entry of the cred 122 * table in the specified domain (the local domain if domain is NULL). 123 * 2. Using the principal name, lookup the DES entry and extract netname. 124 */ 125 126static int | 86extern int key_call(); 87#define OPSYS_LEN 4 88#define PKTABLE_LEN 12 89static const char *OPSYS = "unix"; 90static const char *PKTABLE = "cred.org_dir"; 91 92 93/* --- 25 unchanged lines hidden (view full) --- 119 * 0. If domain is NULL (indicating local domain), first try to get 120 * netname from keyserv (keylogin sets this). 121 * 1. Get the nisplus principal name from the LOCAL entry of the cred 122 * table in the specified domain (the local domain if domain is NULL). 123 * 2. Using the principal name, lookup the DES entry and extract netname. 124 */ 125 126static int |
127user2netname_nisplus(err, netname, uid, domain) 128 int *err; 129 char netname[MAXNETNAMELEN + 1]; 130 uid_t uid; 131 char *domain; | 127user2netname_nisplus(int *err, char netname[MAXNETNAMELEN + 1], uid_t uid, 128 char *domain) |
132{ 133 key_netstres kres; 134 nis_result *nres; 135 int len; 136 uid_t my_uid; 137 char principal[NIS_MAXNAMELEN+1]; 138 char buf[NIS_MAXNAMELEN+1]; 139 int status; 140 mechanism_t **mechs; 141 char auth_type[MECH_MAXATNAME+1]; 142 | 129{ 130 key_netstres kres; 131 nis_result *nres; 132 int len; 133 uid_t my_uid; 134 char principal[NIS_MAXNAMELEN+1]; 135 char buf[NIS_MAXNAMELEN+1]; 136 int status; 137 mechanism_t **mechs; 138 char auth_type[MECH_MAXATNAME+1]; 139 |
143 trace1(TR_user2netname_nisplus, 0); 144 | |
145 my_uid = geteuid(); 146 147 if (my_uid == uid && domain == NULL) { 148 /* 149 * Look up the keyserv interface routines to see if 150 * netname is stored there. 151 */ 152 kres.key_netstres_u.knet.st_netname = NULL; | 140 my_uid = geteuid(); 141 142 if (my_uid == uid && domain == NULL) { 143 /* 144 * Look up the keyserv interface routines to see if 145 * netname is stored there. 146 */ 147 kres.key_netstres_u.knet.st_netname = NULL; |
153 if (key_call((rpcproc_t)KEY_NET_GET, xdr_void, (char *)NULL, | 148 if (key_call((rpcproc_t)KEY_NET_GET, xdr_void, NULL, |
154 xdr_key_netstres, (char *)&kres) && 155 kres.status == KEY_SUCCESS) { 156 len = strlen(kres.key_netstres_u.knet.st_netname); 157 (void) strncpy(netname, 158 kres.key_netstres_u.knet.st_netname, 159 len +1); 160 free(kres.key_netstres_u.knet.st_netname); | 149 xdr_key_netstres, (char *)&kres) && 150 kres.status == KEY_SUCCESS) { 151 len = strlen(kres.key_netstres_u.knet.st_netname); 152 (void) strncpy(netname, 153 kres.key_netstres_u.knet.st_netname, 154 len +1); 155 free(kres.key_netstres_u.knet.st_netname); |
161 trace1(TR_user2netname_nisplus, 1); | |
162 *err = __NSW_SUCCESS; 163 return (1); 164 } 165 } 166 167 168 /* 169 * 1. Determine user's nis+ principal name. --- 27 unchanged lines hidden (view full) --- 197 break; 198 default: 199 *err = __NSW_UNAVAIL; 200 syslog(LOG_ERR, 201 "user2netname: (nis+ lookup): %s\n", 202 nis_sperrno(status)); 203 } 204 | 156 *err = __NSW_SUCCESS; 157 return (1); 158 } 159 } 160 161 162 /* 163 * 1. Determine user's nis+ principal name. --- 27 unchanged lines hidden (view full) --- 191 break; 192 default: 193 *err = __NSW_UNAVAIL; 194 syslog(LOG_ERR, 195 "user2netname: (nis+ lookup): %s\n", 196 nis_sperrno(status)); 197 } 198 |
205 trace1(TR_user2netname_nisplus, 1); | |
206 return (0); 207 } 208 209 /* 210 * 2. use nis+ principal name to get netname by getting a PK entry. 211 * 212 * (Use NOAUTH to prevent recursion.) 213 */ 214 domain = nis_domain_of(principal); 215 if ((strlen(principal)+strlen(domain)+PKTABLE_LEN+ 28) > 216 (size_t)NIS_MAXNAMELEN) { 217 *err = __NSW_UNAVAIL; | 199 return (0); 200 } 201 202 /* 203 * 2. use nis+ principal name to get netname by getting a PK entry. 204 * 205 * (Use NOAUTH to prevent recursion.) 206 */ 207 domain = nis_domain_of(principal); 208 if ((strlen(principal)+strlen(domain)+PKTABLE_LEN+ 28) > 209 (size_t)NIS_MAXNAMELEN) { 210 *err = __NSW_UNAVAIL; |
218 trace1(TR_user2netname_nisplus, 1); | |
219 return (0); 220 } 221 222 if (mechs = __nis_get_mechanisms(FALSE)) { 223 mechanism_t **mpp; 224 225 /* 226 * Loop thru mechanism types till we find one in the 227 * cred table for this user. 228 */ 229 for (mpp = mechs; *mpp; mpp++) { 230 mechanism_t *mp = *mpp; 231 232 if (AUTH_DES_COMPAT_CHK(mp)) { 233 __nis_release_mechanisms(mechs); 234 goto try_auth_des; 235 } | 211 return (0); 212 } 213 214 if (mechs = __nis_get_mechanisms(FALSE)) { 215 mechanism_t **mpp; 216 217 /* 218 * Loop thru mechanism types till we find one in the 219 * cred table for this user. 220 */ 221 for (mpp = mechs; *mpp; mpp++) { 222 mechanism_t *mp = *mpp; 223 224 if (AUTH_DES_COMPAT_CHK(mp)) { 225 __nis_release_mechanisms(mechs); 226 goto try_auth_des; 227 } |
236 if (! VALID_MECH_ENTRY(mp)) | 228 if (!VALID_MECH_ENTRY(mp)) |
237 continue; 238 | 229 continue; 230 |
239 if (! __nis_mechalias2authtype(mp->alias, auth_type, | 231 if (!__nis_mechalias2authtype(mp->alias, auth_type, |
240 sizeof (auth_type))) 241 continue; 242 | 232 sizeof (auth_type))) 233 continue; 234 |
243 (void) sprintf(buf, | 235 (void) snprintf(buf, sizeof (buf), |
244 "[cname=\"%s\",auth_type=\"%s\"],%s.%s", 245 principal, auth_type, PKTABLE, domain); 246 if (buf[strlen(buf)-1] != '.') 247 (void) strcat(buf, "."); 248 249 nres = nis_list(buf, 250 USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS+FOLLOW_PATH, 251 NULL, NULL); --- 7 unchanged lines hidden (view full) --- 259 break; 260 } 261 } else { 262 try_auth_des: 263 /* 264 * No valid mechs exist or the AUTH_DES compat entry was 265 * found in the security cf. 266 */ | 236 "[cname=\"%s\",auth_type=\"%s\"],%s.%s", 237 principal, auth_type, PKTABLE, domain); 238 if (buf[strlen(buf)-1] != '.') 239 (void) strcat(buf, "."); 240 241 nres = nis_list(buf, 242 USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS+FOLLOW_PATH, 243 NULL, NULL); --- 7 unchanged lines hidden (view full) --- 251 break; 252 } 253 } else { 254 try_auth_des: 255 /* 256 * No valid mechs exist or the AUTH_DES compat entry was 257 * found in the security cf. 258 */ |
267 (void) sprintf(buf, "[cname=\"%s\",auth_type=DES],%s.%s", | 259 (void) snprintf(buf, sizeof (buf), 260 "[cname=\"%s\",auth_type=DES],%s.%s", |
268 principal, PKTABLE, domain); 269 if (buf[strlen(buf)-1] != '.') 270 (void) strcat(buf, "."); 271 272 nres = nis_list(buf, 273 USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS+FOLLOW_PATH, 274 NULL, NULL); 275 } 276 277 switch (nres->status) { 278 case NIS_SUCCESS: 279 case NIS_S_SUCCESS: 280 break; /* go and do something useful */ 281 case NIS_NOTFOUND: 282 case NIS_PARTIAL: 283 case NIS_NOSUCHNAME: 284 case NIS_NOSUCHTABLE: 285 *err = __NSW_NOTFOUND; 286 nis_freeresult(nres); | 261 principal, PKTABLE, domain); 262 if (buf[strlen(buf)-1] != '.') 263 (void) strcat(buf, "."); 264 265 nres = nis_list(buf, 266 USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS+FOLLOW_PATH, 267 NULL, NULL); 268 } 269 270 switch (nres->status) { 271 case NIS_SUCCESS: 272 case NIS_S_SUCCESS: 273 break; /* go and do something useful */ 274 case NIS_NOTFOUND: 275 case NIS_PARTIAL: 276 case NIS_NOSUCHNAME: 277 case NIS_NOSUCHTABLE: 278 *err = __NSW_NOTFOUND; 279 nis_freeresult(nres); |
287 trace1(TR_user2netname_nisplus, 1); | |
288 return (0); 289 case NIS_S_NOTFOUND: 290 case NIS_TRYAGAIN: 291 *err = __NSW_TRYAGAIN; 292 syslog(LOG_ERR, 293 "user2netname: (nis+ lookup): %s\n", 294 nis_sperrno(nres->status)); 295 nis_freeresult(nres); | 280 return (0); 281 case NIS_S_NOTFOUND: 282 case NIS_TRYAGAIN: 283 *err = __NSW_TRYAGAIN; 284 syslog(LOG_ERR, 285 "user2netname: (nis+ lookup): %s\n", 286 nis_sperrno(nres->status)); 287 nis_freeresult(nres); |
296 trace1(TR_user2netname_nisplus, 1); | |
297 return (0); 298 default: 299 *err = __NSW_UNAVAIL; 300 syslog(LOG_ERR, "user2netname: (nis+ lookup): %s\n", 301 nis_sperrno(nres->status)); 302 nis_freeresult(nres); | 288 return (0); 289 default: 290 *err = __NSW_UNAVAIL; 291 syslog(LOG_ERR, "user2netname: (nis+ lookup): %s\n", 292 nis_sperrno(nres->status)); 293 nis_freeresult(nres); |
303 trace1(TR_user2netname_nisplus, 1); | |
304 return (0); 305 } 306 307 if (nres->objects.objects_len > 1) { 308 /* 309 * Principal with more than one entry for this mech type? 310 * Something wrong with cred table. Should be unique. 311 * Warn user and continue. --- 4 unchanged lines hidden (view full) --- 316 } 317 318 len = ENTRY_LEN(nres->objects.objects_val, 2); 319 if (len > MAXNETNAMELEN) { 320 *err = __NSW_UNAVAIL; 321 syslog(LOG_ERR, "user2netname: netname of '%s' too long", 322 principal); 323 nis_freeresult(nres); | 294 return (0); 295 } 296 297 if (nres->objects.objects_len > 1) { 298 /* 299 * Principal with more than one entry for this mech type? 300 * Something wrong with cred table. Should be unique. 301 * Warn user and continue. --- 4 unchanged lines hidden (view full) --- 306 } 307 308 len = ENTRY_LEN(nres->objects.objects_val, 2); 309 if (len > MAXNETNAMELEN) { 310 *err = __NSW_UNAVAIL; 311 syslog(LOG_ERR, "user2netname: netname of '%s' too long", 312 principal); 313 nis_freeresult(nres); |
324 trace1(TR_user2netname_nisplus, 1); | |
325 return (0); 326 } 327 (void) strncpy(netname, ENTRY_VAL(nres->objects.objects_val, 2), len); 328 netname[len] = '\0'; 329 nis_freeresult(nres); 330 *err = __NSW_SUCCESS; | 314 return (0); 315 } 316 (void) strncpy(netname, ENTRY_VAL(nres->objects.objects_val, 2), len); 317 netname[len] = '\0'; 318 nis_freeresult(nres); 319 *err = __NSW_SUCCESS; |
331 trace1(TR_user2netname_nisplus, 1); | |
332 return (1); 333} 334 335#define MAXIPRINT (11) /* max length of printed integer */ 336 337/* 338 * Convert unix cred to network-name by concatenating the 339 * 3 pieces of information <opsys type> <uid> <domain>. 340 */ 341 342static int | 320 return (1); 321} 322 323#define MAXIPRINT (11) /* max length of printed integer */ 324 325/* 326 * Convert unix cred to network-name by concatenating the 327 * 3 pieces of information <opsys type> <uid> <domain>. 328 */ 329 330static int |
343user2netname_nis(err, netname, uid, domain) 344 int *err; 345 char netname[MAXNETNAMELEN + 1]; 346 uid_t uid; 347 char *domain; | 331user2netname_nis(int *err, char netname[MAXNETNAMELEN + 1], uid_t uid, 332 char *domain) |
348{ 349 int i; 350 char *dfltdom; 351 if (domain == NULL) { 352 if (__rpc_get_default_domain(&dfltdom) != 0) { | 333{ 334 int i; 335 char *dfltdom; 336 if (domain == NULL) { 337 if (__rpc_get_default_domain(&dfltdom) != 0) { |
353 trace1(TR_user2netname_nis, 1); | |
354 *err = __NSW_UNAVAIL; 355 return (0); 356 } 357 domain = dfltdom; 358 } 359 if ((strlen(domain) + OPSYS_LEN + 3 + MAXIPRINT) > 360 (size_t)MAXNETNAMELEN) { | 338 *err = __NSW_UNAVAIL; 339 return (0); 340 } 341 domain = dfltdom; 342 } 343 if ((strlen(domain) + OPSYS_LEN + 3 + MAXIPRINT) > 344 (size_t)MAXNETNAMELEN) { |
361 trace1(TR_user2netname_nis, 1); | |
362 *err = __NSW_UNAVAIL; 363 return (0); 364 } | 345 *err = __NSW_UNAVAIL; 346 return (0); 347 } |
365 (void) sprintf(netname, "%s.%d@%s", OPSYS, (int)uid, domain); | 348 (void) snprintf(netname, MAXNETNAMELEN + 1, 349 "%s.%d@%s", OPSYS, (int)uid, domain); |
366 i = strlen(netname); 367 if (netname[i-1] == '.') 368 netname[i-1] = '\0'; | 350 i = strlen(netname); 351 if (netname[i-1] == '.') 352 netname[i-1] = '\0'; |
369 trace1(TR_user2netname_nis, 1); | |
370 *err = __NSW_SUCCESS; 371 return (1); 372} 373 374/* 375 * Figure out my fully qualified network name 376 */ 377int | 353 *err = __NSW_SUCCESS; 354 return (1); 355} 356 357/* 358 * Figure out my fully qualified network name 359 */ 360int |
378getnetname(name) 379 char name[MAXNETNAMELEN + 1]; | 361getnetname(char name[MAXNETNAMELEN + 1]) |
380{ 381 uid_t uid; | 362{ 363 uid_t uid; |
382 int dummy; | |
383 | 364 |
384 trace1(TR_getnetname, 0); 385 | |
386 uid = geteuid(); 387 if (uid == 0) | 365 uid = geteuid(); 366 if (uid == 0) |
388 dummy = host2netname(name, (char *)NULL, (char *)NULL); 389 else 390 dummy = user2netname(name, uid, (char *)NULL); 391 392 trace1(TR_getnetname, 1); 393 return (dummy); | 367 return (host2netname(name, NULL, NULL)); 368 return (user2netname(name, uid, NULL)); |
394} 395 396 397/* 398 * Figure out the fully qualified network name for the given uid. 399 * This is a private interface. 400 */ 401int | 369} 370 371 372/* 373 * Figure out the fully qualified network name for the given uid. 374 * This is a private interface. 375 */ 376int |
402__getnetnamebyuid(name, uid) 403char name[MAXNETNAMELEN + 1]; 404uid_t uid; | 377__getnetnamebyuid(char name[MAXNETNAMELEN + 1], uid_t uid) |
405{ | 378{ |
406 int dummy; 407 408 trace1(TR___getnetnamebyuid, 0); 409 | |
410 if (uid == 0) | 379 if (uid == 0) |
411 dummy = host2netname(name, (char *)NULL, (char *)NULL); 412 else 413 dummy = user2netname(name, uid, (char *)NULL); 414 415 trace1(TR___getnetnamebyuid, 1); 416 return (dummy); | 380 return (host2netname(name, NULL, NULL)); 381 return (user2netname(name, uid, NULL)); |
417} 418 419/* 420 * Convert unix cred to network-name 421 * 422 * It uses the publickey policy in the /etc/nsswitch.conf file 423 * (Unless the netname is "nobody", which is special cased). 424 * If there is no publickey policy in /etc/nsswitch.conf, 425 * the default publickey policy is used, which is 426 * publickey: nis [NOTFOUND=return] files 427 * Note that for the non-nisplus case, there is no failover 428 * so only the first entry would be relevant for those cases. 429 */ 430int | 382} 383 384/* 385 * Convert unix cred to network-name 386 * 387 * It uses the publickey policy in the /etc/nsswitch.conf file 388 * (Unless the netname is "nobody", which is special cased). 389 * If there is no publickey policy in /etc/nsswitch.conf, 390 * the default publickey policy is used, which is 391 * publickey: nis [NOTFOUND=return] files 392 * Note that for the non-nisplus case, there is no failover 393 * so only the first entry would be relevant for those cases. 394 */ 395int |
431user2netname(netname, uid, domain) 432 char netname[MAXNETNAMELEN + 1]; 433 const uid_t uid; 434 const char *domain; | 396user2netname(char netname[MAXNETNAMELEN + 1], const uid_t uid, 397 const char *domain) |
435{ 436 struct __nsw_switchconfig *conf; 437 struct __nsw_lookup *look; 438 int needfree = 1, res = 0; 439 enum __nsw_parse_err perr; 440 int err; 441 | 398{ 399 struct __nsw_switchconfig *conf; 400 struct __nsw_lookup *look; 401 int needfree = 1, res = 0; 402 enum __nsw_parse_err perr; 403 int err; 404 |
442 trace1(TR_user2netname, 0); 443 | |
444 /* 445 * Take care of the special case of "nobody". If the uid is 446 * the value assigned by the SVID for nobody, return the string 447 * "nobody". 448 */ 449 450 if (uid == NOBODY_UID) { 451 (void) strcpy(netname, "nobody"); 452 return (1); 453 } 454 455 netname[0] = '\0'; /* make null first (no need for memset) */ 456 | 405 /* 406 * Take care of the special case of "nobody". If the uid is 407 * the value assigned by the SVID for nobody, return the string 408 * "nobody". 409 */ 410 411 if (uid == NOBODY_UID) { 412 (void) strcpy(netname, "nobody"); 413 return (1); 414 } 415 416 netname[0] = '\0'; /* make null first (no need for memset) */ 417 |
457 mutex_lock(&serialize_netname); | 418 (void) mutex_lock(&serialize_netname); |
458 459 conf = __nsw_getconfig("publickey", &perr); | 419 420 conf = __nsw_getconfig("publickey", &perr); |
460 if (! conf) { | 421 if (!conf) { |
461 conf = &publickey_default; 462 needfree = 0; 463 } 464 465 for (look = conf->lookups; look; look = look->next) { 466 if (strcmp(look->service_name, "nisplus") == 0) 467 res = user2netname_nisplus(&err, 468 netname, uid, (char *)domain); --- 11 unchanged lines hidden (view full) --- 480 err = __NSW_UNAVAIL; 481 } 482 switch (look->actions[err]) { 483 case __NSW_CONTINUE : 484 break; 485 case __NSW_RETURN : 486 if (needfree) 487 __nsw_freeconfig(conf); | 422 conf = &publickey_default; 423 needfree = 0; 424 } 425 426 for (look = conf->lookups; look; look = look->next) { 427 if (strcmp(look->service_name, "nisplus") == 0) 428 res = user2netname_nisplus(&err, 429 netname, uid, (char *)domain); --- 11 unchanged lines hidden (view full) --- 441 err = __NSW_UNAVAIL; 442 } 443 switch (look->actions[err]) { 444 case __NSW_CONTINUE : 445 break; 446 case __NSW_RETURN : 447 if (needfree) 448 __nsw_freeconfig(conf); |
488 mutex_unlock(&serialize_netname); 489 trace1(TR_user2netname, 1); | 449 (void) mutex_unlock(&serialize_netname); |
490 return (res); 491 default : 492 syslog(LOG_ERR, 493 "user2netname: Unknown action for nameservice '%s'", 494 look->service_name); 495 } 496 } 497 if (needfree) 498 __nsw_freeconfig(conf); | 450 return (res); 451 default : 452 syslog(LOG_ERR, 453 "user2netname: Unknown action for nameservice '%s'", 454 look->service_name); 455 } 456 } 457 if (needfree) 458 __nsw_freeconfig(conf); |
499 mutex_unlock(&serialize_netname); 500 trace1(TR_user2netname, 1); | 459 (void) mutex_unlock(&serialize_netname); |
501 return (0); 502} 503 504 505/* 506 * Convert host to network-name 507 * This routine returns following netnames given the host and domain 508 * arguments defined below: (domainname=y.z) --- 5 unchanged lines hidden (view full) --- 514 * - - unix.m@y.z (hostname=m.w.x) 515 * - a.b unix.m@a.b (hostname=m.w.x) 516 * h - unix.h@y.z 517 * h a.b unix.h@a.b 518 * h.w.x - unix.h@w.x 519 * h.w.x a.b unix.h@a.b 520 */ 521int | 460 return (0); 461} 462 463 464/* 465 * Convert host to network-name 466 * This routine returns following netnames given the host and domain 467 * arguments defined below: (domainname=y.z) --- 5 unchanged lines hidden (view full) --- 473 * - - unix.m@y.z (hostname=m.w.x) 474 * - a.b unix.m@a.b (hostname=m.w.x) 475 * h - unix.h@y.z 476 * h a.b unix.h@a.b 477 * h.w.x - unix.h@w.x 478 * h.w.x a.b unix.h@a.b 479 */ 480int |
522host2netname(netname, host, domain) 523 char netname[MAXNETNAMELEN + 1]; 524 const char *host; 525 const char *domain; | 481host2netname(char netname[MAXNETNAMELEN + 1], const char *host, 482 const char *domain) |
526{ 527 char *p; 528 char hostname[MAXHOSTNAMELEN + 1]; 529 char domainname[MAXHOSTNAMELEN + 1]; 530 char *dot_in_host; 531 int i; 532 size_t len; 533 | 483{ 484 char *p; 485 char hostname[MAXHOSTNAMELEN + 1]; 486 char domainname[MAXHOSTNAMELEN + 1]; 487 char *dot_in_host; 488 int i; 489 size_t len; 490 |
534 trace1(TR_host2netname, 0); 535 | |
536 netname[0] = '\0'; /* make null first (no need for memset) */ 537 538 if (host == NULL) { 539 (void) strncpy(hostname, nis_local_host(), sizeof (hostname)); 540 p = (char *)strchr(hostname, '.'); 541 if (p) { 542 *p++ = '\0'; 543 /* if no domain passed, use tail of nis_local_host() */ --- 40 unchanged lines hidden (view full) --- 584 domainname[i - 1] = 0; 585 586 if (dot_in_host) { /* strip off rest of name */ 587 *dot_in_host = '\0'; 588 } 589 590 if ((strlen(domainname) + strlen(hostname) + OPSYS_LEN + 3) 591 > (size_t)MAXNETNAMELEN) { | 491 netname[0] = '\0'; /* make null first (no need for memset) */ 492 493 if (host == NULL) { 494 (void) strncpy(hostname, nis_local_host(), sizeof (hostname)); 495 p = (char *)strchr(hostname, '.'); 496 if (p) { 497 *p++ = '\0'; 498 /* if no domain passed, use tail of nis_local_host() */ --- 40 unchanged lines hidden (view full) --- 539 domainname[i - 1] = 0; 540 541 if (dot_in_host) { /* strip off rest of name */ 542 *dot_in_host = '\0'; 543 } 544 545 if ((strlen(domainname) + strlen(hostname) + OPSYS_LEN + 3) 546 > (size_t)MAXNETNAMELEN) { |
592 trace1(TR_host2netname, 1); | |
593 return (0); 594 } 595 | 547 return (0); 548 } 549 |
596 (void) sprintf(netname, "%s.%s@%s", OPSYS, hostname, domainname); 597 trace1(TR_host2netname, 1); | 550 (void) snprintf(netname, MAXNETNAMELEN + 1, 551 "%s.%s@%s", OPSYS, hostname, domainname); |
598 return (1); 599} | 552 return (1); 553} |