1 /* 2 * $Id: info_passwd.c,v 5.2.1.2 91/03/03 20:39:38 jsp Alpha $ 3 * 4 * Copyright (c) 1990 Jan-Simon Pendry 5 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 6 * Copyright (c) 1990 The Regents of the University of California. 7 * All rights reserved. 8 * 9 * This code is derived from software contributed to Berkeley by 10 * Jan-Simon Pendry at Imperial College, London. 11 * 12 * %sccs.include.redist.c% 13 * 14 * @(#)info_passwd.c 5.2 (Berkeley) 03/17/91 15 */ 16 17 /* 18 * Get info from password "file" 19 * 20 * This is experimental and probably doesn't 21 * do what you expect. 22 */ 23 24 #include "am.h" 25 26 #ifdef HAS_PASSWD_MAPS 27 #include <pwd.h> 28 29 #define PASSWD_MAP "/etc/passwd" 30 31 /* 32 * Nothing to probe - check the map name is PASSWD_MAP. 33 */ 34 int passwd_init P((char *map, time_t *tp)); 35 int passwd_init(map, tp) 36 char *map; 37 time_t *tp; 38 { 39 *tp = 0; 40 return strcmp(map, PASSWD_MAP) == 0 ? 0 : ENOENT; 41 } 42 43 44 /* 45 * Grab the entry via the getpwname routine 46 * Modify time is ignored by passwd - XXX 47 */ 48 int passwd_search P((mnt_map *m, char *map, char *key, char **pval, time_t *tp)); 49 int passwd_search(m, map, key, pval, tp) 50 mnt_map *m; 51 char *map; 52 char *key; 53 char **pval; 54 time_t *tp; 55 { 56 char *dir = 0; 57 struct passwd *pw; 58 if (strcmp(key, "/defaults") == 0) { 59 *pval = strdup("type:=nfs"); 60 return 0; 61 } 62 63 pw = getpwnam(key); 64 if (pw) { 65 /* 66 * We chop the home directory up as follows: 67 * /anydir/dom1/dom2/dom3/user 68 * 69 * and return 70 * rfs:=/anydir/dom3;rhost:=dom3.dom2.dom1;sublink:=user 71 * 72 * This allows cross-domain entries in your passwd file. 73 * ... but forget about security! 74 */ 75 char *user; 76 char *p, *q; 77 char val[MAXPATHLEN]; 78 char rhost[MAXHOSTNAMELEN]; 79 dir = strdup(pw->pw_dir); 80 /* 81 * Find user name. If no / then Invalid... 82 */ 83 user = strrchr(dir, '/'); 84 if (!user) 85 goto enoent; 86 *user++ = '\0'; 87 /* 88 * Find start of host "path". If no / then Invalid... 89 */ 90 p = strchr(dir+1, '/'); 91 if (!p) 92 goto enoent; 93 *p++ = '\0'; 94 /* 95 * At this point, p is dom1/dom2/dom3 96 * Copy, backwards, into rhost replacing 97 * / with . 98 */ 99 rhost[0] = '\0'; 100 do { 101 q = strrchr(p, '/'); 102 if (q) { 103 strcat(rhost, q + 1); 104 strcat(rhost, "."); 105 *q = '\0'; 106 } else { 107 strcat(rhost, p); 108 } 109 } while (q); 110 /* 111 * Sanity check 112 */ 113 if (*rhost == '\0' || *user == '\0' || *dir == '\0') 114 goto enoent; 115 /* 116 * Make up return string 117 */ 118 q = strchr(rhost, '.'); 119 if (q) 120 *q = '\0'; 121 sprintf(val, "rfs:=%s/%s;rhost:=%s;sublink:=%s;fs:=${autodir}%s", 122 dir, rhost, rhost, user, pw->pw_dir); 123 if (q) 124 *q = '.'; 125 *pval = strdup(val); 126 return 0; 127 } 128 129 enoent: 130 if (dir) 131 free(dir); 132 133 return ENOENT; 134 } 135 #endif /* HAS_PASSWD_MAPS */ 136