diff options
Diffstat (limited to 'usr/src/cmd')
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.bin/dns-sd/Makefile | 1 | ||||
-rw-r--r-- | usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c | 142 | ||||
-rw-r--r-- | usr/src/cmd/devfsadm/devfsadm.c | 76 | ||||
-rw-r--r-- | usr/src/cmd/devfsadm/disk_link.c | 66 | ||||
-rw-r--r-- | usr/src/cmd/devfsadm/lofi_link.c | 29 | ||||
-rw-r--r-- | usr/src/cmd/format/menu_fdisk.c | 20 | ||||
-rw-r--r-- | usr/src/cmd/lofiadm/main.c | 160 |
7 files changed, 334 insertions, 160 deletions
diff --git a/usr/src/cmd/cmd-inet/usr.bin/dns-sd/Makefile b/usr/src/cmd/cmd-inet/usr.bin/dns-sd/Makefile index cc3ab285c0..01c94af04d 100644 --- a/usr/src/cmd/cmd-inet/usr.bin/dns-sd/Makefile +++ b/usr/src/cmd/cmd-inet/usr.bin/dns-sd/Makefile @@ -24,6 +24,7 @@ OBJS= ClientCommon.o dns-sd.o SRCS= ClientCommon.c dns-sd.c CFLAGS += $(C99_ENABLE) +CPPFLAGS += -DMDNS_VERSIONSTR_NODTS LDLIBS += -lsocket -ldns_sd .KEEP_STATE: diff --git a/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c b/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c index 9acf41e581..3be1426794 100644 --- a/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c +++ b/usr/src/cmd/cmd-inet/usr.bin/dns-sd/dns-sd.c @@ -200,7 +200,7 @@ static const char kFilePathSep = '/'; typedef struct { unsigned short keyTag; - unsigned char alg; + unsigned char alg; unsigned char digestType; unsigned char *digest; } rdataDS; @@ -214,12 +214,12 @@ typedef struct unsigned char *data; } rdataDNSKey; -//size of rdataRRSIG excluding signerName and signature (which are variable fields) +//size of rdataRRSIG excluding signerName and signature (which are variable fields) #define RRSIG_FIXED_SIZE 18 typedef struct { unsigned short typeCovered; - unsigned char alg; + unsigned char alg; unsigned char labels; unsigned int origTTL; unsigned int sigExpireTime; @@ -267,13 +267,13 @@ static volatile int timeOut = LONG_TIME; //************************************************************************************************************* // Supporting Utility Functions -static uint16_t GetRRClass(const char *s) +static uint16_t GetRRClass(const char *s) { - if (!strcasecmp(s, "IN")) + if (!strcasecmp(s, "IN")) return kDNSServiceClass_IN; else return(atoi(s)); -} +} static uint16_t GetRRType(const char *s) { @@ -348,7 +348,7 @@ static char *DNSTypeName(unsigned short rr_type) case kDNSServiceType_RRSIG: return("RRSIG"); case kDNSServiceType_DNSKEY: return("DNSKEY"); case kDNSServiceType_DS: return("DS"); - default: + default: { static char buffer[RR_TYPE_SIZE]; snprintf(buffer, sizeof(buffer), "TYPE%d", rr_type); @@ -363,12 +363,12 @@ static unsigned short swap16(unsigned short x) return (unsigned short)((unsigned short)ptr[0] << 8 | ptr[1]); } -static unsigned int swap32(unsigned int x) +static unsigned int swap32(unsigned int x) { unsigned char *ptr = (unsigned char *)&x; return (unsigned int)((unsigned int)ptr[0] << 24 | (unsigned int)ptr[1] << 16 | (unsigned int)ptr[2] << 8 | ptr[3]); } -static unsigned int keytag(unsigned char *key, unsigned int keysize) +static unsigned int keytag(unsigned char *key, unsigned int keysize) { unsigned long ac; unsigned int i; @@ -397,17 +397,17 @@ static void base64Encode(char *buffer, int buflen, void *rdata, unsigned int rdl null_str = dispatch_data_create("", 1, dispatch_get_global_queue(0, 0), ^{}); if (!null_str) goto done; - + data = dispatch_data_create_concat(dest_data, null_str); if (!data) - goto done; + goto done; - map = dispatch_data_create_map(data, &result, &size); + map = dispatch_data_create_map(data, &result, &size); if (!map) goto done; snprintf(buffer, buflen, " %s", (char *)result); - + done: if (src_data) dispatch_release(src_data); if (dest_data) dispatch_release(dest_data); @@ -418,7 +418,7 @@ done: #else //_DNS_SD_LIBDISPATCH snprintf(buffer, buflen, " %s", "."); return; -#endif //_DNS_SD_LIBDISPATCH +#endif //_DNS_SD_LIBDISPATCH } #if HAS_NAT_PMP_API | HAS_ADDRINFO_API @@ -468,7 +468,7 @@ static void printtimestamp(void) } // formating time to RFC 4034 format -static void FormatTime(unsigned long te, unsigned char *buf, int bufsize) +static void FormatTime(unsigned long te, unsigned char *buf, int bufsize) { struct tm tmTime; #ifdef _WIN32 @@ -696,10 +696,10 @@ static void DNSSD_API browse_reply(DNSServiceRef sdref, const DNSServiceFlags fl if (num_printed++ == 0) printf("Timestamp A/R Flags if %-20s %-20s %s\n", "Domain", "Service Type", "Instance Name"); printtimestamp(); - if (errorCode) + if (errorCode) printf("Error code %d\n", errorCode); - else - printf("%s %8X %3d %-20s %-20s %s\n", + else + printf("%s %8X %3d %-20s %-20s %s\n", op, flags, ifIndex, replyDomain, replyType, replyName); if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout); @@ -869,10 +869,10 @@ static int snprintd(char *p, int max, const unsigned char **rd) { const char *const buf = p; const char *const end = p + max; - while (**rd) - { - p += snprintf(p, end-p, "%.*s.", **rd, *rd+1); - *rd += 1 + **rd; + while (**rd) + { + p += snprintf(p, end-p, "%.*s.", **rd, *rd+1); + *rd += 1 + **rd; } *rd += 1; // Advance over the final zero byte return(p-buf); @@ -881,7 +881,7 @@ static int snprintd(char *p, int max, const unsigned char **rd) static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned const char *rd, uint16_t rdlen) { int rdb_size = 1000; - switch (rrtype) + switch (rrtype) { case kDNSServiceType_DS: { @@ -892,10 +892,10 @@ static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned con rrds->alg, swap16(rrds->keyTag), rrds->digestType); ptr = (unsigned char *)(rd + DS_FIXED_SIZE); for (i = 0; i < (rdlen - DS_FIXED_SIZE); i++) - p += snprintf(p, rdb + rdb_size - p, "%x", ptr[i]); - break; - } - + p += snprintf(p, rdb + rdb_size - p, "%x", ptr[i]); + break; + } + case kDNSServiceType_DNSKEY: { rdataDNSKey *rrkey = (rdataDNSKey *)rd; @@ -904,32 +904,32 @@ static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned con base64Encode(p, rdb + rdb_size - p, (unsigned char *)(rd + DNSKEY_FIXED_SIZE), rdlen - DNSKEY_FIXED_SIZE); break; } - - case kDNSServiceType_NSEC: + + case kDNSServiceType_NSEC: { unsigned char *next = (unsigned char *)rd; int len, bitmaplen; int win, wlen, type; unsigned char *bmap; char *l = NULL; - + l = p; p += snprintd(p, rdb + rdb_size - p, &rd); len = p - l + 1; - + bitmaplen = rdlen - len; bmap = (unsigned char *)((unsigned char *)next + len); - + while (bitmaplen > 0) { int i; - + if (bitmaplen < 3) { printf("Case NSEC: malformed nsec, bitmaplen %d short\n", bitmaplen); break; - } - + } + win = *bmap++; wlen = *bmap++; bitmaplen -= 2; @@ -954,8 +954,8 @@ static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned con } break; } - - case kDNSServiceType_RRSIG: + + case kDNSServiceType_RRSIG: { rdataRRSig *rrsig = (rdataRRSig *)rd; unsigned char expTimeBuf[64]; @@ -965,27 +965,27 @@ static void ParseDNSSECRecords(uint16_t rrtype, char *rdb, char *p, unsigned con const unsigned char *q = NULL; char *k = NULL; int len; - + expClock = (unsigned long)swap32(rrsig->sigExpireTime); FormatTime(expClock, expTimeBuf, sizeof(expTimeBuf)); - + inceptClock = (unsigned long)swap32(rrsig->sigInceptTime); FormatTime(inceptClock, inceptTimeBuf, sizeof(inceptTimeBuf)); - + p += snprintf(p, rdb + rdb_size - p, " %-7s %d %d %d %s %s %7d ", DNSTypeName(swap16(rrsig->typeCovered)), rrsig->alg, rrsig->labels, swap32(rrsig->origTTL), expTimeBuf, inceptTimeBuf, swap16(rrsig->keyTag)); - + q = (const unsigned char *)&rrsig->signerName; k = p; p += snprintd(p, rdb + rdb_size - p, &q); len = p - k + 1; - + base64Encode(p, rdb + rdb_size - p, (unsigned char *)(rd + len + RRSIG_FIXED_SIZE), rdlen - (len + RRSIG_FIXED_SIZE)); break; } } - return; + return; } static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, uint32_t ifIndex, DNSServiceErrorType errorCode, @@ -1009,9 +1009,9 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, if (num_printed++ == 0) { - if (operation == 'D') - printf("Timestamp A/R if %-30s%-6s%-7s%-18s Rdata\n", "Name", "Type", "Class", "DNSSECStatus"); - else + if (operation == 'D') + printf("Timestamp A/R if %-30s%-6s%-7s%-18s Rdata\n", "Name", "Type", "Class", "DNSSECStatus"); + else printf("Timestamp A/R Flags if %-30s%-6s%-7s Rdata\n", "Name", "Type", "Class"); } printtimestamp(); @@ -1036,7 +1036,7 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, case kDNSServiceType_A: snprintf(rdb, sizeof(rdb), "%d.%d.%d.%d", rd[0], rd[1], rd[2], rd[3]); break; - + case kDNSServiceType_NS: case kDNSServiceType_CNAME: case kDNSServiceType_PTR: @@ -1072,13 +1072,13 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, ParseDNSSECRecords(rrtype, rdb, p, rd, rdlen); break; - default: - snprintf(rdb, sizeof(rdb), "%d bytes%s", rdlen, rdlen ? ":" : ""); + default: + snprintf(rdb, sizeof(rdb), "%d bytes%s", rdlen, rdlen ? ":" : ""); unknowntype = 1; break; - } - } - else + } + } + else { strncpy(rdb, "----", sizeof(rdb)); //Clear all o/p bits, and then check for dnssec status @@ -1089,7 +1089,7 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, strncpy(dnssec_status, "Insecure", sizeof(dnssec_status)); else if (check_flags & kDNSServiceFlagsIndeterminate) strncpy(dnssec_status, "Indeterminate", sizeof(dnssec_status)); - else if (check_flags & kDNSServiceFlagsBogus) + else if (check_flags & kDNSServiceFlagsBogus) strncpy(dnssec_status, "Bogus", sizeof(dnssec_status)); } } @@ -1099,13 +1099,13 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, else printf("%s%6X%3d %-30s%-7s%-6s %s", op, flags, ifIndex, fullname, rr_type, rr_class, rdb); if (unknowntype) - { - while (rd < end) + { + while (rd < end) printf(" %02X", *rd++); } if (errorCode) { - if (errorCode == kDNSServiceErr_NoSuchRecord) + if (errorCode == kDNSServiceErr_NoSuchRecord) printf(" No Such Record"); else if (errorCode == kDNSServiceErr_Timeout) { @@ -1120,7 +1120,7 @@ static void DNSSD_API qr_reply(DNSServiceRef sdref, const DNSServiceFlags flags, if (flags & kDNSServiceFlagsAdd) DNSServiceReconfirmRecord(flags, ifIndex, fullname, rrtype, rrclass, rdlen, rdata); - if (!(flags & kDNSServiceFlagsMoreComing)) + if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout); } @@ -1153,7 +1153,7 @@ static void DNSSD_API addrinfo_reply(DNSServiceRef sdref, const DNSServiceFlags { char *op = (flags & kDNSServiceFlagsAdd) ? "Add" : "Rmv"; char addr[256] = ""; - char dnssec_status[15] = "Unknown"; + char dnssec_status[15] = "Unknown"; DNSServiceFlags check_flags = flags; (void) sdref; (void) context; @@ -1162,13 +1162,13 @@ static void DNSSD_API addrinfo_reply(DNSServiceRef sdref, const DNSServiceFlags if (num_printed++ == 0) { - if (operation == 'g') + if (operation == 'g') printf("Timestamp A/R if %-25s %-44s %-18s\n", "Hostname", "Address", "DNSSECStatus"); - else + else printf("Timestamp A/R Flags if %-38s %-44s %s\n", "Hostname", "Address", "TTL"); } printtimestamp(); - + if (address && address->sa_family == AF_INET) { const unsigned char *b = (const unsigned char *) &((struct sockaddr_in *)address)->sin_addr; @@ -1198,24 +1198,24 @@ static void DNSSD_API addrinfo_reply(DNSServiceRef sdref, const DNSServiceFlags strncpy(dnssec_status, "Insecure", sizeof(dnssec_status)); else if (check_flags & kDNSServiceFlagsIndeterminate) strncpy(dnssec_status, "Indeterminate", sizeof(dnssec_status)); - else if (check_flags & kDNSServiceFlagsBogus) + else if (check_flags & kDNSServiceFlagsBogus) strncpy(dnssec_status, "Bogus", sizeof(dnssec_status)); } - + if (operation == 'g') printf("%s%3d %-25s %-44s %-18s", op, interfaceIndex, hostname, addr, dnssec_status); else printf("%s%6X%3d %-38s %-44s %d", op, flags, interfaceIndex, hostname, addr, ttl); if (errorCode) { - if (errorCode == kDNSServiceErr_NoSuchRecord) + if (errorCode == kDNSServiceErr_NoSuchRecord) printf(" No Such Record"); - else + else printf(" Error code %d", errorCode); } printf("\n"); - if (!(flags & kDNSServiceFlagsMoreComing)) + if (!(flags & kDNSServiceFlagsMoreComing)) fflush(stdout); } #endif @@ -1634,7 +1634,7 @@ int main(int argc, char **argv) flags |= kDNSServiceFlagsReturnIntermediates; if (operation == 'q') flags |= kDNSServiceFlagsSuppressUnusable; - if (argc < opi+1) + if (argc < opi+1) goto Fail; rrtype = (argc <= opi+1) ? kDNSServiceType_A : GetRRType(argv[opi+1]); rrclass = (argc <= opi+2) ? kDNSServiceClass_IN : GetRRClass(argv[opi+2]); @@ -1725,9 +1725,9 @@ int main(int argc, char **argv) else flags |= kDNSServiceFlagsValidate; } - if (argc != opi+2) + if (argc != opi+2) goto Fail; - else + else err = DNSServiceGetAddrInfo(&client, flags, opinterface, GetProtocol(argv[opi+0]), argv[opi+1], addrinfo_reply, NULL); break; } @@ -1811,7 +1811,11 @@ Fail: // NOT static -- otherwise the compiler may optimize it out // The "@(#) " pattern is a special prefix the "what" command looks for +#ifndef MDNS_VERSIONSTR_NODTS const char VersionString_SCCS[] = "@(#) dns-sd " STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")"; +#else +const char VersionString_SCCS[] = "@(#) dns-sd " STRINGIFY(mDNSResponderVersion); +#endif #if _BUILDING_XCODE_PROJECT_ // If the process crashes, then this string will be magically included in the automatically-generated crash log diff --git a/usr/src/cmd/devfsadm/devfsadm.c b/usr/src/cmd/devfsadm/devfsadm.c index 448554a5e0..7d7904e9c0 100644 --- a/usr/src/cmd/devfsadm/devfsadm.c +++ b/usr/src/cmd/devfsadm/devfsadm.c @@ -20,6 +20,7 @@ */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -3289,7 +3290,7 @@ rm_parent_dir_if_empty(char *pathname) */ void devfsadm_rm_stale_links(char *dir_re, char *valid_link, di_node_t node, - di_minor_t minor) + di_minor_t minor) { link_t *link; linkhead_t *head; @@ -4837,7 +4838,7 @@ get_component(char *str, const char *comp_str) */ int devfsadm_enumerate_int(char *devfs_path, int index, char **buf, - devfsadm_enumerate_t rules[], int nrules) + devfsadm_enumerate_t rules[], int nrules) { return (find_enum_id(rules, nrules, devfs_path, index, "0", INTEGER, buf, 0)); @@ -4857,7 +4858,7 @@ disk_enumerate_int(char *devfs_path, int index, char **buf, */ static int devfsadm_enumerate_int_start(char *devfs_path, int index, char **buf, - devfsadm_enumerate_t rules[], int nrules, char *start) + devfsadm_enumerate_t rules[], int nrules, char *start) { return (find_enum_id(rules, nrules, devfs_path, index, start, INTEGER, buf, 0)); @@ -4869,7 +4870,7 @@ devfsadm_enumerate_int_start(char *devfs_path, int index, char **buf, */ int devfsadm_enumerate_char(char *devfs_path, int index, char **buf, - devfsadm_enumerate_t rules[], int nrules) + devfsadm_enumerate_t rules[], int nrules) { return (find_enum_id(rules, nrules, devfs_path, index, "a", LETTER, buf, 0)); @@ -4881,7 +4882,7 @@ devfsadm_enumerate_char(char *devfs_path, int index, char **buf, */ int devfsadm_enumerate_char_start(char *devfs_path, int index, char **buf, - devfsadm_enumerate_t rules[], int nrules, char *start) + devfsadm_enumerate_t rules[], int nrules, char *start) { return (find_enum_id(rules, nrules, devfs_path, index, start, LETTER, buf, 0)); @@ -4898,8 +4899,8 @@ devfsadm_enumerate_char_start(char *devfs_path, int index, char **buf, */ static int find_enum_id(devfsadm_enumerate_t rules[], int nrules, - char *devfs_path, int index, char *min, int type, char **buf, - int multiple) + char *devfs_path, int index, char *min, int type, char **buf, + int multiple) { numeral_t *matchnp; numeral_t *numeral; @@ -4999,7 +5000,7 @@ find_enum_id(devfsadm_enumerate_t rules[], int nrules, */ static int lookup_enum_cache(numeral_set_t *set, char *cmp_str, - devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp) + devfsadm_enumerate_t rules[], int index, numeral_t **matchnpp) { int matchcount = 0, rv = -1; int uncached; @@ -5390,7 +5391,7 @@ new_id(numeral_t *numeral, int type, char *min) static int enumerate_parse(char *rsvstr, char *path_left, numeral_set_t *setp, - devfsadm_enumerate_t rules[], int index) + devfsadm_enumerate_t rules[], int index) { char *slash1 = NULL; char *slash2 = NULL; @@ -5506,7 +5507,7 @@ out: */ static void enumerate_recurse(char *current_dir, char *path_left, numeral_set_t *setp, - devfsadm_enumerate_t rules[], int index) + devfsadm_enumerate_t rules[], int index) { char *slash; char *new_path; @@ -5661,7 +5662,7 @@ create_reserved_numeral(numeral_set_t *setp, char *numeral_id) */ static void create_cached_numeral(char *path, numeral_set_t *setp, char *numeral_id, - devfsadm_enumerate_t rules[], int index) + devfsadm_enumerate_t rules[], int index) { char linkbuf[PATH_MAX + 1]; char lpath[PATH_MAX + 1]; @@ -5838,7 +5839,7 @@ devfsadm_copy(void) /*ARGSUSED*/ static int devfsadm_copy_file(const char *file, const struct stat *stat, - int flags, struct FTW *ftw) + int flags, struct FTW *ftw) { struct stat sp; dev_t newdev; @@ -6290,7 +6291,7 @@ read_devlinktab_file(void) */ static int split_devlinktab_entry(char *entry, char **selector, char **p_link, - char **s_link) + char **s_link) { char *tab; @@ -6726,7 +6727,7 @@ get_anchored_re(char *link, char *anchored_re, char *pattern) static int construct_devlink(char *link, link_list_t *link_build, char *contents, - di_minor_t minor, di_node_t node, char *pattern) + di_minor_t minor, di_node_t node, char *pattern) { int counter_offset = -1; devfsadm_enumerate_t rules[1] = {NULL}; @@ -7133,7 +7134,7 @@ dequote(char *src) */ static void getattr(char *phy_path, char *aminor, int spectype, dev_t dev, mode_t *mode, - uid_t *uid, gid_t *gid) + uid_t *uid, gid_t *gid) { char devname[PATH_MAX + 1]; char *node_name; @@ -8219,6 +8220,26 @@ build_event_attributes(char *class, char *subclass, char *node_path, goto out; if (strcmp(subclass, ESC_DISK) == 0) { + /* + * While we're removing labeled lofi device, we will receive + * event for every registered minor device and lastly, + * an event with minor set to NULL, as in following example: + * class: EC_dev_remove subclass: disk + * node_path: /pseudo/lofi@1 driver: lofi minor: u,raw + * class: EC_dev_remove subclass: disk + * node_path: /pseudo/lofi@1 driver: lofi minor: NULL + * + * When we receive this last event with minor set to NULL, + * all lofi minor devices are already removed and the call to + * lookup_disk_dev_name() would result in error. + * To prevent name lookup error messages for this case, we + * need to filter out that last event. + */ + if (strcmp(class, EC_DEV_REMOVE) == 0 && + strcmp(driver_name, "lofi") == 0 && minor == NULL) { + nvlist_free(nvl); + return (NULL); + } if ((dev_name = lookup_disk_dev_name(node_path)) == NULL) { dev_name_lookup_err = 1; goto out; @@ -8239,11 +8260,26 @@ build_event_attributes(char *class, char *subclass, char *node_path, * The raw minor node is created or removed after the block * node. Lofi devfs events are dependent on this behavior. * Generate the sysevent only for the raw minor node. + * + * If the lofi mapping is created, we will receive the following + * event: class: EC_dev_add subclass: lofi minor: NULL + * + * As in case of EC_dev_add, the minor is NULL pointer, + * to get device links created, we will need to provide the + * type of minor node for lookup_lofi_dev_name() + * + * If the lofi device is unmapped, we will receive following + * events: + * class: EC_dev_remove subclass: lofi minor: disk + * class: EC_dev_remove subclass: lofi minor: disk,raw + * class: EC_dev_remove subclass: lofi minor: NULL */ - if (strstr(minor, "raw") == NULL) { - if (nvl) { - nvlist_free(nvl); - } + + if (strcmp(class, EC_DEV_ADD) == 0 && minor == NULL) + minor = "disk,raw"; + + if (minor == NULL || strstr(minor, "raw") == NULL) { + nvlist_free(nvl); return (NULL); } if ((dev_name = lookup_lofi_dev_name(node_path, minor)) == @@ -8374,7 +8410,7 @@ process_syseventq() static void build_and_enq_event(char *class, char *subclass, char *node_path, - di_node_t node, char *minor) + di_node_t node, char *minor) { nvlist_t *nvl; diff --git a/usr/src/cmd/devfsadm/disk_link.c b/usr/src/cmd/devfsadm/disk_link.c index 80e75c1694..0baa608912 100644 --- a/usr/src/cmd/devfsadm/disk_link.c +++ b/usr/src/cmd/devfsadm/disk_link.c @@ -19,6 +19,7 @@ * CDDL HEADER END */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright 2012 Nexenta Systems, Inc. All rights reserved. * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -30,11 +31,13 @@ #include <stdlib.h> #include <limits.h> #include <ctype.h> +#include <unistd.h> #include <sys/int_fmtio.h> #include <sys/stat.h> #include <bsm/devalloc.h> #include <sys/scsi/scsi_address.h> #include <sys/libdevid.h> +#include <sys/lofi.h> #define DISK_SUBPATH_MAX 100 #define RM_STALE 0x01 @@ -69,6 +72,7 @@ static void disk_common(di_minor_t minor, di_node_t node, char *disk, int flags); static char *diskctrl(di_node_t node, di_minor_t minor); static int reserved_links_exist(di_node_t node, di_minor_t minor, int nflags); +static void disk_rm_lofi_all(char *file); static devfsadm_create_t disk_cbt[] = { @@ -104,9 +108,12 @@ static devfsadm_create_t disk_cbt[] = { DEVFSADM_CREATE_INIT_V0(disk_cbt); /* - * HOT auto cleanup of disks not desired. + * HOT auto cleanup of disks is done for lofi devices only. */ static devfsadm_remove_t disk_remove_cbt[] = { + { "disk", DISK_LINK_RE, RM_HOT | RM_POST | RM_ALWAYS, + ILEVEL_0, disk_rm_lofi_all + }, { "disk", DISK_LINK_RE, RM_POST, ILEVEL_0, devfsadm_rm_all } @@ -124,6 +131,44 @@ static devlink_re_t disks_re_array[] = { static char *disk_mid = "disk_mid"; static char *modname = "disk_link"; +/* + * Check if link is from lofi by checking path from readlink(). + */ +static int +is_lofi_disk(char *file) +{ + char buf[PATH_MAX + 1]; + char filepath[PATH_MAX]; + char *ptr; + ssize_t size; + + size = snprintf(filepath, sizeof (filepath), "%s/dev/%s", + devfsadm_root_path(), file); + if (size > sizeof (filepath)) + return (0); + + size = readlink(filepath, buf, sizeof (buf) - 1); + if (size == -1) + return (0); + buf[size] = '\0'; + ptr = strchr(buf, '@'); + if (ptr == NULL) + return (0); + ptr[1] = '\0'; + if (strcmp(buf, "../../devices/pseudo/lofi@") != 0) + return (0); + return (1); +} + +/* + * Wrapper around devfsadm_rm_link() for lofi devices. + */ +static void disk_rm_lofi_all(char *file) +{ + if (is_lofi_disk(file)) + devfsadm_rm_link(file); +} + int minor_init() { @@ -137,13 +182,20 @@ static int disk_callback_chan(di_minor_t minor, di_node_t node) { char *addr; - char disk[20]; - uint_t targ; - uint_t lun; + char disk[23]; + char *driver; + uint_t targ = 0; + uint_t lun = 0; + + driver = di_driver_name(node); + if (strcmp(driver, LOFI_DRIVER_NAME) != 0) { + addr = di_bus_addr(node); + (void) sscanf(addr, "%X,%X", &targ, &lun); + } else { + targ = di_instance(node); + } - addr = di_bus_addr(node); - (void) sscanf(addr, "%X,%X", &targ, &lun); - (void) sprintf(disk, "t%dd%d", targ, lun); + (void) snprintf(disk, sizeof (disk), "t%dd%d", targ, lun); disk_common(minor, node, disk, 0); return (DEVFSADM_CONTINUE); diff --git a/usr/src/cmd/devfsadm/lofi_link.c b/usr/src/cmd/devfsadm/lofi_link.c index d86089f0bb..36fbe987d4 100644 --- a/usr/src/cmd/devfsadm/lofi_link.c +++ b/usr/src/cmd/devfsadm/lofi_link.c @@ -19,12 +19,11 @@ * CDDL HEADER END */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <regex.h> #include <devfsadm.h> #include <stdio.h> @@ -73,16 +72,14 @@ lofi_rm_all(char *link) * For the master device: * /dev/lofictl -> /devices/pseudo/lofi@0:ctl * For each other device - * /dev/lofi/1 -> /devices/pseudo/lofi@0:1 - * /dev/rlofi/1 -> /devices/pseudo/lofi@0:1,raw + * /dev/lofi/1 -> /devices/pseudo/lofi@1:disk + * /dev/rlofi/1 -> /devices/pseudo/lofi@1:disk,raw */ static int lofi(di_minor_t minor, di_node_t node) { - dev_t dev; + int instance; char mn[MAXNAMELEN + 1]; - char blkname[MAXNAMELEN + 1]; - char rawname[MAXNAMELEN + 1]; char path[PATH_MAX + 1]; (void) strcpy(mn, di_minor_name(minor)); @@ -90,18 +87,14 @@ lofi(di_minor_t minor, di_node_t node) if (strcmp(mn, "ctl") == 0) { (void) devfsadm_mklink(LOFI_CTL_NAME, node, minor, 0); } else { - dev = di_minor_devt(minor); - (void) snprintf(blkname, sizeof (blkname), "%d", - (int)minor(dev)); - (void) snprintf(rawname, sizeof (rawname), "%d,raw", - (int)minor(dev)); + instance = di_instance(node); - if (strcmp(mn, blkname) == 0) { - (void) snprintf(path, sizeof (path), "%s/%s", - LOFI_BLOCK_NAME, blkname); - } else if (strcmp(mn, rawname) == 0) { - (void) snprintf(path, sizeof (path), "%s/%s", - LOFI_CHAR_NAME, blkname); + if (strcmp(mn, LOFI_BLOCK_NODE) == 0) { + (void) snprintf(path, sizeof (path), "%s/%d", + LOFI_BLOCK_NAME, instance); + } else if (strcmp(mn, LOFI_CHAR_NODE) == 0) { + (void) snprintf(path, sizeof (path), "%s/%d", + LOFI_CHAR_NAME, instance); } else { return (DEVFSADM_CONTINUE); } diff --git a/usr/src/cmd/format/menu_fdisk.c b/usr/src/cmd/format/menu_fdisk.c index c3d9bcdcac..317954221f 100644 --- a/usr/src/cmd/format/menu_fdisk.c +++ b/usr/src/cmd/format/menu_fdisk.c @@ -20,6 +20,7 @@ */ /* * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2016 Toomas Soome <tsoome@me.com> */ /* @@ -709,6 +710,16 @@ copy_solaris_part(struct ipart *ipart) } if ((fd = open(buf, O_RDONLY)) < 0) { + /* + * Labeled device support in lofi provides p0 partition on + * both x86 and sparc. However, sparc does not implement fdisk + * partitioning. This workaround will allow format + * to ignore fdisk errors in case of lofi devices. + */ + if (strcmp(cur_disk->disk_dkinfo.dki_cname, "lofi") == 0) { + solaris_offset = 0; + return (0); + } err_print("Error: can't open disk '%s'.\n", buf); return (-1); } @@ -965,6 +976,15 @@ good_fdisk() if (lel(cur_disk->fdisk_part.numsect) > 0) { return (1); } else { + /* + * Labeled device support in lofi provides p0 partition on + * both x86 and sparc. However, sparc does not implement fdisk + * partitioning. This workaround will allow format + * to ignore fdisk errors in case of lofi devices. + */ + if (strcmp(cur_disk->disk_dkinfo.dki_cname, "lofi") == 0) { + return (1); + } err_print("WARNING - "); err_print("This disk may be in use by an application " "that has\n\t modified the fdisk table. Ensure " diff --git a/usr/src/cmd/lofiadm/main.c b/usr/src/cmd/lofiadm/main.c index d41ceaead3..87c6435386 100644 --- a/usr/src/cmd/lofiadm/main.c +++ b/usr/src/cmd/lofiadm/main.c @@ -59,6 +59,8 @@ #include <cryptoutil.h> #include <sys/crypto/ioctl.h> #include <sys/crypto/ioctladmin.h> +#include <sys/cmlb.h> +#include <sys/mkdev.h> #include "utils.h" #include <LzmaEnc.h> @@ -68,7 +70,7 @@ #include <blowfish/blowfish_impl.h> static const char USAGE[] = - "Usage: %s [-r] -a file [ device ]\n" + "Usage: %s [-r] [-l] -a file [ device ]\n" " %s [-r] -c crypto_algorithm -a file [device]\n" " %s [-r] -c crypto_algorithm -k raw_key_file -a file [device]\n" " %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key " @@ -218,7 +220,7 @@ static ISzAlloc g_Alloc = { /*ARGSUSED*/ static int lzma_compress(void *src, size_t srclen, void *dst, - size_t *dstlen, int level) + size_t *dstlen, int level) { CLzmaEncProps props; size_t outsize2; @@ -280,14 +282,30 @@ lzma_compress(void *src, size_t srclen, void *dst, static int name_to_minor(const char *devicename) { - int minor; + struct stat st; + + /* + * If devicename does not exist, then devicename contains + * the name of the device to be created. + * Note we only allow non-labeled devices here. + */ + if (stat(devicename, &st)) { + int minor, rv; - if (sscanf(devicename, "/dev/" LOFI_BLOCK_NAME "/%d", &minor) == 1) { - return (minor); + rv = sscanf(devicename, "/dev/" LOFI_BLOCK_NAME "/%d", &minor); + if (rv == 1) + return (minor); + rv = sscanf(devicename, "/dev/" LOFI_CHAR_NAME "/%d", &minor); + if (rv == 1) + return (minor); + + return (0); } - if (sscanf(devicename, "/dev/" LOFI_CHAR_NAME "/%d", &minor) == 1) { - return (minor); + + if (st.st_mode & S_IFCHR || st.st_mode & S_IFBLK) { + return (LOFI_MINOR2ID(minor(st.st_rdev))); } + return (0); } @@ -303,7 +321,32 @@ static int sleeptime = 2; /* number of seconds to sleep between stat's */ static int maxsleep = 120; /* maximum number of seconds to sleep */ static void -wait_until_dev_complete(int minor) +make_blkdevname(struct lofi_ioctl *li, char *path, size_t len) +{ + char *r1, *r2; + size_t l1; + + if (li->li_devpath[0] == '\0') { + if (li->li_labeled) + (void) strlcpy(path, "unknown", len); + else + (void) snprintf(path, len, + "/dev/" LOFI_BLOCK_NAME "/%d", li->li_id); + return; + } + (void) strlcpy(path, li->li_devpath, len); + r1 = strchr(path, 'r'); + l1 = r1 - path; + r2 = strchr(li->li_devpath, 'r'); + (void) strlcpy(r1, r2+1, len - l1); + + if (li->li_labeled) { + (void) strlcat(path, "p0", len); + } +} + +static void +wait_until_dev_complete(struct lofi_ioctl *li) { struct stat64 buf; int cursleep; @@ -311,10 +354,12 @@ wait_until_dev_complete(int minor) char charpath[MAXPATHLEN]; di_devlink_handle_t hdl; - (void) snprintf(blkpath, sizeof (blkpath), "/dev/%s/%d", - LOFI_BLOCK_NAME, minor); - (void) snprintf(charpath, sizeof (charpath), "/dev/%s/%d", - LOFI_CHAR_NAME, minor); + make_blkdevname(li, blkpath, sizeof (blkpath)); + (void) strlcpy(charpath, li->li_devpath, sizeof (charpath)); + + if (li->li_labeled) { + (void) strlcat(charpath, "p0", sizeof (charpath)); + } /* Check if links already present */ if (stat64(blkpath, &buf) == 0 && stat64(charpath, &buf) == 0) @@ -352,14 +397,14 @@ out: * DO NOT use this function if the filename is actually the device name. */ static int -lofi_map_file(int lfd, struct lofi_ioctl li, const char *filename, +lofi_map_file(int lfd, struct lofi_ioctl *li, const char *filename, boolean_t no_devlink_flag) { int minor; - li.li_minor = 0; - (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename)); - minor = ioctl(lfd, LOFI_MAP_FILE, &li); + li->li_id = 0; + (void) strlcpy(li->li_filename, filename, sizeof (li->li_filename)); + minor = ioctl(lfd, LOFI_MAP_FILE, li); if (minor == -1) { if (errno == ENOTSUP) warn(gettext("encrypting compressed files is " @@ -367,7 +412,7 @@ lofi_map_file(int lfd, struct lofi_ioctl li, const char *filename, die(gettext("could not map file %s"), filename); } if (!no_devlink_flag) - wait_until_dev_complete(minor); + wait_until_dev_complete(li); return (minor); } @@ -377,12 +422,14 @@ lofi_map_file(int lfd, struct lofi_ioctl li, const char *filename, */ static void add_mapping(int lfd, const char *devicename, const char *filename, - mech_alias_t *cipher, const char *rkey, size_t rksz, - boolean_t rdonly, boolean_t no_devlink_flag) + mech_alias_t *cipher, const char *rkey, size_t rksz, boolean_t rdonly, + boolean_t label, boolean_t no_devlink_flag) { struct lofi_ioctl li; + bzero(&li, sizeof (li)); li.li_readonly = rdonly; + li.li_labeled = label; li.li_crypto_enabled = B_FALSE; if (cipher != NULL) { @@ -412,17 +459,22 @@ add_mapping(int lfd, const char *devicename, const char *filename, if (devicename == NULL) { int minor; + char path[MAXPATHLEN]; /* pick one via the driver */ - minor = lofi_map_file(lfd, li, filename, no_devlink_flag); - /* if mapping succeeds, print the one picked */ - (void) printf("/dev/%s/%d\n", LOFI_BLOCK_NAME, minor); + minor = lofi_map_file(lfd, &li, filename, no_devlink_flag); + if (minor > 0) { + make_blkdevname(&li, path, sizeof (path)); + + /* if mapping succeeds, print the one picked */ + (void) printf("%s\n", path); + } return; } /* use device we were given */ - li.li_minor = name_to_minor(devicename); - if (li.li_minor == 0) { + li.li_id = name_to_minor(devicename); + if (li.li_id == 0) { die(gettext("malformed device name %s\n"), devicename); } (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename)); @@ -436,7 +488,7 @@ add_mapping(int lfd, const char *devicename, const char *filename, devicename); } if (!no_devlink_flag) - wait_until_dev_complete(li.li_minor); + wait_until_dev_complete(&li); } /* @@ -456,7 +508,7 @@ delete_mapping(int lfd, const char *devicename, const char *filename, /* delete by filename */ (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename)); - li.li_minor = 0; + li.li_id = 0; if (ioctl(lfd, LOFI_UNMAP_FILE, &li) == -1) { die(gettext("could not unmap file %s"), filename); } @@ -464,8 +516,8 @@ delete_mapping(int lfd, const char *devicename, const char *filename, } /* delete by device */ - li.li_minor = name_to_minor(devicename); - if (li.li_minor == 0) { + li.li_id = name_to_minor(devicename); + if (li.li_id == 0) { die(gettext("malformed device name %s\n"), devicename); } if (ioctl(lfd, LOFI_UNMAP_FILE_MINOR, &li) == -1) { @@ -480,22 +532,24 @@ static void print_one_mapping(int lfd, const char *devicename, const char *filename) { struct lofi_ioctl li; + char blkpath[MAXPATHLEN]; if (devicename == NULL) { /* given filename, print devicename */ - li.li_minor = 0; + li.li_id = 0; (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename)); if (ioctl(lfd, LOFI_GET_MINOR, &li) == -1) { die(gettext("could not find device for %s"), filename); } - (void) printf("/dev/%s/%d\n", LOFI_BLOCK_NAME, li.li_minor); + make_blkdevname(&li, blkpath, sizeof (blkpath)); + (void) printf("%s\n", blkpath); return; } /* given devicename, print filename */ - li.li_minor = name_to_minor(devicename); - if (li.li_minor == 0) { + li.li_id = name_to_minor(devicename); + if (li.li_id == 0) { die(gettext("malformed device name %s\n"), devicename); } if (ioctl(lfd, LOFI_GET_FILENAME, &li) == -1) { @@ -516,24 +570,23 @@ print_mappings(int fd) char path[MAXPATHLEN]; char options[MAXPATHLEN] = { 0 }; - li.li_minor = 0; + li.li_id = 0; if (ioctl(fd, LOFI_GET_MAXMINOR, &li) == -1) { die("ioctl"); } - maxminor = li.li_minor; + maxminor = li.li_id; (void) printf(FORMAT, gettext("Block Device"), gettext("File"), gettext("Options")); for (minor = 1; minor <= maxminor; minor++) { - li.li_minor = minor; + li.li_id = minor; if (ioctl(fd, LOFI_GET_FILENAME, &li) == -1) { if (errno == ENXIO) continue; warn("ioctl"); break; } - (void) snprintf(path, sizeof (path), "/dev/%s/%d", - LOFI_BLOCK_NAME, minor); + make_blkdevname(&li, path, sizeof (path)); options[0] = '\0'; @@ -548,14 +601,22 @@ print_mappings(int fd) gettext("Compressed(%s)"), li.li_algorithm); if (li.li_readonly) { if (strlen(options) != 0) { - (void) strlcat(options, ",", sizeof (options)); - (void) strlcat(options, "Readonly", + (void) strlcat(options, ",Readonly", sizeof (options)); } else { (void) snprintf(options, sizeof (options), gettext("Readonly")); } } + if (li.li_labeled) { + if (strlen(options) != 0) { + (void) strlcat(options, ",Labeled", + sizeof (options)); + } else { + (void) snprintf(options, sizeof (options), + gettext("Labeled")); + } + } if (strlen(options) == 0) (void) snprintf(options, sizeof (options), "-"); @@ -1308,7 +1369,7 @@ lofi_uncompress(int lfd, const char *filename) * already mapped. */ li.li_crypto_enabled = B_FALSE; - li.li_minor = 0; + li.li_id = 0; (void) strlcpy(li.li_filename, filename, sizeof (li.li_filename)); if (ioctl(lfd, LOFI_GET_MINOR, &li) != -1) die(gettext("%s must be unmapped before uncompressing"), @@ -1320,7 +1381,7 @@ lofi_uncompress(int lfd, const char *filename) if (statbuf.st_size == 0) return; - minor = lofi_map_file(lfd, li, filename, B_FALSE); + minor = lofi_map_file(lfd, &li, filename, B_FALSE); (void) snprintf(devicename, sizeof (devicename), "/dev/%s/%d", LOFI_BLOCK_NAME, minor); @@ -1432,7 +1493,7 @@ lofi_compress(int *lfd, const char *filename, int compress_index, * Disallow compressing the file if it is * already mapped */ - lic.li_minor = 0; + lic.li_id = 0; (void) strlcpy(lic.li_filename, filename, sizeof (lic.li_filename)); if (ioctl(*lfd, LOFI_GET_MINOR, &lic) != -1) die(gettext("%s must be unmapped before compressing"), @@ -1849,13 +1910,14 @@ main(int argc, char *argv[]) const char *algname = COMPRESS_ALGORITHM; int openflag; int minor; - int compress_index; + int compress_index; uint32_t segsize = SEGSIZE; static char *lofictl = "/dev/" LOFI_CTL_NAME; boolean_t force = B_FALSE; const char *pname; boolean_t errflag = B_FALSE; boolean_t addflag = B_FALSE; + boolean_t labelflag = B_FALSE; boolean_t rdflag = B_FALSE; boolean_t deleteflag = B_FALSE; boolean_t ephflag = B_FALSE; @@ -1877,7 +1939,7 @@ main(int argc, char *argv[]) (void) setlocale(LC_ALL, ""); (void) textdomain(TEXT_DOMAIN); - while ((c = getopt(argc, argv, "a:c:Cd:efk:rs:T:UX")) != EOF) { + while ((c = getopt(argc, argv, "a:c:Cd:efk:lrs:T:UX")) != EOF) { switch (c) { case 'a': addflag = B_TRUE; @@ -1932,6 +1994,9 @@ main(int argc, char *argv[]) need_crypto = B_TRUE; cipher_only = B_FALSE; /* need to unset cipher_only */ break; + case 'l': + labelflag = B_TRUE; + break; case 'r': rdflag = B_TRUE; break; @@ -1972,9 +2037,12 @@ main(int argc, char *argv[]) /* Check for mutually exclusive combinations of options */ if (errflag || (addflag && deleteflag) || + (labelflag && !addflag) || (rdflag && !addflag) || (!addflag && need_crypto) || - ((compressflag || uncompressflag) && (addflag || deleteflag))) + (need_crypto && labelflag) || + ((compressflag || uncompressflag) && + (labelflag || addflag || deleteflag))) usage(pname); /* ephemeral key, and key from either file or token are incompatible */ @@ -2091,7 +2159,7 @@ main(int argc, char *argv[]) */ if (addflag) add_mapping(lfd, devicename, filename, cipher, rkey, rksz, - rdflag, no_devlink_flag); + rdflag, labelflag, no_devlink_flag); else if (compressflag) lofi_compress(&lfd, filename, compress_index, segsize); else if (uncompressflag) |