📄 nt_printing.c
字号:
default: /* no change */ break; } } /* create a new SEC_DESC with the appropriate owner and group SIDs */ string_to_sid(&sid, "S-1-5-32-544" ); new_sec = make_sec_desc( ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, &sid, &sid, NULL, NULL, &size_new_sec ); sd_new = make_sec_desc_buf( ctx, size_new_sec, new_sec ); if ( !(sd_store = sec_desc_merge( ctx, sd_new, sd_orig )) ) { DEBUG(0,("sec_desc_upg_fn: Failed to update sec_desc for %s\n", key.dptr )); return 0; } /* store it back */ sd_size = sec_desc_size(sd_store->sec) + sizeof(SEC_DESC_BUF); prs_init(&ps, sd_size, ctx, MARSHALL); if ( !sec_io_desc_buf( "sec_desc_upg_fn", &sd_store, &ps, 1 ) ) { DEBUG(0,("sec_desc_upg_fn: Failed to parse new sec_desc for %s\n", key.dptr )); return 0; } data.dptr = prs_data_p( &ps ); data.dsize = sd_size; result = tdb_store( tdb_printers, key, data, TDB_REPLACE ); prs_mem_free( &ps ); /* 0 to continue and non-zero to stop traversal */ return (result == -1);}/**************************************************************************************************************************************/static BOOL upgrade_to_version_4(void){ TALLOC_CTX *ctx; int result; DEBUG(0,("upgrade_to_version_4: upgrading printer security descriptors\n")); if ( !(ctx = talloc_init( "upgrade_to_version_4" )) ) return False; result = tdb_traverse( tdb_printers, sec_desc_upg_fn, ctx ); talloc_destroy( ctx ); return ( result != -1 );}/******************************************************************* Fix an issue with security descriptors. Printer sec_desc must use more than the generic bits that were previously used in <= 3.0.14a. They must also have a owner and group SID assigned. Otherwise, any printers than have been migrated to a Windows host using printmig.exe will not be accessible.*******************************************************************/static int normalize_printers_fn( TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA data, void *state ){ TDB_DATA new_key; if (!data.dptr || data.dsize == 0) return 0; /* upgrade printer records and security descriptors */ if ( strncmp( key.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX) ) == 0 ) { new_key = make_printer_tdbkey( key.dptr+strlen(PRINTERS_PREFIX) ); } else if ( strncmp( key.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX) ) == 0 ) { new_key.dptr = make_printers_secdesc_tdbkey( key.dptr+strlen(SECDESC_PREFIX) ); new_key.dsize = strlen( new_key.dptr ) + 1; } else { /* ignore this record */ return 0; } /* delete the original record and store under the normalized key */ if ( tdb_delete( the_tdb, key ) != 0 ) { DEBUG(0,("normalize_printers_fn: tdb_delete for [%s] failed!\n", key.dptr)); return 1; } if ( tdb_store( the_tdb, new_key, data, TDB_REPLACE) != 0 ) { DEBUG(0,("normalize_printers_fn: failed to store new record for [%s]!\n", key.dptr)); return 1; } return 0;}/**************************************************************************************************************************************/static BOOL upgrade_to_version_5(void){ TALLOC_CTX *ctx; int result; DEBUG(0,("upgrade_to_version_5: normalizing printer keys\n")); if ( !(ctx = talloc_init( "upgrade_to_version_5" )) ) return False; result = tdb_traverse( tdb_printers, normalize_printers_fn, NULL ); talloc_destroy( ctx ); return ( result != -1 );}/**************************************************************************** Open the NT printing tdbs. Done once before fork().****************************************************************************/BOOL nt_printing_init(void){ const char *vstring = "INFO/version"; WERROR win_rc; int32 vers_id; if ( tdb_drivers && tdb_printers && tdb_forms ) return True; if (tdb_drivers) tdb_close(tdb_drivers); tdb_drivers = tdb_open_log(lock_path("ntdrivers.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (!tdb_drivers) { DEBUG(0,("nt_printing_init: Failed to open nt drivers database %s (%s)\n", lock_path("ntdrivers.tdb"), strerror(errno) )); return False; } if (tdb_printers) tdb_close(tdb_printers); tdb_printers = tdb_open_log(lock_path("ntprinters.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (!tdb_printers) { DEBUG(0,("nt_printing_init: Failed to open nt printers database %s (%s)\n", lock_path("ntprinters.tdb"), strerror(errno) )); return False; } if (tdb_forms) tdb_close(tdb_forms); tdb_forms = tdb_open_log(lock_path("ntforms.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); if (!tdb_forms) { DEBUG(0,("nt_printing_init: Failed to open nt forms database %s (%s)\n", lock_path("ntforms.tdb"), strerror(errno) )); return False; } /* handle a Samba upgrade */ vers_id = tdb_fetch_int32(tdb_drivers, vstring); if (vers_id == -1) { DEBUG(10, ("Fresh database\n")); tdb_store_int32( tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5 ); vers_id = NTDRIVERS_DATABASE_VERSION_5; } if ( vers_id != NTDRIVERS_DATABASE_VERSION_5 ) { if ((vers_id == NTDRIVERS_DATABASE_VERSION_1) || (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) { if (!upgrade_to_version_3()) return False; tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3); vers_id = NTDRIVERS_DATABASE_VERSION_3; } if ((vers_id == NTDRIVERS_DATABASE_VERSION_2) || (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_2)) { /* Written on a bigendian machine with old fetch_int code. Save as le. */ /* The only upgrade between V2 and V3 is to save the version in little-endian. */ tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_3); vers_id = NTDRIVERS_DATABASE_VERSION_3; } if (vers_id == NTDRIVERS_DATABASE_VERSION_3 ) { if ( !upgrade_to_version_4() ) return False; tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4); vers_id = NTDRIVERS_DATABASE_VERSION_4; } if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) { if ( !upgrade_to_version_5() ) return False; tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5); vers_id = NTDRIVERS_DATABASE_VERSION_5; } if ( vers_id != NTDRIVERS_DATABASE_VERSION_5 ) { DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id)); return False; } } update_c_setprinter(True); /* * register callback to handle updating printers as new * drivers are installed */ message_register( MSG_PRINTER_DRVUPGRADE, do_drv_upgrade_printer ); /* * register callback to handle updating printer data * when a driver is initialized */ message_register( MSG_PRINTERDATA_INIT_RESET, reset_all_printerdata ); /* of course, none of the message callbacks matter if you don't tell messages.c that you interested in receiving PRINT_GENERAL msgs. This is done in claim_connection() */ if ( lp_security() == SEC_ADS ) { win_rc = check_published_printers(); if (!W_ERROR_IS_OK(win_rc)) DEBUG(0, ("nt_printing_init: error checking published printers: %s\n", dos_errstr(win_rc))); } return True;}/******************************************************************* Function to allow filename parsing "the old way".********************************************************************/static BOOL driver_unix_convert(char *name,connection_struct *conn, char *saved_last_component, BOOL *bad_path, SMB_STRUCT_STAT *pst){ unix_format(name); unix_clean_name(name); trim_string(name,"/","/"); return unix_convert(name, conn, saved_last_component, bad_path, pst);}/******************************************************************* tdb traversal function for counting printers.********************************************************************/static int traverse_counting_printers(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *context){ int *printer_count = (int*)context; if (memcmp(PRINTERS_PREFIX, key.dptr, sizeof(PRINTERS_PREFIX)-1) == 0) { (*printer_count)++; DEBUG(10,("traverse_counting_printers: printer = [%s] printer_count = %d\n", key.dptr, *printer_count)); } return 0;} /******************************************************************* Update the spooler global c_setprinter. This variable is initialized when the parent smbd starts with the number of existing printers. It is monotonically increased by the current number of printers *after* each add or delete printer RPC. Only Microsoft knows why... JRR020119********************************************************************/uint32 update_c_setprinter(BOOL initialize){ int32 c_setprinter; int32 printer_count = 0; tdb_lock_bystring(tdb_printers, GLOBAL_C_SETPRINTER, 0); /* Traverse the tdb, counting the printers */ tdb_traverse(tdb_printers, traverse_counting_printers, (void *)&printer_count); /* If initializing, set c_setprinter to current printers count * otherwise, bump it by the current printer count */ if (!initialize) c_setprinter = tdb_fetch_int32(tdb_printers, GLOBAL_C_SETPRINTER) + printer_count; else c_setprinter = printer_count; DEBUG(10,("update_c_setprinter: c_setprinter = %u\n", (unsigned int)c_setprinter)); tdb_store_int32(tdb_printers, GLOBAL_C_SETPRINTER, c_setprinter); tdb_unlock_bystring(tdb_printers, GLOBAL_C_SETPRINTER); return (uint32)c_setprinter;}/******************************************************************* Get the spooler global c_setprinter, accounting for initialization.********************************************************************/uint32 get_c_setprinter(void){ int32 c_setprinter = tdb_fetch_int32(tdb_printers, GLOBAL_C_SETPRINTER); if (c_setprinter == (int32)-1) c_setprinter = update_c_setprinter(True); DEBUG(10,("get_c_setprinter: c_setprinter = %d\n", c_setprinter)); return (uint32)c_setprinter;}/**************************************************************************** Get builtin form struct list.****************************************************************************/int get_builtin_ntforms(nt_forms_struct **list){ *list = (nt_forms_struct *)memdup(&default_forms[0], sizeof(default_forms)); return sizeof(default_forms) / sizeof(default_forms[0]);}/**************************************************************************** get a builtin form struct****************************************************************************/BOOL get_a_builtin_ntform(UNISTR2 *uni_formname,nt_forms_struct *form){ int i,count; fstring form_name; unistr2_to_ascii(form_name, uni_formname, sizeof(form_name)-1); DEBUGADD(6,("Looking for builtin form %s \n", form_name)); count = sizeof(default_forms) / sizeof(default_forms[0]); for (i=0;i<count;i++) { if (strequal(form_name,default_forms[i].name)) { DEBUGADD(6,("Found builtin form %s \n", form_name)); memcpy(form,&default_forms[i],sizeof(*form)); break; } } return (i !=count);}/****************************************************************************get a form struct list****************************************************************************/int get_ntforms(nt_forms_struct **list){ TDB_DATA kbuf, newkey, dbuf; nt_forms_struct *tl; nt_forms_struct form; int ret; int i; int n = 0; for (kbuf = tdb_firstkey(tdb_forms); kbuf.dptr; newkey = tdb_nextkey(tdb_forms, kbuf), safe_free(kbuf.dptr), kbuf=newkey) { if (strncmp(kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) != 0) continue; dbuf = tdb_fetch(tdb_forms, kbuf); if (!dbuf.dptr) continue; fstrcpy(form.name, kbuf.dptr+strlen(FORMS_PREFIX)); ret = tdb_unpack(dbuf.dptr, dbuf.dsize, "dddddddd", &i, &form.flag, &form.width, &form.length, &form.left, &form.top, &form.right, &form.bottom); SAFE_FREE(dbuf.dptr); if (ret != dbuf.dsize) continue; tl = SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1); if (!tl) { DEBUG(0,("get_ntforms: Realloc fail.\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -