xref: /illumos-gate/usr/src/test/smbclient-tests/include/smbutil_common.ksh (revision 96c8483a3fb53529bbf410957b0ad69cfb5d9229)
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#
25
26#
27# NAME
28#       parse_status_output
29#
30# DESCRIPTION
31#       Parse the output of the smbutil status, and print the
32#	workgroup and the server
33#
34# RETURN
35#       no return
36#
37
38parse_status_output() {
39	typeset w_tag a_tag Workgroup Server
40	w_tag=0
41	s_tag=0
42	while getopts w:s: opt
43	do
44	        case $opt in
45		w)
46			w_tag=1
47	                output="$OPTARG";;
48		s)
49			s_tag=1
50	                output="$OPTARG";;
51	        esac
52	done
53	if [[ w_tag == 1 ]]; then
54		Workgroup=$(cat $output|grep Workgroup \
55			|awk -F: '{print $2}')
56		echo $Workgroup
57	else
58		Server=$(cat $output|grep Server \
59			|awk -F: '{print $2}')
60		echo $Server
61	fi
62}
63
64#
65# NAME
66#       parse_view_output
67#
68# DESCRIPTION
69#       Parse the output of the smbutil view, and print the shares
70#
71# RETURN
72#       0 - success
73#
74parse_view_output() {
75	typeset share str
76	share=$1
77	stdout=$2
78	str=$(cat $stdout |grep -v -- "---"|grep $share)
79	name=$(echo $str |awk '{print $1}')
80	type=$(echo $str |awk '{print $2}')
81	if [[ "$name" != "$share" ]]; then
82		cti_fail "FAIL: share name should be $share"
83		return 1
84	fi
85	if [[ "$type" != "disk" ]]; then
86		cti_fail "FAIL: share type is $type, should be disk"
87		return 1
88	fi
89	return 0
90}
91