]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/res_mkupdate.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / BsdSocketLib / res_mkupdate.c
diff --git a/StdLib/BsdSocketLib/res_mkupdate.c b/StdLib/BsdSocketLib/res_mkupdate.c
deleted file mode 100644 (file)
index db8540a..0000000
+++ /dev/null
@@ -1,461 +0,0 @@
-/** @file\r
-  Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available\r
-  under the terms and conditions of the BSD License which accompanies this\r
-  distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-/*\r
- * Copyright (c) 1996 by Internet Software Consortium.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- */\r
-\r
-/*\r
- * Portions copyright (c) 1999, 2000\r
- * Intel Corporation.\r
- * All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- *\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- *\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- *\r
- * 3. All advertising materials mentioning features or use of this software\r
- *    must display the following acknowledgement:\r
- *\r
- *    This product includes software developed by Intel Corporation and\r
- *    its contributors.\r
- *\r
- * 4. Neither the name of Intel Corporation or its contributors may be\r
- *    used to endorse or promote products derived from this software\r
- *    without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
- * THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- */\r
-\r
-/*\r
- * Based on the Dynamic DNS reference implementation by Viraj Bais\r
- * <viraj_bais@ccm.fm.intel.com>\r
- */\r
-\r
-#include <sys/types.h>\r
-#include <sys/param.h>\r
-\r
-#include <netinet/in.h>\r
-#include <arpa/nameser.h>\r
-#include <arpa/inet.h>\r
-\r
-#include <errno.h>\r
-#include <limits.h>\r
-#include <netdb.h>\r
-#include <resolv.h>\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#include <ctype.h>\r
-\r
-#include "res_config.h"\r
-\r
-static int getnum_str(u_char **, u_char *);\r
-static int getword_str(char *, int, u_char **, u_char *);\r
-\r
-#define ShrinkBuffer(x)  if ((buflen -= x) < 0) return (-2);\r
-\r
-/*\r
- * Form update packets.\r
- * Returns the size of the resulting packet if no error\r
- * On error,\r
- *  returns -1 if error in reading a word/number in rdata\r
- *         portion for update packets\r
- *      -2 if length of buffer passed is insufficient\r
- *      -3 if zone section is not the first section in\r
- *         the linked list, or section order has a problem\r
- *      -4 on a number overflow\r
- *      -5 unknown operation or no records\r
- */\r
-int\r
-res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {\r
-    ns_updrec *rrecp_start = rrecp_in;\r
-    HEADER *hp;\r
-    u_char *cp, *sp2, *startp, *endp;\r
-    int n, i, soanum, multiline;\r
-    ns_updrec *rrecp;\r
-    struct in_addr ina;\r
-        char buf2[MAXDNAME];\r
-    int section, numrrs = 0, counts[ns_s_max];\r
-    u_int16_t rtype, rclass;\r
-    u_int32_t n1, rttl;\r
-    u_char *dnptrs[20], **dpp, **lastdnptr;\r
-\r
-    if ((_res.options & RES_INIT) == 0 && res_init() == -1) {\r
-        h_errno = NETDB_INTERNAL;\r
-        return (-1);\r
-    }\r
-\r
-    /*\r
-     * Initialize header fields.\r
-     */\r
-    if ((buf == NULL) || (buflen < HFIXEDSZ))\r
-        return (-1);\r
-    memset(buf, 0, HFIXEDSZ);\r
-    hp = (HEADER *) buf;\r
-    hp->id = htons(++_res.id);\r
-    hp->opcode = ns_o_update;\r
-    hp->rcode = NOERROR;\r
-    cp = buf + HFIXEDSZ;\r
-    buflen -= HFIXEDSZ;\r
-    dpp = dnptrs;\r
-    *dpp++ = buf;\r
-    *dpp++ = NULL;\r
-    lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];\r
-\r
-    if (rrecp_start == NULL)\r
-        return (-5);\r
-    else if (rrecp_start->r_section != S_ZONE)\r
-        return (-3);\r
-\r
-    memset(counts, 0, sizeof counts);\r
-    for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {\r
-        numrrs++;\r
-                section = rrecp->r_section;\r
-        if (section < 0 || section >= ns_s_max)\r
-            return (-1);\r
-        counts[section]++;\r
-        for (i = section + 1; i < ns_s_max; i++)\r
-            if (counts[i])\r
-                return (-3);\r
-        rtype = rrecp->r_type;\r
-        rclass = rrecp->r_class;\r
-        rttl = rrecp->r_ttl;\r
-        /* overload class and type */\r
-        if (section == S_PREREQ) {\r
-            rttl = 0;\r
-            switch (rrecp->r_opcode) {\r
-            case YXDOMAIN:\r
-                rclass = C_ANY;\r
-                rtype = T_ANY;\r
-                rrecp->r_size = 0;\r
-                break;\r
-            case NXDOMAIN:\r
-                rclass = C_NONE;\r
-                rtype = T_ANY;\r
-                rrecp->r_size = 0;\r
-                break;\r
-            case NXRRSET:\r
-                rclass = C_NONE;\r
-                rrecp->r_size = 0;\r
-                break;\r
-            case YXRRSET:\r
-                if (rrecp->r_size == 0)\r
-                    rclass = C_ANY;\r
-                break;\r
-            default:\r
-                fprintf(stderr,\r
-                    "res_mkupdate: incorrect opcode: %d\n",\r
-                    rrecp->r_opcode);\r
-                fflush(stderr);\r
-                return (-1);\r
-            }\r
-        } else if (section == S_UPDATE) {\r
-            switch (rrecp->r_opcode) {\r
-            case DELETE:\r
-                rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;\r
-                break;\r
-            case ADD:\r
-                break;\r
-            default:\r
-                fprintf(stderr,\r
-                    "res_mkupdate: incorrect opcode: %d\n",\r
-                    rrecp->r_opcode);\r
-                fflush(stderr);\r
-                return (-1);\r
-            }\r
-        }\r
-\r
-        /*\r
-         * XXX  appending default domain to owner name is omitted,\r
-         *  fqdn must be provided\r
-         */\r
-        if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,\r
-                 lastdnptr)) < 0)\r
-            return (-1);\r
-        cp += n;\r
-        ShrinkBuffer(n + 2*INT16SZ);\r
-        PUTSHORT(rtype, cp);\r
-        PUTSHORT(rclass, cp);\r
-        if (section == S_ZONE) {\r
-            if (numrrs != 1 || rrecp->r_type != T_SOA)\r
-                return (-3);\r
-            continue;\r
-        }\r
-        ShrinkBuffer(INT32SZ + INT16SZ);\r
-        PUTLONG(rttl, cp);\r
-        sp2 = cp;  /* save pointer to length byte */\r
-        cp += INT16SZ;\r
-        if (rrecp->r_size == 0) {\r
-            if (section == S_UPDATE && rclass != C_ANY)\r
-                return (-1);\r
-            else {\r
-                PUTSHORT(0, sp2);\r
-                continue;\r
-            }\r
-        }\r
-        startp = rrecp->r_data;\r
-        endp = startp + rrecp->r_size - 1;\r
-        /* XXX this should be done centrally. */\r
-        switch (rrecp->r_type) {\r
-        case T_A:\r
-            if (!getword_str(buf2, sizeof buf2, &startp, endp))\r
-                return (-1);\r
-            if (!inet_aton(buf2, &ina))\r
-                return (-1);\r
-            n1 = ntohl(ina.s_addr);\r
-            ShrinkBuffer(INT32SZ);\r
-            PUTLONG(n1, cp);\r
-            break;\r
-        case T_CNAME:\r
-        case T_MB:\r
-        case T_MG:\r
-        case T_MR:\r
-        case T_NS:\r
-        case T_PTR:\r
-            if (!getword_str(buf2, sizeof buf2, &startp, endp))\r
-                return (-1);\r
-            n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);\r
-            if (n < 0)\r
-                return (-1);\r
-            cp += n;\r
-            ShrinkBuffer(n);\r
-            break;\r
-        case T_MINFO:\r
-        case T_SOA:\r
-        case T_RP:\r
-            for (i = 0; i < 2; i++) {\r
-                if (!getword_str(buf2, sizeof buf2, &startp,\r
-                         endp))\r
-                return (-1);\r
-                n = dn_comp(buf2, cp, buflen,\r
-                        dnptrs, lastdnptr);\r
-                if (n < 0)\r
-                    return (-1);\r
-                cp += n;\r
-                ShrinkBuffer(n);\r
-            }\r
-            if (rrecp->r_type == T_SOA) {\r
-                ShrinkBuffer(5 * INT32SZ);\r
-                while (isspace(*startp) || !*startp)\r
-                    startp++;\r
-                if (*startp == '(') {\r
-                    multiline = 1;\r
-                    startp++;\r
-                } else\r
-                    multiline = 0;\r
-                /* serial, refresh, retry, expire, minimum */\r
-                for (i = 0; i < 5; i++) {\r
-                    soanum = getnum_str(&startp, endp);\r
-                    if (soanum < 0)\r
-                        return (-1);\r
-                    PUTLONG(soanum, cp);\r
-                }\r
-                if (multiline) {\r
-                    while (isspace(*startp) || !*startp)\r
-                        startp++;\r
-                    if (*startp != ')')\r
-                        return (-1);\r
-                }\r
-            }\r
-            break;\r
-        case T_MX:\r
-        case T_AFSDB:\r
-        case T_RT:\r
-            n = getnum_str(&startp, endp);\r
-            if (n < 0)\r
-                return (-1);\r
-            PUTSHORT(n, cp);\r
-            ShrinkBuffer(INT16SZ);\r
-            if (!getword_str(buf2, sizeof buf2, &startp, endp))\r
-                return (-1);\r
-            n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);\r
-            if (n < 0)\r
-                return (-1);\r
-            cp += n;\r
-            ShrinkBuffer(n);\r
-            break;\r
-        case T_PX:\r
-            n = getnum_str(&startp, endp);\r
-            if (n < 0)\r
-                return (-1);\r
-            PUTSHORT(n, cp);\r
-            ShrinkBuffer(INT16SZ);\r
-            for (i = 0; i < 2; i++) {\r
-                if (!getword_str(buf2, sizeof buf2, &startp,\r
-                         endp))\r
-                    return (-1);\r
-                n = dn_comp(buf2, cp, buflen, dnptrs,\r
-                        lastdnptr);\r
-                if (n < 0)\r
-                    return (-1);\r
-                cp += n;\r
-                ShrinkBuffer(n);\r
-            }\r
-            break;\r
-        case T_WKS:\r
-        case T_HINFO:\r
-        case T_TXT:\r
-        case T_X25:\r
-        case T_ISDN:\r
-        case T_NSAP:\r
-        case T_LOC:\r
-            /* XXX - more fine tuning needed here */\r
-            ShrinkBuffer(rrecp->r_size);\r
-            memcpy(cp, rrecp->r_data, rrecp->r_size);\r
-            cp += rrecp->r_size;\r
-            break;\r
-        default:\r
-            return (-1);\r
-        } /*switch*/\r
-        n = (u_int16_t)((cp - sp2) - INT16SZ);\r
-        PUTSHORT(n, sp2);\r
-    } /*for*/\r
-\r
-    hp->qdcount = htons(counts[0]);\r
-    hp->ancount = htons(counts[1]);\r
-    hp->nscount = htons(counts[2]);\r
-    hp->arcount = htons(counts[3]);\r
-    return ((int)(cp - buf));\r
-}\r
-\r
-/*\r
- * Get a whitespace delimited word from a string (not file)\r
- * into buf. modify the start pointer to point after the\r
- * word in the string.\r
- */\r
-static int\r
-getword_str(char *buf, int size, u_char **startpp, u_char *endp) {\r
-        char *cp;\r
-        int c;\r
-\r
-        for (cp = buf; *startpp <= endp; ) {\r
-                c = **startpp;\r
-                if (isspace(c) || c == '\0') {\r
-                        if (cp != buf) /* trailing whitespace */\r
-                                break;\r
-                        else { /* leading whitespace */\r
-                                (*startpp)++;\r
-                                continue;\r
-                        }\r
-                }\r
-                (*startpp)++;\r
-                if (cp >= buf+size-1)\r
-                        break;\r
-                *cp++ = (u_char)c;\r
-        }\r
-        *cp = '\0';\r
-        return (cp != buf);\r
-}\r
-\r
-/*\r
- * Get a whitespace delimited number from a string (not file) into buf\r
- * update the start pointer to point after the number in the string.\r
- */\r
-static int\r
-getnum_str(u_char **startpp, u_char *endp) {\r
-        int c;\r
-        int n;\r
-        int seendigit = 0;\r
-        int m = 0;\r
-\r
-        for (n = 0; *startpp <= endp; ) {\r
-                c = **startpp;\r
-                if (isspace(c) || c == '\0') {\r
-                        if (seendigit) /* trailing whitespace */\r
-                                break;\r
-                        else { /* leading whitespace */\r
-                                (*startpp)++;\r
-                                continue;\r
-                        }\r
-                }\r
-                if (c == ';') {\r
-                        while ((*startpp <= endp) &&\r
-                   ((c = **startpp) != '\n'))\r
-                    (*startpp)++;\r
-                        if (seendigit)\r
-                                break;\r
-                        continue;\r
-                }\r
-                if (!isdigit(c)) {\r
-                        if (c == ')' && seendigit) {\r
-                                (*startpp)--;\r
-                                break;\r
-                        }\r
-            return (-1);\r
-                }\r
-                (*startpp)++;\r
-                n = n * 10 + (c - '0');\r
-                seendigit = 1;\r
-        }\r
-        return (n + m);\r
-}\r
-\r
-/*\r
- * Allocate a resource record buffer & save rr info.\r
- */\r
-ns_updrec *\r
-res_mkupdrec(int section, const char *dname,\r
-         u_int class, u_int type, u_long ttl) {\r
-    ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));\r
-\r
-    if (!rrecp || !(rrecp->r_dname = strdup(dname))) {\r
-        free(rrecp);\r
-        return (NULL);\r
-    }\r
-    rrecp->r_class = (u_int16_t)class;\r
-    rrecp->r_type = (u_int16_t)type;\r
-    rrecp->r_ttl = (u_int32_t)ttl;\r
-    rrecp->r_section = (u_int8_t)section;\r
-    return (rrecp);\r
-}\r
-\r
-/*\r
- * Free a resource record buffer created by res_mkupdrec.\r
- */\r
-void\r
-res_freeupdrec(ns_updrec *rrecp) {\r
-    /* Note: freeing r_dp is the caller's responsibility. */\r
-    if (rrecp->r_dname != NULL)\r
-        free(rrecp->r_dname);\r
-    free(rrecp);\r
-}\r