7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #include <strings.h>
  28 #include <stdlib.h>
  29 #include <netdir.h>
  30 #include <errno.h>
  31 #include <alloca.h>
  32 #include <locale.h>
  33 #include <uuid/uuid.h>
  34 
  35 #include <sys/fm/protocol.h>
  36 #include <fmd_adm_impl.h>
  37 #include <fmd_rpc_adm.h>
  38 
  39 static const uint_t _fmd_adm_bufsize = 128 * 1024;
  40 static const char _url_fallback[] = "http://illumos.org/msg/";
  41 
  42 fmd_adm_t *
  43 fmd_adm_open(const char *host, uint32_t prog, int version)
  44 {
  45         fmd_adm_t *ap;
  46         CLIENT *c;
  47         rpcvers_t v;
  48 
  49         if (version != FMD_ADM_VERSION) {
  50                 errno = ENOTSUP;
  51                 return (NULL);
  52         }
  53 
  54         if (host == NULL)
  55                 host = HOST_SELF;
 
 856                         return (fmd_adm_set_errno(ap, rv));
 857                 }
 858 
 859                 if ((rv = nvlist_lookup_string(aci.aci_event, FM_SUSPECT_UUID,
 860                     (char **)&aci.aci_uuid)) != 0) {
 861                         xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 862                         free(uuids);
 863                         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 864                         nvlist_free(aci.aci_event);
 865                         return (fmd_adm_set_errno(ap, rv));
 866                 }
 867                 if ((rv = nvlist_lookup_string(aci.aci_event,
 868                     FM_SUSPECT_DIAG_CODE, (char **)&aci.aci_code)) != 0) {
 869                         xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 870                         free(uuids);
 871                         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 872                         nvlist_free(aci.aci_event);
 873                         return (fmd_adm_set_errno(ap, rv));
 874                 }
 875 
 876                 rv = fmd_adm_case_one(&aci, url_token, func, arg);
 877 
 878                 xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 879                 nvlist_free(aci.aci_event);
 880 
 881                 if (rv != 0)
 882                         break;
 883         }
 884 
 885         free(uuids);
 886         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 887         return (0);
 888 }
 889 
 890 static int
 891 fmd_adm_serd_cmp(const void *lp, const void *rp)
 892 {
 893         return (strcmp(*(char **)lp, *(char **)rp));
 894 }
 895 
 
