From 896e133c3cf3ce9e012fbc4dbc7d2a1a5aa826cc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Feb 2003 19:13:37 +0000 Subject: Remove obsolete files (This used to be commit 1a68ead4332bd9f5123bd3690784e7e179e3cb1f) --- source3/rpcclient/display_spool.c | 927 -------------------------------------- source3/rpcclient/samsync.c | 772 ------------------------------- 2 files changed, 1699 deletions(-) delete mode 100644 source3/rpcclient/display_spool.c delete mode 100644 source3/rpcclient/samsync.c (limited to 'source3/rpcclient') diff --git a/source3/rpcclient/display_spool.c b/source3/rpcclient/display_spool.c deleted file mode 100644 index b4baf570f1..0000000000 --- a/source3/rpcclient/display_spool.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1999 - Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -/**************************************************************************** -printer info level 0 display function -****************************************************************************/ -static void display_print_info_0(FILE *out_hnd, PRINTER_INFO_0 *i1) -{ - fstring name; - fstring server; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->printername.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(server, i1->servername.buffer, sizeof(server), 0, STR_TERMINATE); - - report(out_hnd, "\tprintername:[%s]\n", name); - report(out_hnd, "\tservername:[%s]\n", server); - report(out_hnd, "\tcjobs:[%x]\n", i1->cjobs); - report(out_hnd, "\ttotal_jobs:[%x]\n", i1->total_jobs); - - report(out_hnd, "\t:date: [%d]-[%d]-[%d] (%d)\n", i1->year, i1->month, i1->day, i1->dayofweek); - report(out_hnd, "\t:time: [%d]-[%d]-[%d]-[%d]\n", i1->hour, i1->minute, i1->second, i1->milliseconds); - - report(out_hnd, "\tglobal_counter:[%x]\n", i1->global_counter); - report(out_hnd, "\ttotal_pages:[%x]\n", i1->total_pages); - - report(out_hnd, "\tmajorversion:[%x]\n", i1->major_version); - report(out_hnd, "\tbuildversion:[%x]\n", i1->build_version); - - report(out_hnd, "\tunknown7:[%x]\n", i1->unknown7); - report(out_hnd, "\tunknown8:[%x]\n", i1->unknown8); - report(out_hnd, "\tunknown9:[%x]\n", i1->unknown9); - report(out_hnd, "\tsession_counter:[%x]\n", i1->session_counter); - report(out_hnd, "\tunknown11:[%x]\n", i1->unknown11); - report(out_hnd, "\tprinter_errors:[%x]\n", i1->printer_errors); - report(out_hnd, "\tunknown13:[%x]\n", i1->unknown13); - report(out_hnd, "\tunknown14:[%x]\n", i1->unknown14); - report(out_hnd, "\tunknown15:[%x]\n", i1->unknown15); - report(out_hnd, "\tunknown16:[%x]\n", i1->unknown16); - report(out_hnd, "\tchange_id:[%x]\n", i1->change_id); - report(out_hnd, "\tunknown18:[%x]\n", i1->unknown18); - report(out_hnd, "\tstatus:[%x]\n", i1->status); - report(out_hnd, "\tunknown20:[%x]\n", i1->unknown20); - report(out_hnd, "\tc_setprinter:[%x]\n", i1->c_setprinter); - report(out_hnd, "\tunknown22:[%x]\n", i1->unknown22); - report(out_hnd, "\tunknown23:[%x]\n", i1->unknown23); - report(out_hnd, "\tunknown24:[%x]\n", i1->unknown24); - report(out_hnd, "\tunknown25:[%x]\n", i1->unknown25); - report(out_hnd, "\tunknown26:[%x]\n", i1->unknown26); - report(out_hnd, "\tunknown27:[%x]\n", i1->unknown27); - report(out_hnd, "\tunknown28:[%x]\n", i1->unknown28); - report(out_hnd, "\tunknown29:[%x]\n", i1->unknown29); -} - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_print_info_1(FILE *out_hnd, PRINTER_INFO_1 *i1) -{ - fstring desc; - fstring name; - fstring comm; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(desc, i1->description.buffer, sizeof(desc), 0, STR_TERMINATE); - rpcstr_pull(comm, i1->comment.buffer, sizeof(comm), 0, STR_TERMINATE); - - report(out_hnd, "\tflags:[%x]\n", i1->flags); - report(out_hnd, "\tname:[%s]\n", name); - report(out_hnd, "\tdescription:[%s]\n", desc); - report(out_hnd, "\tcomment:[%s]\n\n", comm); -} - -/**************************************************************************** -printer info level 2 display function -****************************************************************************/ -static void display_print_info_2(FILE *out_hnd, PRINTER_INFO_2 *i2) -{ - fstring servername; - fstring printername; - fstring sharename; - fstring portname; - fstring drivername; - fstring comment; - fstring location; - fstring sepfile; - fstring printprocessor; - fstring datatype; - fstring parameters; - - if (i2 == NULL) - return; - - rpcstr_pull(servername, i2->servername.buffer,sizeof(servername), 0, STR_TERMINATE); - rpcstr_pull(printername, i2->printername.buffer,sizeof(printername), 0, STR_TERMINATE); - rpcstr_pull(sharename, i2->sharename.buffer,sizeof(sharename), 0, STR_TERMINATE); - rpcstr_pull(portname, i2->portname.buffer,sizeof(portname), 0, STR_TERMINATE); - rpcstr_pull(drivername, i2->drivername.buffer,sizeof(drivername), 0, STR_TERMINATE); - rpcstr_pull(comment, i2->comment.buffer,sizeof(comment), 0, STR_TERMINATE); - rpcstr_pull(location, i2->location.buffer,sizeof(location), 0, STR_TERMINATE); - rpcstr_pull(sepfile, i2->sepfile.buffer,sizeof(sepfile), 0, STR_TERMINATE); - rpcstr_pull(printprocessor, i2->printprocessor.buffer,sizeof(printprocessor), 0, STR_TERMINATE); - rpcstr_pull(datatype, i2->datatype.buffer,sizeof(datatype), 0, STR_TERMINATE); - rpcstr_pull(parameters, i2->parameters.buffer,sizeof(parameters), 0, STR_TERMINATE); - - report(out_hnd, "\tservername:[%s]\n", servername); - report(out_hnd, "\tprintername:[%s]\n", printername); - report(out_hnd, "\tsharename:[%s]\n", sharename); - report(out_hnd, "\tportname:[%s]\n", portname); - report(out_hnd, "\tdrivername:[%s]\n", drivername); - report(out_hnd, "\tcomment:[%s]\n", comment); - report(out_hnd, "\tlocation:[%s]\n", location); - report(out_hnd, "\tsepfile:[%s]\n", sepfile); - report(out_hnd, "\tprintprocessor:[%s]\n", printprocessor); - report(out_hnd, "\tdatatype:[%s]\n", datatype); - report(out_hnd, "\tparameters:[%s]\n", parameters); - report(out_hnd, "\tattributes:[%x]\n", i2->attributes); - report(out_hnd, "\tpriority:[%x]\n", i2->priority); - report(out_hnd, "\tdefaultpriority:[%x]\n", i2->defaultpriority); - report(out_hnd, "\tstarttime:[%x]\n", i2->starttime); - report(out_hnd, "\tuntiltime:[%x]\n", i2->untiltime); - report(out_hnd, "\tstatus:[%x]\n", i2->status); - report(out_hnd, "\tcjobs:[%x]\n", i2->cjobs); - report(out_hnd, "\taverageppm:[%x]\n\n", i2->averageppm); - - if (i2->secdesc != NULL) - { - display_sec_desc(out_hnd, ACTION_HEADER , i2->secdesc); - display_sec_desc(out_hnd, ACTION_ENUMERATE, i2->secdesc); - display_sec_desc(out_hnd, ACTION_FOOTER , i2->secdesc); - } -} - -/**************************************************************************** -printer info level 3 display function -****************************************************************************/ -static void display_print_info_3(FILE *out_hnd, PRINTER_INFO_3 *i3) -{ - if (i3 == NULL) - return; - - report(out_hnd, "\tflags:[%x]\n", i3->flags); - - display_sec_desc(out_hnd, ACTION_HEADER , i3->secdesc); - display_sec_desc(out_hnd, ACTION_ENUMERATE, i3->secdesc); - display_sec_desc(out_hnd, ACTION_FOOTER , i3->secdesc); -} - -/**************************************************************************** -connection info level 0 container display function -****************************************************************************/ -static void display_printer_info_0_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_0 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 0:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_0; - display_print_info_0(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printer_info_1_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_1 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_1; - display_print_info_1(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -static void display_printer_info_2_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_2 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_2; - display_print_info_2(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_printer_info_3_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_3 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 3:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_3; - display_print_info_3(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PRINTER_INFO_CTR ctr) -{ - switch (level) { - case 0: - display_printer_info_0_ctr(out_hnd, action, count, ctr); - break; - case 1: - display_printer_info_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_printer_info_2_ctr(out_hnd, action, count, ctr); - break; - case 3: - display_printer_info_3_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_printer_info_ctr: Unknown Info Level\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_port_info_1_ctr(FILE *out_hnd, enum action_type action, - uint32 count, PORT_INFO_CTR *ctr) -{ - uint32 i = 0; - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i=0; iport.info_1[i]); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_port_info_2_ctr(FILE *out_hnd, enum action_type action, - uint32 count, PORT_INFO_CTR *ctr) -{ - uint32 i = 0; - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port Info Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i=0; iport.info_2[i]); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PORT_INFO_CTR *ctr) -{ - switch (level) { - case 1: - display_port_info_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_port_info_2_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_port_info_ctr: Unknown Info Level\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_1(FILE *out_hnd, enum action_type action, PORT_INFO_1 *i1) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port:\n"); - break; - case ACTION_ENUMERATE: - rpcstr_pull(buffer, i1->port_name.buffer, sizeof(bufferi), 0, STR_TERMINATE); - fprintf (out_hnd, "\tPort Name:\t[%s]\n\n", buffer); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_2(FILE *out_hnd, enum action_type action, PORT_INFO_2 *i2) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port:\n"); - break; - case ACTION_ENUMERATE: - rpcstr_pull(buffer, i2->port_name.buffer, sizeof(buffer), 0, STR_TERMINATE); - fprintf (out_hnd, "\tPort Name:\t[%s]\n", buffer); - rpcstr_pull(buffer, i2->monitor_name.buffer, sizeof(buffer), 0, STR_TERMINATE); - - fprintf (out_hnd, "\tMonitor Name:\t[%s]\n", buffer); - rpcstr_pull(buffer, i2->description.buffer, sizeof(buffer), 0, STR_TERMINATE); - fprintf (out_hnd, "\tDescription:\t[%s]\n", buffer); - fprintf (out_hnd, "\tPort Type:\t[%d]\n", i2->port_type); - fprintf (out_hnd, "\tReserved:\t[%d]\n", i2->reserved); - fprintf (out_hnd, "\n"); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_enumdata(FILE *out_hnd, enum action_type action, uint32 idx, - uint32 valuelen, uint16 *value, uint32 rvaluelen, - uint32 type, - uint32 datalen, uint8 *data, uint32 rdatalen) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer enum data:\n"); - report(out_hnd, "index\tvaluelen\tvalue\t\trvaluelen"); - report(out_hnd, "\ttype\tdatalen\tdata\trdatalen\n"); - break; - case ACTION_ENUMERATE: - report(out_hnd, "[%d]", idx); - report(out_hnd, "\t[%d]", valuelen); - rpcstr_pull(buffer, value, sizeof(buffer), 0, STR_TERMINATE); - report(out_hnd, "\t[%s]", buffer); - report(out_hnd, "\t[%d]", rvaluelen); - report(out_hnd, "\t\t[%d]", type); - report(out_hnd, "\t[%d]", datalen); -/* report(out_hnd, "\t[%s]", data);*/ - report(out_hnd, "\t[%d]\n", rdatalen); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -job info level 2 display function -****************************************************************************/ -void display_job_info_2(FILE *out_hnd, enum action_type action, - JOB_INFO_2 *const i2) -{ - if (i2 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - report(out_hnd, "Job Info Level 2:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring tmp; - - report(out_hnd, "\tjob id:\t%d\n", i2->jobid); - rpcstr_pull(tmp, i2->printername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprinter name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->machinename.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tmachine name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->username.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tusername:\t%s\n", tmp); - rpcstr_pull(tmp, i2->document.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdocument:\t%s\n", tmp); - rpcstr_pull(tmp, i2->notifyname.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tnotify name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->datatype.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdata type:\t%s\n", tmp); - rpcstr_pull(tmp, i2->printprocessor.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprint processor:\t%s\n", tmp); - rpcstr_pull(tmp, i2->parameters.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tparameters:\t%s\n", tmp); - rpcstr_pull(tmp, i2->drivername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdriver name:\t%s\n", tmp); - report(out_hnd, "\tDevice Mode:\tNOT DISPLAYED YET\n"); - - rpcstr_pull(tmp, i2->text_status.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\ttext status:\t%s\n", tmp); - /* SEC_DESC sec_desc;*/ - report(out_hnd, "\tstatus:\t%d\n", i2->status); - report(out_hnd, "\tpriority:\t%d\n", i2->priority); - report(out_hnd, "\tposition:\t%d\n", i2->position); - report(out_hnd, "\tstarttime:\t%d\n", i2->starttime); - report(out_hnd, "\tuntiltime:\t%d\n", i2->untiltime); - report(out_hnd, "\ttotalpages:\t%d\n", i2->totalpages); - report(out_hnd, "\tsize:\t%d\n", i2->size); -/* - SYSTEMTIME submitted; -*/ - report(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); - report(out_hnd, "\ttimeelapsed:\t%d\n", i2->timeelapsed); - report(out_hnd, "\tpagesprinted:\t%d\n", i2->pagesprinted); - } - case ACTION_FOOTER: - { - report(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -job info level 1 display function -****************************************************************************/ -void display_job_info_1(FILE *out_hnd, enum action_type action, - JOB_INFO_1 *const i1) -{ - if (i1 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - report(out_hnd, "Job Info Level 1:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring tmp; - - report(out_hnd, "\tjob id:\t%d\n", i1->jobid); - rpcstr_pull(tmp, i1->printername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprinter name:\t%s\n", tmp); - rpcstr_pull(tmp, i1->machinename.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tmachine name:\t%s\n", tmp); - rpcstr_pull(tmp, i1->username.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tusername:\t%s\n", tmp); - rpcstr_pull(tmp, i1->document.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdocument:\t%s\n", tmp); - rpcstr_pull(tmp, i1->datatype.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdata type:\t%s\n", tmp); - rpcstr_pull(tmp, i1->text_status.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\ttext status:\t%s\n", tmp); - report(out_hnd, "\tstatus:\t%d\n", i1->status); - report(out_hnd, "\tpriority:\t%d\n", i1->priority); - report(out_hnd, "\tposition:\t%d\n", i1->position); - report(out_hnd, "\ttotalpages:\t%d\n", i1->totalpages); -/* - SYSTEMTIME submitted; -*/ - report(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); - report(out_hnd, "\tpagesprinted:\t%d\n", i1->pagesprinted); - - break; - } - case ACTION_FOOTER: - { - report(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -void display_job_info_2_ctr(FILE *out_hnd, enum action_type action, - uint32 count, JOB_INFO_2 *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_2_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < count; i++) - { - display_job_info_2(out_hnd, ACTION_HEADER , ctr[i]); - display_job_info_2(out_hnd, ACTION_ENUMERATE, ctr[i]); - display_job_info_2(out_hnd, ACTION_FOOTER , ctr[i]); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -void display_job_info_1_ctr(FILE *out_hnd, enum action_type action, - uint32 count, JOB_INFO_1 *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_1_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < count; i++) - { - display_job_info_1(out_hnd, ACTION_HEADER , ctr[i]); - display_job_info_1(out_hnd, ACTION_ENUMERATE, ctr[i]); - display_job_info_1(out_hnd, ACTION_FOOTER , ctr[i]); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_job_info_ctr(FILE *out_hnd, enum action_type action, - uint32 level, uint32 count, - void *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_ctr: unavailable due to an internal error\n"); - return; - } - - switch (level) - { - case 1: - { - display_job_info_1_ctr(out_hnd, action, - count, (JOB_INFO_1*const*const)ctr); - break; - } - case 2: - { - display_job_info_2_ctr(out_hnd, action, - count, (JOB_INFO_2*const*const)ctr); - break; - } - default: - { - report(out_hnd, "display_job_info_ctr: Unknown Info Level\n"); - break; - } - } -} - -/**************************************************************************** -printer info level 0 display function -****************************************************************************/ -static void display_print_driver_1(FILE *out_hnd, DRIVER_INFO_1 *i1) -{ - fstring name; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - - report(out_hnd, "\tname:[%s]\n", name); -} - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_print_driver_2(FILE *out_hnd, DRIVER_INFO_2 *i1) -{ - fstring name; - fstring architecture; - fstring driverpath; - fstring datafile; - fstring configfile; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), 0, STR_TERMINATE); - rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), 0, STR_TERMINATE); - rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), 0, STR_TERMINATE); - rpcstr_pull(configfile, i1->conigfile.buffer, sizeof(configfile), 0, STR_TERMINATE); - - report(out_hnd, "\tversion:[%x]\n", i1->version); - report(out_hnd, "\tname:[%s]\n", name); - report(out_hnd, "\tarchitecture:[%s]\n", architecture); - report(out_hnd, "\tdriverpath:[%s]\n", driverpath); - report(out_hnd, "\tdatafile:[%s]\n", datafile); - report(out_hnd, "\tconfigfile:[%s]\n", configfile); -} - -/**************************************************************************** -printer info level 2 display function -****************************************************************************/ -static void display_print_driver_3(FILE *out_hnd, DRIVER_INFO_3 *i1) -{ - fstring name; - fstring architecture; - fstring driverpath; - fstring datafile; - fstring configfile; - fstring helpfile; - fstring dependentfiles; - fstring monitorname; - fstring defaultdatatype; - - int length=0; - BOOL valid = True; - - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), 0, STR_TERMINATE); - rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), 0, STR_TERMINATE); - rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), 0, STR_TERMINATE); - rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), 0, STR_TERMINATE); - rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), 0, STR_TERMINATE); - rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), 0, STR_TERMINATE); - rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), 0, STR_TERMINATE); - - report(out_hnd, "\tversion:[%x]\n", i1->version); - report(out_hnd, "\tname:[%s]\n",name); - report(out_hnd, "\tarchitecture:[%s]\n", architecture); - report(out_hnd, "\tdriverpath:[%s]\n", driverpath); - report(out_hnd, "\tdatafile:[%s]\n", datafile); - report(out_hnd, "\tconfigfile:[%s]\n", configfile); - report(out_hnd, "\thelpfile:[%s]\n\n", helpfile); - - while (valid) - { - rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), 0, STR_TERMINATE); - length+=strlen(dependentfiles)+1; - - if (strlen(dependentfiles) > 0) - { - report(out_hnd, "\tdependentfiles:[%s]\n", dependentfiles); - } - else - { - valid = False; - } - } - - report(out_hnd, "\n\tmonitorname:[%s]\n", monitorname); - report(out_hnd, "\tdefaultdatatype:[%s]\n", defaultdatatype); - -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printer_driver_1_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_1 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info1; - display_print_driver_1(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -static void display_printer_driver_2_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_2 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info2; - display_print_driver_2(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_printer_driver_3_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_3 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 3:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info3; - display_print_driver_3(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_driver_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PRINTER_DRIVER_CTR ctr) -{ - switch (level) { - case 1: - display_printer_driver_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_printer_driver_2_ctr(out_hnd, action, count, ctr); - break; - case 3: - display_printer_driver_3_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_printer_driver_ctr: Unknown Info Level\n"); - break; - } -} - - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_printdriverdir_info_1(FILE *out_hnd, DRIVER_DIRECTORY_1 *i1) -{ - fstring name; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - - report(out_hnd, "\tname:[%s]\n", name); -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printerdriverdir_info_1_ctr(FILE *out_hnd, enum action_type action, DRIVER_DIRECTORY_CTR ctr) -{ - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver dir Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - display_printdriverdir_info_1(out_hnd, &(ctr.driver.info_1) ); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printerdriverdir_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - DRIVER_DIRECTORY_CTR ctr) -{ - switch (level) { - case 1: - display_printerdriverdir_info_1_ctr(out_hnd, action, ctr); - break; - default: - report(out_hnd, "display_printerdriverdir_info_ctr: Unknown Info Level\n"); - break; - } -} diff --git a/source3/rpcclient/samsync.c b/source3/rpcclient/samsync.c deleted file mode 100644 index f941d70e5e..0000000000 --- a/source3/rpcclient/samsync.c +++ /dev/null @@ -1,772 +0,0 @@ -/* - Unix SMB/CIFS implementation. - SAM synchronisation and replication - - Copyright (C) Tim Potter 2001,2002 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -DOM_SID domain_sid; - -static void decode_domain_info(SAM_DOMAIN_INFO *a) -{ - fstring temp; - printf("Domain Information\n"); - printf("------------------\n"); - - unistr2_to_ascii(temp, &a->uni_dom_name, sizeof(temp)-1); - printf("\tDomain :%s\n", temp); - printf("\tMin password len :%d\n", a->min_pwd_len); - printf("\tpassword history len:%d\n", a->pwd_history_len); - printf("\tcreation time :%s\n", http_timestring(nt_time_to_unix(&a->creation_time))); -} - -static void decode_sam_group_info(SAM_GROUP_INFO *a) -{ - fstring temp; - printf("\nDomain Group Information\n"); - printf("------------------------\n"); - - unistr2_to_ascii(temp, &a->uni_grp_name, sizeof(temp)-1); - printf("\tGroup name :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_grp_desc, sizeof(temp)-1); - printf("\tGroup description :%s\n", temp); - printf("\trid :%d\n", a->gid.g_rid); - printf("\tattribute :%d\n", a->gid.attr); -} - -static void decode_sam_account_info(SAM_ACCOUNT_INFO *a) -{ - fstring temp; - printf("\nUser Information\n"); - printf("----------------\n"); - - unistr2_to_ascii(temp, &a->uni_acct_name, sizeof(temp)-1); - printf("\tUser name :%s\n", temp); - printf("\tuser's rid :%d\n", a->user_rid); - printf("\tuser's primary gid :%d\n", a->group_rid); - unistr2_to_ascii(temp, &a->uni_full_name, sizeof(temp)-1); - printf("\tfull name :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_home_dir, sizeof(temp)-1); - printf("\thome directory :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_dir_drive, sizeof(temp)-1); - printf("\tdrive :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_logon_script, sizeof(temp)-1); - printf("\tlogon script :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_acct_desc, sizeof(temp)-1); - printf("\tdescription :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_workstations, sizeof(temp)-1); - printf("\tworkstations :%s\n", temp); -} - -static void decode_sam_grp_mem_info(SAM_GROUP_MEM_INFO *a) -{ - int i; - printf("\nGroup members information\n"); - printf("-------------------------\n"); - printf("\tnum members :%d\n", a->num_members); - - for (i=0; inum_members; i++) { - printf("\trid, attr:%d, %d\n", a->rids[i], a->attribs[i]); - } -} - -static void decode_sam_alias_info(SAM_ALIAS_INFO *a) -{ - fstring temp; - printf("\nAlias Information\n"); - printf("-----------------\n"); - - unistr2_to_ascii(temp, &a->uni_als_name, sizeof(temp)-1); - printf("\tname :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_als_desc, sizeof(temp)-1); - printf("\tdescription :%s\n", temp); - printf("\trid :%d\n", a->als_rid); -} - -static void decode_sam_als_mem_info(SAM_ALIAS_MEM_INFO *a) -{ - int i; - fstring temp; - printf("\nAlias members Information\n"); - printf("-------------------------\n"); - printf("\tnum members :%d\n", a->num_members); - printf("\tnum sids :%d\n", a->num_sids); - for (i=0; inum_sids; i++) { - printf("\tsid :%s\n", sid_to_string(temp, &a->sids[i].sid)); - } - - -} - -static void decode_sam_dom_info(SAM_DELTA_DOM *a) -{ - fstring temp; - printf("\nDomain information\n"); - printf("------------------\n"); - - unistr2_to_ascii(temp, &a->domain_name, sizeof(temp)-1); - printf("\tdomain name :%s\n", temp); - printf("\tsid :%s\n", sid_to_string(temp, &a->domain_sid.sid)); -} - -static void decode_sam_unk0e_info(SAM_DELTA_UNK0E *a) -{ - fstring temp; - printf("\nTrust information\n"); - printf("-----------------\n"); - - unistr2_to_ascii(temp, &a->domain, sizeof(temp)-1); - printf("\tdomain name :%s\n", temp); - printf("\tsid :%s\n", sid_to_string(temp, &a->sid.sid)); - display_sec_desc(a->sec_desc); -} - -static void decode_sam_privs_info(SAM_DELTA_PRIVS *a) -{ - int i; - fstring temp; - printf("\nSID and privileges information\n"); - printf("------------------------------\n"); - printf("\tsid :%s\n", sid_to_string(temp, &a->sid.sid)); - display_sec_desc(a->sec_desc); - printf("\tprivileges count :%d\n", a->privlist_count); - for (i=0; iprivlist_count; i++) { - unistr2_to_ascii(temp, &a->uni_privslist[i], sizeof(temp)-1); - printf("\tprivilege name :%s\n", temp); - printf("\tattribute :%d\n", a->attributes[i]); - } -} - -static void decode_sam_unk12_info(SAM_DELTA_UNK12 *a) -{ - fstring temp; - printf("\nTrusted information\n"); - printf("-------------------\n"); - - unistr2_to_ascii(temp, &a->secret, sizeof(temp)-1); - printf("\tsecret name :%s\n", temp); - display_sec_desc(a->sec_desc); - - printf("\ttime 1 :%s\n", http_timestring(nt_time_to_unix(&a->time1))); - printf("\ttime 2 :%s\n", http_timestring(nt_time_to_unix(&a->time2))); - - display_sec_desc(a->sec_desc2); -} - -static void decode_sam_stamp(SAM_DELTA_STAMP *a) -{ - printf("\nStamp information\n"); - printf("-----------------\n"); - printf("\tsequence number :%d\n", a->seqnum); -} - -static void decode_sam_deltas(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas, SAM_DELTA_CTR *deltas) -{ - int i; - for (i = 0; i < num_deltas; i++) { - switch (hdr_deltas[i].type) { - case SAM_DELTA_DOMAIN_INFO: { - SAM_DOMAIN_INFO *a; - a = &deltas[i].domain_info; - decode_domain_info(a); - break; - } - case SAM_DELTA_GROUP_INFO: { - SAM_GROUP_INFO *a; - a = &deltas[i].group_info; - decode_sam_group_info(a); - break; - } - case SAM_DELTA_ACCOUNT_INFO: { - SAM_ACCOUNT_INFO *a; - a = &deltas[i].account_info; - decode_sam_account_info(a); - break; - } - case SAM_DELTA_GROUP_MEM: { - SAM_GROUP_MEM_INFO *a; - a = &deltas[i].grp_mem_info; - decode_sam_grp_mem_info(a); - break; - } - case SAM_DELTA_ALIAS_INFO: { - SAM_ALIAS_INFO *a; - a = &deltas[i].alias_info; - decode_sam_alias_info(a); - break; - } - case SAM_DELTA_ALIAS_MEM: { - SAM_ALIAS_MEM_INFO *a; - a = &deltas[i].als_mem_info; - decode_sam_als_mem_info(a); - break; - } - case SAM_DELTA_POLICY_INFO: { - SAM_DELTA_POLICY *a; - a = &deltas[i].dom_info; - decode_sam_dom_info(a); - break; - } - case SAM_DELTA_UNK0E_INFO: { - SAM_DELTA_UNK0E *a; - a = &deltas[i].unk0e_info; - decode_sam_unk0e_info(a); - break; - } - case SAM_DELTA_PRIVS_INFO: { - SAM_DELTA_PRIVS *a; - a = &deltas[i].privs_info; - decode_sam_privs_info(a); - break; - } - case SAM_DELTA_UNK12_INFO: { - SAM_DELTA_UNK12 *a; - a = &deltas[i].unk12_info; - decode_sam_unk12_info(a); - break; - } - case SAM_DELTA_SAM_STAMP: { - SAM_DELTA_STAMP *a; - a = &deltas[i].stamp; - decode_sam_stamp(a); - break; - } - default: - DEBUG(0,("unknown delta type: %d\n", hdr_deltas[i].type)); - break; - } - } -} - -/* Convert a SAM_ACCOUNT_DELTA to a SAM_ACCOUNT. */ - -static void sam_account_from_delta(SAM_ACCOUNT *account, - SAM_ACCOUNT_INFO *delta) -{ - DOM_SID sid; - fstring s; - - /* Username, fullname, home dir, dir drive, logon script, acct - desc, workstations, profile. */ - - unistr2_to_ascii(s, &delta->uni_acct_name, sizeof(s) - 1); - pdb_set_nt_username(account, s); - - /* Unix username is the same - for sainity */ - pdb_set_username(account, s); - - unistr2_to_ascii(s, &delta->uni_full_name, sizeof(s) - 1); - pdb_set_fullname(account, s); - - unistr2_to_ascii(s, &delta->uni_home_dir, sizeof(s) - 1); - pdb_set_homedir(account, s, True); - - unistr2_to_ascii(s, &delta->uni_dir_drive, sizeof(s) - 1); - pdb_set_dir_drive(account, s, True); - - unistr2_to_ascii(s, &delta->uni_logon_script, sizeof(s) - 1); - pdb_set_logon_script(account, s, True); - - unistr2_to_ascii(s, &delta->uni_acct_desc, sizeof(s) - 1); - pdb_set_acct_desc(account, s); - - unistr2_to_ascii(s, &delta->uni_workstations, sizeof(s) - 1); - pdb_set_workstations(account, s); - - unistr2_to_ascii(s, &delta->uni_profile, sizeof(s) - 1); - pdb_set_profile_path(account, s, True); - - /* User and group sid */ - - sid_copy(&sid, &domain_sid); - sid_append_rid(&sid, delta->user_rid); - pdb_set_user_sid(account, &sid); - - sid_copy(&sid, &domain_sid); - sid_append_rid(&sid, delta->group_rid); - pdb_set_group_sid(account, &sid); - - /* Logon and password information */ - - pdb_set_logon_time(account, nt_time_to_unix(&delta->logon_time), True); - pdb_set_logoff_time(account, nt_time_to_unix(&delta->logoff_time), - True); - - pdb_set_logon_divs(account, delta->logon_divs); - - /* TODO: logon hours */ - /* TODO: bad password count */ - /* TODO: logon count */ - - pdb_set_pass_last_set_time( - account, nt_time_to_unix(&delta->pwd_last_set_time)); - - /* TODO: account expiry time */ - - pdb_set_acct_ctrl(account, delta->acb_info); -} - -static void apply_account_info(SAM_ACCOUNT_INFO *sam_acct_delta) -{ - SAM_ACCOUNT *sam_acct; - BOOL result; - - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) { - return; - } - - sam_account_from_delta(sam_acct, sam_acct_delta); - result = pdb_add_sam_account(sam_acct); -} - -/* Apply an array of deltas to the SAM database */ - -static void apply_deltas(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas, - SAM_DELTA_CTR *deltas) -{ - uint32 i; - - for (i = 0; i < num_deltas; i++) { - switch(hdr_deltas[i].type) { - case SAM_DELTA_ACCOUNT_INFO: - apply_account_info(&deltas[i].account_info); - break; - } - } -} - -/* Synchronise sam database */ - -static NTSTATUS sam_sync(struct cli_state *cli, unsigned char trust_passwd[16], - BOOL do_smbpasswd_output, BOOL verbose) -{ - TALLOC_CTX *mem_ctx; - SAM_DELTA_HDR *hdr_deltas_0, *hdr_deltas_2; - SAM_DELTA_CTR *deltas_0, *deltas_2; - uint32 num_deltas_0, num_deltas_2; - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - struct pdb_context *in; - uint32 neg_flags = 0x000001ff; - - DOM_CRED ret_creds; - - /* Initialise */ - - if (!NT_STATUS_IS_OK(make_pdb_context_list(&in, lp_passdb_backend()))){ - DEBUG(0, ("Can't initialize passdb backend.\n")); - return result; - } - - if (!(mem_ctx = talloc_init("sam_sync"))) { - DEBUG(0,("talloc_init failed\n")); - return result; - } - - if (!cli_nt_session_open (cli, PI_NETLOGON)) { - DEBUG(0, ("Could not initialize netlogon pipe!\n")); - goto done; - } - - /* Request a challenge */ - - if (!NT_STATUS_IS_OK(cli_nt_setup_creds(cli, SEC_CHAN_BDC, trust_passwd, &neg_flags, 2))) { - DEBUG(0, ("Error initialising session creds\n")); - goto done; - } - - /* on first call the returnAuthenticator is empty */ - memset(&ret_creds, 0, sizeof(ret_creds)); - - /* Do sam synchronisation on the SAM database*/ - - result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, 0, 0, - &num_deltas_0, &hdr_deltas_0, - &deltas_0); - - if (!NT_STATUS_IS_OK(result)) - goto done; - - - /* Update sam */ - - apply_deltas(num_deltas_0, hdr_deltas_0, deltas_0); - - - /* - * we can't yet do several sam_sync in a raw, it's a credential problem - * we must chain the credentials - */ - -#if 1 - /* Do sam synchronisation on the LSA database */ - - result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, 2, 0, &num_deltas_2, &hdr_deltas_2, &deltas_2); - - if (!NT_STATUS_IS_OK(result)) - goto done; - - /* verbose mode */ - if (verbose) - decode_sam_deltas(num_deltas_2, hdr_deltas_2, deltas_2); -#endif - - /* Produce smbpasswd output - good for migrating from NT! */ - - if (do_smbpasswd_output) { - int i; - - for (i = 0; i < num_deltas_0; i++) { - SAM_ACCOUNT_INFO *a; - fstring acct_name, hex_nt_passwd, hex_lm_passwd; - uchar lm_passwd[16], nt_passwd[16]; - - /* Skip non-user accounts */ - - if (hdr_deltas_0[i].type != SAM_DELTA_ACCOUNT_INFO) - continue; - - a = &deltas_0[i].account_info; - - unistr2_to_ascii(acct_name, &a->uni_acct_name, - sizeof(acct_name) - 1); - - /* Decode hashes from password hash */ - - sam_pwd_hash(a->user_rid, a->pass.buf_lm_pwd, - lm_passwd, 0); - sam_pwd_hash(a->user_rid, a->pass.buf_nt_pwd, - nt_passwd, 0); - - /* Encode as strings */ - - smbpasswd_sethexpwd(hex_lm_passwd, lm_passwd, - a->acb_info); - smbpasswd_sethexpwd(hex_nt_passwd, nt_passwd, - a->acb_info); - - /* Display user info */ - - printf("%s:%d:%s:%s:%s:LCT-0\n", acct_name, - a->user_rid, hex_lm_passwd, hex_nt_passwd, - smbpasswd_encode_acb_info(a->acb_info)); - } - - goto done; - } - - done: - cli_nt_session_close(cli); - talloc_destroy(mem_ctx); - - return result; -} - -/* Replicate sam deltas */ - -static NTSTATUS sam_repl(struct cli_state *cli, unsigned char trust_passwde[16], - uint32 low_serial) -{ - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - - return result; -} - -/* Connect to primary domain controller */ - -static struct cli_state *init_connection(struct cli_state **cli, - char *username, char *domain, - char *password) -{ - extern pstring global_myname; - struct in_addr pdc_ip; - fstring dest_host; - - /* Initialise myname */ - - if (!global_myname[0]) { - char *p; - - fstrcpy(global_myname, myhostname()); - p = strchr(global_myname, '.'); - if (p) - *p = 0; - } - - /* Look up name of PDC controller */ - - if (!get_pdc_ip(lp_workgroup(), &pdc_ip)) { - DEBUG(0, ("Cannot find domain controller for domain %s\n", - lp_workgroup())); - return NULL; - } - - if (!lookup_dc_name(global_myname, lp_workgroup(), pdc_ip, - dest_host)) { - DEBUG(0, ("Could not lookup up PDC name for domain %s\n", - lp_workgroup())); - return NULL; - } - - if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host, - pdc_ip, 0, - "IPC$", "IPC", - username, domain, - password, 0))) { - return *cli; - } - - return NULL; -} - -/* Main function */ - -static fstring popt_username, popt_domain, popt_password; -static BOOL popt_got_pass; - -static void user_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - const char *p, *ch; - - if (!arg) - return; - - switch(opt->val) { - - /* Check for [DOMAIN\\]username[%password]*/ - - case 'U': - - p = arg; - - if ((ch = strchr(p, '\\'))) { - fstrcpy(popt_domain, p); - popt_domain[ch - p] = 0; - } - - fstrcpy(popt_username, p); - - if ((ch = strchr(p, '%'))) { - popt_username[ch - p] = 0; - fstrcpy(popt_password, ch + 1); - popt_got_pass = True; - } - - break; - - case 'W': - fstrcpy(popt_domain, arg); - break; - } -} - -/* Return domain, username and password passed in from cmd line */ - -void popt_common_get_auth_info(char **domain, char **username, char **password, - BOOL *got_pass) -{ - *domain = popt_domain; - *username = popt_username; - *password = popt_password; - *got_pass = popt_got_pass; -} - -struct poptOption popt_common_auth_info[] = { - { NULL, 0, POPT_ARG_CALLBACK, user_callback }, - { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set username", - "[DOMAIN\\]username[%password]" }, - { "domain", 'W', POPT_ARG_STRING, NULL, 'W', "Set domain name", - "DOMAIN"}, - { 0 } -}; - -static BOOL popt_interactive; - -BOOL popt_common_is_interactive(void) -{ - return popt_interactive; -} - -struct poptOption popt_common_interactive[] = { - { "interactive", 'i', POPT_ARG_NONE, &popt_interactive, 'i', - "Log to stdout" }, - { 0 } -}; - - int main(int argc, char **argv) -{ - BOOL do_sam_sync = False, do_sam_repl = False; - struct cli_state *cli; - NTSTATUS result; - pstring logfile; - BOOL do_smbpasswd_output = False; - BOOL verbose = True, got_pass = False; - uint32 serial = 0; - unsigned char trust_passwd[16]; - char *username, *domain, *password; - poptContext pc; - char c; - - struct poptOption popt_samsync_opts[] = { - { "synchronise", 'S', POPT_ARG_NONE, &do_sam_sync, 'S', - "Perform full SAM synchronisation" }, - { "replicate", 'R', POPT_ARG_NONE, &do_sam_repl, 'R', - "Replicate SAM changes" }, - { "serial", 0, POPT_ARG_INT, &serial, 0, "SAM serial number" }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_auth_info }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_interactive }, - POPT_AUTOHELP - { 0 } - }; - - /* Read command line options */ - - pc = poptGetContext("samsync", argc, (const char **)argv, - popt_samsync_opts, 0); - - if (argc == 1) { - poptPrintUsage(pc, stdout, 0); - return 1; - } - - while ((c = poptGetNextOpt(pc)) != -1) { - - /* Argument processing error */ - - if (c < -1) { - fprintf(stderr, "samsync: %s: %s\n", - poptBadOption(pc, POPT_BADOPTION_NOALIAS), - poptStrerror(c)); - return 1; - } - - /* Handle arguments */ - - switch (c) { - case 'h': - poptPrintHelp(pc, stdout, 0); - return 1; - case 'u': - poptPrintUsage(pc, stdout, 0); - return 1; - } - } - - /* Bail out if any extra args were passed */ - - if (poptPeekArg(pc)) { - fprintf(stderr, "samsync: invalid argument %s\n", - poptPeekArg(pc)); - poptPrintUsage(pc, stdout, 0); - return 1; - } - - poptFreeContext(pc); - - /* Setup logging */ - - dbf = x_stdout; - - if (!lp_load(dyn_CONFIGFILE, True, False, False)) { - d_fprintf(stderr, "samsync: error opening config file %s. " - "Error was %s\n", dyn_CONFIGFILE, strerror(errno)); - return 1; - } - - slprintf(logfile, sizeof(logfile) - 1, "%s/log.%s", dyn_LOGFILEBASE, - "samsync"); - - lp_set_logfile(logfile); - - setup_logging("samsync", popt_common_is_interactive()); - - if (!popt_common_is_interactive()) - reopen_logs(); - - load_interfaces(); - - /* Check arguments make sense */ - - if (do_sam_sync && do_sam_repl) { - DEBUG(0, ("cannot specify both -S and -R\n")); - return 1; - - } - - if (!do_sam_sync && !do_sam_repl) { - DEBUG(0, ("samsync: you must either --synchronise or " - "--replicate the SAM database\n")); - return 1; - } - - if (do_sam_repl && serial == 0) { - DEBUG(0, ("samsync: must specify serial number\n")); - return 1; - } - - if (do_sam_sync && serial != 0) { - DEBUG(0, ("samsync: you can't specify a serial number when " - "synchonising the SAM database\n")); - return 1; - } - - /* BDC operations require the machine account password */ - - if (!secrets_init()) { - DEBUG(0, ("samsync: unable to initialise secrets database\n")); - return 1; - } - - if (!secrets_fetch_trust_account_password(lp_workgroup(), - trust_passwd, NULL)) { - DEBUG(0, ("samsync: could not fetch trust account password\n")); - return 1; - } - - /* I wish the domain sid wasn't stored in secrets.tdb */ - - if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) { - DEBUG(0, ("samsync: could not retrieve domain sid\n")); - return 1; - } - - /* Perform sync or replication */ - - popt_common_get_auth_info(&domain, &username, &password, &got_pass); - - if (!init_connection(&cli, username, domain, password)) - return 1; - - if (do_sam_sync) - result = sam_sync(cli, trust_passwd, do_smbpasswd_output, - verbose); - - if (do_sam_repl) - result = sam_repl(cli, trust_passwd, serial); - - if (!NT_STATUS_IS_OK(result)) { - DEBUG(0, ("%s\n", nt_errstr(result))); - return 1; - } - - return 0; -} -- cgit