~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source3/lib/netapi/examples/server/server_getinfo.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Unix SMB/CIFS implementation.
 
3
 *  NetServerGetInfo query
 
4
 *  Copyright (C) Guenther Deschner 2008
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 3 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <sys/types.h>
 
21
#include <inttypes.h>
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
 
 
26
#include <netapi.h>
 
27
 
 
28
#include "common.h"
 
29
 
 
30
int main(int argc, const char **argv)
 
31
{
 
32
        NET_API_STATUS status;
 
33
        struct libnetapi_ctx *ctx = NULL;
 
34
        const char *hostname = NULL;
 
35
        uint8_t *buffer = NULL;
 
36
        uint32_t level = 100;
 
37
 
 
38
        struct SERVER_INFO_100 *i100;
 
39
        struct SERVER_INFO_101 *i101;
 
40
        struct SERVER_INFO_102 *i102;
 
41
        struct SERVER_INFO_402 *i402;
 
42
        struct SERVER_INFO_403 *i403;
 
43
        struct SERVER_INFO_502 *i502;
 
44
        struct SERVER_INFO_503 *i503;
 
45
        struct SERVER_INFO_1005 *i1005;
 
46
 
 
47
        poptContext pc;
 
48
        int opt;
 
49
 
 
50
        struct poptOption long_options[] = {
 
51
                POPT_AUTOHELP
 
52
                POPT_COMMON_LIBNETAPI_EXAMPLES
 
53
                POPT_TABLEEND
 
54
        };
 
55
 
 
56
        status = libnetapi_init(&ctx);
 
57
        if (status != 0) {
 
58
                return status;
 
59
        }
 
60
 
 
61
        pc = poptGetContext("server_getinfo", argc, argv, long_options, 0);
 
62
 
 
63
        poptSetOtherOptionHelp(pc, "hostname level");
 
64
        while((opt = poptGetNextOpt(pc)) != -1) {
 
65
        }
 
66
 
 
67
        if (!poptPeekArg(pc)) {
 
68
                poptPrintHelp(pc, stderr, 0);
 
69
                goto out;
 
70
        }
 
71
        hostname = poptGetArg(pc);
 
72
 
 
73
        if (poptPeekArg(pc)) {
 
74
                level = atoi(poptGetArg(pc));
 
75
        }
 
76
 
 
77
        /* NetServerGetInfo */
 
78
 
 
79
        status = NetServerGetInfo(hostname,
 
80
                                  level,
 
81
                                  &buffer);
 
82
        if (status != 0) {
 
83
                printf("NetServerGetInfo failed with: %s\n",
 
84
                        libnetapi_get_error_string(ctx, status));
 
85
                goto out;
 
86
        }
 
87
 
 
88
        switch (level) {
 
89
                case 100:
 
90
                        i100 = (struct SERVER_INFO_100 *)buffer;
 
91
                        printf("platform id: %d\n", i100->sv100_platform_id);
 
92
                        printf("name: %s\n", i100->sv100_name);
 
93
                        break;
 
94
                case 101:
 
95
                        i101 = (struct SERVER_INFO_101 *)buffer;
 
96
                        printf("platform id: %d\n", i101->sv101_platform_id);
 
97
                        printf("name: %s\n", i101->sv101_name);
 
98
                        printf("version major: %d\n", i101->sv101_version_major);
 
99
                        printf("version minor: %d\n", i101->sv101_version_minor);
 
100
                        printf("type: 0x%08x\n", i101->sv101_type);
 
101
                        printf("comment: %s\n", i101->sv101_comment);
 
102
                        break;
 
103
                case 102:
 
104
                        i102 = (struct SERVER_INFO_102 *)buffer;
 
105
                        printf("platform id: %d\n", i102->sv102_platform_id);
 
106
                        printf("name: %s\n", i102->sv102_name);
 
107
                        printf("version major: %d\n", i102->sv102_version_major);
 
108
                        printf("version minor: %d\n", i102->sv102_version_minor);
 
109
                        printf("type: 0x%08x\n", i102->sv102_type);
 
110
                        printf("comment: %s\n", i102->sv102_comment);
 
111
                        printf("users: %d\n", i102->sv102_users);
 
112
                        printf("disc: %d\n", i102->sv102_disc);
 
113
                        printf("hidden: %d\n", i102->sv102_hidden);
 
114
                        printf("announce: %d\n", i102->sv102_announce);
 
115
                        printf("anndelta: %d\n", i102->sv102_anndelta);
 
116
                        printf("licenses: %d\n", i102->sv102_licenses);
 
117
                        printf("userpath: %s\n", i102->sv102_userpath);
 
118
                        break;
 
119
                case 402:
 
120
                        i402 = (struct SERVER_INFO_402 *)buffer;
 
121
                        break;
 
122
                case 403:
 
123
                        i403 = (struct SERVER_INFO_403 *)buffer;
 
124
                        break;
 
125
                case 502:
 
126
                        i502 = (struct SERVER_INFO_502 *)buffer;
 
127
                        break;
 
128
                case 503:
 
129
                        i503 = (struct SERVER_INFO_503 *)buffer;
 
130
                        break;
 
131
                case 1005:
 
132
                        i1005 = (struct SERVER_INFO_1005 *)buffer;
 
133
                        printf("comment: %s\n", i1005->sv1005_comment);
 
134
                        break;
 
135
                default:
 
136
                        break;
 
137
        }
 
138
 
 
139
 out:
 
140
        libnetapi_free(ctx);
 
141
        poptFreeContext(pc);
 
142
 
 
143
        return status;
 
144
}