1082 
1083         return (fmd_adm_set_svcerr(ap, err));
1084 }
1085 
1086 /*
1087  * Custom XDR routine for our API structure fmd_stat_t.  This function must
1088  * match the definition of fmd_stat_t in <fm/fmd_api.h> and must also match
1089  * the corresponding routine in usr/src/cmd/fm/fmd/common/fmd_rpc_adm.c.
1090  */
1091 bool_t
1092 xdr_fmd_stat(XDR *xp, fmd_stat_t *sp)
1093 {
1094         bool_t rv = TRUE;
1095 
1096         rv &= xdr_opaque(xp, sp->fmds_name, sizeof (sp->fmds_name));
1097         rv &= xdr_u_int(xp, &sp->fmds_type);
1098         rv &= xdr_opaque(xp, sp->fmds_desc, sizeof (sp->fmds_desc));
1099 
1100         switch (sp->fmds_type) {
1101         case FMD_TYPE_BOOL:
1102                 rv &= xdr_int(xp, &sp->fmds_value.bool);
1103                 break;
1104         case FMD_TYPE_INT32:
1105                 rv &= xdr_int32_t(xp, &sp->fmds_value.i32);
1106                 break;
1107         case FMD_TYPE_UINT32:
1108                 rv &= xdr_uint32_t(xp, &sp->fmds_value.ui32);
1109                 break;
1110         case FMD_TYPE_INT64:
1111                 rv &= xdr_int64_t(xp, &sp->fmds_value.i64);
1112                 break;
1113         case FMD_TYPE_UINT64:
1114         case FMD_TYPE_TIME:
1115         case FMD_TYPE_SIZE:
1116                 rv &= xdr_uint64_t(xp, &sp->fmds_value.ui64);
1117                 break;
1118         case FMD_TYPE_STRING:
1119                 rv &= xdr_string(xp, &sp->fmds_value.str, ~0);
1120                 break;
1121         }
1122 
 | 
 
 
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2018 Nexenta Systems, Inc.
  29  */
  30 
  31 #include <sys/fm/protocol.h>
  32 
  33 #include <alloca.h>
  34 #include <errno.h>
  35 #include <locale.h>
  36 #include <netdir.h>
  37 #include <stdlib.h>
  38 #include <strings.h>
  39 #include <uuid/uuid.h>
  40 
  41 #include <fmd_adm_impl.h>
  42 #include <fmd_rpc_adm.h>
  43 
  44 static const uint_t _fmd_adm_bufsize = 128 * 1024;
  45 static const char _url_fallback[] = "http://illumos.org/msg/";
  46 
  47 fmd_adm_t *
  48 fmd_adm_open(const char *host, uint32_t prog, int version)
  49 {
  50         fmd_adm_t *ap;
  51         CLIENT *c;
  52         rpcvers_t v;
  53 
  54         if (version != FMD_ADM_VERSION) {
  55                 errno = ENOTSUP;
  56                 return (NULL);
  57         }
  58 
  59         if (host == NULL)
  60                 host = HOST_SELF;
 
 861                         return (fmd_adm_set_errno(ap, rv));
 862                 }
 863 
 864                 if ((rv = nvlist_lookup_string(aci.aci_event, FM_SUSPECT_UUID,
 865                     (char **)&aci.aci_uuid)) != 0) {
 866                         xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 867                         free(uuids);
 868                         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 869                         nvlist_free(aci.aci_event);
 870                         return (fmd_adm_set_errno(ap, rv));
 871                 }
 872                 if ((rv = nvlist_lookup_string(aci.aci_event,
 873                     FM_SUSPECT_DIAG_CODE, (char **)&aci.aci_code)) != 0) {
 874                         xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 875                         free(uuids);
 876                         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 877                         nvlist_free(aci.aci_event);
 878                         return (fmd_adm_set_errno(ap, rv));
 879                 }
 880 
 881                 /*
 882                  * Don't treat absence of type, severity, or description as
 883                  * fatal error.
 884                  */
 885                 (void) nvlist_lookup_string(aci.aci_event, FM_SUSPECT_TYPE,
 886                     (char **)&aci.aci_type);
 887                 (void) nvlist_lookup_string(aci.aci_event, FM_SUSPECT_SEVERITY,
 888                     (char **)&aci.aci_severity);
 889                 (void) nvlist_lookup_string(aci.aci_event, FM_SUSPECT_DESC,
 890                     (char **)&aci.aci_desc);
 891 
 892                 rv = fmd_adm_case_one(&aci, url_token, func, arg);
 893 
 894                 xdr_free(xdr_fmd_rpc_caseinfo, (char *)&rci);
 895                 nvlist_free(aci.aci_event);
 896 
 897                 if (rv != 0)
 898                         break;
 899         }
 900 
 901         free(uuids);
 902         xdr_free(xdr_fmd_rpc_caselist, (char *)&rcl);
 903         return (0);
 904 }
 905 
 906 static int
 907 fmd_adm_serd_cmp(const void *lp, const void *rp)
 908 {
 909         return (strcmp(*(char **)lp, *(char **)rp));
 910 }
 911 
 
1098 
1099         return (fmd_adm_set_svcerr(ap, err));
1100 }
1101 
1102 /*
1103  * Custom XDR routine for our API structure fmd_stat_t.  This function must
1104  * match the definition of fmd_stat_t in <fm/fmd_api.h> and must also match
1105  * the corresponding routine in usr/src/cmd/fm/fmd/common/fmd_rpc_adm.c.
1106  */
1107 bool_t
1108 xdr_fmd_stat(XDR *xp, fmd_stat_t *sp)
1109 {
1110         bool_t rv = TRUE;
1111 
1112         rv &= xdr_opaque(xp, sp->fmds_name, sizeof (sp->fmds_name));
1113         rv &= xdr_u_int(xp, &sp->fmds_type);
1114         rv &= xdr_opaque(xp, sp->fmds_desc, sizeof (sp->fmds_desc));
1115 
1116         switch (sp->fmds_type) {
1117         case FMD_TYPE_BOOL:
1118                 rv &= xdr_int(xp, &sp->fmds_value.b);
1119                 break;
1120         case FMD_TYPE_INT32:
1121                 rv &= xdr_int32_t(xp, &sp->fmds_value.i32);
1122                 break;
1123         case FMD_TYPE_UINT32:
1124                 rv &= xdr_uint32_t(xp, &sp->fmds_value.ui32);
1125                 break;
1126         case FMD_TYPE_INT64:
1127                 rv &= xdr_int64_t(xp, &sp->fmds_value.i64);
1128                 break;
1129         case FMD_TYPE_UINT64:
1130         case FMD_TYPE_TIME:
1131         case FMD_TYPE_SIZE:
1132                 rv &= xdr_uint64_t(xp, &sp->fmds_value.ui64);
1133                 break;
1134         case FMD_TYPE_STRING:
1135                 rv &= xdr_string(xp, &sp->fmds_value.str, ~0);
1136                 break;
1137         }
1138 
 |