diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/include/nt_printing.h samba-3.0.7/source/include/nt_printing.h --- samba-3.0.7-orig/source/include/nt_printing.h 2004-04-04 01:37:23.000000000 -0600 +++ samba-3.0.7/source/include/nt_printing.h 2004-10-19 11:32:44.304839201 -0500 @@ -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 { diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/include/rpc_spoolss.h samba-3.0.7/source/include/rpc_spoolss.h --- samba-3.0.7-orig/source/include/rpc_spoolss.h 2004-09-11 22:47:18.000000000 -0500 +++ samba-3.0.7/source/include/rpc_spoolss.h 2004-10-19 11:32:44.309837988 -0500 @@ -206,6 +206,7 @@ #define PRINTER_NOTIFY_TYPE 0x00 #define JOB_NOTIFY_TYPE 0x01 +#define PRINT_TABLE_END 0xFF #define MAX_PRINTER_NOTIFY 26 #define MAX_JOB_NOTIFY 24 diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/lib/util.c samba-3.0.7/source/lib/util.c --- samba-3.0.7-orig/source/lib/util.c 2004-09-11 22:47:17.000000000 -0500 +++ samba-3.0.7/source/lib/util.c 2004-10-19 11:32:44.313837018 -0500 @@ -1701,17 +1701,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; @@ -1722,10 +1764,6 @@ } } - /* check for an alias */ - if (is_myname(s)) - return True; - /* no match */ return False; } diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/libsmb/namequery.c samba-3.0.7/source/libsmb/namequery.c --- samba-3.0.7-orig/source/libsmb/namequery.c 2004-07-08 12:06:13.000000000 -0500 +++ samba-3.0.7/source/libsmb/namequery.c 2004-10-19 11:32:44.317836047 -0500 @@ -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) { diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/param/loadparm.c samba-3.0.7/source/param/loadparm.c --- samba-3.0.7-orig/source/param/loadparm.c 2004-09-11 22:47:16.000000000 -0500 +++ samba-3.0.7/source/param/loadparm.c 2004-10-19 11:32:44.325834106 -0500 @@ -4263,28 +4263,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. ********************************************************************/ diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/printing/nt_printing.c samba-3.0.7/source/printing/nt_printing.c --- samba-3.0.7-orig/source/printing/nt_printing.c 2004-09-11 22:47:16.000000000 -0500 +++ samba-3.0.7/source/printing/nt_printing.c 2004-10-19 11:32:44.334831922 -0500 @@ -3211,7 +3211,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; @@ -3220,9 +3220,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); @@ -3290,7 +3290,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; @@ -3308,7 +3308,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, @@ -3339,9 +3339,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); @@ -4000,6 +3999,7 @@ { WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; + fstring servername; *pp_printer = NULL; @@ -4013,6 +4013,13 @@ } 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 * to another printer object so we only check that the printer @@ -4046,12 +4053,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 */ @@ -5057,3 +5064,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; +} diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/rpc_server/srv_spoolss_nt.c samba-3.0.7/source/rpc_server/srv_spoolss_nt.c --- samba-3.0.7-orig/source/rpc_server/srv_spoolss_nt.c 2004-09-11 22:47:17.000000000 -0500 +++ samba-3.0.7/source/rpc_server/srv_spoolss_nt.c 2004-10-19 11:32:51.081194537 -0500 @@ -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; } @@ -428,8 +428,8 @@ 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); + DEBUG(4,("short name:%s\n", Printer->sharename)); + *number = print_queue_snum(Printer->sharename); return (*number != -1); case PRINTER_HANDLE_IS_PRINTSERVER: 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,28 +483,37 @@ 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; - } - - if (Printer->printer_type!=PRINTER_HANDLE_IS_PRINTER) - return False; - - if (*handlename=='\\') { - aprinter=strchr_m(handlename+2, '\\'); + aprinter = handlename; + if ( *handlename == '\\' ) { + servername = handlename + 2; + if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) { + *aprinter = '\0'; aprinter++; } + } else { - aprinter=handlename; + servername = ""; } - DEBUGADD(5, ("searching for [%s] (len=%lu)\n", aprinter, (unsigned long)strlen(aprinter))); + /* save the servername to fill in replies on this handle */ - /* have to search on sharename and PRINTER_INFO2->printername */ + if ( !is_myname_or_ipaddr( servername ) ) + return False; - for (snum=0; snumservername, servername ); + + if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER ) + return True; + + if ( Printer->printer_type != PRINTER_HANDLE_IS_PRINTER ) + return False; + + DEBUGADD(5, ("searching for [%s]\n", aprinter )); + + /* Search all sharenames first as this is easier than pulling + the printer_info_2 off of disk */ + + for (snum=0; !found && 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; } @@ -2746,12 +2758,10 @@ NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx) { - pstring temp_name, temp; + pstring temp; uint32 len; - slprintf(temp_name, sizeof(temp_name)-1, "\\\\%s", get_called_name()); - - len = rpcstr_push(temp, temp_name, sizeof(temp)-2, STR_TERMINATE); + len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE); data->notify_data.data.length = len; data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len); @@ -3485,6 +3495,7 @@ { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_PAGES, "JOB_NOTIFY_TOTAL_PAGES", NOTIFY_ONE_VALUE, spoolss_notify_total_pages }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_PAGES_PRINTED, "JOB_NOTIFY_PAGES_PRINTED", NOTIFY_ONE_VALUE, spoolss_notify_pages_printed }, { JOB_NOTIFY_TYPE, JOB_NOTIFY_TOTAL_BYTES, "JOB_NOTIFY_TOTAL_BYTES", NOTIFY_ONE_VALUE, spoolss_notify_job_size }, +{ PRINT_TABLE_END, 0x0, NULL, 0x0, NULL }, }; /******************************************************************* @@ -3550,7 +3561,7 @@ { int i; - for (i = 0; i < sizeof(notify_info_data_table); i++) { + for (i = 0; notify_info_data_table[i].type != PRINT_TABLE_END; i++) { if (notify_info_data_table[i].type == type && notify_info_data_table[i].field == field && notify_info_data_table[i].fn != NULL) { @@ -3980,7 +3991,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; @@ -4445,6 +4456,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. *********************************************************************/ @@ -4459,9 +4471,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) @@ -4469,8 +4482,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); @@ -4500,6 +4513,8 @@ return WERR_OK; } +#endif + /******************************************************************** enum_all_printers_info_1_network. *********************************************************************/ @@ -4606,8 +4621,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); @@ -5544,6 +5561,7 @@ uint32 *needed = &r_u->needed; uint32 *servermajorversion = &r_u->servermajorversion; uint32 *serverminorversion = &r_u->serverminorversion; + Printer_entry *printer; fstring servername; fstring architecture; @@ -5555,11 +5573,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)) @@ -5841,11 +5864,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; @@ -5904,7 +5925,7 @@ goto done; } - result = nt_printing_setsec(Printer->dev.handlename, new_secdesc_ctr); + result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr); done: @@ -5912,9 +5933,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) @@ -5922,11 +5946,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 */ @@ -5939,7 +5965,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; @@ -6317,18 +6343,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"); @@ -6350,17 +6374,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); @@ -6393,6 +6415,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) { @@ -6407,7 +6430,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); @@ -6440,10 +6463,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; @@ -6456,12 +6479,6 @@ 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 */ devmode = construct_dev_mode(snum); @@ -6518,7 +6535,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; @@ -6532,9 +6549,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)); @@ -6545,16 +6568,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; } /**************************************************************************** @@ -6582,7 +6608,7 @@ return WERR_BADFID; } - if (!print_job_exists(snum, jobid)) { + if (!print_job_exists(lp_const_servicename(snum), jobid)) { return WERR_INVALID_PRINTER_NAME; } @@ -6861,7 +6887,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; @@ -6877,11 +6902,14 @@ 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: @@ -7382,7 +7410,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); @@ -7654,18 +7685,32 @@ { pstring path; pstring long_archi; + fstring servername; + char *pservername; 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); + /* check for beginning double '\'s and that the server + long enough */ + + pservername = servername; + if ( *pservername == '\\' && strlen(servername)>2 ) { + pservername += 2; + } + + if ( !is_myname_or_ipaddr( pservername ) ) + return WERR_INVALID_PARAM; + if (!(short_archi = get_short_archi(long_archi))) return WERR_INVALID_ENVIRONMENT; 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", pservername, short_archi); DEBUG(4,("printer driver directory: [%s]\n", path)); @@ -8491,7 +8536,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; @@ -8514,7 +8562,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); @@ -8536,12 +8584,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; @@ -8569,17 +8619,13 @@ 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 * a failure condition */ - if ( !(nt_devmode=print_job_devmode( snum, jobid )) ) + if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) ) devmode = construct_dev_mode(snum); else { if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) != NULL) { @@ -8611,7 +8657,6 @@ free_job_info_2(info_2); /* Also frees devmode */ SAFE_FREE(info_2); - free_a_printer(&ntprinter, 2); return ret; } @@ -8628,7 +8673,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; @@ -8645,6 +8690,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", @@ -8652,11 +8701,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: @@ -8665,6 +8714,8 @@ } SAFE_FREE(queue); + free_a_printer( &ntprinter, 2 ); + return wstatus; } diff -uBbr --exclude-from=/misc/src/samba-cvs/diff.excludes samba-3.0.7-orig/source/smbd/lanman.c samba-3.0.7/source/smbd/lanman.c --- samba-3.0.7-orig/source/smbd/lanman.c 2004-07-08 12:06:10.000000000 -0500 +++ samba-3.0.7/source/smbd/lanman.c 2004-10-19 11:32:44.371822944 -0500 @@ -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 */