diff -u -r samba-2.2.7a/source/lib/substitute.c samba-2.2.7a.mypatched/source/lib/substitute.c
--- samba-2.2.7a/source/lib/substitute.c	2002-12-10 14:58:15.000000000 +0000
+++ samba-2.2.7a.mypatched/source/lib/substitute.c	2003-01-03 14:27:35.000000000 +0000
@@ -260,7 +260,13 @@
 		int l = len - (int)(p-str);
 		
 		switch (*(p+1)) {
-		case 'N' : string_sub(p,"%N", automount_server(user),l); break;
+		case 'N':
+		       	string_sub(p,"%N", automount_server(user),l);
+			/* Patch from jkf@soton.ac.uk Left the %N (NIS
+			 * server name) in standard_sub_basic as it is
+			 * a feature for logon servers, hence uses the
+			 * username. */
+			break;
 		case 'H':
 			if ((home = get_user_home_dir(user))) {
 				string_sub(p,"%H",home, l);
@@ -282,16 +288,14 @@
 		case 'u': 
 			string_sub(p,"%u", user, l); 
 			break;
-			
-			/* Patch from jkf@soton.ac.uk Left the %N (NIS
-			 * server name) in standard_sub_basic as it is
-			 * a feature for logon servers, hence uses the
-			 * username.  The %p (NIS server path) code is
-			 * here as it is used instead of the default
-			 * "path =" string in [homes] and so needs the
-			 * service name, not the username.  */
 		case 'p': 
-			string_sub(p,"%p", automount_path(lp_servicename(snum)), l); 
+		        string_sub(p,"%p", automount_path(user),l);
+		       	/* The %p (NIS server path) code is
+			 * here as it is used instead of the default
+			 * "path =" string in [homes]. The %p should 
+			 * return the automount path when looked up in 
+			 * the automount map with the username as the
+			 * key */
 			break;
 		case '\0': 
 			p++; 
diff -u -r samba-2.2.7a/source/lib/util.c samba-2.2.7a.mypatched/source/lib/util.c
--- samba-2.2.7a/source/lib/util.c	2002-07-26 14:36:45.000000000 +0100
+++ samba-2.2.7a.mypatched/source/lib/util.c	2002-12-30 13:46:04.000000000 +0000
@@ -873,36 +873,45 @@
   char *nis_map = (char *)lp_nis_home_map_name();
  
   char buffer[NIS_MAXATTRVAL + 1];
-  nis_result *result;
+  nis_result *result,*wildresult;
   nis_object *object;
   entry_obj  *entry;
  
-  if (strcmp(user_name, last_key))
-  {
+  if (strcmp(user_name, last_key)) {
+
     slprintf(buffer, sizeof(buffer)-1, "[key=%s],%s", user_name, nis_map);
     DEBUG(5, ("NIS+ querystring: %s\n", buffer));
  
-    if (result = nis_list(buffer, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP, NULL, NULL))
-    {
-       if (result->status != NIS_SUCCESS)
-      {
-        DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
-        fstrcpy(last_key, ""); pstrcpy(last_value, "");
-      }
-      else
-      {
-        object = result->objects.objects_val;
-        if (object->zo_data.zo_type == ENTRY_OBJ)
-        {
-           entry = &object->zo_data.objdata_u.en_data;
-           DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
-           DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
+    if (result = nis_list(buffer, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP, NULL, NULL)) {
+
+       if(result->status == NIS_NOTFOUND) {
+          slprintf(buffer, sizeof(buffer)-1, "[key=*],%s", nis_map);
+          if (wildresult = nis_list(buffer, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP, NULL, NULL)) {
+             if (wildresult->status == NIS_SUCCESS) {
+                DEBUG(3, ("NIS+ query failed: using wildcard entry for \"%s\" in map \"%s\"\n", user_name, nis_map)); 
+                nis_freeresult(result);
+                result=wildresult;
+             } else {
+                nis_freeresult(wildresult);
+             }
+          }
+       }
+
+       if (result->status != NIS_SUCCESS) {
+          DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
+          fstrcpy(last_key, ""); pstrcpy(last_value, "");
+       } else {
+          object = result->objects.objects_val;
+          if (object->zo_data.zo_type == ENTRY_OBJ) {
+             entry = &object->zo_data.objdata_u.en_data;
+             DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
+             DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
  
-           pstrcpy(last_value, entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
-           pstring_sub(last_value, "&", user_name);
-           fstrcpy(last_key, user_name);
-        }
-      }
+             pstrcpy(last_value, entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
+             pstring_sub(last_value, "&", user_name);
+             fstrcpy(last_key, user_name);
+          }
+       }
     }
     nis_freeresult(result);
   }
@@ -940,14 +949,24 @@
 
     if ((nis_error = yp_match(nis_domain, nis_map,
                               user_name, strlen(user_name),
-                              &nis_result, &nis_result_len)) == 0) {
+                              &nis_result, &nis_result_len)) == YPERR_KEY) {
+       /* check for wildcard entry */
+       if ((nis_error = yp_match(nis_domain, nis_map,
+                                 "*", 1,
+                                 &nis_result, &nis_result_len)) == 0) {
+          DEBUG(3, ("YP Key not found: using wildcard entry for \"%s\" in map \"%s\"\n", user_name, nis_map));
+       }
+    }
+
+    if (nis_error == 0) {
        if (!nis_error && nis_result_len >= sizeof(pstring)) {
                nis_result_len = sizeof(pstring)-1;
        }
        fstrcpy(last_key, user_name);
        strncpy(last_value, nis_result, nis_result_len);
        last_value[nis_result_len] = '\0';
-        strip_mount_options(&last_value);
+       strip_mount_options(&last_value);
+       pstring_sub(last_value, "&", user_name);                         /* substitute lookup key back into result */
 
     } else if(nis_error == YPERR_KEY) {
 
