// sambatest.cpp -- // // This file implements a test case for the Samba CreateDirectory bug. // // Copyright (c) 2006 Electric Cloud, Inc. // All rights reserved #include #include using namespace std; char *getErrorMessage( bool verbose) // Return a verbose error message. { const int BUFFER_SIZE = 500; static char buffer[BUFFER_SIZE]; int lastIndex, code; code = GetLastError(); // if (code == 0) { // // This is a bit of a kludge. For some reason, socket errors // // are recorded separately from system call errors. If there // // is no system call error pending, assume that the problem was // // actually in the socket system. // code = WSAGetLastError(); // } if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, BUFFER_SIZE, NULL) == 0) { sprintf(buffer, "??"); } lastIndex = strlen(buffer) - 1; if (buffer[lastIndex] == '\n') { // Get rid of any trailing newline character or CRLF sequence; // it just makes our printouts ugly. --lastIndex; if (buffer[lastIndex] == '\r') { --lastIndex; } } if (buffer[lastIndex] == '.') { // Get rid of a trailing period also, since it messes up our // output. --lastIndex; } if (verbose) { // Add the numerical error code to the end of the message. sprintf(buffer + lastIndex + 1, " (error code %d)", code); } else { buffer[lastIndex + 1] = 0; } return buffer; } int main(int argc, char* argv[]) { if (argc != 2) { cout << "Usage: " << argv[0] << " dirName" << endl; return 2; } if (CreateDirectory(argv[1], 0)) { cout << "No error" << endl; } else { cout << getErrorMessage(true) << endl; } return 0; }