[PATCH] wildcard usage in automount map

BIRD-nonTRW, Andrew (York Rd) Andrew.Bird-nonTRW at trw.com
Fri Jan 3 14:58:00 GMT 2003


Hi All
    Here is a little patch to allow usage of the wildcard entry in the
(YP/NIS+) automount map. Basic operation is a follows; In a automounting
environment it is common to use a map like this with a catchall wildcard
entry.

user1    server-a:/path/to/disk1/user1     # explicit entry
user2    server-b:/path/to/disk2/&           # slightly less work for admin
- looked up key(user2) is substituted back in for ampersand 
*           server-c:/path/to/disk3/&           # any user not in the map
explicitly, gets this entry again with key replacement.

I have added code for both YP and NIS+ but have not had the opportunity to
test NIS+ as I don't have a running NIS+ domain.
You will notice the change in substitute.c. The present behavior is not
correct in any share but happens to work in the [homes] one since both
username and resolved sharename are the same. So currently when using %N /
%p in a share called [test] the automount server is looked up in the map
with key(username) but the path is looked up in the same map with key(test).


Best Regards

Andrew Bird(Unix Consultant)

diff -c -r -N 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,266 ****
    int l = len - (int)(p-str);
    
    switch (*(p+1)) {
!   case 'N' : string_sub(p,"%N", automount_server(user),l); break;
    case 'H':
     if ((home = get_user_home_dir(user))) {
      string_sub(p,"%H",home, l);
--- 260,272 ----
    int l = len - (int)(p-str);
    
    switch (*(p+1)) {
!   case 'N':
!           string_sub(p,"%N", automount_server(user),l);
!    /* Patch from jkf at 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,297 ****
    case 'u': 
     string_sub(p,"%u", user, l); 
     break;
-    
-    /* Patch from jkf at 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); 
     break;
    case '\0': 
     p++; 
--- 288,301 ----
    case 'u': 
     string_sub(p,"%u", user, l); 
     break;
    case 'p': 
!           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 -c -r -N 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,908 ****
    char *nis_map = (char *)lp_nis_home_map_name();
   
    char buffer[NIS_MAXATTRVAL + 1];
!   nis_result *result;
    nis_object *object;
    entry_obj  *entry;
   
!   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));
   
!            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);
    }
--- 873,917 ----
    char *nis_map = (char *)lp_nis_home_map_name();
   
    char buffer[NIS_MAXATTRVAL + 1];
!   nis_result *result,*wildresult;
    nis_object *object;
    entry_obj  *entry;
   
!   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_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);
!           }
!        }
      }
      nis_freeresult(result);
    }
***************
*** 940,953 ****
  
      if ((nis_error = yp_match(nis_domain, nis_map,
                                user_name, strlen(user_name),
!                               &nis_result, &nis_result_len)) == 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);
  
      } else if(nis_error == YPERR_KEY) {
  
--- 949,972 ----
  
      if ((nis_error = yp_match(nis_domain, nis_map,
                                user_name, strlen(user_name),
!                               &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);
!        pstring_sub(last_value, "&", user_name);                         /*
substitute lookup key back into result */
  
      } else if(nis_error == YPERR_KEY) {
  
 



More information about the samba-technical mailing list