Platform SDK: Network Management |
Windows 95/98: The following code sample demonstrates use of the NetSecurityGetInfo function.
The code sample specifies the security_info_1 information level. The example allocates and frees the memory required for the information buffer.
#include <stdio.h> #include <assert.h> #include <windows.h> #include <svrapi.h> int main(int argc, char FAR * argv[]) { char FAR * pszServerName = NULL; short nLevel = 1; struct security_info_1* pBuf = NULL; unsigned short cbBuffer; unsigned short nTotalAvail = 0; NET_API_STATUS nStatus; // // ServerName can be NULL to indicate the local computer. // if (argc > 2) { printf("Usage: %s [\\\\ServerName]\n", argv[0]); exit(1); } if (argc == 2) pszServerName = argv[1]; // // Allocate the memory for the buffer. // cbBuffer = sizeof(struct security_info_1); pBuf = (struct security_info_1*)malloc(cbBuffer); if (pBuf == NULL) printf("No memory\n"); // // Call the NetSecurityGetInfo function, // specifying information level 1. // nStatus = NetSecurityGetInfo(pszServerName, nLevel, (char FAR *)pBuf, cbBuffer, &nTotalAvail); // // If the call is successful, display the data. // if (nStatus == NERR_Success) { printf("\n\tContainer: %s\n", pBuf->sec1_container); printf("\tAddress book server: %s\n", pBuf->sec1_ab_server); printf("\tAddress book provider DLL: %s\n", pBuf->sec1_ab_dll); if (pBuf->sec1_security == SEC_SECURITY_SHARE) printf("\tSecurity: Share-level\n"); else // SEC_SECURITY_WINNT, SEC_SECURITY_WINNTAS, or SEC_SECURITY_NETWARE printf("\tSecurity: User-level\n"); } else fprintf(stderr, "A system error has occurred: %d\n", nStatus); // // Free the allocated memory. // if (pBuf != NULL) free(pBuf); return 0; }