/***************************************************** * localui_ConfigurePortUI [exported through MONITORUI] * * Display the Configuration-Dialog for a specific Port * * PARAMS * pName [I] Servername or NULL (local Computer) * hWnd [I] Handle to parent Window for the Dialog-Box or NULL * pPortName [I] Name of the Port, that should be configured * * RETURNS * Success: TRUE * Failure: FALSE * */ static BOOL WINAPI localui_ConfigurePortUI(PCWSTR pName, HWND hWnd, PCWSTR pPortName) { HANDLE hXcv; DWORD res; TRACE("(%s, %p, %s)\n", debugstr_w(pName), hWnd, debugstr_w(pPortName)); if (open_monitor_by_name(XcvPortW, pPortName, &hXcv)) { res = get_type_from_name(pPortName); switch(res) { case PORT_IS_COM: res = dlg_configure_com(hXcv, hWnd, pPortName); break; case PORT_IS_LPT: res = dlg_configure_lpt(hXcv, hWnd); break; default: dlg_nothingtoconfig(hWnd); SetLastError(ERROR_CANCELLED); res = FALSE; } ClosePrinter(hXcv); return res; } return FALSE; }
static DWORD get_type_from_local_name(LPCWSTR nameW) { LPPORT_INFO_1W pi; LPWSTR myname = NULL; DWORD needed = 0; DWORD numentries = 0; DWORD id = 0; TRACE("(%s)\n", debugstr_w(myname)); needed = get_ports_from_reg(1, NULL, 0, &numentries); pi = heap_alloc(needed); if (pi) needed = get_ports_from_reg(1, (LPBYTE) pi, needed, &numentries); if (pi && needed && numentries > 0) { /* we got a number of valid ports. */ while ((myname == NULL) && (id < numentries)) { if (lstrcmpiW(nameW, pi[id].pName) == 0) { TRACE("(%u) found %s\n", id, debugstr_w(pi[id].pName)); myname = pi[id].pName; } id++; } } id = (myname) ? get_type_from_name(myname) : PORT_IS_UNKNOWN; heap_free(pi); return id; }
ya_result read_classtype(char* argv[], int argc, int* argi, u16* qclass, u16* qtype) { const char* name = next_arg(argv, argc, argi); if(name == NULL) { return COMMAND_ARGUMENT_EXPECTED; } if(FAIL(get_class_from_name(name, qclass))) { *qclass = CLASS_IN; if(FAIL(get_type_from_name(name, qtype))) { fprintf(stdout, "Wrong class '%s'\n", name); fflush(stdout); return ERROR - 2; } } else { const char* name = next_arg(argv, argc, argi); if(name == NULL) { return ERROR - 4; } if(FAIL(get_type_from_name((const u_char*)name, qtype))) { fprintf(stdout, "Wrong type '%s'\n", name); fflush(stdout); return ERROR - 5; } } return OK; }
/** @brief Parse the resource record in its components * * For not found values, default values will be used. * Default values are "origin" and "label". "Origin" always exists, but if * "label" does not exist, "origin" will be the "label" * * @param[in] rr_line * @param[in,out] label * @param[in,out] origin * @param[in] default_ttl * @param[in] default qclass * @param[out] rr * * @retval OK * @retval NOK */ ya_result rr_parse_line(char *src, const u8 *origin, u8 *label, u32 *ttl, resource_record *rr, int *bracket_status) { ya_result return_code = OK; char *needle = NULL; /* ------------------------------------------------------------ */ if(*bracket_status == BRACKET_CLOSED) { bool no_ttl = TRUE; if(FAIL(return_code = rr_check_qname(&src, rr->name, origin, label))) { return return_code; } while(*src) { if(rr->type != 0 ) { break; } needle = src; /* Search for word and cut */ CUT_WORD(needle); if(FAIL(return_code = parse_u32_check_range(src, &rr->ttl, 0, MAX_U32, /*BASE_*/10))) { if(FAIL(return_code = get_class_from_name(src, &rr->class))) { if(FAIL(return_code = get_type_from_name(src, &rr->type))) { return ZRE_NO_TYPE_FOUND; } } } else { no_ttl = FALSE; } // format("rr_parse_line 1: %s\n", src); src = needle; // format("rr_parse_line 2: %s\n", src); SKIP_WHSPACE(src); // format("rr_parse_line 3: %s\n", src); }
/***************************************************** * localmon_XcvDataPort [exported through MONITOREX] * * Execute command through a Communication-Channel * * PARAMS * hXcv [i] The Handle to work with * pszDataName [i] Name of the command to execute * pInputData [i] Buffer for extra Input Data (needed only for some commands) * cbInputData [i] Size in Bytes of Buffer at pInputData * pOutputData [o] Buffer to receive additional Data (needed only for some commands) * cbOutputData [i] Size in Bytes of Buffer at pOutputData * pcbOutputNeeded [o] PTR to receive the minimal Size in Bytes of the Buffer at pOutputData * * RETURNS * Success: ERROR_SUCCESS * Failure: win32 error code * * NOTES * * Minimal List of commands, that every Printmonitor DLL should support: * *| "MonitorUI" : Return the Name of the Userinterface-DLL as WSTR in pOutputData *| "AddPort" : Add a Port (Name as WSTR in pInputData) *| "DeletePort": Delete a Port (Name as WSTR in pInputData) * * */ static DWORD WINAPI localmon_XcvDataPort(HANDLE hXcv, LPCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded) { WCHAR buffer[16]; /* buffer for a decimal number */ LPWSTR ptr; DWORD res; DWORD needed; HKEY hroot; TRACE("(%p, %s, %p, %d, %p, %d, %p)\n", hXcv, debugstr_w(pszDataName), pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded); if (!lstrcmpW(pszDataName, cmd_AddPortW)) { TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData)); res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot); if (res == ERROR_SUCCESS) { if (does_port_exist((LPWSTR) pInputData)) { RegCloseKey(hroot); TRACE("=> %u\n", ERROR_ALREADY_EXISTS); return ERROR_ALREADY_EXISTS; } res = RegSetValueExW(hroot, (LPWSTR) pInputData, 0, REG_SZ, (const BYTE *) emptyW, sizeof(emptyW)); RegCloseKey(hroot); } TRACE("=> %u\n", res); return res; } if (!lstrcmpW(pszDataName, cmd_ConfigureLPTPortCommandOKW)) { TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData)); res = RegCreateKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsW, &hroot); if (res == ERROR_SUCCESS) { res = RegSetValueExW(hroot, TransmissionRetryTimeoutW, 0, REG_SZ, pInputData, cbInputData); RegCloseKey(hroot); } return res; } if (!lstrcmpW(pszDataName, cmd_DeletePortW)) { TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData)); res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot); if (res == ERROR_SUCCESS) { res = RegDeleteValueW(hroot, (LPWSTR) pInputData); RegCloseKey(hroot); TRACE("=> %u with %u\n", res, GetLastError() ); return res; } return ERROR_FILE_NOT_FOUND; } if (!lstrcmpW(pszDataName, cmd_GetDefaultCommConfigW)) { TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData)); *pcbOutputNeeded = cbOutputData; res = GetDefaultCommConfigW((LPWSTR) pInputData, (LPCOMMCONFIG) pOutputData, pcbOutputNeeded); TRACE("got %u with %u\n", res, GetLastError() ); return res ? ERROR_SUCCESS : GetLastError(); } if (!lstrcmpW(pszDataName, cmd_GetTransmissionRetryTimeoutW)) { * pcbOutputNeeded = sizeof(DWORD); if (cbOutputData >= sizeof(DWORD)) { /* the w2k resource kit documented a default of 90, but that's wrong */ *((LPDWORD) pOutputData) = 45; res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsW, &hroot); if (res == ERROR_SUCCESS) { needed = sizeof(buffer) - sizeof(WCHAR); res = RegQueryValueExW(hroot, TransmissionRetryTimeoutW, NULL, NULL, (LPBYTE) buffer, &needed); if ((res == ERROR_SUCCESS) && (buffer[0])) { *((LPDWORD) pOutputData) = strtoulW(buffer, NULL, 0); } RegCloseKey(hroot); } return ERROR_SUCCESS; } return ERROR_INSUFFICIENT_BUFFER; } if (!lstrcmpW(pszDataName, cmd_MonitorUIW)) { * pcbOutputNeeded = sizeof(dllnameuiW); if (cbOutputData >= sizeof(dllnameuiW)) { memcpy(pOutputData, dllnameuiW, sizeof(dllnameuiW)); return ERROR_SUCCESS; } return ERROR_INSUFFICIENT_BUFFER; } if (!lstrcmpW(pszDataName, cmd_PortIsValidW)) { TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData)); res = get_type_from_name((LPCWSTR) pInputData); TRACE("detected as %u\n", res); /* names, that we have recognized, are valid */ if (res) return ERROR_SUCCESS; /* ERROR_ACCESS_DENIED, ERROR_PATH_NOT_FOUND or something else */ TRACE("=> %u\n", GetLastError()); return GetLastError(); } if (!lstrcmpW(pszDataName, cmd_SetDefaultCommConfigW)) { /* get the portname from the Handle */ ptr = strchrW(((xcv_t *)hXcv)->nameW, ' '); if (ptr) { ptr++; /* skip the space */ } else { ptr = ((xcv_t *)hXcv)->nameW; } lstrcpynW(buffer, ptr, sizeof(buffer)/sizeof(WCHAR)); if (buffer[0]) buffer[lstrlenW(buffer)-1] = '\0'; /* remove the ':' */ res = SetDefaultCommConfigW(buffer, (LPCOMMCONFIG) pInputData, cbInputData); TRACE("got %u with %u\n", res, GetLastError() ); return res ? ERROR_SUCCESS : GetLastError(); } FIXME("command not supported: %s\n", debugstr_w(pszDataName)); return ERROR_INVALID_PARAMETER; }