libcli/cldap: make use of samba_tevent_context_init()
[Samba/gebeck_regimport.git] / source3 / lib / netapi / tests / netdisplay.c
blob090792cec2f73947d127a0e6174ef61b641edf0f
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetGroup testsuite
4 * Copyright (C) Guenther Deschner 2008
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.
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.
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/>.
20 #include <sys/types.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
26 #include <netapi.h>
28 #include "common.h"
30 static NET_API_STATUS test_netquerydisplayinformation(const char *hostname,
31 uint32_t level,
32 const char *name)
34 NET_API_STATUS status;
35 uint32_t entries_read = 0;
36 int found_name = 0;
37 const char *current_name;
38 uint8_t *buffer = NULL;
39 uint32_t idx = 0;
40 int i;
42 struct NET_DISPLAY_USER *user;
43 struct NET_DISPLAY_GROUP *group;
44 struct NET_DISPLAY_MACHINE *machine;
46 printf("testing NetQueryDisplayInformation level %d\n", level);
48 do {
49 status = NetQueryDisplayInformation(hostname,
50 level,
51 idx,
52 1000,
53 (uint32_t)-1,
54 &entries_read,
55 (void **)&buffer);
56 if (status == 0 || status == ERROR_MORE_DATA) {
57 switch (level) {
58 case 1:
59 user = (struct NET_DISPLAY_USER *)buffer;
60 break;
61 case 2:
62 machine = (struct NET_DISPLAY_MACHINE *)buffer;
63 break;
64 case 3:
65 group = (struct NET_DISPLAY_GROUP *)buffer;
66 break;
67 default:
68 return -1;
71 for (i=0; i<entries_read; i++) {
73 switch (level) {
74 case 1:
75 current_name = user->usri1_name;
76 break;
77 case 2:
78 current_name = machine->usri2_name;
79 break;
80 case 3:
81 current_name = group->grpi3_name;
82 break;
83 default:
84 break;
87 if (name && strcasecmp(current_name, name) == 0) {
88 found_name = 1;
91 switch (level) {
92 case 1:
93 user++;
94 break;
95 case 2:
96 machine++;
97 break;
98 case 3:
99 group++;
100 break;
103 NetApiBufferFree(buffer);
105 idx += entries_read;
106 } while (status == ERROR_MORE_DATA);
108 if (status) {
109 return status;
112 if (name && !found_name) {
113 printf("failed to get name\n");
114 return -1;
117 return 0;
120 NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx,
121 const char *hostname)
123 NET_API_STATUS status = 0;
124 uint32_t levels[] = { 1, 2, 3};
125 int i;
127 printf("NetDisplay tests\n");
129 /* test enum */
131 for (i=0; i<ARRAY_SIZE(levels); i++) {
133 status = test_netquerydisplayinformation(hostname, levels[i], NULL);
134 if (status) {
135 NETAPI_STATUS(ctx, status, "NetQueryDisplayInformation");
136 goto out;
140 status = 0;
142 printf("NetDisplay tests succeeded\n");
143 out:
144 if (status != 0) {
145 printf("NetDisplay testsuite failed with: %s\n",
146 libnetapi_get_error_string(ctx, status));
149 return status;