| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | * NetGroup testsuite
|
|---|
| 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 | static NET_API_STATUS test_netquerydisplayinformation(const char *hostname,
|
|---|
| 31 | uint32_t level,
|
|---|
| 32 | const char *name)
|
|---|
| 33 | {
|
|---|
| 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;
|
|---|
| 41 |
|
|---|
| 42 | struct NET_DISPLAY_USER *user;
|
|---|
| 43 | struct NET_DISPLAY_GROUP *group;
|
|---|
| 44 | struct NET_DISPLAY_MACHINE *machine;
|
|---|
| 45 |
|
|---|
| 46 | printf("testing NetQueryDisplayInformation level %d\n", level);
|
|---|
| 47 |
|
|---|
| 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;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | for (i=0; i<entries_read; i++) {
|
|---|
| 72 |
|
|---|
| 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;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if (name && strcasecmp(current_name, name) == 0) {
|
|---|
| 88 | found_name = 1;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | switch (level) {
|
|---|
| 92 | case 1:
|
|---|
| 93 | user++;
|
|---|
| 94 | break;
|
|---|
| 95 | case 2:
|
|---|
| 96 | machine++;
|
|---|
| 97 | break;
|
|---|
| 98 | case 3:
|
|---|
| 99 | group++;
|
|---|
| 100 | break;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | NetApiBufferFree(buffer);
|
|---|
| 104 | }
|
|---|
| 105 | idx += entries_read;
|
|---|
| 106 | } while (status == ERROR_MORE_DATA);
|
|---|
| 107 |
|
|---|
| 108 | if (status) {
|
|---|
| 109 | return status;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if (name && !found_name) {
|
|---|
| 113 | printf("failed to get name\n");
|
|---|
| 114 | return -1;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | return 0;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | NET_API_STATUS netapitest_display(struct libnetapi_ctx *ctx,
|
|---|
| 121 | const char *hostname)
|
|---|
| 122 | {
|
|---|
| 123 | NET_API_STATUS status = 0;
|
|---|
| 124 | uint32_t levels[] = { 1, 2, 3};
|
|---|
| 125 | int i;
|
|---|
| 126 |
|
|---|
| 127 | printf("NetDisplay tests\n");
|
|---|
| 128 |
|
|---|
| 129 | /* test enum */
|
|---|
| 130 |
|
|---|
| 131 | for (i=0; i<ARRAY_SIZE(levels); i++) {
|
|---|
| 132 |
|
|---|
| 133 | status = test_netquerydisplayinformation(hostname, levels[i], NULL);
|
|---|
| 134 | if (status) {
|
|---|
| 135 | NETAPI_STATUS(ctx, status, "NetQueryDisplayInformation");
|
|---|
| 136 | goto out;
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | status = 0;
|
|---|
| 141 |
|
|---|
| 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));
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | return status;
|
|---|
| 150 | }
|
|---|