/* * Used to get printer device information from a printer name. This * can fail if the user has no right to read printer properties, so * this function can return NULL. */ GtkPrintWin32Devnames * gtk_print_win32_devnames_from_printer_name (const char *printer_name) { HANDLE hprinter; gunichar2* win32_printer_name; GtkPrintWin32Devnames *devnames; win32_printer_name = g_utf8_to_utf16 (printer_name, -1, NULL, NULL, NULL); if (OpenPrinterW (win32_printer_name, &hprinter, NULL)) { DWORD needed; PRINTER_INFO_2W* printer_info; GetPrinterW (hprinter, 2, NULL, 0, &needed); printer_info = (PRINTER_INFO_2W* )g_malloc ((gsize) needed); GetPrinterW (hprinter, 2, (LPBYTE) printer_info, needed, &needed); devnames = g_new (GtkPrintWin32Devnames, 1); devnames->driver = g_utf16_to_utf8 (printer_info->pDriverName, -1, NULL, NULL, NULL); devnames->device = g_strdup (printer_name); devnames->output = g_utf16_to_utf8 (printer_info->pPortName, -1, NULL, NULL, NULL); devnames->flags = 0; ClosePrinter (hprinter); g_free (printer_info); } else { /* Could not open printer */ devnames = NULL; } g_free (win32_printer_name); return devnames; }
bool DeleteShare(UserManager *panel,bool selection) { bool res=false; CFarPanelSelection sp((HANDLE)panel,selection); if(sp.Number()) { TCHAR warning[TINY_BUFFER]; if(sp.Number()==1) { TCHAR Truncated[MAX_PATH]; _tcscpy(Truncated,sp[0].FileName); FSF.TruncPathStr(Truncated,50); FSF.sprintf(warning,GetMsg(mDelOne),Truncated); } else FSF.sprintf(warning,GetMsg(mDelShareN+NumberType(sp.Number())),sp.Number()); const TCHAR *MsgItems[]={GetMsg(mButtonDelete),warning,GetMsg(mButtonDelete),GetMsg(mButtonCancel)}; if(!Info.Message(&MainGuid,&DelShareMessageGuid,0,NULL,MsgItems,sizeof(MsgItems)/sizeof(MsgItems[0]),2)) { res=true; for(int i=0;i<sp.Number();i++) if(panel->level==levelPrinterShared) { HANDLE printer; PRINTER_DEFAULTSW defaults; PRINTER_INFO_2W *data=NULL; memset(&defaults,0,sizeof(defaults)); defaults.DesiredAccess=PRINTER_ALL_ACCESS; if(OpenPrinterW(panel->hostfile,&printer,&defaults)) { DWORD Needed; if(!GetPrinterW(printer,2,NULL,0,&Needed)) { if(GetLastError()==ERROR_INSUFFICIENT_BUFFER) { data=(PRINTER_INFO_2W *)malloc(Needed); if(data) { if(GetPrinterW(printer,2,(PBYTE)data,Needed,&Needed)) { data->Attributes&=~PRINTER_ATTRIBUTE_SHARED; if(SetPrinterW(printer,2,(PBYTE)data,0)) res=true; } free(data); data=NULL; } } } ClosePrinter(printer); } } else if(sp[i].UserData.FreeData) { NetShareDel(panel->computer_ptr,GetWideNameFromUserData(sp[i].UserData.Data),0); } } } return res; }
DWORD _RpcGetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE* pPrinter, DWORD cbBuf, DWORD* pcbNeeded) { DWORD dwErrorCode; PBYTE pPrinterAligned; dwErrorCode = RpcImpersonateClient(NULL); if (dwErrorCode != ERROR_SUCCESS) { ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); return dwErrorCode; } pPrinterAligned = AlignRpcPtr(pPrinter, &cbBuf); if (GetPrinterW(hPrinter, Level, pPrinterAligned, cbBuf, pcbNeeded)) { // Replace absolute pointer addresses in the output by relative offsets. ASSERT(Level <= 9); MarshallDownStructure(pPrinterAligned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE); } else { dwErrorCode = GetLastError(); } RpcRevertToSelf(); UndoAlignRpcPtr(pPrinter, pPrinterAligned, cbBuf, pcbNeeded); return dwErrorCode; }