1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2012 Milan Jurik. All rights reserved.
25 */
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <strings.h>
30 #include <sys/types.h>
31 #include <unistd.h>
32 #include <wchar.h>
33 #include <libintl.h>
34 #include <errno.h>
35 #include <time.h>
36 #include <string.h>
37 #include <assert.h>
38 #include <getopt.h>
39 #include <cmdparse.h>
40 #include <stmfadm.h>
41 #include <libstmf.h>
42 #include <signal.h>
43 #include <pthread.h>
44 #include <locale.h>
518 return (-1);
519 }
520 for (i = 0; i < len; i++) {
521 mbString[i] = tolower(mbString[i]);
522 }
523 if (checkIscsiName(input + 4) != 0) {
524 return (-1);
525 }
526 } else if (strncmp(mbString, "wwn.", 4) == 0) {
527 if ((len = strlen(mbString + 4)) != SNS_WWN_16) {
528 return (-1);
529 } else if (checkHexUpper(mbString + 4) != 0) {
530 return (-1);
531 }
532 } else if (strncmp(mbString, "eui.", 4) == 0) {
533 if ((len = strlen(mbString + 4)) != SNS_EUI_16) {
534 return (-1);
535 } else if (checkHexUpper(mbString + 4) != 0) {
536 return (-1);
537 }
538 } else {
539 return (-1);
540 }
541
542 /*
543 * We have a validated name string.
544 * Go ahead and set the length and copy it.
545 */
546 devid->identLength = strlen(mbString);
547 bzero(devid->ident, STMF_IDENT_LENGTH);
548 bcopy(mbString, devid->ident, devid->identLength);
549
550 return (0);
551 }
552
553
554 /*
555 * Checks whether the entire string is in hex and converts to upper
556 */
557 static int
558 checkHexUpper(char *input)
559 {
|
1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2012 Milan Jurik. All rights reserved.
27 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
28 */
29
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <strings.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <wchar.h>
36 #include <libintl.h>
37 #include <errno.h>
38 #include <time.h>
39 #include <string.h>
40 #include <assert.h>
41 #include <getopt.h>
42 #include <cmdparse.h>
43 #include <stmfadm.h>
44 #include <libstmf.h>
45 #include <signal.h>
46 #include <pthread.h>
47 #include <locale.h>
521 return (-1);
522 }
523 for (i = 0; i < len; i++) {
524 mbString[i] = tolower(mbString[i]);
525 }
526 if (checkIscsiName(input + 4) != 0) {
527 return (-1);
528 }
529 } else if (strncmp(mbString, "wwn.", 4) == 0) {
530 if ((len = strlen(mbString + 4)) != SNS_WWN_16) {
531 return (-1);
532 } else if (checkHexUpper(mbString + 4) != 0) {
533 return (-1);
534 }
535 } else if (strncmp(mbString, "eui.", 4) == 0) {
536 if ((len = strlen(mbString + 4)) != SNS_EUI_16) {
537 return (-1);
538 } else if (checkHexUpper(mbString + 4) != 0) {
539 return (-1);
540 }
541 /*
542 * If none of iqn., wwn., and eui. matches, it might be a
543 * name string for AoE.
544 */
545 }
546
547 /*
548 * We have a validated name string.
549 * Go ahead and set the length and copy it.
550 */
551 devid->identLength = strlen(mbString);
552 bzero(devid->ident, STMF_IDENT_LENGTH);
553 bcopy(mbString, devid->ident, devid->identLength);
554
555 return (0);
556 }
557
558
559 /*
560 * Checks whether the entire string is in hex and converts to upper
561 */
562 static int
563 checkHexUpper(char *input)
564 {
|