]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: libsmb: Add utility function sockaddr_storage_to_samba_sockaddr().
authorJeremy Allison <jra@samba.org>
Tue, 28 Jul 2020 18:28:19 +0000 (11:28 -0700)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 7 Aug 2020 06:34:37 +0000 (06:34 +0000)
As requested by Andreas and Metze, ensure new code uses
struct samba_sockaddr. This is part of changing dns_lookup_list_async()
and callers to use struct samba_sockaddr.

Currently putting this into namequery.c even though it's
used inside dsgetdcname.c as I have future patches that
heavily make use of this to convert sockaddr_storage -> samba_sockaddr.

I'm not committed to putting it here, it may fit better
in lib/util/util_net.[ch]. It just needs to be somewhere
other functions inside source/libsmb/*.c can get to it,
and currently namequery.h exports the most stuff.

Not yet used.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/libsmb/namequery.c
source3/libsmb/namequery.h

index 73e0f172d58f3970a8754fb46bdb398262f7c0dc..317c5dd02621bce9334f9d3b399c4dbc6af50cae 100644 (file)
 #include "libads/kerberos_proto.h"
 #include "lib/gencache.h"
 #include "librpc/gen_ndr/dns.h"
+#include "lib/util/util_net.h"
 
 /* nmbd.c sets this to True. */
 bool global_in_nmbd = False;
 
+/*
+ * Utility function that copes only with AF_INET and AF_INET6
+ * as that's all we're going to get out of DNS / NetBIOS / WINS
+ * name resolution functions.
+ */
+
+bool sockaddr_storage_to_samba_sockaddr(struct samba_sockaddr *sa,
+                                       const struct sockaddr_storage *ss)
+{
+       sa->u.ss = *ss;
+
+       switch (ss->ss_family) {
+       case AF_INET:
+               sa->sa_socklen = sizeof(struct sockaddr_in);
+               break;
+#ifdef HAVE_IPV6
+       case AF_INET6:
+               sa->sa_socklen = sizeof(struct sockaddr_in6);
+               break;
+#endif
+       default:
+               return false;
+       }
+       return true;
+}
+
 /****************************
  * SERVER AFFINITY ROUTINES *
  ****************************/
index d6f5d21673371dbde7392351601ce8193f40e165..b1b138b1f3e5424bb26d977ca911b6c258e306c2 100644 (file)
@@ -23,7 +23,8 @@
 #include <tevent.h>
 
 /* The following definitions come from libsmb/namequery.c  */
-
+bool sockaddr_storage_to_samba_sockaddr(struct samba_sockaddr *sa,
+                                       const struct sockaddr_storage *ss);
 bool saf_store( const char *domain, const char *servername );
 bool saf_join_store( const char *domain, const char *servername );
 bool saf_delete( const char *domain );