summarylogtreecommitdiffstats
path: root/search-local.patch
blob: 76427934f6d7ff27fadb3b069d80eac4a1d48e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
*** orig-nss.c	2018-02-19 15:33:31.000000000 +0000
--- nss.c	2020-06-05 17:29:03.659841552 +0100
***************
*** 126,131 ****
--- 126,149 ----
      }
  }
  
+ static enum nss_status _convert_avahi_result(avahi_resolve_result_t r, int* errnop, int* h_errnop) {
+     switch (r) {
+     case AVAHI_RESOLVE_RESULT_SUCCESS:
+         return NSS_STATUS_SUCCESS;
+ 
+     case AVAHI_RESOLVE_RESULT_HOST_NOT_FOUND:
+         *errnop = ETIMEDOUT;
+         *h_errnop = HOST_NOT_FOUND;
+         return NSS_STATUS_NOTFOUND;
+ 
+     case AVAHI_RESOLVE_RESULT_UNAVAIL:
+     default:
+         *errnop = ETIMEDOUT;
+         *h_errnop = NO_RECOVERY;
+         return NSS_STATUS_UNAVAIL;
+     }
+ }
+ 
  static enum nss_status gethostbyname_impl(const char* name, int af,
                                            userdata_t* u, int* errnop,
                                            int* h_errnop) {
***************
*** 168,195 ****
      if (mdns_allow_file)
          fclose(mdns_allow_file);
  #endif
- 
      if (!name_allowed) {
          *errnop = EINVAL;
          *h_errnop = NO_RECOVERY;
          return NSS_STATUS_UNAVAIL;
      }
  
!     switch (do_avahi_resolve_name(af, name, u)) {
!     case AVAHI_RESOLVE_RESULT_SUCCESS:
!         return NSS_STATUS_SUCCESS;
! 
!     case AVAHI_RESOLVE_RESULT_HOST_NOT_FOUND:
!         *errnop = ETIMEDOUT;
!         *h_errnop = HOST_NOT_FOUND;
!         return NSS_STATUS_NOTFOUND;
! 
!     case AVAHI_RESOLVE_RESULT_UNAVAIL:
!     default:
!         *errnop = ETIMEDOUT;
!         *h_errnop = NO_RECOVERY;
!         return NSS_STATUS_UNAVAIL;
!     }
  }
  
  enum nss_status _nss_mdns_gethostbyname4_r(const char* name,
--- 186,211 ----
      if (mdns_allow_file)
          fclose(mdns_allow_file);
  #endif
      if (!name_allowed) {
+ 		if (!strstr(name, ".")) {
+ 			const char *p="local";
+ 			int fullnamesize;
+ 			char *fullname;
+ 			fullnamesize = strlen(name) + strlen(p) + 2;
+ 			if ((fullname = malloc(fullnamesize))){
+ 				avahi_resolve_result_t r;
+ 				snprintf(fullname, fullnamesize, "%s.%s", name, p);
+     			r = do_avahi_resolve_name(af, fullname, u);
+ 				free(fullname);
+ 				return _convert_avahi_result(r, errnop, h_errnop);
+ 				}
+ 			}
          *errnop = EINVAL;
          *h_errnop = NO_RECOVERY;
          return NSS_STATUS_UNAVAIL;
      }
  
!     return _convert_avahi_result(do_avahi_resolve_name(af, name, u), errnop, h_errnop);
  }
  
  enum nss_status _nss_mdns_gethostbyname4_r(const char* name,