Index: source/smbd/lanman.c =================================================================== --- source/smbd/lanman.c (revision 2734) +++ source/smbd/lanman.c (working copy) @@ -548,9 +548,8 @@ PACKS(desc, "z", driver.info_3->datafile); /* Datafile name */ PACKS(desc, "z", driver.info_3->monitorname); /* language monitor */ - fstrcpy(location, "\\\\"); - fstrcat(location, get_called_name()); - fstrcat(location, "\\print$\\WIN40\\0"); + fstrcpy(location, "\\\\%L\\print$\\WIN40\\0"); + standard_sub_basic( NULL, location, sizeof(location)-1 ); PACKS(desc,"z", location); /* share to retrieve files */ PACKS(desc,"z", driver.info_3->defaultdatatype); /* default data type */ Index: source/printing/nt_printing.c =================================================================== --- source/printing/nt_printing.c (revision 2734) +++ source/printing/nt_printing.c (working copy) @@ -3270,7 +3270,7 @@ /**************************************************************************** Get a default printer info 2 struct. ****************************************************************************/ -static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sharename) +static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *servername, const char* sharename) { int snum; NT_PRINTER_INFO_LEVEL_2 info; @@ -3279,9 +3279,9 @@ snum = lp_servicenumber(sharename); - slprintf(info.servername, sizeof(info.servername)-1, "\\\\%s", get_called_name()); + slprintf(info.servername, sizeof(info.servername)-1, "\\\\%s", servername); slprintf(info.printername, sizeof(info.printername)-1, "\\\\%s\\%s", - get_called_name(), sharename); + servername, sharename); fstrcpy(info.sharename, sharename); fstrcpy(info.portname, SAMBA_PRINTER_PORT_NAME); @@ -3349,7 +3349,7 @@ /**************************************************************************** ****************************************************************************/ -static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sharename) +static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *servername, const char *sharename) { pstring key; NT_PRINTER_INFO_LEVEL_2 info; @@ -3367,7 +3367,7 @@ dbuf = tdb_fetch(tdb_printers, kbuf); if (!dbuf.dptr) - return get_a_printer_2_default(info_ptr, sharename); + return get_a_printer_2_default(info_ptr, servername, sharename); len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffPfffff", &info.attributes, @@ -3398,9 +3398,8 @@ info.attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; /* Restore the stripped strings. */ - slprintf(info.servername, sizeof(info.servername)-1, "\\\\%s", get_called_name()); - slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", get_called_name(), - info.printername); + slprintf(info.servername, sizeof(info.servername)-1, "\\\\%s", servername); + slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, info.printername); fstrcpy(info.printername, printername); len += unpack_devicemode(&info.devmode,dbuf.dptr+len, dbuf.dsize-len); @@ -4059,6 +4058,7 @@ { WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; + fstring servername; *pp_printer = NULL; @@ -4071,6 +4071,13 @@ return WERR_NOMEM; } ZERO_STRUCTP(printer); + + if ( print_hnd ) + fstrcpy( servername, print_hnd->servername ); + else { + fstrcpy( servername, "%L" ); + standard_sub_basic( NULL, servername, sizeof(servername)-1 ); + } /* * check for cache first. A Printer handle cannot changed @@ -4105,12 +4112,12 @@ Make sure to use a short lived talloc ctx */ if ( print_hnd ) - result = find_printer_in_print_hnd_cache(get_talloc_ctx(), &printer->info_2, sharename); + result = find_printer_in_print_hnd_cache(get_talloc_ctx(), &printer->info_2, servername, sharename); /* fail to disk if we don't have it with any open handle */ if ( !print_hnd || !W_ERROR_IS_OK(result) ) - result = get_a_printer_2(&printer->info_2, sharename); + result = get_a_printer_2(&printer->info_2, servername, sharename ); /* we have a new printer now. Save it with this handle */ @@ -5116,3 +5123,11 @@ return ok; } + +/**************************************************************************** + Fill in the servername sent in the _spoolss_open_printer_ex() call +****************************************************************************/ +char* get_server_name( Printer_entry *printer ) +{ + return printer->servername; +} Index: source/param/loadparm.c =================================================================== --- source/param/loadparm.c (revision 2734) +++ source/param/loadparm.c (working copy) @@ -4267,28 +4267,6 @@ } /******************************************************************* - Return the NetBIOS called name, or my IP - but never global_myname(). -********************************************************************/ - -const char *get_called_name(void) -{ - extern fstring local_machine; - static fstring called_name; - - if ( (!*local_machine) || - (client_socket_port() == 445) ) { - /* Everybody coming in on 445 should be able to live with the - * IP address */ - fstrcpy(called_name, client_socket_addr()); - DEBUG(8,("get_called_name: assuming that client used IP address [%s] as called name.\n", - called_name)); - return called_name; - } - - return local_machine; -} - -/******************************************************************* Return the max print jobs per queue. ********************************************************************/ Index: source/lib/util.c =================================================================== --- source/lib/util.c (revision 2734) +++ source/lib/util.c (working copy) @@ -1700,17 +1700,59 @@ BOOL is_myname_or_ipaddr(const char *s) { + fstring name, dnsname; + char *servername; + + if ( !s ) + return False; + + /* santize the string from '\\name' */ + + fstrcpy( name, s ); + + servername = strrchr_m( name, '\\' ); + if ( !servername ) + servername = name; + else + servername++; + /* optimize for the common case */ - if (strequal(s, global_myname())) + + if (strequal(servername, global_myname())) return True; + /* check for an alias */ + + if (is_myname(servername)) + return True; + + /* maybe it's my dns name */ + + if ( get_mydnsfullname( dnsname ) ) + if ( strequal( servername, dnsname ) ) + return True; + + /* handle possible CNAME records */ + + if ( !is_ipaddress( servername ) ) { + /* use DNS to resolve the name, but only the first address */ + struct hostent *hp; + + if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) { + struct in_addr return_ip; + putip( (char*)&return_ip, (char*)hp->h_addr ); + fstrcpy( name, inet_ntoa( return_ip ) ); + servername = name; + } + } + /* maybe its an IP address? */ - if (is_ipaddress(s)) { + if (is_ipaddress(servername)) { struct iface_struct nics[MAX_INTERFACES]; int i, n; uint32 ip; - ip = interpret_addr(s); + ip = interpret_addr(servername); if ((ip==0) || (ip==0xffffffff)) return False; @@ -1721,10 +1763,6 @@ } } - /* check for an alias */ - if (is_myname(s)) - return True; - /* no match */ return False; } Index: source/libsmb/namequery.c =================================================================== --- source/libsmb/namequery.c (revision 2734) +++ source/libsmb/namequery.c (working copy) @@ -991,7 +991,7 @@ resolve_hosts() when looking up DC's via SRV RR entries in DNS **********************************************************************/ -static BOOL internal_resolve_name(const char *name, int name_type, +BOOL internal_resolve_name(const char *name, int name_type, struct ip_service **return_iplist, int *return_count, const char *resolve_order) { Index: source/rpc_server/srv_spoolss_nt.c =================================================================== --- source/rpc_server/srv_spoolss_nt.c (revision 2734) +++ source/rpc_server/srv_spoolss_nt.c (working copy) @@ -201,7 +201,7 @@ snum = -1; srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); } else if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTER) { - snum = print_queue_snum(Printer->dev.handlename); + snum = print_queue_snum(Printer->sharename); if (snum != -1) srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd); @@ -277,17 +277,19 @@ ****************************************************************************/ WERROR find_printer_in_print_hnd_cache( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL_2 **info2, - const char *printername ) + const char *servername, const char *printername ) { Printer_entry *p; - DEBUG(10,("find_printer_in_print_hnd_cache: printer [%s]\n", printername)); + DEBUG(10,("find_printer_in_print_hnd_cache: printer [\\\\%s\\%s]\n", + servername, printername)); for ( p=printers_list; p; p=p->next ) { if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER && p->printer_info - && StrCaseCmp(p->dev.handlename, printername) == 0 ) + && strequal( p->sharename, printername ) + && strequal( p->servername, servername ) ) { DEBUG(10,("Found printer\n")); *info2 = dup_printer_2( ctx, p->printer_info->info_2 ); @@ -313,7 +315,7 @@ { if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER && p->printer_info - && StrCaseCmp(p->dev.handlename, printername)==0) + && StrCaseCmp(p->sharename, printername)==0) { DEBUG(10,("invalidating printer_info cache for handl:\n")); free_a_printer( &p->printer_info, 2 ); @@ -378,8 +380,8 @@ } #endif - if (del_a_printer(Printer->dev.handlename) != 0) { - DEBUG(3,("Error deleting printer %s\n", Printer->dev.handlename)); + if (del_a_printer( Printer->sharename ) != 0) { + DEBUG(3,("Error deleting printer %s\n", Printer->sharename)); return WERR_BADFID; } @@ -389,9 +391,7 @@ pstring command; int ret; - /* Printer->dev.handlename equals portname equals sharename */ - slprintf(command, sizeof(command)-1, "%s \"%s\"", cmd, - Printer->dev.handlename); + pstr_sprintf(command, "%s \"%s\"", cmd, Printer->sharename); DEBUG(10,("Running [%s]\n", command)); ret = smbrun(command, NULL); @@ -406,7 +406,7 @@ /* go ahead and re-read the services immediately */ reload_services( False ); - if ( lp_servicenumber( Printer->dev.handlename ) < 0 ) + if ( lp_servicenumber( Printer->sharename ) < 0 ) return WERR_ACCESS_DENIED; } @@ -427,14 +427,14 @@ } switch (Printer->printer_type) { - case PRINTER_HANDLE_IS_PRINTER: - DEBUG(4,("short name:%s\n", Printer->dev.handlename)); - *number = print_queue_snum(Printer->dev.handlename); - return (*number != -1); - case PRINTER_HANDLE_IS_PRINTSERVER: - return False; - default: - return False; + case PRINTER_HANDLE_IS_PRINTER: + DEBUG(4,("short name:%s\n", Printer->sharename)); + *number = print_queue_snum(Printer->sharename); + return (*number != -1); + case PRINTER_HANDLE_IS_PRINTSERVER: + return False; + default: + return False; } } @@ -475,6 +475,7 @@ int snum; int n_services=lp_numservices(); char *aprinter, *printername; + const char *servername; fstring sname; BOOL found=False; NT_PRINTER_INFO_LEVEL *printer; @@ -482,29 +483,38 @@ DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename, (unsigned long)strlen(handlename))); - if (Printer->printer_type==PRINTER_HANDLE_IS_PRINTSERVER) { - ZERO_STRUCT(Printer->dev.printerservername); - strncpy(Printer->dev.printerservername, handlename, strlen(handlename)); - return True; + aprinter = handlename; + if ( *handlename == '\\' ) { + servername = handlename + 2; + if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) { + *aprinter = '\0'; + aprinter++; + } } - - if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) - return False; - - if (*handlename=='\\') { - aprinter=strchr_m(handlename+2, '\\'); - aprinter++; - } else { - aprinter=handlename; + servername = ""; } + + /* save the servername to fill in replies on this handle */ + + if ( !is_myname_or_ipaddr( servername ) ) + return False; - DEBUGADD(5, ("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); + fstrcpy( Printer->servername, servername ); + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + return True; - /* have to search on sharename and PRINTER_INFO2->printername */ + if ( Printer->printer_type != PRINTER_HANDLE_IS_PRINTER ) + return False; - for (snum=0; snum %s\n", aprinter, sname)); - ZERO_STRUCT(Printer->dev.handlename); - fstrcpy(Printer->dev.handlename, sname); + fstrcpy(Printer->sharename, sname); return True; } @@ -696,10 +708,8 @@ } } - DEBUG(10, ("%s is not monitoring 0x%02x/0x%02x\n", - (p->printer_type == PRINTER_HANDLE_IS_PRINTER) ? - p->dev.handlename : p->dev.printerservername, - notify_type, notify_field)); + DEBUG(10, ("Open handle for \\\\%s\\%s is not monitoring 0x%02x/0x%02x\n", + p->servername, p->sharename, notify_type, notify_field)); return False; } @@ -995,13 +1005,13 @@ if ( !p->notify.client_connected ) continue; - DEBUG(10,("Client connected! [%s]\n", p->dev.handlename)); + DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename)); /* For this printer? Print servers always receive notifications. */ if ( ( p->printer_type == PRINTER_HANDLE_IS_PRINTER ) && - ( !strequal(msg_group->printername, p->dev.handlename) ) ) + ( !strequal(msg_group->printername, p->sharename) ) ) continue; DEBUG(10,("Our printer\n")); @@ -1027,7 +1037,7 @@ DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n", - msg->type, msg->field, p->dev.handlename)); + msg->type, msg->field, p->sharename)); /* * if the is a printer notification handle and not a job notification @@ -1323,7 +1333,7 @@ if ( (printer->printer_type == PRINTER_HANDLE_IS_PRINTER) && printer->notify.client_connected ) { - snum = print_queue_snum(printer->dev.handlename); + snum = print_queue_snum(printer->sharename); print_queue_status( snum, NULL, NULL ); } @@ -1619,9 +1629,9 @@ return WERR_INVALID_PRINTER_NAME; Printer=find_printer_index_by_hnd(p, handle); - if (!Printer) { - DEBUG(0,(" _spoolss_open_printer_ex: logic error. \ -Can't find printer handle we created for printer %s\n", name )); + if ( !Printer ) { + DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer " + "handle we created for printer %s\n", name )); close_printer_handle(p,handle); return WERR_INVALID_PRINTER_NAME; } @@ -1765,10 +1775,11 @@ if ( (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER) && q_u->printer_default.devmode_cont.devmode_ptr ) { - convert_devicemode( Printer->dev.handlename, q_u->printer_default.devmode_cont.devmode, + convert_devicemode( Printer->sharename, q_u->printer_default.devmode_cont.devmode, &Printer->nt_devmode ); } +#if 0 /* JERRY -- I'm doubtful this is really effective */ /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN optimization in Windows 2000 clients --jerry */ @@ -1778,6 +1789,7 @@ DEBUG(10,("_spoolss_open_printer_ex: Enabling LAN/WAN hack for Win2k clients.\n")); sys_usleep( 500000 ); } +#endif return WERR_OK; } @@ -2737,6 +2749,8 @@ return WERR_OK; } +#if 0 /* JERRY -- disabled; not used for now */ + /******************************************************************* * fill a notify_info_data with the servername ********************************************************************/ @@ -2750,8 +2764,10 @@ pstring temp_name, temp; uint32 len; - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); + fstrcpy( temp_name, "\\\\%L" ); + standard_sub_basic( NULL, temp_name, sizeof(temp_name)-1 ); + len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; @@ -2765,6 +2781,9 @@ memcpy(data->notify_data.data.string, temp, len); } +#endif + + /******************************************************************* * fill a notify_info_data with the printername (not including the servername). ********************************************************************/ @@ -3437,7 +3456,7 @@ static const struct s_notify_info_data_table notify_info_data_table[] = { -{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SERVER_NAME, "PRINTER_NOTIFY_SERVER_NAME", NOTIFY_STRING, NULL}, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PRINTER_NAME, "PRINTER_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_SHARE_NAME, "PRINTER_NOTIFY_SHARE_NAME", NOTIFY_STRING, spoolss_notify_share_name }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_PORT_NAME, "PRINTER_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, @@ -3464,7 +3483,7 @@ { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_TOTAL_BYTES, "PRINTER_NOTIFY_TOTAL_BYTES", NOTIFY_POINTER, NULL }, { PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_BYTES_PRINTED, "PRINTER_NOTIFY_BYTES_PRINTED", NOTIFY_POINTER, NULL }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PRINTER_NAME, "JOB_NOTIFY_PRINTER_NAME", NOTIFY_STRING, spoolss_notify_printer_name }, -{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, spoolss_notify_server_name }, +{ JOB_NOTIFY_TYPE, JOB_NOTIFY_MACHINE_NAME, "JOB_NOTIFY_MACHINE_NAME", NOTIFY_STRING, NULL}, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PORT_NAME, "JOB_NOTIFY_PORT_NAME", NOTIFY_STRING, spoolss_notify_port_name }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, "JOB_NOTIFY_USER_NAME", NOTIFY_STRING, spoolss_notify_username }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_NOTIFY_NAME, "JOB_NOTIFY_NOTIFY_NAME", NOTIFY_STRING, spoolss_notify_username }, @@ -3979,7 +3998,7 @@ init_unistr(&printer->printername, chaine); - slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_called_name()); + slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd)); init_unistr(&printer->servername, chaine); printer->cjobs = count; @@ -4444,6 +4463,7 @@ return WERR_INVALID_NAME; } +#if 0 /* JERRY -- disabled for now. Don't think this is used, tested, or correct */ /******************************************************************** enum_all_printers_info_1_remote. *********************************************************************/ @@ -4458,9 +4478,10 @@ /* JFM: currently it's more a place holder than anything else. * In the spooler world there is a notion of server registration. - * the print servers are registring (sp ?) on the PDC (in the same domain) + * the print servers are registered on the PDC (in the same domain) * - * We should have a TDB here. The registration is done thru an undocumented RPC call. + * We should have a TDB here. The registration is done thru an + * undocumented RPC call. */ if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL) @@ -4468,8 +4489,8 @@ *returned=1; - slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", get_called_name()); - slprintf(desc, sizeof(desc)-1,"%s", get_called_name()); + slprintf(printername, sizeof(printername)-1,"Windows NT Remote Printers!!\\\\%s", name); + slprintf(desc, sizeof(desc)-1,"%s", name); slprintf(comment, sizeof(comment)-1, "Logged on Domain"); init_unistr(&printer->description, desc); @@ -4499,6 +4520,8 @@ return WERR_OK; } +#endif + /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ @@ -4605,8 +4628,10 @@ if (flags & PRINTER_ENUM_NAME) return enum_all_printers_info_1_name(name, buffer, offered, needed, returned); +#if 0 /* JERRY - disabled for now */ if (flags & PRINTER_ENUM_REMOTE) return enum_all_printers_info_1_remote(name, buffer, offered, needed, returned); +#endif if (flags & PRINTER_ENUM_NETWORK) return enum_all_printers_info_1_network(name, buffer, offered, needed, returned); @@ -5543,6 +5568,7 @@ uint32 *needed = &r_u->needed; uint32 *servermajorversion = &r_u->servermajorversion; uint32 *serverminorversion = &r_u->serverminorversion; + Printer_entry *printer; fstring servername; fstring architecture; @@ -5554,11 +5580,16 @@ DEBUG(4,("_spoolss_getprinterdriver2\n")); + if ( !(printer = find_printer_index_by_hnd( p, handle )) ) { + DEBUG(0,("_spoolss_getprinterdriver2: invalid printer handle!\n")); + return WERR_INVALID_PRINTER_NAME; + } + *needed = 0; *servermajorversion = 0; *serverminorversion = 0; - fstrcpy(servername, get_called_name()); + fstrcpy(servername, get_server_name( printer )); unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1); if (!get_printer_snum(p, handle, &snum)) @@ -5840,11 +5871,9 @@ } /* NT seems to like setting the security descriptor even though - nothing may have actually changed. This causes annoying - dialog boxes when the user doesn't have permission to change - the security descriptor. */ + nothing may have actually changed. */ - nt_printing_getsec(p->mem_ctx, Printer->dev.handlename, &old_secdesc_ctr); + nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr); if (DEBUGLEVEL >= 10) { SEC_ACL *the_acl; @@ -5903,7 +5932,7 @@ goto done; } - result = nt_printing_setsec(Printer->dev.handlename, new_secdesc_ctr); + result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr); done: @@ -5911,9 +5940,12 @@ } /******************************************************************** - Do Samba sanity checks on a printer info struct. - this has changed purpose: it now "canonicalises" printer - info from a client rather than just checking it is correct + Canonicalize printer info from a client + + ATTN: It does not matter what we set the servername to hear + since we do the necessary work in get_a_printer() to set it to + the correct value based on what the client sent in the + _spoolss_open_printer_ex(). ********************************************************************/ static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum) @@ -5921,11 +5953,13 @@ fstring printername; const char *p; - DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s portname=%s drivername=%s comment=%s location=%s\n", - info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location)); + DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s " + "portname=%s drivername=%s comment=%s location=%s\n", + info->servername, info->printername, info->sharename, + info->portname, info->drivername, info->comment, info->location)); /* we force some elements to "correct" values */ - slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", get_called_name()); + slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname()); fstrcpy(info->sharename, lp_servicename(snum)); /* make sure printername is in \\server\printername format */ @@ -5938,7 +5972,7 @@ } slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - get_called_name(), p ); + global_myname(), p ); info->attributes |= PRINTER_ATTRIBUTE_SAMBA; info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; @@ -6322,18 +6356,16 @@ ****************************************************************************/ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue, - int position, int snum) + int position, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter) { - pstring temp_name; - struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; init_unistr(&job_info->printername, lp_servicename(snum)); - init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); init_unistr(&job_info->document, queue->fs_file); init_unistr(&job_info->datatype, "RAW"); @@ -6355,17 +6387,15 @@ NT_PRINTER_INFO_LEVEL *ntprinter, DEVICEMODE *devmode) { - pstring temp_name; struct tm *t; t=gmtime(&queue->time); - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); job_info->jobid=queue->job; init_unistr(&job_info->printername, ntprinter->info_2->printername); - init_unistr(&job_info->machinename, temp_name); + init_unistr(&job_info->machinename, ntprinter->info_2->servername); init_unistr(&job_info->username, queue->fs_user); init_unistr(&job_info->document, queue->fs_file); init_unistr(&job_info->notifyname, queue->fs_user); @@ -6398,6 +6428,7 @@ ****************************************************************************/ static WERROR enumjobs_level1(print_queue_struct *queue, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -6412,7 +6443,7 @@ } for (i=0; i<*returned; i++) - fill_job_info_1(&info[i], &queue[i], i, snum); + fill_job_info_1( &info[i], &queue[i], i, snum, ntprinter ); SAFE_FREE(queue); @@ -6445,10 +6476,10 @@ ****************************************************************************/ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - NT_PRINTER_INFO_LEVEL *ntprinter = NULL; JOB_INFO_2 *info = NULL; int i; WERROR result; @@ -6460,12 +6491,6 @@ result = WERR_NOMEM; goto done; } - - result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(result)) { - *returned = 0; - goto done; - } /* this should not be a failure condition if the devmode is NULL */ @@ -6523,7 +6548,7 @@ uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; WERROR wret; - + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; int snum; print_status_struct prt_status; print_queue_struct *queue=NULL; @@ -6537,9 +6562,15 @@ *needed=0; *returned=0; + /* lookup the printer snum and tdb entry */ + if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + wret = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(wret) ) + return wret; + *returned = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], status:[%d], [%s]\n", *returned, prt_status.status, prt_status.message)); @@ -6550,16 +6581,19 @@ switch (level) { case 1: - wret = enumjobs_level1(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level1(queue, snum, ntprinter, buffer, offered, needed, returned); return wret; case 2: - wret = enumjobs_level2(queue, snum, buffer, offered, needed, returned); + wret = enumjobs_level2(queue, snum, ntprinter, buffer, offered, needed, returned); return wret; default: SAFE_FREE(queue); *returned=0; - return WERR_UNKNOWN_LEVEL; + wret = WERR_UNKNOWN_LEVEL; } + + free_a_printer( &ntprinter, 2 ); + return wret; } /**************************************************************************** @@ -6866,7 +6900,6 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u) { - UNISTR2 *environment = &q_u->environment; uint32 level = q_u->level; NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; @@ -6882,12 +6915,15 @@ buffer = r_u->buffer; DEBUG(4,("_spoolss_enumprinterdrivers\n")); - fstrcpy(servername, get_called_name()); *needed=0; *returned=0; - unistr2_to_ascii(architecture, environment, sizeof(architecture)-1); + unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)-1); + unistr2_to_ascii(servername, &q_u->name, sizeof(servername)-1); + if ( !is_myname_or_ipaddr( servername ) ) + return WERR_UNKNOWN_PRINTER_DRIVER; + switch (level) { case 1: return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned); @@ -7387,7 +7423,10 @@ } } - slprintf(name, sizeof(name)-1, "\\\\%s\\%s", get_called_name(), + /* use our primary netbios name since get_a_printer() will convert + it to what the client expects on a case by case basis */ + + slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(), printer->info_2->sharename); @@ -7659,10 +7698,15 @@ { pstring path; pstring long_archi; + fstring servername; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; + unistr2_to_ascii(servername, name, sizeof(servername)-1); unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1); + + if ( !is_myname_or_ipaddr( servername ) ) + return WERR_INVALID_PARAM; if (!(short_archi = get_short_archi(long_archi))) return WERR_INVALID_ENVIRONMENT; @@ -7670,7 +7714,7 @@ if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL) return WERR_NOMEM; - slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", get_called_name(), short_archi); + slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", servername, short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -8496,7 +8540,10 @@ /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, + uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) { int i=0; BOOL found=False; @@ -8519,7 +8566,7 @@ return WERR_INVALID_PARAM; } - fill_job_info_1(info_1, &((*queue)[i-1]), i, snum); + fill_job_info_1( info_1, &((*queue)[i-1]), i, snum, ntprinter ); *needed += spoolss_size_job_info_1(info_1); @@ -8541,12 +8588,14 @@ /**************************************************************************** ****************************************************************************/ -static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, + NT_PRINTER_INFO_LEVEL *ntprinter, + uint32 jobid, NEW_BUFFER *buffer, uint32 offered, + uint32 *needed) { int i = 0; BOOL found = False; JOB_INFO_2 *info_2; - NT_PRINTER_INFO_LEVEL *ntprinter = NULL; WERROR ret; DEVICEMODE *devmode = NULL; NT_DEVICEMODE *nt_devmode = NULL; @@ -8574,10 +8623,6 @@ goto done; } - ret = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum)); - if (!W_ERROR_IS_OK(ret)) - goto done; - /* * if the print job does not have a DEVMODE associated with it, * just use the one for the printer. A NULL devicemode is not @@ -8633,7 +8678,7 @@ uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; WERROR wstatus = WERR_OK; - + NT_PRINTER_INFO_LEVEL *ntprinter = NULL; int snum; int count; print_queue_struct *queue = NULL; @@ -8650,6 +8695,10 @@ if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; + wstatus = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); + if ( !W_ERROR_IS_OK(wstatus) ) + return wstatus; + count = print_queue_status(snum, &queue, &prt_status); DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n", @@ -8657,11 +8706,11 @@ switch ( level ) { case 1: - wstatus = getjob_level_1(&queue, count, snum, jobid, + wstatus = getjob_level_1(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; case 2: - wstatus = getjob_level_2(&queue, count, snum, jobid, + wstatus = getjob_level_2(&queue, count, snum, ntprinter, jobid, buffer, offered, needed); break; default: @@ -8670,6 +8719,8 @@ } SAFE_FREE(queue); + free_a_printer( &ntprinter, 2 ); + return wstatus; } Index: source/include/nt_printing.h =================================================================== --- source/include/nt_printing.h (revision 2734) +++ source/include/nt_printing.h (working copy) @@ -450,10 +450,8 @@ uint32 jobid; /* jobid in printing backend */ BOOL printer_type; TALLOC_CTX *ctx; - union { - fstring handlename; - fstring printerservername; - } dev; + fstring servername; + fstring sharename; uint32 type; uint32 access_granted; struct {