summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-05-24 17:28:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:56:12 -0500
commitf1a8a690fcd9e8824dade9278e83902a6229b092 (patch)
tree049543f3ae4eb7514cb8d9cde6da72dad79c50a4
parentd17ca56aed836b5cf0725e7c74f34ecbf5dcdab3 (diff)
downloadsamba-f1a8a690fcd9e8824dade9278e83902a6229b092.tar.gz
samba-f1a8a690fcd9e8824dade9278e83902a6229b092.tar.bz2
samba-f1a8a690fcd9e8824dade9278e83902a6229b092.zip
r852: remove unused utility progs
metze (This used to be commit 4ef0b3656abdebb698d93936ae6ca492a8d35ef8)
-rw-r--r--source4/utils/debug2html.c253
-rw-r--r--source4/utils/editreg.c2069
-rw-r--r--source4/utils/pdbedit.c696
-rw-r--r--source4/utils/profiles.c729
-rw-r--r--source4/utils/rpccheck.c62
-rw-r--r--source4/utils/smbcacls.c937
-rw-r--r--source4/utils/smbcontrol.c714
-rw-r--r--source4/utils/smbfilter.c245
-rw-r--r--source4/utils/smbgroupedit.c410
-rw-r--r--source4/utils/smbpasswd.c605
-rw-r--r--source4/utils/smbtree.c369
-rw-r--r--source4/utils/smbw_sample.c94
-rw-r--r--source4/utils/status.c665
-rw-r--r--source4/utils/testparm.c338
-rw-r--r--source4/utils/testprns.c61
15 files changed, 0 insertions, 8247 deletions
diff --git a/source4/utils/debug2html.c b/source4/utils/debug2html.c
deleted file mode 100644
index f9a1f43f46..0000000000
--- a/source4/utils/debug2html.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/* ========================================================================== **
- * debug2html.c
- *
- * Copyright (C) 1998 by Christopher R. Hertel
- *
- * Email: crh@ubiqx.mn.org
- *
- * -------------------------------------------------------------------------- **
- * Parse Samba debug logs (2.0 & greater) and output the results as HTML.
- * -------------------------------------------------------------------------- **
- *
- * 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.
- *
- * -------------------------------------------------------------------------- **
- * This program provides an example of the use of debugparse.c, and also
- * does a decent job of converting Samba logs into HTML.
- * -------------------------------------------------------------------------- **
- *
- * Revision 1.4 1998/11/13 03:37:01 tridge
- * fixes for OSF1 compilation
- *
- * Revision 1.3 1998/10/28 20:33:35 crh
- * I've moved the debugparse module files into the ubiqx directory because I
- * know that 'make proto' will ignore them there. The debugparse.h header
- * file is included in includes.h, and includes.h is included in debugparse.c,
- * so all of the pieces "see" each other. I've compiled and tested this,
- * and it does seem to work. It's the same compromise model I used when
- * adding the ubiqx modules into the system, which is why I put it all into
- * the same directory.
- *
- * Chris -)-----
- *
- * Revision 1.1 1998/10/26 23:21:37 crh
- * Here is the simple debug parser and the debug2html converter. Still to do:
- *
- * * Debug message filtering.
- * * I need to add all this to Makefile.in
- * (If it looks at all strange I'll ask for help.)
- *
- * If you want to compile debug2html, you'll need to do it by hand until I
- * make the changes to Makefile.in. Sorry.
- *
- * Chris -)-----
- *
- * ========================================================================== **
- */
-
-#include "debugparse.h"
-
-/* -------------------------------------------------------------------------- **
- * The size of the read buffer.
- */
-
-#define DBG_BSIZE 1024
-
-/* -------------------------------------------------------------------------- **
- * Functions...
- */
-
-static dbg_Token modechange( dbg_Token new, dbg_Token mode )
- /* ------------------------------------------------------------------------ **
- * Handle a switch between header and message printing.
- *
- * Input: new - The token value of the current token. This indicates
- * the lexical item currently being recognized.
- * mode - The current mode. This is either dbg_null or
- * dbg_message. It could really be any toggle
- * (true/false, etc.)
- *
- * Output: The new mode. This will be the same as the input mode unless
- * there was a transition in or out of message processing.
- *
- * Notes: The purpose of the mode value is to mark the beginning and end
- * of the message text block. In order to show the text in its
- * correct format, it must be included within a <PRE></PRE> block.
- *
- * ------------------------------------------------------------------------ **
- */
- {
- switch( new )
- {
- case dbg_null:
- case dbg_ignore:
- return( mode );
- case dbg_message:
- if( dbg_message != mode )
- {
- /* Switching to message mode. */
- (void)printf( "<PRE>\n" );
- return( dbg_message );
- }
- break;
- default:
- if( dbg_message == mode )
- {
- /* Switching out of message mode. */
- (void)printf( "</PRE>\n\n" );
- return( dbg_null );
- }
- }
-
- return( mode );
- } /* modechange */
-
-static void newblock( dbg_Token old, dbg_Token new )
- /* ------------------------------------------------------------------------ **
- * Handle the transition between tokens.
- *
- * Input: old - The previous token.
- * new - The current token.
- *
- * Output: none.
- *
- * Notes: This is called whenever there is a transition from one token
- * type to another. It first prints the markup tags that close
- * the previous token, and then the markup tags for the new
- * token.
- *
- * ------------------------------------------------------------------------ **
- */
- {
- switch( old )
- {
- case dbg_timestamp:
- (void)printf( ",</B>" );
- break;
- case dbg_level:
- (void)printf( "</FONT>]</B>\n " );
- break;
- case dbg_sourcefile:
- (void)printf( ":" );
- break;
- case dbg_lineno:
- (void)printf( ")" );
- break;
- }
-
- switch( new )
- {
- case dbg_timestamp:
- (void)printf( "<B>[" );
- break;
- case dbg_level:
- (void)printf( " <B><FONT COLOR=MAROON>" );
- break;
- case dbg_lineno:
- (void)printf( "(" );
- break;
- }
- } /* newblock */
-
-static void charprint( dbg_Token tok, int c )
- /* ------------------------------------------------------------------------ **
- * Filter the input characters to determine what goes to output.
- *
- * Input: tok - The token value of the current character.
- * c - The current character.
- *
- * Output: none.
- *
- * ------------------------------------------------------------------------ **
- */
- {
- switch( tok )
- {
- case dbg_ignore:
- case dbg_header:
- break;
- case dbg_null:
- case dbg_eof:
- (void)putchar( '\n' );
- break;
- default:
- switch( c )
- {
- case '<':
- (void)printf( "&lt;" );
- break;
- case '>':
- (void)printf( "&gt;" );
- break;
- case '&':
- (void)printf( "&amp;" );
- break;
- case '\"':
- (void)printf( "&#34;" );
- break;
- default:
- (void)putchar( c );
- break;
- }
- }
- } /* charprint */
-
-int main( int argc, char *argv[] )
- /* ------------------------------------------------------------------------ **
- * This simple program scans and parses Samba debug logs, and produces HTML
- * output.
- *
- * Input: argc - Currently ignored.
- * argv - Currently ignored.
- *
- * Output: Always zero.
- *
- * Notes: The HTML output is sent to stdout.
- *
- * ------------------------------------------------------------------------ **
- */
- {
- int i;
- int len;
- char bufr[DBG_BSIZE];
- dbg_Token old = dbg_null,
- new = dbg_null,
- state = dbg_null,
- mode = dbg_null;
-
- (void)printf( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" );
- (void)printf( "<HTML>\n<HEAD>\n" );
- (void)printf( " <TITLE>Samba Debug Output</TITLE>\n</HEAD>\n\n<BODY>\n" );
-
- while( (!feof( stdin ))
- && ((len = fread( bufr, 1, DBG_BSIZE, stdin )) > 0) )
- {
- for( i = 0; i < len; i++ )
- {
- old = new;
- new = dbg_char2token( &state, bufr[i] );
- if( new != old )
- {
- mode = modechange( new, mode );
- newblock( old, new );
- }
- charprint( new, bufr[i] );
- }
- }
- (void)modechange( dbg_eof, mode );
-
- (void)printf( "</BODY>\n</HTML>\n" );
- return( 0 );
- } /* main */
diff --git a/source4/utils/editreg.c b/source4/utils/editreg.c
deleted file mode 100644
index 2cf8e2c9df..0000000000
--- a/source4/utils/editreg.c
+++ /dev/null
@@ -1,2069 +0,0 @@
-/*
- Samba Unix/Linux SMB client utility editreg.c
- Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
-
- 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. */
-
-/*************************************************************************
-
- A utility to edit a Windows NT/2K etc registry file.
-
- Many of the ideas in here come from other people and software.
- I first looked in Wine in misc/registry.c and was also influenced by
- http://www.wednesday.demon.co.uk/dosreg.html
-
- Which seems to contain comments from someone else. I reproduce them here
- incase the site above disappears. It actually comes from
- http://home.eunet.no/~pnordahl/ntpasswd/WinReg.txt.
-
- The goal here is to read the registry into memory, manipulate it, and then
- write it out if it was changed by any actions of the user.
-
-The windows NT registry has 2 different blocks, where one can occur many
-times...
-
-the "regf"-Block
-================
-
-"regf" is obviosly the abbreviation for "Registry file". "regf" is the
-signature of the header-block which is always 4kb in size, although only
-the first 64 bytes seem to be used and a checksum is calculated over
-the first 0x200 bytes only!
-
-Offset Size Contents
-0x00000000 D-Word ID: ASCII-"regf" = 0x66676572
-0x00000004 D-Word ???? //see struct REGF
-0x00000008 D-Word ???? Always the same value as at 0x00000004
-0x0000000C Q-Word last modify date in WinNT date-format
-0x00000014 D-Word 1
-0x00000018 D-Word 3
-0x0000001C D-Word 0
-0x00000020 D-Word 1
-0x00000024 D-Word Offset of 1st key record
-0x00000028 D-Word Size of the data-blocks (Filesize-4kb)
-0x0000002C D-Word 1
-0x000001FC D-Word Sum of all D-Words from 0x00000000 to
-0x000001FB //XOR of all words. Nigel
-
-I have analyzed more registry files (from multiple machines running
-NT 4.0 german version) and could not find an explanation for the values
-marked with ???? the rest of the first 4kb page is not important...
-
-the "hbin"-Block
-================
-I don't know what "hbin" stands for, but this block is always a multiple
-of 4kb in size.
-
-Inside these hbin-blocks the different records are placed. The memory-
-management looks like a C-compiler heap management to me...
-
-hbin-Header
-===========
-Offset Size Contents
-0x0000 D-Word ID: ASCII-"hbin" = 0x6E696268
-0x0004 D-Word Offset from the 1st hbin-Block
-0x0008 D-Word Offset to the next hbin-Block
-0x001C D-Word Block-size
-
-The values in 0x0008 and 0x001C should be the same, so I don't know
-if they are correct or swapped...
-
-From offset 0x0020 inside a hbin-block data is stored with the following
-format:
-
-Offset Size Contents
-0x0000 D-Word Data-block size //this size must be a
-multiple of 8. Nigel
-0x0004 ???? Data
-
-If the size field is negative (bit 31 set), the corresponding block
-is free and has a size of -blocksize!
-
-That does not seem to be true. All block lengths seem to be negative! (Richard Sharpe)
-
-The data is stored as one record per block. Block size is a multiple
-of 4 and the last block reaches the next hbin-block, leaving no room.
-
-Records in the hbin-blocks
-==========================
-
-nk-Record
-
- The nk-record can be treated as a kombination of tree-record and
- key-record of the win 95 registry.
-
-lf-Record
-
- The lf-record is the counterpart to the RGKN-record (the
- hash-function)
-
-vk-Record
-
- The vk-record consists information to a single value.
-
-sk-Record
-
- sk (? Security Key ?) is the ACL of the registry.
-
-Value-Lists
-
- The value-lists contain information about which values are inside a
- sub-key and don't have a header.
-
-Datas
-
- The datas of the registry are (like the value-list) stored without a
- header.
-
-All offset-values are relative to the first hbin-block and point to the
-block-size field of the record-entry. to get the file offset, you have to add
-the header size (4kb) and the size field (4 bytes)...
-
-the nk-Record
-=============
-Offset Size Contents
-0x0000 Word ID: ASCII-"nk" = 0x6B6E
-0x0002 Word for the root-key: 0x2C, otherwise 0x20 //key symbolic links 0x10. Nigel
-0x0004 Q-Word write-date/time in windows nt notation
-0x0010 D-Word Offset of Owner/Parent key
-0x0014 D-Word number of sub-Keys
-0x001C D-Word Offset of the sub-key lf-Records
-0x0024 D-Word number of values
-0x0028 D-Word Offset of the Value-List
-0x002C D-Word Offset of the sk-Record
-
-0x0030 D-Word Offset of the Class-Name //see NK structure for the use of these fields. Nigel
-0x0044 D-Word Unused (data-trash) //some kind of run time index. Does not appear to be important. Nigel
-0x0048 Word name-length
-0x004A Word class-name length
-0x004C ???? key-name
-
-the Value-List
-==============
-Offset Size Contents
-0x0000 D-Word Offset 1st Value
-0x0004 D-Word Offset 2nd Value
-0x???? D-Word Offset nth Value
-
-To determine the number of values, you have to look at the owner-nk-record!
-
-Der vk-Record
-=============
-Offset Size Contents
-0x0000 Word ID: ASCII-"vk" = 0x6B76
-0x0002 Word name length
-0x0004 D-Word length of the data //if top bit is set when offset contains data. Nigel
-0x0008 D-Word Offset of Data
-0x000C D-Word Type of value
-0x0010 Word Flag
-0x0012 Word Unused (data-trash)
-0x0014 ???? Name
-
-If bit 0 of the flag-word is set, a name is present, otherwise the value has no name (=default)
-
-If the data-size is lower 5, the data-offset value is used to store the data itself!
-
-The data-types
-==============
-Wert Beteutung
-0x0001 RegSZ: character string (in UNICODE!)
-0x0002 ExpandSZ: string with "%var%" expanding (UNICODE!)
-0x0003 RegBin: raw-binary value
-0x0004 RegDWord: Dword
-0x0007 RegMultiSZ: multiple strings, seperated with 0
- (UNICODE!)
-
-The "lf"-record
-===============
-Offset Size Contents
-0x0000 Word ID: ASCII-"lf" = 0x666C
-0x0002 Word number of keys
-0x0004 ???? Hash-Records
-
-Hash-Record
-===========
-Offset Size Contents
-0x0000 D-Word Offset of corresponding "nk"-Record
-0x0004 D-Word ASCII: the first 4 characters of the key-name, padded with 0's. Case sensitiv!
-
-Keep in mind, that the value at 0x0004 is used for checking the data-consistency! If you change the
-key-name you have to change the hash-value too!
-
-//These hashrecords must be sorted low to high within the lf record. Nigel.
-
-The "sk"-block
-==============
-(due to the complexity of the SAM-info, not clear jet)
-(This is just a security descriptor in the data. R Sharpe.)
-
-
-Offset Size Contents
-0x0000 Word ID: ASCII-"sk" = 0x6B73
-0x0002 Word Unused
-0x0004 D-Word Offset of previous "sk"-Record
-0x0008 D-Word Offset of next "sk"-Record
-0x000C D-Word usage-counter
-0x0010 D-Word Size of "sk"-record in bytes
-???? //standard self
-relative security desciptor. Nigel
-???? ???? Security and auditing settings...
-????
-
-The usage counter counts the number of references to this
-"sk"-record. You can use one "sk"-record for the entire registry!
-
-Windows nt date/time format
-===========================
-The time-format is a 64-bit integer which is incremented every
-0,0000001 seconds by 1 (I don't know how accurate it realy is!)
-It starts with 0 at the 1st of january 1601 0:00! All values are
-stored in GMT time! The time-zone is important to get the real
-time!
-
-Common values for win95 and win-nt
-==================================
-Offset values marking an "end of list", are either 0 or -1 (0xFFFFFFFF).
-If a value has no name (length=0, flag(bit 0)=0), it is treated as the
-"Default" entry...
-If a value has no data (length=0), it is displayed as empty.
-
-simplyfied win-3.?? registry:
-=============================
-
-+-----------+
-| next rec. |---+ +----->+------------+
-| first sub | | | | Usage cnt. |
-| name | | +-->+------------+ | | length |
-| value | | | | next rec. | | | text |------->+-------+
-+-----------+ | | | name rec. |--+ +------------+ | xxxxx |
- +------------+ | | value rec. |-------->+------------+ +-------+
- v | +------------+ | Usage cnt. |
-+-----------+ | | length |
-| next rec. | | | text |------->+-------+
-| first sub |------+ +------------+ | xxxxx |
-| name | +-------+
-| value |
-+-----------+
-
-Greatly simplyfied structure of the nt-registry:
-================================================
-
-+---------------------------------------------------------------+
-| |
-v |
-+---------+ +---------->+-----------+ +----->+---------+ |
-| "nk" | | | lf-rec. | | | nk-rec. | |
-| ID | | | # of keys | | | parent |---+
-| Date | | | 1st key |--+ | .... |
-| parent | | +-----------+ +---------+
-| suk-keys|-----+
-| values |--------------------->+----------+
-| SK-rec. |---------------+ | 1. value |--> +----------+
-| class |--+ | +----------+ | vk-rec. |
-+---------+ | | | .... |
- v | | data |--> +-------+
- +------------+ | +----------+ | xxxxx |
- | Class name | | +-------+
- +------------+ |
- v
- +---------+ +---------+
- +----->| next sk |--->| Next sk |--+
- | +---| prev sk |<---| prev sk | |
- | | | .... | | ... | |
- | | +---------+ +---------+ |
- | | ^ |
- | | | |
- | +--------------------+ |
- +----------------------------------+
-
----------------------------------------------------------------------------
-
-Hope this helps.... (Although it was "fun" for me to uncover this things,
- it took me several sleepless nights ;)
-
- B.D.
-
-*************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <fcntl.h>
-
-static int verbose = 0;
-
-/*
- * These definitions are for the in-memory registry structure.
- * It is a tree structure that mimics what you see with tools like regedit
- */
-
-/*
- * DateTime struct for Windows
- */
-
-typedef struct date_time_s {
- unsigned int low, high;
-} NTTIME;
-
-/*
- * Definition of a Key. It has a name, classname, date/time last modified,
- * sub-keys, values, and a security descriptor
- */
-
-#define REG_ROOT_KEY 1
-#define REG_SUB_KEY 2
-#define REG_SYM_LINK 3
-
-typedef struct reg_key_s {
- char *name; /* Name of the key */
- char *class_name;
- int type; /* One of REG_ROOT_KEY or REG_SUB_KEY */
- NTTIME last_mod; /* Time last modified */
- struct reg_key_s *owner;
- struct key_list_s *sub_keys;
- struct val_list_s *values;
- struct key_sec_desc_s *security;
-} REG_KEY;
-
-/*
- * The KEY_LIST struct lists sub-keys.
- */
-
-typedef struct key_list_s {
- int key_count;
- REG_KEY *keys[1];
-} KEY_LIST;
-
-typedef struct val_key_s {
- char *name;
- int has_name;
- int data_type;
- int data_len;
- void *data_blk; /* Might want a separate block */
-} VAL_KEY;
-
-typedef struct val_list_s {
- int val_count;
- VAL_KEY *vals[1];
-} VAL_LIST;
-
-#ifndef MAXSUBAUTHS
-#define MAXSUBAUTHS 15
-#endif
-
-typedef struct dom_sid_s {
- unsigned char ver, auths;
- unsigned char auth[6];
- unsigned int sub_auths[MAXSUBAUTHS];
-} DOM_SID;
-
-typedef struct ace_struct_s {
- unsigned char type, flags;
- unsigned int perms; /* Perhaps a better def is in order */
- DOM_SID *trustee;
-} ACE;
-
-typedef struct acl_struct_s {
- unsigned short rev, refcnt;
- unsigned short num_aces;
- ACE *aces[1];
-} ACL;
-
-typedef struct sec_desc_s {
- unsigned int rev, type;
- DOM_SID *owner, *group;
- ACL *sacl, *dacl;
-} SEC_DESC;
-
-#define SEC_DESC_NON 0
-#define SEC_DESC_RES 1
-#define SEC_DESC_OCU 2
-
-typedef struct key_sec_desc_s {
- struct key_sec_desc_s *prev, *next;
- int ref_cnt;
- int state;
- SEC_DESC *sec_desc;
-} KEY_SEC_DESC;
-
-
-/*
- * An API for accessing/creating/destroying items above
- */
-
-/*
- * Iterate over the keys, depth first, calling a function for each key
- * and indicating if it is terminal or non-terminal and if it has values.
- *
- * In addition, for each value in the list, call a value list function
- */
-
-/*
- * There should eventually be one to deal with security keys as well
- */
-
-typedef int (*key_print_f)(const char *path, char *key_name, char *class_name,
- int root, int terminal, int values);
-
-typedef int (*val_print_f)(const char *path, char *val_name, int val_type,
- int data_len, void *data_blk, int terminal,
- int first, int last);
-
-typedef int (*sec_print_f)(SEC_DESC *sec_desc);
-
-typedef struct regf_struct_s REGF;
-
-int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf, const char *path,
- key_print_f key_print, sec_print_f sec_print,
- val_print_f val_print);
-
-int nt_val_list_iterator(REGF *regf, VAL_LIST *val_list, int bf, char *path,
- int terminal, val_print_f val_print)
-{
- int i;
-
- if (!val_list) return 1;
-
- if (!val_print) return 1;
-
- for (i=0; i<val_list->val_count; i++) {
- if (!val_print(path, val_list->vals[i]->name, val_list->vals[i]->data_type,
- val_list->vals[i]->data_len, val_list->vals[i]->data_blk,
- terminal,
- (i == 0),
- (i == val_list->val_count))) {
-
- return 0;
-
- }
- }
-
- return 1;
-}
-
-int nt_key_list_iterator(REGF *regf, KEY_LIST *key_list, int bf,
- const char *path,
- key_print_f key_print, sec_print_f sec_print,
- val_print_f val_print)
-{
- int i;
-
- if (!key_list) return 1;
-
- for (i=0; i< key_list->key_count; i++) {
- if (!nt_key_iterator(regf, key_list->keys[i], bf, path, key_print,
- sec_print, val_print)) {
- return 0;
- }
- }
- return 1;
-}
-
-int nt_key_iterator(REGF *regf, REG_KEY *key_tree, int bf, const char *path,
- key_print_f key_print, sec_print_f sec_print,
- val_print_f val_print)
-{
- int path_len = strlen(path);
- char *new_path;
-
- if (!regf || !key_tree)
- return -1;
-
- /* List the key first, then the values, then the sub-keys */
-
- if (key_print) {
-
- if (!(*key_print)(path, key_tree->name,
- key_tree->class_name,
- (key_tree->type == REG_ROOT_KEY),
- (key_tree->sub_keys == NULL),
- (key_tree->values?(key_tree->values->val_count):0)))
- return 0;
- }
-
- /*
- * If we have a security print routine, call it
- * If the security print routine returns false, stop.
- */
- if (sec_print) {
- if (key_tree->security && !(*sec_print)(key_tree->security->sec_desc))
- return 0;
- }
-
- new_path = (char *)malloc(path_len + 1 + strlen(key_tree->name) + 1);
- if (!new_path) return 0; /* Errors? */
- new_path[0] = '\0';
- strcat(new_path, path);
- strcat(new_path, "\\");
- strcat(new_path, key_tree->name);
-
- /*
- * Now, iterate through the values in the val_list
- */
-
- if (key_tree->values &&
- !nt_val_list_iterator(regf, key_tree->values, bf, new_path,
- (key_tree->values!=NULL),
- val_print)) {
-
- free(new_path);
- return 0;
- }
-
- /*
- * Now, iterate through the keys in the key list
- */
-
- if (key_tree->sub_keys &&
- !nt_key_list_iterator(regf, key_tree->sub_keys, bf, new_path, key_print,
- sec_print, val_print)) {
- free(new_path);
- return 0;
- }
-
- free(new_path);
- return 1;
-}
-
-/* Make, delete keys */
-
-int nt_delete_val_key(VAL_KEY *val_key)
-{
-
- if (val_key) {
- if (val_key->data_blk) free(val_key->data_blk);
- free(val_key);
- };
- return 1;
-}
-
-int nt_delete_val_list(VAL_LIST *vl)
-{
- int i;
-
- if (vl) {
- for (i=0; i<vl->val_count; i++)
- nt_delete_val_key(vl->vals[i]);
- free(vl);
- }
- return 1;
-}
-
-int nt_delete_reg_key(REG_KEY *key);
-int nt_delete_key_list(KEY_LIST *key_list)
-{
- int i;
-
- if (key_list) {
- for (i=0; i<key_list->key_count; i++)
- nt_delete_reg_key(key_list->keys[i]);
- free(key_list);
- }
- return 1;
-}
-
-int nt_delete_sid(DOM_SID *sid)
-{
-
- if (sid) free(sid);
- return 1;
-
-}
-
-int nt_delete_ace(ACE *ace)
-{
-
- if (ace) {
- nt_delete_sid(ace->trustee);
- free(ace);
- }
- return 1;
-
-}
-
-int nt_delete_acl(ACL *acl)
-{
-
- if (acl) {
- int i;
-
- for (i=0; i<acl->num_aces; i++)
- nt_delete_ace(acl->aces[i]);
-
- free(acl);
- }
- return 1;
-}
-
-int nt_delete_sec_desc(SEC_DESC *sec_desc)
-{
-
- if (sec_desc) {
-
- nt_delete_sid(sec_desc->owner);
- nt_delete_sid(sec_desc->group);
- nt_delete_acl(sec_desc->sacl);
- nt_delete_acl(sec_desc->dacl);
- free(sec_desc);
-
- }
- return 1;
-}
-
-int nt_delete_key_sec_desc(KEY_SEC_DESC *key_sec_desc)
-{
-
- if (key_sec_desc) {
- key_sec_desc->ref_cnt--;
- if (key_sec_desc->ref_cnt<=0) {
- /*
- * There should always be a next and prev, even if they point to us
- */
- key_sec_desc->next->prev = key_sec_desc->prev;
- key_sec_desc->prev->next = key_sec_desc->next;
- nt_delete_sec_desc(key_sec_desc->sec_desc);
- }
- }
- return 1;
-}
-
-int nt_delete_reg_key(REG_KEY *key)
-{
-
- if (key) {
- if (key->name) free(key->name);
- if (key->class_name) free(key->class_name);
-
- /*
- * Do not delete the owner ...
- */
-
- if (key->sub_keys) nt_delete_key_list(key->sub_keys);
- if (key->values) nt_delete_val_list(key->values);
- if (key->security) nt_delete_key_sec_desc(key->security);
- free(key);
- }
- return 1;
-}
-
-/*
- * Create/delete key lists and add delete keys to/from a list, count the keys
- */
-
-
-/*
- * Create/delete value lists, add/delete values, count them
- */
-
-
-/*
- * Create/delete security descriptors, add/delete SIDS, count SIDS, etc.
- * We reference count the security descriptors. Any new reference increments
- * the ref count. If we modify an SD, we copy the old one, dec the ref count
- * and make the change. We also want to be able to check for equality so
- * we can reduce the number of SDs in use.
- */
-
-/*
- * Code to parse registry specification from command line or files
- *
- * Format:
- * [cmd:]key:type:value
- *
- * cmd = a|d|c|add|delete|change|as|ds|cs
- *
- */
-
-
-/*
- * Load and unload a registry file.
- *
- * Load, loads it into memory as a tree, while unload sealizes/flattens it
- */
-
-/*
- * Get the starting record for NT Registry file
- */
-
-/* A map of sk offsets in the regf to KEY_SEC_DESCs for quick lookup etc */
-typedef struct sk_map_s {
- int sk_off;
- KEY_SEC_DESC *key_sec_desc;
-} SK_MAP;
-
-/*
- * Where we keep all the regf stuff for one registry.
- * This is the structure that we use to tie the in memory tree etc
- * together. By keeping separate structs, we can operate on different
- * registries at the same time.
- * Currently, the SK_MAP is an array of mapping structure.
- * Since we only need this on input and output, we fill in the structure
- * as we go on input. On output, we know how many SK items we have, so
- * we can allocate the structure as we need to.
- * If you add stuff here that is dynamically allocated, add the
- * appropriate free statements below.
- */
-
-#define REGF_REGTYPE_NONE 0
-#define REGF_REGTYPE_NT 1
-#define REGF_REGTYPE_W9X 2
-
-#define TTTONTTIME(r, t1, t2) (r)->last_mod_time.low = (t1); \
- (r)->last_mod_time.high = (t2);
-
-#define REGF_HDR_BLKSIZ 0x1000
-
-struct regf_struct_s {
- int reg_type;
- char *regfile_name, *outfile_name;
- int fd;
- struct stat sbuf;
- char *base;
- int modified;
- NTTIME last_mod_time;
- REG_KEY *root; /* Root of the tree for this file */
- int sk_count, sk_map_size;
- SK_MAP *sk_map;
-};
-
-/*
- * Structures for dealing with the on-disk format of the registry
- */
-
-#define IVAL(buf) ((unsigned int) \
- (unsigned int)*((unsigned char *)(buf)+3)<<24| \
- (unsigned int)*((unsigned char *)(buf)+2)<<16| \
- (unsigned int)*((unsigned char *)(buf)+1)<<8| \
- (unsigned int)*((unsigned char *)(buf)+0))
-
-#define SVAL(buf) ((unsigned short) \
- (unsigned short)*((unsigned char *)(buf)+1)<<8| \
- (unsigned short)*((unsigned char *)(buf)+0))
-
-#define CVAL(buf) ((unsigned char)*((unsigned char *)(buf)))
-
-#define OFF(f) ((f) + REGF_HDR_BLKSIZ + 4)
-#define LOCN(base, f) ((base) + OFF(f))
-
-/*
- * All of the structures below actually have a four-byte lenght before them
- * which always seems to be negative. The following macro retrieves that
- * size as an integer
- */
-
-#define BLK_SIZE(b) ((int)*(int *)(((int *)b)-1))
-
-typedef unsigned int DWORD;
-typedef unsigned short WORD;
-
-#define REG_REGF_ID 0x66676572
-
-typedef struct regf_block {
- DWORD REGF_ID; /* regf */
- DWORD uk1;
- DWORD uk2;
- DWORD tim1, tim2;
- DWORD uk3; /* 1 */
- DWORD uk4; /* 3 */
- DWORD uk5; /* 0 */
- DWORD uk6; /* 1 */
- DWORD first_key; /* offset */
- unsigned int dblk_size;
- DWORD uk7[116]; /* 1 */
- DWORD chksum;
-} REGF_HDR;
-
-typedef struct hbin_sub_struct {
- DWORD dblocksize;
- char data[1];
-} HBIN_SUB_HDR;
-
-#define REG_HBIN_ID 0x6E696268
-
-typedef struct hbin_struct {
- DWORD HBIN_ID; /* hbin */
- DWORD next_off;
- DWORD prev_off;
- DWORD uk1;
- DWORD uk2;
- DWORD uk3;
- DWORD uk4;
- DWORD blk_size;
- HBIN_SUB_HDR hbin_sub_hdr;
-} HBIN_HDR;
-
-#define REG_NK_ID 0x6B6E
-
-typedef struct nk_struct {
- WORD NK_ID;
- WORD type;
- DWORD t1, t2;
- DWORD uk1;
- DWORD own_off;
- DWORD subk_num;
- DWORD uk2;
- DWORD lf_off;
- DWORD uk3;
- DWORD val_cnt;
- DWORD val_off;
- DWORD sk_off;
- DWORD clsnam_off;
- DWORD unk4[4];
- DWORD unk5;
- WORD nam_len;
- WORD clsnam_len;
- char key_nam[1]; /* Actual length determined by nam_len */
-} NK_HDR;
-
-#define REG_SK_ID 0x6B73
-
-typedef struct sk_struct {
- WORD SK_ID;
- WORD uk1;
- DWORD prev_off;
- DWORD next_off;
- DWORD ref_cnt;
- DWORD rec_size;
- char sec_desc[1];
-} SK_HDR;
-
-typedef struct ace_struct {
- unsigned char type;
- unsigned char flags;
- unsigned short length;
- unsigned int perms;
- DOM_SID trustee;
-} REG_ACE;
-
-typedef struct acl_struct {
- WORD rev;
- WORD size;
- DWORD num_aces;
- REG_ACE *aces; /* One or more ACEs */
-} REG_ACL;
-
-typedef struct sec_desc_rec {
- WORD rev;
- WORD type;
- DWORD owner_off;
- DWORD group_off;
- DWORD sacl_off;
- DWORD dacl_off;
-} REG_SEC_DESC;
-
-typedef struct hash_struct {
- DWORD nk_off;
- char hash[4];
-} HASH_REC;
-
-#define REG_LF_ID 0x666C
-
-typedef struct lf_struct {
- WORD LF_ID;
- WORD key_count;
- struct hash_struct hr[1]; /* Array of hash records, depending on key_count */
-} LF_HDR;
-
-typedef DWORD VL_TYPE[1]; /* Value list is an array of vk rec offsets */
-
-#define REG_VK_ID 0x6B76
-
-typedef struct vk_struct {
- WORD VK_ID;
- WORD nam_len;
- DWORD dat_len; /* If top-bit set, offset contains the data */
- DWORD dat_off;
- DWORD dat_type;
- WORD flag; /* =1, has name, else no name (=Default). */
- WORD unk1;
- char dat_name[1]; /* Name starts here ... */
-} VK_HDR;
-
-#define REG_TYPE_REGSZ 1
-#define REG_TYPE_EXPANDSZ 2
-#define REG_TYPE_BIN 3
-#define REG_TYPE_DWORD 4
-#define REG_TYPE_MULTISZ 7
-
-typedef struct _val_str {
- unsigned int val;
- const char * str;
-} VAL_STR;
-
-const VAL_STR reg_type_names[] = {
- { 1, "REG_SZ" },
- { 2, "REG_EXPAND_SZ" },
- { 3, "REG_BIN" },
- { 4, "REG_DWORD" },
- { 7, "REG_MULTI_SZ" },
- { 0, NULL },
-};
-
-const char *val_to_str(unsigned int val, const VAL_STR *val_array)
-{
- int i = 0;
-
- if (!val_array) return NULL;
-
- while (val_array[i].val && val_array[i].str) {
-
- if (val_array[i].val == val) return val_array[i].str;
- i++;
-
- }
-
- return NULL;
-
-}
-
-/*
- * Convert from UniCode to Ascii ... Does not take into account other lang
- * Restrict by ascii_max if > 0
- */
-int uni_to_ascii(unsigned char *uni, unsigned char *ascii, int ascii_max,
- int uni_max)
-{
- int i = 0;
-
- while (i < ascii_max && !(!uni[i*2] && !uni[i*2+1])) {
- if (uni_max > 0 && (i*2) >= uni_max) break;
- ascii[i] = uni[i*2];
- i++;
-
- }
-
- ascii[i] = '\0';
-
- return i;
-}
-
-/*
- * Convert a data value to a string for display
- */
-int data_to_ascii(unsigned char *datap, int len, int type, char *ascii, int ascii_max)
-{
- unsigned char *asciip;
- int i;
-
- switch (type) {
- case REG_TYPE_REGSZ:
- fprintf(stderr, "Len: %d\n", len);
- return uni_to_ascii(datap, ascii, len, ascii_max);
- break;
-
- case REG_TYPE_EXPANDSZ:
- return uni_to_ascii(datap, ascii, len, ascii_max);
- break;
-
- case REG_TYPE_BIN:
- asciip = ascii;
- for (i=0; (i<len)&&(i+1)*3<ascii_max; i++) {
- int str_rem = ascii_max - ((int)asciip - (int)ascii);
- asciip += snprintf(asciip, str_rem, "%02x", *(unsigned char *)(datap+i));
- if (i < len && str_rem > 0)
- *asciip = ' '; asciip++;
- }
- *asciip = '\0';
- return ((int)asciip - (int)ascii);
- break;
-
- case REG_TYPE_DWORD:
- if (*(int *)datap == 0)
- return snprintf(ascii, ascii_max, "0");
- else
- return snprintf(ascii, ascii_max, "0x%x", *(int *)datap);
- break;
-
- case REG_TYPE_MULTISZ:
-
- break;
-
- default:
- return 0;
- break;
- }
-
- return len;
-
-}
-
-REG_KEY *nt_get_key_tree(REGF *regf, NK_HDR *nk_hdr, int size);
-
-int nt_set_regf_input_file(REGF *regf, char *filename)
-{
- return ((regf->regfile_name = strdup(filename)) != NULL);
-}
-
-int nt_set_regf_output_file(REGF *regf, char *filename)
-{
- return ((regf->outfile_name = strdup(filename)) != NULL);
-}
-
-/* Create a regf structure and init it */
-
-REGF *nt_create_regf(void)
-{
- REGF *tmp = (REGF *)malloc(sizeof(REGF));
- if (!tmp) return tmp;
- bzero(tmp, sizeof(REGF));
- return tmp;
-}
-
-/* Free all the bits and pieces ... Assumes regf was malloc'd */
-/* If you add stuff to REGF, add the relevant free bits here */
-int nt_free_regf(REGF *regf)
-{
- if (!regf) return 0;
-
- if (regf->regfile_name) free(regf->regfile_name);
- if (regf->outfile_name) free(regf->outfile_name);
-
- /* Free the mmap'd area */
-
- if (regf->base) munmap(regf->base, regf->sbuf.st_size);
- regf->base = NULL;
- close(regf->fd); /* Ignore the error :-) */
-
- nt_delete_reg_key(regf->root); /* Free the tree */
- free(regf->sk_map);
- regf->sk_count = regf->sk_map_size = 0;
-
- free(regf);
-
- return 1;
-}
-
-/* Get the header of the registry. Return a pointer to the structure
- * If the mmap'd area has not been allocated, then mmap the input file
- */
-REGF_HDR *nt_get_regf_hdr(REGF *regf)
-{
- if (!regf)
- return NULL; /* What about errors */
-
- if (!regf->regfile_name)
- return NULL; /* What about errors */
-
- if (!regf->base) { /* Try to mmap etc the file */
-
- if ((regf->fd = open(regf->regfile_name, O_RDONLY, 0000)) <0) {
- return NULL; /* What about errors? */
- }
-
- if (fstat(regf->fd, &regf->sbuf) < 0) {
- return NULL;
- }
-
- regf->base = mmap(0, regf->sbuf.st_size, PROT_READ, MAP_SHARED, regf->fd, 0);
-
- if ((int)regf->base == 1) {
- fprintf(stderr, "Could not mmap file: %s, %s\n", regf->regfile_name,
- strerror(errno));
- return NULL;
- }
- }
-
- /*
- * At this point, regf->base != NULL, and we should be able to read the
- * header
- */
-
- assert(regf->base != NULL);
-
- return (REGF_HDR *)regf->base;
-}
-
-/*
- * Validate a regf header
- * For now, do nothing, but we should check the checksum
- */
-int valid_regf_hdr(REGF_HDR *regf_hdr)
-{
- if (!regf_hdr) return 0;
-
- return 1;
-}
-
-/*
- * Process an SK header ...
- * Every time we see a new one, add it to the map. Otherwise, just look it up.
- * We will do a simple linear search for the moment, since many KEYs have the
- * same security descriptor.
- * We allocate the map in increments of 10 entries.
- */
-
-/*
- * Create a new entry in the map, and increase the size of the map if needed
- */
-
-SK_MAP *alloc_sk_map_entry(REGF *regf, KEY_SEC_DESC *tmp, int sk_off)
-{
- if (!regf->sk_map) { /* Allocate a block of 10 */
- regf->sk_map = (SK_MAP *)malloc(sizeof(SK_MAP) * 10);
- if (!regf->sk_map) {
- free(tmp);
- return NULL;
- }
- regf->sk_map_size = 10;
- regf->sk_count = 1;
- (regf->sk_map)[0].sk_off = sk_off;
- (regf->sk_map)[0].key_sec_desc = tmp;
- }
- else { /* Simply allocate a new slot, unless we have to expand the list */
- int ndx = regf->sk_count;
- if (regf->sk_count >= regf->sk_map_size) {
- regf->sk_map = (SK_MAP *)realloc(regf->sk_map,
- (regf->sk_map_size + 10)*sizeof(SK_MAP));
- if (!regf->sk_map) {
- free(tmp);
- return NULL;
- }
- /*
- * ndx already points at the first entry of the new block
- */
- regf->sk_map_size += 10;
- }
- (regf->sk_map)[ndx].sk_off = sk_off;
- (regf->sk_map)[ndx].key_sec_desc = tmp;
- regf->sk_count++;
- }
- return regf->sk_map;
-}
-
-/*
- * Search for a KEY_SEC_DESC in the sk_map, but dont create one if not
- * found
- */
-
-KEY_SEC_DESC *lookup_sec_key(SK_MAP *sk_map, int count, int sk_off)
-{
- int i;
-
- if (!sk_map) return NULL;
-
- for (i = 0; i < count; i++) {
-
- if (sk_map[i].sk_off == sk_off)
- return sk_map[i].key_sec_desc;
-
- }
-
- return NULL;
-
-}
-
-/*
- * Allocate a KEY_SEC_DESC if we can't find one in the map
- */
-
-KEY_SEC_DESC *lookup_create_sec_key(REGF *regf, SK_MAP *sk_map, int sk_off)
-{
- KEY_SEC_DESC *tmp = lookup_sec_key(regf->sk_map, regf->sk_count, sk_off);
-
- if (tmp) {
- return tmp;
- }
- else { /* Allocate a new one */
- tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC));
- if (!tmp) {
- return NULL;
- }
- tmp->state = SEC_DESC_RES;
- if (!alloc_sk_map_entry(regf, tmp, sk_off)) {
- return NULL;
- }
- return tmp;
- }
-}
-
-/*
- * Allocate storage and duplicate a SID
- * We could allocate the SID to be only the size needed, but I am too lazy.
- */
-DOM_SID *dup_sid(DOM_SID *sid)
-{
- DOM_SID *tmp = (DOM_SID *)malloc(sizeof(DOM_SID));
- int i;
-
- if (!tmp) return NULL;
- tmp->ver = sid->ver;
- tmp->auths = sid->auths;
- for (i=0; i<6; i++) {
- tmp->auth[i] = sid->auth[i];
- }
- for (i=0; i<tmp->auths&&i<MAXSUBAUTHS; i++) {
- tmp->sub_auths[i] = sid->sub_auths[i];
- }
- return tmp;
-}
-
-/*
- * Allocate space for an ACE and duplicate the registry encoded one passed in
- */
-ACE *dup_ace(REG_ACE *ace)
-{
- ACE *tmp = NULL;
-
- tmp = (ACE *)malloc(sizeof(ACE));
-
- if (!tmp) return NULL;
-
- tmp->type = CVAL(&ace->type);
- tmp->flags = CVAL(&ace->flags);
- tmp->perms = IVAL(&ace->perms);
- tmp->trustee = dup_sid(&ace->trustee);
- return tmp;
-}
-
-/*
- * Allocate space for an ACL and duplicate the registry encoded one passed in
- */
-ACL *dup_acl(REG_ACL *acl)
-{
- ACL *tmp = NULL;
- REG_ACE* ace;
- int i, num_aces;
-
- num_aces = IVAL(&acl->num_aces);
-
- tmp = (ACL *)malloc(sizeof(ACL) + (num_aces - 1)*sizeof(ACE *));
- if (!tmp) return NULL;
-
- tmp->num_aces = num_aces;
- tmp->refcnt = 1;
- tmp->rev = SVAL(&acl->rev);
- ace = (REG_ACE *)&acl->aces;
- for (i=0; i<num_aces; i++) {
- tmp->aces[i] = dup_ace(ace);
- ace = (REG_ACE *)((char *)ace + SVAL(&ace->length));
- /* XXX: FIXME, should handle malloc errors */
- }
-
- return tmp;
-}
-
-SEC_DESC *process_sec_desc(REGF *regf, REG_SEC_DESC *sec_desc)
-{
- SEC_DESC *tmp = NULL;
-
- tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC));
-
- if (!tmp) {
- return NULL;
- }
-
- tmp->rev = SVAL(&sec_desc->rev);
- tmp->type = SVAL(&sec_desc->type);
- tmp->owner = dup_sid((DOM_SID *)((char *)sec_desc + IVAL(&sec_desc->owner_off)));
- if (!tmp->owner) {
- free(tmp);
- return NULL;
- }
- tmp->group = dup_sid((DOM_SID *)((char *)sec_desc + IVAL(&sec_desc->group_off)));
- if (!tmp->group) {
- free(tmp);
- return NULL;
- }
-
- /* Now pick up the SACL and DACL */
-
- if (sec_desc->sacl_off)
- tmp->sacl = dup_acl((REG_ACL *)((char *)sec_desc + IVAL(&sec_desc->sacl_off)));
- else
- tmp->sacl = NULL;
-
- if (sec_desc->dacl_off)
- tmp->dacl = dup_acl((REG_ACL *)((char *)sec_desc + IVAL(&sec_desc->dacl_off)));
- else
- tmp->dacl = NULL;
-
- return tmp;
-}
-
-KEY_SEC_DESC *process_sk(REGF *regf, SK_HDR *sk_hdr, int sk_off, int size)
-{
- KEY_SEC_DESC *tmp = NULL;
- int sk_next_off, sk_prev_off, sk_size;
- REG_SEC_DESC *sec_desc;
-
- if (!sk_hdr) return NULL;
-
- if (SVAL(&sk_hdr->SK_ID) != REG_SK_ID) {
- fprintf(stderr, "Unrecognized SK Header ID: %08X, %s\n", (int)sk_hdr,
- regf->regfile_name);
- return NULL;
- }
-
- if (-size < (sk_size = IVAL(&sk_hdr->rec_size))) {
- fprintf(stderr, "Incorrect SK record size: %d vs %d. %s\n",
- -size, sk_size, regf->regfile_name);
- return NULL;
- }
-
- /*
- * Now, we need to look up the SK Record in the map, and return it
- * Since the map contains the SK_OFF mapped to KEY_SEC_DESC, we can
- * use that
- */
-
- if (regf->sk_map &&
- ((tmp = lookup_sec_key(regf->sk_map, regf->sk_count, sk_off)) != NULL)
- && (tmp->state == SEC_DESC_OCU)) {
- tmp->ref_cnt++;
- return tmp;
- }
-
- /* Here, we have an item in the map that has been reserved, or tmp==NULL. */
-
- assert(tmp == NULL || (tmp && tmp->state != SEC_DESC_NON));
-
- /*
- * Now, allocate a KEY_SEC_DESC, and parse the structure here, and add the
- * new KEY_SEC_DESC to the mapping structure, since the offset supplied is
- * the actual offset of structure. The same offset will be used by all
- * all future references to this structure
- * We chould put all this unpleasantness in a function.
- */
-
- if (!tmp) {
- tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC));
- if (!tmp) return NULL;
- bzero(tmp, sizeof(KEY_SEC_DESC));
-
- /*
- * Allocate an entry in the SK_MAP ...
- * We don't need to free tmp, because that is done for us if the
- * sm_map entry can't be expanded when we need more space in the map.
- */
-
- if (!alloc_sk_map_entry(regf, tmp, sk_off)) {
- return NULL;
- }
- }
-
- tmp->ref_cnt++;
- tmp->state = SEC_DESC_OCU;
-
- /*
- * Now, process the actual sec desc and plug the values in
- */
-
- sec_desc = (REG_SEC_DESC *)&sk_hdr->sec_desc[0];
- tmp->sec_desc = process_sec_desc(regf, sec_desc);
-
- /*
- * Now forward and back links. Here we allocate an entry in the sk_map
- * if it does not exist, and mark it reserved
- */
-
- sk_prev_off = IVAL(&sk_hdr->prev_off);
- tmp->prev = lookup_create_sec_key(regf, regf->sk_map, sk_prev_off);
- assert(tmp->prev != NULL);
- sk_next_off = IVAL(&sk_hdr->next_off);
- tmp->next = lookup_create_sec_key(regf, regf->sk_map, sk_next_off);
- assert(tmp->next != NULL);
-
- return tmp;
-}
-
-/*
- * Process a VK header and return a value
- */
-VAL_KEY *process_vk(REGF *regf, VK_HDR *vk_hdr, int size)
-{
- char val_name[1024];
- int nam_len, dat_len, flag, dat_type, dat_off, vk_id;
- const char *val_type;
- VAL_KEY *tmp = NULL;
-
- if (!vk_hdr) return NULL;
-
- if ((vk_id = SVAL(&vk_hdr->VK_ID)) != REG_VK_ID) {
- fprintf(stderr, "Unrecognized VK header ID: %0X, block: %0X, %s\n",
- vk_id, (int)vk_hdr, regf->regfile_name);
- return NULL;
- }
-
- nam_len = SVAL(&vk_hdr->nam_len);
- val_name[nam_len] = '\0';
- flag = SVAL(&vk_hdr->flag);
- dat_type = IVAL(&vk_hdr->dat_type);
- dat_len = IVAL(&vk_hdr->dat_len); /* If top bit, offset contains data */
- dat_off = IVAL(&vk_hdr->dat_off);
-
- tmp = (VAL_KEY *)malloc(sizeof(VAL_KEY));
- if (!tmp) {
- goto error;
- }
- bzero(tmp, sizeof(VAL_KEY));
- tmp->has_name = flag;
- tmp->data_type = dat_type;
-
- if (flag & 0x01) {
- strncpy(val_name, vk_hdr->dat_name, nam_len);
- tmp->name = strdup(val_name);
- if (!tmp->name) {
- goto error;
- }
- }
- else
- strncpy(val_name, "<No Name>", 10);
-
- /*
- * Allocate space and copy the data as a BLOB
- */
-
- if (dat_len) {
-
- char *dtmp = (char *)malloc(dat_len&0x7FFFFFFF);
-
- if (!dtmp) {
- goto error;
- }
-
- tmp->data_blk = dtmp;
-
- if ((dat_len&0x80000000) == 0) { /* The data is pointed to by the offset */
- char *dat_ptr = LOCN(regf->base, dat_off);
- bcopy(dat_ptr, dtmp, dat_len);
- }
- else { /* The data is in the offset */
- dat_len = dat_len & 0x7FFFFFFF;
- bcopy(&dat_off, dtmp, dat_len);
- }
-
- tmp->data_len = dat_len;
- }
-
- val_type = val_to_str(dat_type, reg_type_names);
-
- /*
- * We need to save the data area as well
- */
-
- if (verbose) fprintf(stdout, " %s : %s : \n", val_name, val_type);
-
- return tmp;
-
- error:
- /* XXX: FIXME, free the partially allocated struct */
- return NULL;
-
-}
-
-/*
- * Process a VL Header and return a list of values
- */
-VAL_LIST *process_vl(REGF *regf, VL_TYPE vl, int count, int size)
-{
- int i, vk_off;
- VK_HDR *vk_hdr;
- VAL_LIST *tmp = NULL;
-
- if (!vl) return NULL;
-
- if (-size < (count+1)*sizeof(int)){
- fprintf(stderr, "Error in VL header format. Size less than space required. %d\n", -size);
- return NULL;
- }
-
- tmp = (VAL_LIST *)malloc(sizeof(VAL_LIST) + (count - 1) * sizeof(VAL_KEY *));
- if (!tmp) {
- goto error;
- }
-
- for (i=0; i<count; i++) {
- vk_off = IVAL(&vl[i]);
- vk_hdr = (VK_HDR *)LOCN(regf->base, vk_off);
- tmp->vals[i] = process_vk(regf, vk_hdr, BLK_SIZE(vk_hdr));
- if (!tmp->vals[i]){
- goto error;
- }
- }
-
- tmp->val_count = count;
-
- return tmp;
-
- error:
- /* XXX: FIXME, free the partially allocated structure */
- return NULL;
-}
-
-/*
- * Process an LF Header and return a list of sub-keys
- */
-KEY_LIST *process_lf(REGF *regf, LF_HDR *lf_hdr, int size)
-{
- int count, i, nk_off;
- unsigned int lf_id;
- KEY_LIST *tmp;
-
- if (!lf_hdr) return NULL;
-
- if ((lf_id = SVAL(&lf_hdr->LF_ID)) != REG_LF_ID) {
- fprintf(stderr, "Unrecognized LF Header format: %0X, Block: %0X, %s.\n",
- lf_id, (int)lf_hdr, regf->regfile_name);
- return NULL;
- }
-
- assert(size < 0);
-
- count = SVAL(&lf_hdr->key_count);
-
- if (count <= 0) return NULL;
-
- /* Now, we should allocate a KEY_LIST struct and fill it in ... */
-
- tmp = (KEY_LIST *)malloc(sizeof(KEY_LIST) + (count - 1) * sizeof(REG_KEY *));
- if (!tmp) {
- goto error;
- }
-
- tmp->key_count = count;
-
- for (i=0; i<count; i++) {
- NK_HDR *nk_hdr;
-
- nk_off = IVAL(&lf_hdr->hr[i].nk_off);
- nk_hdr = (NK_HDR *)LOCN(regf->base, nk_off);
- tmp->keys[i] = nt_get_key_tree(regf, nk_hdr, BLK_SIZE(nk_hdr));
- if (!tmp->keys[i]) {
- goto error;
- }
- }
-
- return tmp;
-
- error:
- /* XXX: FIXME, free the partially allocated structure */
- return NULL;
-}
-
-/*
- * This routine is passed a NK_HDR pointer and retrieves the entire tree
- * from there down. It return a REG_KEY *.
- */
-REG_KEY *nt_get_key_tree(REGF *regf, NK_HDR *nk_hdr, int size)
-{
- REG_KEY *tmp = NULL;
- int name_len, clsname_len, lf_off, val_off, val_count, sk_off;
- unsigned int nk_id;
- LF_HDR *lf_hdr;
- VL_TYPE *vl;
- SK_HDR *sk_hdr;
- char key_name[1024], cls_name[1024];
-
- if (!nk_hdr) return NULL;
-
- if ((nk_id = SVAL(&nk_hdr->NK_ID)) != REG_NK_ID) {
- fprintf(stderr, "Unrecognized NK Header format: %08X, Block: %0X. %s\n",
- nk_id, (int)nk_hdr, regf->regfile_name);
- return NULL;
- }
-
- assert(size < 0);
-
- name_len = SVAL(&nk_hdr->nam_len);
- clsname_len = SVAL(&nk_hdr->clsnam_len);
-
- /*
- * The value of -size should be ge
- * (sizeof(NK_HDR) - 1 + name_len)
- * The -1 accounts for the fact that we included the first byte of
- * the name in the structure. clsname_len is the length of the thing
- * pointed to by clsnam_off
- */
-
- if (-size < (sizeof(NK_HDR) - 1 + name_len)) {
- fprintf(stderr, "Incorrect NK_HDR size: %d, %0X\n", -size, (int)nk_hdr);
- fprintf(stderr, "Sizeof NK_HDR: %d, name_len %d, clsname_len %d\n",
- sizeof(NK_HDR), name_len, clsname_len);
- /*return NULL;*/
- }
-
- if (verbose) fprintf(stdout, "NK HDR: Name len: %d, class name len: %d\n",
- name_len, clsname_len);
-
- /* Fish out the key name and process the LF list */
-
- assert(name_len < sizeof(key_name));
-
- /* Allocate the key struct now */
- tmp = (REG_KEY *)malloc(sizeof(REG_KEY));
- if (!tmp) return tmp;
- bzero(tmp, sizeof(REG_KEY));
-
- tmp->type = (SVAL(&nk_hdr->type)==0x2C?REG_ROOT_KEY:REG_SUB_KEY);
-
- strncpy(key_name, nk_hdr->key_nam, name_len);
- key_name[name_len] = '\0';
-
- if (verbose) fprintf(stdout, "Key name: %s\n", key_name);
-
- tmp->name = strdup(key_name);
- if (!tmp->name) {
- goto error;
- }
-
- /*
- * Fish out the class name, it is in UNICODE, while the key name is
- * ASCII :-)
- */
-
- if (clsname_len) { /* Just print in Ascii for now */
- char *clsnamep;
- int clsnam_off;
-
- clsnam_off = IVAL(&nk_hdr->clsnam_off);
- clsnamep = LOCN(regf->base, clsnam_off);
-
- bzero(cls_name, clsname_len);
- uni_to_ascii(clsnamep, cls_name, sizeof(cls_name), clsname_len);
-
- /*
- * I am keeping class name as an ascii string for the moment.
- * That means it needs to be converted on output.
- * XXX: FIXME
- */
-
- tmp->class_name = strdup(cls_name);
- if (!tmp->class_name) {
- goto error;
- }
-
- if (verbose) fprintf(stdout, " Class Name: %s\n", cls_name);
-
- }
-
- /*
- * If there are any values, process them here
- */
-
- val_count = IVAL(&nk_hdr->val_cnt);
-
- if (val_count) {
-
- val_off = IVAL(&nk_hdr->val_off);
- vl = (VL_TYPE *)LOCN(regf->base, val_off);
-
- tmp->values = process_vl(regf, *vl, val_count, BLK_SIZE(vl));
- if (!tmp->values) {
- goto error;
- }
-
- }
-
- /*
- * Also handle the SK header ...
- */
-
- sk_off = IVAL(&nk_hdr->sk_off);
- sk_hdr = (SK_HDR *)LOCN(regf->base, sk_off);
-
- if (sk_off != -1) {
-
- tmp->security = process_sk(regf, sk_hdr, sk_off, BLK_SIZE(sk_hdr));
-
- }
-
- lf_off = IVAL(&nk_hdr->lf_off);
-
- /*
- * No more subkeys if lf_off == -1
- */
-
- if (lf_off != -1) {
-
- lf_hdr = (LF_HDR *)LOCN(regf->base, lf_off);
-
- tmp->sub_keys = process_lf(regf, lf_hdr, BLK_SIZE(lf_hdr));
- if (!tmp->sub_keys){
- goto error;
- }
-
- }
-
- return tmp;
-
- error:
- if (tmp) nt_delete_reg_key(tmp);
- return NULL;
-}
-
-int nt_load_registry(REGF *regf)
-{
- REGF_HDR *regf_hdr;
- unsigned int regf_id, hbin_id;
- HBIN_HDR *hbin_hdr;
- NK_HDR *first_key;
-
- /* Get the header */
-
- if ((regf_hdr = nt_get_regf_hdr(regf)) == NULL) {
- return -1;
- }
-
- /* Now process that header and start to read the rest in */
-
- if ((regf_id = IVAL(&regf_hdr->REGF_ID)) != REG_REGF_ID) {
- fprintf(stderr, "Unrecognized NT registry header id: %0X, %s\n",
- regf_id, regf->regfile_name);
- return -1;
- }
-
- /*
- * Validate the header ...
- */
- if (!valid_regf_hdr(regf_hdr)) {
- fprintf(stderr, "Registry file header does not validate: %s\n",
- regf->regfile_name);
- return -1;
- }
-
- /* Update the last mod date, and then go get the first NK record and on */
-
- TTTONTTIME(regf, IVAL(&regf_hdr->tim1), IVAL(&regf_hdr->tim2));
-
- /*
- * The hbin hdr seems to be just uninteresting garbage. Check that
- * it is there, but that is all.
- */
-
- hbin_hdr = (HBIN_HDR *)(regf->base + REGF_HDR_BLKSIZ);
-
- if ((hbin_id = IVAL(&hbin_hdr->HBIN_ID)) != REG_HBIN_ID) {
- fprintf(stderr, "Unrecognized registry hbin hdr ID: %0X, %s\n",
- hbin_id, regf->regfile_name);
- return -1;
- }
-
- /*
- * Get a pointer to the first key from the hreg_hdr
- */
-
- first_key = (NK_HDR *)LOCN(regf->base, IVAL(&regf_hdr->first_key));
-
- /*
- * Now, get the registry tree by processing that NK recursively
- */
-
- regf->root = nt_get_key_tree(regf, first_key, BLK_SIZE(first_key));
-
- assert(regf->root != NULL);
-
- return 1;
-}
-
-/*
- * Routines to parse a REGEDIT4 file
- *
- * The file consists of:
- *
- * REGEDIT4
- * \[[-]key-path\]\n
- * <value-spec>*
- *
- * There can be more than one key-path and value-spec.
- *
- * Since we want to support more than one type of file format, we
- * construct a command-file structure that keeps info about the command file
- */
-
-#define FMT_UNREC -1
-#define FMT_REGEDIT4 0
-#define FMT_EDITREG1_1 1
-
-typedef struct command_s {
- int cmd;
- char *key;
- void *val_spec_list;
-} CMD;
-
-/*
- * We seek to offset 0, read in the required number of bytes,
- * and compare to the correct value.
- * We then seek back to the original location
- */
-int regedit4_file_type(int fd)
-{
- int cur_ofs = 0;
-
- cur_ofs = lseek(fd, 0, SEEK_CUR); /* Get current offset */
- if (cur_ofs < 0) {
- fprintf(stderr, "Unable to get current offset: %s\n", strerror(errno));
- exit(1);
- }
-
- if (cur_ofs) {
- lseek(fd, 0, SEEK_SET);
- }
-
- return FMT_UNREC;
-}
-
-CMD *regedit4_get_cmd(int fd)
-{
- return NULL;
-}
-
-int regedit4_exec_cmd(CMD *cmd)
-{
-
- return 0;
-}
-
-int editreg_1_1_file_type(int fd)
-{
-
- return FMT_UNREC;
-}
-
-CMD *editreg_1_1_get_cmd(int fd)
-{
- return NULL;
-}
-
-int editreg_1_1_exec_cmd(CMD *cmd)
-{
-
- return -1;
-}
-
-typedef struct command_ops_s {
- int type;
- int (*file_type)(int fd);
- CMD *(*get_cmd)(int fd);
- int (*exec_cmd)(CMD *cmd);
-} CMD_OPS;
-
-CMD_OPS default_cmd_ops[] = {
- {0, regedit4_file_type, regedit4_get_cmd, regedit4_exec_cmd},
- {1, editreg_1_1_file_type, editreg_1_1_get_cmd, editreg_1_1_exec_cmd},
- {-1, NULL, NULL, NULL}
-};
-
-typedef struct command_file_s {
- char *name;
- int type, fd;
- CMD_OPS cmd_ops;
-} CMD_FILE;
-
-/*
- * Create a new command file structure
- */
-
-CMD_FILE *cmd_file_create(char *file)
-{
- CMD_FILE *tmp;
- struct stat sbuf;
- int i = 0;
-
- /*
- * Let's check if the file exists ...
- * No use creating the cmd_file structure if the file does not exist
- */
-
- if (stat(file, &sbuf) < 0) { /* Not able to access file */
-
- return NULL;
- }
-
- tmp = (CMD_FILE *)malloc(sizeof(CMD_FILE));
- if (!tmp) {
- return NULL;
- }
-
- /*
- * Let's fill in some of the fields;
- */
-
- tmp->name = strdup(file);
-
- if ((tmp->fd = open(file, O_RDONLY, 666)) < 0) {
- free(tmp);
- return NULL;
- }
-
- /*
- * Now, try to find the format by indexing through the table
- */
- while (default_cmd_ops[i].type != -1) {
- if ((tmp->type = default_cmd_ops[i].file_type(tmp->fd)) >= 0) {
- tmp->cmd_ops = default_cmd_ops[i];
- return tmp;
- }
- i++;
- }
-
- /*
- * If we got here, return NULL, as we could not figure out the type
- * of command file.
- *
- * What about errors?
- */
-
- free(tmp);
- return NULL;
-}
-
-/*
- * Extract commands from the command file, and execute them.
- * We pass a table of command callbacks for that
- */
-
-/*
- * Main code from here on ...
- */
-
-/*
- * key print function here ...
- */
-
-int print_key(const char *path, char *name, char *class_name, int root,
- int terminal, int vals)
-{
-
- if (terminal) fprintf(stdout, "%s\\%s\n", path, name);
-
- return 1;
-}
-
-/*
- * Sec Desc print functions
- */
-
-void print_sid(DOM_SID *sid)
-{
- int i, comps = sid->auths;
- fprintf(stdout, "S-%u-%u", sid->ver, sid->auth[5]);
-
- for (i = 0; i < comps; i++) {
-
- fprintf(stdout, "-%u", sid->sub_auths[i]);
-
- }
- fprintf(stdout, "\n");
-}
-
-int print_sec(SEC_DESC *sec_desc)
-{
-
- fprintf(stdout, " SECURITY\n");
- fprintf(stdout, " Owner: ");
- print_sid(sec_desc->owner);
- fprintf(stdout, " Group: ");
- print_sid(sec_desc->group);
- return 1;
-}
-
-/*
- * Value print function here ...
- */
-int print_val(const char *path, char *val_name, int val_type, int data_len,
- void *data_blk, int terminal, int first, int last)
-{
- char data_asc[1024];
-
- bzero(data_asc, sizeof(data_asc));
- if (!terminal && first)
- fprintf(stdout, "%s\n", path);
- data_to_ascii((unsigned char *)data_blk, data_len, val_type, data_asc,
- sizeof(data_asc) - 1);
- fprintf(stdout, " %s : %s : %s\n", (val_name?val_name:"<No Name>"),
- val_to_str(val_type, reg_type_names), data_asc);
- return 1;
-}
-
-void usage(void)
-{
- fprintf(stderr, "Usage: editreg [-v] [-k] [-c <command-file>] <registryfile>\n");
- fprintf(stderr, "Version: 0.1\n\n");
- fprintf(stderr, "\n\t-v\t sets verbose mode");
- fprintf(stderr, "\n\t-c <command-file>\t specifies a command file");
- fprintf(stderr, "\n");
-}
-
-int main(int argc, char *argv[])
-{
- REGF *regf;
- extern char *optarg;
- extern int optind;
- int opt;
- int commands = 0;
- char *cmd_file = NULL;
-
- if (argc < 2) {
- usage();
- exit(1);
- }
-
- /*
- * Now, process the arguments
- */
-
- while ((opt = getopt(argc, argv, "vkc:")) != EOF) {
- switch (opt) {
- case 'c':
- commands = 1;
- cmd_file = optarg;
- break;
-
- case 'v':
- verbose++;
- break;
-
- case 'k':
- break;
-
- default:
- usage();
- exit(1);
- break;
- }
- }
-
- if ((regf = nt_create_regf()) == NULL) {
- fprintf(stderr, "Could not create registry object: %s\n", strerror(errno));
- exit(2);
- }
-
- if (!nt_set_regf_input_file(regf, argv[optind])) {
- fprintf(stderr, "Could not set name of registry file: %s, %s\n",
- argv[1], strerror(errno));
- exit(3);
- }
-
- /* Now, open it, and bring it into memory :-) */
-
- if (nt_load_registry(regf) < 0) {
- fprintf(stderr, "Could not load registry: %s\n", argv[1]);
- exit(4);
- }
-
- /*
- * At this point, we should have a registry in memory and should be able
- * to iterate over it.
- */
-
- nt_key_iterator(regf, regf->root, 0, "", print_key, print_sec, print_val);
- return 0;
-}
diff --git a/source4/utils/pdbedit.c b/source4/utils/pdbedit.c
deleted file mode 100644
index 8038900c28..0000000000
--- a/source4/utils/pdbedit.c
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- passdb editing frontend
-
- Copyright (C) Simo Sorce 2000
- Copyright (C) Andrew Bartlett 2001
- Copyright (C) Jelmer Vernooij 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"
-
-#define BIT_BACKEND 0x00000004
-#define BIT_VERBOSE 0x00000008
-#define BIT_SPSTYLE 0x00000010
-#define BIT_RESERV_1 0x00000020
-#define BIT_RESERV_2 0x00000040
-#define BIT_RESERV_3 0x00000080
-#define BIT_FULLNAME 0x00000100
-#define BIT_HOMEDIR 0x00000200
-#define BIT_HDIRDRIVE 0x00000400
-#define BIT_LOGSCRIPT 0x00000800
-#define BIT_PROFILE 0x00001000
-#define BIT_MACHINE 0x00002000
-#define BIT_RESERV_4 0x00004000
-#define BIT_USER 0x00008000
-#define BIT_LIST 0x00010000
-#define BIT_MODIFY 0x00020000
-#define BIT_CREATE 0x00040000
-#define BIT_DELETE 0x00080000
-#define BIT_ACCPOLICY 0x00100000
-#define BIT_ACCPOLVAL 0x00200000
-#define BIT_ACCTCTRL 0x00400000
-#define BIT_RESERV_7 0x00800000
-#define BIT_IMPORT 0x01000000
-#define BIT_EXPORT 0x02000000
-
-#define MASK_ALWAYS_GOOD 0x0000001F
-#define MASK_USER_GOOD 0x00401F00
-
-/*********************************************************
- Add all currently available users to another db
- ********************************************************/
-
-static int export_database (struct pdb_context *in, struct pdb_context *out) {
- SAM_ACCOUNT *user = NULL;
-
- if (NT_STATUS_IS_ERR(in->pdb_setsampwent(in, 0))) {
- fprintf(stderr, "Can't sampwent!\n");
- return 1;
- }
-
- if (!NT_STATUS_IS_OK(pdb_init_sam(&user))) {
- fprintf(stderr, "Can't initialize new SAM_ACCOUNT!\n");
- return 1;
- }
-
- while (NT_STATUS_IS_OK(in->pdb_getsampwent(in, user))) {
- out->pdb_add_sam_account(out, user);
- if (!NT_STATUS_IS_OK(pdb_reset_sam(user))){
- fprintf(stderr, "Can't reset SAM_ACCOUNT!\n");
- return 1;
- }
- }
-
- in->pdb_endsampwent(in);
-
- return 0;
-}
-
-/*********************************************************
- Print info from sam structure
-**********************************************************/
-
-static int print_sam_info (SAM_ACCOUNT *sam_pwent, BOOL verbosity, BOOL smbpwdstyle)
-{
- uid_t uid;
- gid_t gid;
- time_t tmp;
-
- /* TODO: chaeck if entry is a user or a workstation */
- if (!sam_pwent) return -1;
-
- if (verbosity) {
- printf ("Unix username: %s\n", pdb_get_username(sam_pwent));
- printf ("NT username: %s\n", pdb_get_nt_username(sam_pwent));
- printf ("Account Flags: %s\n", pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent), NEW_PW_FORMAT_SPACE_PADDED_LEN));
-
- if (IS_SAM_UNIX_USER(sam_pwent)) {
- uid = pdb_get_uid(sam_pwent);
- gid = pdb_get_gid(sam_pwent);
- printf ("User ID/Group ID: %d/%d\n", uid, gid);
- }
- printf ("User SID: %s\n",
- sid_string_static(pdb_get_user_sid(sam_pwent)));
- printf ("Primary Group SID: %s\n",
- sid_string_static(pdb_get_group_sid(sam_pwent)));
- printf ("Full Name: %s\n", pdb_get_fullname(sam_pwent));
- printf ("Home Directory: %s\n", pdb_get_homedir(sam_pwent));
- printf ("HomeDir Drive: %s\n", pdb_get_dir_drive(sam_pwent));
- printf ("Logon Script: %s\n", pdb_get_logon_script(sam_pwent));
- printf ("Profile Path: %s\n", pdb_get_profile_path(sam_pwent));
- printf ("Domain: %s\n", pdb_get_domain(sam_pwent));
- printf ("Account desc: %s\n", pdb_get_acct_desc(sam_pwent));
- printf ("Workstations: %s\n", pdb_get_workstations(sam_pwent));
- printf ("Munged dial: %s\n", pdb_get_munged_dial(sam_pwent));
-
- tmp = pdb_get_logon_time(sam_pwent);
- printf ("Logon time: %s\n", tmp ? timestring(tmp) : "0");
-
- tmp = pdb_get_logoff_time(sam_pwent);
- printf ("Logoff time: %s\n", tmp ? timestring(tmp) : "0");
-
- tmp = pdb_get_kickoff_time(sam_pwent);
- printf ("Kickoff time: %s\n", tmp ? timestring(tmp) : "0");
-
- tmp = pdb_get_pass_last_set_time(sam_pwent);
- printf ("Password last set: %s\n", tmp ? timestring(tmp) : "0");
-
- tmp = pdb_get_pass_can_change_time(sam_pwent);
- printf ("Password can change: %s\n", tmp ? timestring(tmp) : "0");
-
- tmp = pdb_get_pass_must_change_time(sam_pwent);
- printf ("Password must change: %s\n", tmp ? timestring(tmp) : "0");
-
- } else if (smbpwdstyle) {
- if (IS_SAM_UNIX_USER(sam_pwent)) {
- char lm_passwd[33];
- char nt_passwd[33];
-
- uid = pdb_get_uid(sam_pwent);
- pdb_sethexpwd(lm_passwd,
- pdb_get_lanman_passwd(sam_pwent),
- pdb_get_acct_ctrl(sam_pwent));
- pdb_sethexpwd(nt_passwd,
- pdb_get_nt_passwd(sam_pwent),
- pdb_get_acct_ctrl(sam_pwent));
-
- printf("%s:%d:%s:%s:%s:LCT-%08X:\n",
- pdb_get_username(sam_pwent),
- uid,
- lm_passwd,
- nt_passwd,
- pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent),NEW_PW_FORMAT_SPACE_PADDED_LEN),
- (uint32)pdb_get_pass_last_set_time(sam_pwent));
- } else {
- fprintf(stderr, "Can't output in smbpasswd format, no uid on this record.\n");
- }
- } else {
- if (IS_SAM_UNIX_USER(sam_pwent)) {
- printf ("%s:%d:%s\n", pdb_get_username(sam_pwent), pdb_get_uid(sam_pwent),
- pdb_get_fullname(sam_pwent));
- } else {
- printf ("%s:(null):%s\n", pdb_get_username(sam_pwent), pdb_get_fullname(sam_pwent));
- }
- }
-
- return 0;
-}
-
-/*********************************************************
- Get an Print User Info
-**********************************************************/
-
-static int print_user_info (struct pdb_context *in, const char *username, BOOL verbosity, BOOL smbpwdstyle)
-{
- SAM_ACCOUNT *sam_pwent=NULL;
- BOOL ret;
-
- if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
- return -1;
- }
-
- ret = NT_STATUS_IS_OK(in->pdb_getsampwnam (in, sam_pwent, username));
-
- if (ret==False) {
- fprintf (stderr, "Username not found!\n");
- pdb_free_sam(&sam_pwent);
- return -1;
- }
-
- ret=print_sam_info (sam_pwent, verbosity, smbpwdstyle);
- pdb_free_sam(&sam_pwent);
-
- return ret;
-}
-
-/*********************************************************
- List Users
-**********************************************************/
-static int print_users_list (struct pdb_context *in, BOOL verbosity, BOOL smbpwdstyle)
-{
- SAM_ACCOUNT *sam_pwent=NULL;
- BOOL check, ret;
-
- check = NT_STATUS_IS_OK(in->pdb_setsampwent(in, False));
- if (!check) {
- return 1;
- }
-
- check = True;
- if (!(NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)))) return 1;
-
- while (check && (ret = NT_STATUS_IS_OK(in->pdb_getsampwent (in, sam_pwent)))) {
- if (verbosity)
- printf ("---------------\n");
- print_sam_info (sam_pwent, verbosity, smbpwdstyle);
- pdb_free_sam(&sam_pwent);
- check = NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent));
- }
- if (check) pdb_free_sam(&sam_pwent);
-
- in->pdb_endsampwent(in);
- return 0;
-}
-
-/*********************************************************
- Set User Info
-**********************************************************/
-
-static int set_user_info (struct pdb_context *in, const char *username,
- const char *fullname, const char *homedir,
- const char *drive, const char *script,
- const char *profile, const char *account_control)
-{
- SAM_ACCOUNT *sam_pwent=NULL;
- BOOL ret;
-
- pdb_init_sam(&sam_pwent);
-
- ret = NT_STATUS_IS_OK(in->pdb_getsampwnam (in, sam_pwent, username));
- if (ret==False) {
- fprintf (stderr, "Username not found!\n");
- pdb_free_sam(&sam_pwent);
- return -1;
- }
-
- if (fullname)
- pdb_set_fullname(sam_pwent, fullname, PDB_CHANGED);
- if (homedir)
- pdb_set_homedir(sam_pwent, homedir, PDB_CHANGED);
- if (drive)
- pdb_set_dir_drive(sam_pwent,drive, PDB_CHANGED);
- if (script)
- pdb_set_logon_script(sam_pwent, script, PDB_CHANGED);
- if (profile)
- pdb_set_profile_path (sam_pwent, profile, PDB_CHANGED);
-
- if (account_control) {
- uint16 not_settable = ~(ACB_DISABLED|ACB_HOMDIRREQ|ACB_PWNOTREQ|
- ACB_PWNOEXP|ACB_AUTOLOCK);
-
- uint16 newflag = pdb_decode_acct_ctrl(account_control);
-
- if (newflag & not_settable) {
- fprintf(stderr, "Can only set [NDHLX] flags\n");
- pdb_free_sam(&sam_pwent);
- return -1;
- }
-
- pdb_set_acct_ctrl(sam_pwent,
- (pdb_get_acct_ctrl(sam_pwent) & not_settable) | newflag,
- PDB_CHANGED);
- }
-
- if (NT_STATUS_IS_OK(in->pdb_update_sam_account (in, sam_pwent)))
- print_user_info (in, username, True, False);
- else {
- fprintf (stderr, "Unable to modify entry!\n");
- pdb_free_sam(&sam_pwent);
- return -1;
- }
- pdb_free_sam(&sam_pwent);
- return 0;
-}
-
-/*********************************************************
- Add New User
-**********************************************************/
-static int new_user (struct pdb_context *in, const char *username, const char *fullname, const char *homedir, const char *drive, const char *script, const char *profile)
-{
- SAM_ACCOUNT *sam_pwent=NULL;
- struct passwd *pwd = NULL;
- char *password1, *password2, *staticpass;
-
- ZERO_STRUCT(sam_pwent);
-
- if ((pwd = getpwnam_alloc(username))) {
- pdb_init_sam_pw (&sam_pwent, pwd);
- passwd_free(&pwd);
- } else {
- fprintf (stderr, "WARNING: user %s does not exist in system passwd\n", username);
- pdb_init_sam(&sam_pwent);
- if (!pdb_set_username(sam_pwent, username, PDB_CHANGED)) {
- return False;
- }
- }
-
- staticpass = getpass("new password:");
- password1 = strdup(staticpass);
- memset(staticpass, 0, strlen(staticpass));
- staticpass = getpass("retype new password:");
- password2 = strdup(staticpass);
- memset(staticpass, 0, strlen(staticpass));
- if (strcmp (password1, password2)) {
- fprintf (stderr, "Passwords does not match!\n");
- memset(password1, 0, strlen(password1));
- SAFE_FREE(password1);
- memset(password2, 0, strlen(password2));
- SAFE_FREE(password2);
- pdb_free_sam (&sam_pwent);
- return -1;
- }
-
- pdb_set_plaintext_passwd(sam_pwent, password1);
- memset(password1, 0, strlen(password1));
- SAFE_FREE(password1);
- memset(password2, 0, strlen(password2));
- SAFE_FREE(password2);
-
- if (fullname)
- pdb_set_fullname(sam_pwent, fullname, PDB_CHANGED);
- if (homedir)
- pdb_set_homedir (sam_pwent, homedir, PDB_CHANGED);
- if (drive)
- pdb_set_dir_drive (sam_pwent, drive, PDB_CHANGED);
- if (script)
- pdb_set_logon_script(sam_pwent, script, PDB_CHANGED);
- if (profile)
- pdb_set_profile_path (sam_pwent, profile, PDB_CHANGED);
-
- pdb_set_acct_ctrl (sam_pwent, ACB_NORMAL, PDB_CHANGED);
-
- if (NT_STATUS_IS_OK(in->pdb_add_sam_account (in, sam_pwent))) {
- print_user_info (in, username, True, False);
- } else {
- fprintf (stderr, "Unable to add user! (does it alredy exist?)\n");
- pdb_free_sam (&sam_pwent);
- return -1;
- }
- pdb_free_sam (&sam_pwent);
- return 0;
-}
-
-/*********************************************************
- Add New Machine
-**********************************************************/
-
-static int new_machine (struct pdb_context *in, const char *machine_in)
-{
- SAM_ACCOUNT *sam_pwent=NULL;
- fstring machinename;
- struct passwd *pwd = NULL;
- char name[16];
-
- fstrcpy(machinename, machine_in);
-
- if (machinename[strlen (machinename) -1] == '$')
- machinename[strlen (machinename) -1] = '\0';
-
- strlower_m(machinename);
-
- safe_strcpy (name, machinename, 16);
- safe_strcat (name, "$", 16);
-
- if ((pwd = getpwnam_alloc(name))) {
- if (!NT_STATUS_IS_OK(pdb_init_sam_pw( &sam_pwent, pwd))) {
- fprintf(stderr, "Could not init sam from pw\n");
- passwd_free(&pwd);
- return -1;
- }
- passwd_free(&pwd);
- } else {
- if (!NT_STATUS_IS_OK(pdb_init_sam (&sam_pwent))) {
- fprintf(stderr, "Could not init sam from pw\n");
- return -1;
- }
- }
-
- pdb_set_plaintext_passwd (sam_pwent, machinename);
-
- pdb_set_username (sam_pwent, name, PDB_CHANGED);
-
- pdb_set_acct_ctrl (sam_pwent, ACB_WSTRUST, PDB_CHANGED);
-
- pdb_set_group_sid_from_rid(sam_pwent, DOMAIN_GROUP_RID_COMPUTERS, PDB_CHANGED);
-
- if (NT_STATUS_IS_OK(in->pdb_add_sam_account (in, sam_pwent))) {
- print_user_info (in, name, True, False);
- } else {
- fprintf (stderr, "Unable to add machine! (does it already exist?)\n");
- pdb_free_sam (&sam_pwent);
- return -1;
- }
- pdb_free_sam (&sam_pwent);
- return 0;
-}
-
-/*********************************************************
- Delete user entry
-**********************************************************/
-
-static int delete_user_entry (struct pdb_context *in, const char *username)
-{
- SAM_ACCOUNT *samaccount = NULL;
-
- if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
- return -1;
- }
-
- if (NT_STATUS_IS_ERR(in->pdb_getsampwnam(in, samaccount, username))) {
- fprintf (stderr, "user %s does not exist in the passdb\n", username);
- return -1;
- }
-
- return NT_STATUS_IS_OK(in->pdb_delete_sam_account (in, samaccount));
-}
-
-/*********************************************************
- Delete machine entry
-**********************************************************/
-
-static int delete_machine_entry (struct pdb_context *in, const char *machinename)
-{
- char name[16];
- SAM_ACCOUNT *samaccount = NULL;
-
- safe_strcpy (name, machinename, 16);
- if (name[strlen(name)] != '$')
- safe_strcat (name, "$", 16);
-
- if (!NT_STATUS_IS_OK(pdb_init_sam (&samaccount))) {
- return -1;
- }
-
- if (NT_STATUS_IS_ERR(in->pdb_getsampwnam(in, samaccount, name))) {
- fprintf (stderr, "machine %s does not exist in the passdb\n", name);
- return -1;
- }
-
- return NT_STATUS_IS_OK(in->pdb_delete_sam_account (in, samaccount));
-}
-
-/*********************************************************
- Start here.
-**********************************************************/
-
-int main (int argc, char **argv)
-{
- static BOOL list_users = False;
- static BOOL verbose = False;
- static BOOL spstyle = False;
- static BOOL machine = False;
- static BOOL add_user = False;
- static BOOL delete_user = False;
- static BOOL modify_user = False;
- uint32 setparms, checkparms;
- int opt;
- static char *full_name = NULL;
- static const char *user_name = NULL;
- static char *home_dir = NULL;
- static char *home_drive = NULL;
- static char *backend = NULL;
- static char *backend_in = NULL;
- static char *backend_out = NULL;
- static char *logon_script = NULL;
- static char *profile_path = NULL;
- static char *account_control = NULL;
- static char *account_policy = NULL;
- static long int account_policy_value = 0;
- BOOL account_policy_value_set = False;
-
- struct pdb_context *bin;
- struct pdb_context *bout;
- struct pdb_context *bdef;
- poptContext pc;
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- {"list", 'l', POPT_ARG_NONE, &list_users, 0, "list all users", NULL},
- {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "be verbose", NULL },
- {"smbpasswd-style", 'w',POPT_ARG_NONE, &spstyle, 0, "give output in smbpasswd style", NULL},
- {"user", 'u', POPT_ARG_STRING, &user_name, 0, "use username", "USER" },
- {"fullname", 'f', POPT_ARG_STRING, &full_name, 0, "set full name", NULL},
- {"homedir", 'h', POPT_ARG_STRING, &home_dir, 0, "set home directory", NULL},
- {"drive", 'D', POPT_ARG_STRING, &home_drive, 0, "set home drive", NULL},
- {"script", 'S', POPT_ARG_STRING, &logon_script, 0, "set logon script", NULL},
- {"profile", 'p', POPT_ARG_STRING, &profile_path, 0, "set profile path", NULL},
- {"create", 'a', POPT_ARG_NONE, &add_user, 0, "create user", NULL},
- {"modify", 'r', POPT_ARG_NONE, &modify_user, 0, "modify user", NULL},
- {"machine", 'm', POPT_ARG_NONE, &machine, 0, "account is a machine account", NULL},
- {"delete", 'x', POPT_ARG_NONE, &delete_user, 0, "delete user", NULL},
- {"backend", 'b', POPT_ARG_STRING, &backend, 0, "use different passdb backend as default backend", NULL},
- {"import", 'i', POPT_ARG_STRING, &backend_in, 0, "import user accounts from this backend", NULL},
- {"export", 'e', POPT_ARG_STRING, &backend_out, 0, "export user accounts to this backend", NULL},
- {"account-policy", 'P', POPT_ARG_STRING, &account_policy, 0,"value of an account policy (like maximum password age)",NULL},
- {"value", 'V', POPT_ARG_LONG, &account_policy_value, 'V',"set the account policy to this value", NULL},
- {"account-control", 'c', POPT_ARG_STRING, &account_control, 0, "Values of account control", NULL},
- { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug },
- { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile },
- {0,0,0,0}
- };
-
- setup_logging("pdbedit", DEBUG_STDOUT);
-
- pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
-
- while((opt = poptGetNextOpt(pc)) != -1) {
- switch (opt) {
- case 'V':
- account_policy_value_set = True;
- break;
- }
- }
-
- poptGetArg(pc); /* Drop argv[0], the program name */
-
- if (user_name == NULL)
- user_name = poptGetArg(pc);
-
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- exit(1);
- }
-
- init_modules();
-
- if (!init_names())
- exit(1);
-
- setparms = (backend ? BIT_BACKEND : 0) +
- (verbose ? BIT_VERBOSE : 0) +
- (spstyle ? BIT_SPSTYLE : 0) +
- (full_name ? BIT_FULLNAME : 0) +
- (home_dir ? BIT_HOMEDIR : 0) +
- (home_drive ? BIT_HDIRDRIVE : 0) +
- (logon_script ? BIT_LOGSCRIPT : 0) +
- (profile_path ? BIT_PROFILE : 0) +
- (machine ? BIT_MACHINE : 0) +
- (user_name ? BIT_USER : 0) +
- (list_users ? BIT_LIST : 0) +
- (modify_user ? BIT_MODIFY : 0) +
- (add_user ? BIT_CREATE : 0) +
- (delete_user ? BIT_DELETE : 0) +
- (account_control ? BIT_ACCTCTRL : 0) +
- (account_policy ? BIT_ACCPOLICY : 0) +
- (account_policy_value_set ? BIT_ACCPOLVAL : 0) +
- (backend_in ? BIT_IMPORT : 0) +
- (backend_out ? BIT_EXPORT : 0);
-
- if (setparms & BIT_BACKEND) {
- if (!NT_STATUS_IS_OK(make_pdb_context_string(&bdef, backend))) {
- fprintf(stderr, "Can't initialize passdb backend.\n");
- return 1;
- }
- } else {
- if (!NT_STATUS_IS_OK(make_pdb_context_list(&bdef, lp_passdb_backend()))) {
- fprintf(stderr, "Can't initialize passdb backend.\n");
- return 1;
- }
- }
-
- /* the lowest bit options are always accepted */
- checkparms = setparms & ~MASK_ALWAYS_GOOD;
-
- /* account policy operations */
- if ((checkparms & BIT_ACCPOLICY) && !(checkparms & ~(BIT_ACCPOLICY + BIT_ACCPOLVAL))) {
- uint32 value;
- int field = account_policy_name_to_fieldnum(account_policy);
- if (field == 0) {
- fprintf(stderr, "No account policy by that name\n");
- exit(1);
- }
- if (!account_policy_get(field, &value)) {
- fprintf(stderr, "valid account policy, but unable to fetch value!\n");
- exit(1);
- }
- if (account_policy_value_set) {
- printf("account policy value for %s was %u\n", account_policy, value);
- if (!account_policy_set(field, account_policy_value)) {
- fprintf(stderr, "valid account policy, but unable to set value!\n");
- exit(1);
- }
- printf("account policy value for %s is now %lu\n", account_policy, account_policy_value);
- exit(0);
- } else {
- printf("account policy value for %s is %u\n", account_policy, value);
- exit(0);
- }
- }
-
- /* import and export operations */
- if (((checkparms & BIT_IMPORT) || (checkparms & BIT_EXPORT))
- && !(checkparms & ~(BIT_IMPORT +BIT_EXPORT))) {
- if (backend_in) {
- if (!NT_STATUS_IS_OK(make_pdb_context_string(&bin, backend_in))) {
- fprintf(stderr, "Can't initialize passdb backend.\n");
- return 1;
- }
- } else {
- bin = bdef;
- }
- if (backend_out) {
- if (!NT_STATUS_IS_OK(make_pdb_context_string(&bout, backend_out))) {
- fprintf(stderr, "Can't initialize %s.\n", backend_out);
- return 1;
- }
- } else {
- bout = bdef;
- }
- return export_database(bin, bout);
- }
-
- /* if BIT_USER is defined but nothing else then threat it as -l -u for compatibility */
- /* fake up BIT_LIST if only BIT_USER is defined */
- if ((checkparms & BIT_USER) && !(checkparms & ~BIT_USER)) {
- checkparms += BIT_LIST;
- }
-
- /* modify flag is optional to maintain backwards compatibility */
- /* fake up BIT_MODIFY if BIT_USER and at least one of MASK_USER_GOOD is defined */
- if (!((checkparms & ~MASK_USER_GOOD) & ~BIT_USER) && (checkparms & MASK_USER_GOOD)) {
- checkparms += BIT_MODIFY;
- }
-
- /* list users operations */
- if (checkparms & BIT_LIST) {
- if (!(checkparms & ~BIT_LIST)) {
- return print_users_list (bdef, verbose, spstyle);
- }
- if (!(checkparms & ~(BIT_USER + BIT_LIST))) {
- return print_user_info (bdef, user_name, verbose, spstyle);
- }
- }
-
- /* mask out users options */
- checkparms &= ~MASK_USER_GOOD;
-
- /* account operation */
- if ((checkparms & BIT_CREATE) || (checkparms & BIT_MODIFY) || (checkparms & BIT_DELETE)) {
- /* check use of -u option */
- if (!(checkparms & BIT_USER)) {
- fprintf (stderr, "Username not specified! (use -u option)\n");
- return -1;
- }
-
- /* account creation operations */
- if (!(checkparms & ~(BIT_CREATE + BIT_USER + BIT_MACHINE))) {
- if (checkparms & BIT_MACHINE) {
- return new_machine (bdef, user_name);
- } else {
- return new_user (bdef, user_name, full_name, home_dir,
- home_drive, logon_script,
- profile_path);
- }
- }
-
- /* account deletion operations */
- if (!(checkparms & ~(BIT_DELETE + BIT_USER + BIT_MACHINE))) {
- if (checkparms & BIT_MACHINE) {
- return delete_machine_entry (bdef, user_name);
- } else {
- return delete_user_entry (bdef, user_name);
- }
- }
-
- /* account modification operations */
- if (!(checkparms & ~(BIT_MODIFY + BIT_USER))) {
- return set_user_info (bdef, user_name, full_name,
- home_dir,
- home_drive,
- logon_script,
- profile_path, account_control);
- }
- }
-
- if (setparms >= 0x20) {
- fprintf (stderr, "Incompatible or insufficient options on command line!\n");
- }
- poptPrintHelp(pc, stderr, 0);
-
- return 1;
-}
diff --git a/source4/utils/profiles.c b/source4/utils/profiles.c
deleted file mode 100644
index 4f40b93810..0000000000
--- a/source4/utils/profiles.c
+++ /dev/null
@@ -1,729 +0,0 @@
-/*
- Samba Unix/Linux SMB client utility profiles.c
- Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
-
- 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. */
-
-/*************************************************************************
-
- A utility to report and change SIDs in registry files
-
- Many of the ideas in here come from other people and software.
- I first looked in Wine in misc/registry.c and was also influenced by
- http://www.wednesday.demon.co.uk/dosreg.html
-
- Which seems to contain comments from someone else. I reproduce them here
- incase the site above disappears. It actually comes from
- http://home.eunet.no/~pnordahl/ntpasswd/WinReg.txt.
-
-The windows NT registry has 2 different blocks, where one can occure many
-times...
-
-the "regf"-Block
-================
-
-"regf" is obviosly the abbreviation for "Registry file". "regf" is the
-signature of the header-block which is always 4kb in size, although only
-the first 64 bytes seem to be used and a checksum is calculated over
-the first 0x200 bytes only!
-
-Offset Size Contents
-0x00000000 D-Word ID: ASCII-"regf" = 0x66676572
-0x00000004 D-Word ???? //see struct REGF
-0x00000008 D-Word ???? Always the same value as at 0x00000004
-0x0000000C Q-Word last modify date in WinNT date-format
-0x00000014 D-Word 1
-0x00000018 D-Word 3
-0x0000001C D-Word 0
-0x00000020 D-Word 1
-0x00000024 D-Word Offset of 1st key record
-0x00000028 D-Word Size of the data-blocks (Filesize-4kb)
-0x0000002C D-Word 1
-0x000001FC D-Word Sum of all D-Words from 0x00000000 to
-0x000001FB //XOR of all words. Nigel
-
-I have analyzed more registry files (from multiple machines running
-NT 4.0 german version) and could not find an explanation for the values
-marked with ???? the rest of the first 4kb page is not important...
-
-the "hbin"-Block
-================
-I don't know what "hbin" stands for, but this block is always a multiple
-of 4kb in size.
-
-Inside these hbin-blocks the different records are placed. The memory-
-management looks like a C-compiler heap management to me...
-
-hbin-Header
-===========
-Offset Size Contents
-0x0000 D-Word ID: ASCII-"hbin" = 0x6E696268
-0x0004 D-Word Offset from the 1st hbin-Block
-0x0008 D-Word Offset to the next hbin-Block
-0x001C D-Word Block-size
-
-The values in 0x0008 and 0x001C should be the same, so I don't know
-if they are correct or swapped...
-
-From offset 0x0020 inside a hbin-block data is stored with the following
-format:
-
-Offset Size Contents
-0x0000 D-Word Data-block size //this size must be a
-multiple of 8. Nigel
-0x0004 ???? Data
-
-If the size field is negative (bit 31 set), the corresponding block
-is free and has a size of -blocksize!
-
-The data is stored as one record per block. Block size is a multiple
-of 4 and the last block reaches the next hbin-block, leaving no room.
-
-Records in the hbin-blocks
-==========================
-
-nk-Record
-
- The nk-record can be treated as a kombination of tree-record and
- key-record of the win 95 registry.
-
-lf-Record
-
- The lf-record is the counterpart to the RGKN-record (the
- hash-function)
-
-vk-Record
-
- The vk-record consists information to a single value.
-
-sk-Record
-
- sk (? Security Key ?) is the ACL of the registry.
-
-Value-Lists
-
- The value-lists contain information about which values are inside a
- sub-key and don't have a header.
-
-Datas
-
- The datas of the registry are (like the value-list) stored without a
- header.
-
-All offset-values are relative to the first hbin-block and point to the
-block-size field of the record-entry. to get the file offset, you have to add
-the header size (4kb) and the size field (4 bytes)...
-
-the nk-Record
-=============
-Offset Size Contents
-0x0000 Word ID: ASCII-"nk" = 0x6B6E
-0x0002 Word for the root-key: 0x2C, otherwise 0x20 //key symbolic links 0x10. Nigel
-0x0004 Q-Word write-date/time in windows nt notation
-0x0010 D-Word Offset of Owner/Parent key
-0x0014 D-Word number of sub-Keys
-0x001C D-Word Offset of the sub-key lf-Records
-0x0024 D-Word number of values
-0x0028 D-Word Offset of the Value-List
-0x002C D-Word Offset of the sk-Record
-
-0x0030 D-Word Offset of the Class-Name //see NK structure for the use of these fields. Nigel
-0x0044 D-Word Unused (data-trash) //some kind of run time index. Does not appear to be important. Nigel
-0x0048 Word name-length
-0x004A Word class-name length
-0x004C ???? key-name
-
-the Value-List
-==============
-Offset Size Contents
-0x0000 D-Word Offset 1st Value
-0x0004 D-Word Offset 2nd Value
-0x???? D-Word Offset nth Value
-
-To determine the number of values, you have to look at the owner-nk-record!
-
-Der vk-Record
-=============
-Offset Size Contents
-0x0000 Word ID: ASCII-"vk" = 0x6B76
-0x0002 Word name length
-0x0004 D-Word length of the data //if top bit is set when offset contains data. Nigel
-0x0008 D-Word Offset of Data
-0x000C D-Word Type of value
-0x0010 Word Flag
-0x0012 Word Unused (data-trash)
-0x0014 ???? Name
-
-If bit 0 of the flag-word is set, a name is present, otherwise the value has no name (=default)
-
-If the data-size is lower 5, the data-offset value is used to store the data itself!
-
-The data-types
-==============
-Wert Beteutung
-0x0001 RegSZ: character string (in UNICODE!)
-0x0002 ExpandSZ: string with "%var%" expanding (UNICODE!)
-0x0003 RegBin: raw-binary value
-0x0004 RegDWord: Dword
-0x0007 RegMultiSZ: multiple strings, separated with 0
- (UNICODE!)
-
-The "lf"-record
-===============
-Offset Size Contents
-0x0000 Word ID: ASCII-"lf" = 0x666C
-0x0002 Word number of keys
-0x0004 ???? Hash-Records
-
-Hash-Record
-===========
-Offset Size Contents
-0x0000 D-Word Offset of corresponding "nk"-Record
-0x0004 D-Word ASCII: the first 4 characters of the key-name, padded with 0's. Case sensitiv!
-
-Keep in mind, that the value at 0x0004 is used for checking the data-consistency! If you change the
-key-name you have to change the hash-value too!
-
-//These hashrecords must be sorted low to high within the lf record. Nigel.
-
-The "sk"-block
-==============
-(due to the complexity of the SAM-info, not clear jet)
-
-Offset Size Contents
-0x0000 Word ID: ASCII-"sk" = 0x6B73
-0x0002 Word Unused
-0x0004 D-Word Offset of previous "sk"-Record
-0x0008 D-Word Offset of next "sk"-Record
-0x000C D-Word usage-counter
-0x0010 D-Word Size of "sk"-record in bytes
-???? //standard self
-relative security desciptor. Nigel
-???? ???? Security and auditing settings...
-????
-
-The usage counter counts the number of references to this
-"sk"-record. You can use one "sk"-record for the entire registry!
-
-Windows nt date/time format
-===========================
-The time-format is a 64-bit integer which is incremented every
-0,0000001 seconds by 1 (I don't know how accurate it realy is!)
-It starts with 0 at the 1st of january 1601 0:00! All values are
-stored in GMT time! The time-zone is important to get the real
-time!
-
-Common values for win95 and win-nt
-==================================
-Offset values marking an "end of list", are either 0 or -1 (0xFFFFFFFF).
-If a value has no name (length=0, flag(bit 0)=0), it is treated as the
-"Default" entry...
-If a value has no data (length=0), it is displayed as empty.
-
-simplyfied win-3.?? registry:
-=============================
-
-+-----------+
-| next rec. |---+ +----->+------------+
-| first sub | | | | Usage cnt. |
-| name | | +-->+------------+ | | length |
-| value | | | | next rec. | | | text |------->+-------+
-+-----------+ | | | name rec. |--+ +------------+ | xxxxx |
- +------------+ | | value rec. |-------->+------------+ +-------+
- v | +------------+ | Usage cnt. |
-+-----------+ | | length |
-| next rec. | | | text |------->+-------+
-| first sub |------+ +------------+ | xxxxx |
-| name | +-------+
-| value |
-+-----------+
-
-Greatly simplyfied structure of the nt-registry:
-================================================
-
-+---------------------------------------------------------------+
-| |
-v |
-+---------+ +---------->+-----------+ +----->+---------+ |
-| "nk" | | | lf-rec. | | | nk-rec. | |
-| ID | | | # of keys | | | parent |---+
-| Date | | | 1st key |--+ | .... |
-| parent | | +-----------+ +---------+
-| suk-keys|-----+
-| values |--------------------->+----------+
-| SK-rec. |---------------+ | 1. value |--> +----------+
-| class |--+ | +----------+ | vk-rec. |
-+---------+ | | | .... |
- v | | data |--> +-------+
- +------------+ | +----------+ | xxxxx |
- | Class name | | +-------+
- +------------+ |
- v
- +---------+ +---------+
- +----->| next sk |--->| Next sk |--+
- | +---| prev sk |<---| prev sk | |
- | | | .... | | ... | |
- | | +---------+ +---------+ |
- | | ^ | |
- | +----------+ |
- +-------------------------------+
-
----------------------------------------------------------------------------
-
-Hope this helps.... (Although it was "fun" for me to uncover this things,
- it took me several sleepless nights ;)
-
- B.D.
-
-*************************************************************************/
-#include "includes.h"
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/mman.h>
-
-typedef unsigned int DWORD;
-typedef unsigned short WORD;
-
-#define REG_REGF_ID 0x66676572
-
-typedef struct regf_block {
- DWORD REGF_ID; /* regf */
- DWORD uk1;
- DWORD uk2;
- DWORD tim1, tim2;
- DWORD uk3; /* 1 */
- DWORD uk4; /* 3 */
- DWORD uk5; /* 0 */
- DWORD uk6; /* 1 */
- DWORD first_key; /* offset */
- unsigned int dblk_size;
- DWORD uk7[116]; /* 1 */
- DWORD chksum;
-} REGF_HDR;
-
-typedef struct hbin_sub_struct {
- DWORD dblocksize;
- char data[1];
-} HBIN_SUB_HDR;
-
-#define REG_HBIN_ID 0x6E696268
-
-typedef struct hbin_struct {
- DWORD HBIN_ID; /* hbin */
- DWORD next_off;
- DWORD prev_off;
- DWORD uk1;
- DWORD uk2;
- DWORD uk3;
- DWORD uk4;
- DWORD blk_size;
- HBIN_SUB_HDR hbin_sub_hdr;
-} HBIN_HDR;
-
-#define REG_NK_ID 0x6B6E
-
-typedef struct nk_struct {
- WORD NK_ID;
- WORD type;
- DWORD t1, t2;
- DWORD uk1;
- DWORD own_off;
- DWORD subk_num;
- DWORD uk2;
- DWORD lf_off;
- DWORD uk3;
- DWORD val_cnt;
- DWORD val_off;
- DWORD sk_off;
- DWORD clsnam_off;
-} NK_HDR;
-
-#define REG_SK_ID 0x6B73
-
-typedef struct sk_struct {
- WORD SK_ID;
- WORD uk1;
- DWORD prev_off;
- DWORD next_off;
- DWORD ref_cnt;
- DWORD rec_size;
- char sec_desc[1];
-} SK_HDR;
-
-typedef struct sec_desc_rec {
- WORD rev;
- WORD type;
- DWORD owner_off;
- DWORD group_off;
- DWORD sacl_off;
- DWORD dacl_off;
-} MY_SEC_DESC;
-
-typedef struct ace_struct {
- unsigned char type;
- unsigned char flags;
- unsigned short length;
- unsigned int perms;
- DOM_SID trustee;
-} ACE;
-
-typedef struct acl_struct {
- WORD rev;
- WORD size;
- DWORD num_aces;
- ACE *aces; /* One or more ACEs */
-} ACL;
-
-#define OFF(f) (0x1000 + (f) + 4)
-
-static void print_sid(DOM_SID *sid);
-
-int verbose = 1;
-DOM_SID old_sid, new_sid;
-int change = 0, new = 0;
-
-/* Compare two SIDs for equality */
-static int my_sid_equal(DOM_SID *s1, DOM_SID *s2)
-{
- int sa1, sa2;
-
- if (s1->sid_rev_num != s2->sid_rev_num) return 0;
-
- sa1 = s1->num_auths; sa2 = s2->num_auths;
-
- if (sa1 != sa2) return 0;
-
- return !memcmp((char *)&s1->id_auth, (char *)&s2->id_auth,
- 6 + sa1 * 4);
-
-}
-
-/*
- * Quick and dirty to read a SID in S-1-5-21-x-y-z-rid format and
- * construct a DOM_SID
- */
-static int get_sid(DOM_SID *sid, char *sid_str)
-{
- int i = 0, auth;
- char *lstr;
-
- if (strncmp(sid_str, "S-1-5", 5)) {
- fprintf(stderr, "Does not conform to S-1-5...: %s\n", sid_str);
- return 0;
- }
-
- /* We only allow strings of form S-1-5... */
-
- sid->sid_rev_num = 1;
- sid->id_auth[5] = 5;
-
- lstr = sid_str + 5;
-
- while (1) {
- if (!lstr || !lstr[0] || sscanf(lstr, "-%u", &auth) == 0) {
- if (i < 4) {
- fprintf(stderr, "Not of form -d-d...: %s, %u\n", lstr, i);
- return 0;
- }
- sid->num_auths=i;
- print_sid(sid);
- return 1;
- }
-
- SIVAL(&sid->sub_auths[i], 0, auth);
- i++;
- lstr = strchr(lstr + 1, '-');
- }
-
- return 1;
-}
-
-/*
- * Replace SID1, component by component with SID2
- * Assumes will never be called with unequal length SIDS
- * so only touches 21-x-y-z-rid portion
- * This routine does not need to deal with endianism as
- * long as the incoming SIDs are both in the same (LE) format.
- */
-static void change_sid(DOM_SID *s1, DOM_SID *s2)
-{
- int i;
-
- for (i=0; i<s1->num_auths; i++) {
- s1->sub_auths[i] = s2->sub_auths[i];
- }
-}
-
-static void print_sid(DOM_SID *sid)
-{
- int i, comps = sid->num_auths;
- fprintf(stdout, "S-%u-%u", sid->sid_rev_num, sid->id_auth[5]);
-
- for (i = 0; i < comps; i++) {
-
- fprintf(stdout, "-%u", IVAL(&sid->sub_auths[i],0));
-
- }
- fprintf(stdout, "\n");
-}
-
-static void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid)
-{
- int i;
- if (my_sid_equal(sid, o_sid)) {
-
- for (i=0; i<sid->num_auths; i++) {
- sid->sub_auths[i] = n_sid->sub_auths[i];
-
- }
-
- }
-
-}
-
-static void process_acl(ACL *acl, const char *prefix)
-{
- int ace_cnt, i;
- ACE *ace;
-
- ace_cnt = IVAL(&acl->num_aces, 0);
- ace = (ACE *)&acl->aces;
- if (verbose) fprintf(stdout, "%sACEs: %u\n", prefix, ace_cnt);
- for (i=0; i<ace_cnt; i++) {
- if (verbose) fprintf(stdout, "%s Perms: %08X, SID: ", prefix,
- IVAL(&ace->perms, 0));
- if (change)
- process_sid(&ace->trustee, &old_sid, &new_sid);
- print_sid(&ace->trustee);
- ace = (ACE *)((char *)ace + SVAL(&ace->length, 0));
- }
-}
-
-static void usage(void)
-{
- fprintf(stderr, "usage: profiles [-c <OLD-SID> -n <NEW-SID>] <profilefile>\n");
- fprintf(stderr, "Version: %s\n", VERSION);
- fprintf(stderr, "\n\t-v\t sets verbose mode");
- fprintf(stderr, "\n\t-c S-1-5-21-z-y-x-oldrid - provides SID to change");
- fprintf(stderr, "\n\t-n S-1-5-21-a-b-c-newrid - provides SID to change to");
- fprintf(stderr, "\n\t\tBoth must be present if the other is.");
- fprintf(stderr, "\n\t\tIf neither present, just report the SIDs found\n");
-}
-
-int main(int argc, char *argv[])
-{
- extern char *optarg;
- extern int optind;
- int opt;
- int fd, start = 0;
- char *base;
- struct stat sbuf;
- REGF_HDR *regf_hdr;
- HBIN_HDR *hbin_hdr;
- NK_HDR *nk_hdr;
- SK_HDR *sk_hdr;
- DWORD first_sk_off, sk_off;
- MY_SEC_DESC *sec_desc;
- int *ptr;
-
- if (argc < 2) {
- usage();
- exit(1);
- }
-
- /*
- * Now, process the arguments
- */
-
- while ((opt = getopt(argc, argv, "c:n:v")) != EOF) {
- switch (opt) {
- case 'c':
- change = 1;
- if (!get_sid(&old_sid, optarg)) {
- fprintf(stderr, "Argument to -c should be a SID in form of S-1-5-...\n");
- usage();
- exit(254);
- }
- break;
-
- case 'n':
- new = 1;
- if (!get_sid(&new_sid, optarg)) {
- fprintf(stderr, "Argument to -n should be a SID in form of S-1-5-...\n");
- usage();
- exit(253);
- }
-
- break;
-
- case 'v':
- verbose++;
- break;
-
- default:
- usage();
- exit(255);
- }
- }
-
- if ((!change & new) || (change & !new)) {
- fprintf(stderr, "You must specify both -c and -n if one or the other is set!\n");
- usage();
- exit(252);
- }
-
- fd = open(argv[optind], O_RDWR, 0000);
-
- if (fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n", argv[optind],
- strerror(errno));
- exit(2);
- }
-
- if (fstat(fd, &sbuf) < 0) {
- fprintf(stderr, "Could not stat file %s, %s\n", argv[optind],
- strerror(errno));
- exit(3);
- }
-
- /*
- * Now, mmap the file into memory, check the header and start
- * dealing with the records. We are interested in the sk record
- */
- start = 0;
- base = mmap(&start, sbuf.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-
- if ((int)base == -1) {
- fprintf(stderr, "Could not mmap file: %s, %s\n", argv[optind],
- strerror(errno));
- exit(4);
- }
-
- /*
- * In what follows, and in places above, in order to work on both LE and
- * BE platforms, we have to use the Samba macros to extract SHORT, LONG
- * and associated UNSIGNED quantities from the data in the mmap'd file.
- * NOTE, however, that we do not need to do anything with memory
- * addresses that we construct from pointers in our address space.
- * For example,
- *
- * sec_desc = (MY_SEC_DESC *)&(sk_hdr->sec_desc[0]);
- *
- * is simply taking the address of a structure we already have the address
- * of in our address space, while, the fields within it, will have to
- * be accessed with the macros:
- *
- * owner_sid = (DOM_SID *)(&sk_hdr->sec_desc[0] +
- * IVAL(&sec_desc->owner_off, 0));
- *
- * Which is pulling out an offset and adding it to an existing pointer.
- *
- */
-
- regf_hdr = (REGF_HDR *)base;
-
- if (verbose) fprintf(stdout, "Registry file size: %u\n", (unsigned int)sbuf.st_size);
-
- if (IVAL(&regf_hdr->REGF_ID, 0) != REG_REGF_ID) {
- fprintf(stderr, "Incorrect Registry file (doesn't have header ID): %s\n", argv[optind]);
- exit(5);
- }
-
- if (verbose) fprintf(stdout, "First Key Off: %u, Data Block Size: %u\n",
- IVAL(&regf_hdr->first_key, 0),
- IVAL(&regf_hdr->dblk_size, 0));
-
- hbin_hdr = (HBIN_HDR *)(base + 0x1000); /* No need for Endian stuff */
-
- /*
- * This should be the hbin_hdr
- */
-
- if (IVAL(&hbin_hdr->HBIN_ID, 0) != REG_HBIN_ID) {
- fprintf(stderr, "Incorrect hbin hdr: %s\n", argv[optind]);
- exit(6);
- }
-
- if (verbose) fprintf(stdout, "Next Off: %u, Prev Off: %u\n",
- IVAL(&hbin_hdr->next_off, 0),
- IVAL(&hbin_hdr->prev_off, 0));
-
- nk_hdr = (NK_HDR *)(base + 0x1000 + IVAL(&regf_hdr->first_key, 0) + 4);
-
- if (SVAL(&nk_hdr->NK_ID, 0) != REG_NK_ID) {
- fprintf(stderr, "Incorrect NK Header: %s\n", argv[optind]);
- exit(7);
- }
-
- sk_off = first_sk_off = IVAL(&nk_hdr->sk_off, 0);
- if (verbose) {
- fprintf(stdout, "Type: %0x\n", SVAL(&nk_hdr->type, 0));
- fprintf(stdout, "SK Off : %o\n", (0x1000 + sk_off + 4));
- }
-
- sk_hdr = (SK_HDR *)(base + 0x1000 + sk_off + 4);
-
- do {
- DOM_SID *owner_sid, *group_sid;
- ACL *sacl, *dacl;
- if (SVAL(&sk_hdr->SK_ID, 0) != REG_SK_ID) {
- fprintf(stderr, "Incorrect SK Header format: %08X\n",
- (0x1000 + sk_off + 4));
- exit(8);
- }
- ptr = (int *)sk_hdr;
- if (verbose) fprintf(stdout, "Off: %08X, Refs: %u, Size: %u\n",
- sk_off, IVAL(&sk_hdr->ref_cnt, 0),
- IVAL(&sk_hdr->rec_size, 0));
-
- sec_desc = (MY_SEC_DESC *)&(sk_hdr->sec_desc[0]);
- owner_sid = (DOM_SID *)(&sk_hdr->sec_desc[0] +
- IVAL(&sec_desc->owner_off, 0));
- group_sid = (DOM_SID *)(&sk_hdr->sec_desc[0] +
- IVAL(&sec_desc->group_off, 0));
- sacl = (ACL *)(&sk_hdr->sec_desc[0] +
- IVAL(&sec_desc->sacl_off, 0));
- dacl = (ACL *)(&sk_hdr->sec_desc[0] +
- IVAL(&sec_desc->dacl_off, 0));
- if (verbose)fprintf(stdout, " Owner SID: ");
- if (change) process_sid(owner_sid, &old_sid, &new_sid);
- if (verbose) print_sid(owner_sid);
- if (verbose) fprintf(stdout, " Group SID: ");
- if (change) process_sid(group_sid, &old_sid, &new_sid);
- if (verbose) print_sid(group_sid);
- fprintf(stdout, " SACL: ");
- if (!sec_desc->sacl_off) { /* LE zero == BE zero */
- if (verbose) fprintf(stdout, "NONE\n");
- }
- else
- process_acl(sacl, " ");
- if (verbose) fprintf(stdout, " DACL: ");
- if (!sec_desc->dacl_off) {
- if (verbose) fprintf(stdout, "NONE\n");
- }
- else
- process_acl(dacl, " ");
- sk_off = IVAL(&sk_hdr->prev_off, 0);
- sk_hdr = (SK_HDR *)(base + OFF(IVAL(&sk_hdr->prev_off, 0)));
- } while (sk_off != first_sk_off);
-
- munmap(base, sbuf.st_size);
-
- close(fd);
- return 0;
-}
diff --git a/source4/utils/rpccheck.c b/source4/utils/rpccheck.c
deleted file mode 100644
index dd357794fe..0000000000
--- a/source4/utils/rpccheck.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
-
- Copyright (C) Jean François Micouleau 2001
-
- 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"
-
-main()
-{
- char filter[]="0123456789ABCDEF";
-
- char s[128];
- char d=0;
- int x=0;
- prs_struct ps;
- TALLOC_CTX *ctx;
-
- /* change that struct */
- SAMR_R_QUERY_USERINFO rpc_stub;
-
- ZERO_STRUCT(rpc_stub);
-
- setup_logging("", DEBUG_STDOUT);
- DEBUGLEVEL=10;
-
- ctx=talloc_init("main");
- if (!ctx) exit(1);
-
- prs_init(&ps, 1600, 4, ctx, MARSHALL);
-
- while (scanf("%s", s)!=-1) {
- if (strlen(s)==2 && strchr_m(filter, *s)!=NULL && strchr_m(filter, *(s+1))!=NULL) {
- d=strtol(s, NULL, 16);
- if(!prs_append_data(&ps, &d, 1))
- printf("error while reading data\n");
- }
- }
-
- prs_switch_type(&ps, UNMARSHALL);
- prs_set_offset(&ps, 0);
-
- /* change that call */
- if(!samr_io_r_query_userinfo("", &rpc_stub, &ps, 0))
- printf("error while UNMARSHALLING the data\n");
-
- printf("\n");
-}
diff --git a/source4/utils/smbcacls.c b/source4/utils/smbcacls.c
deleted file mode 100644
index 41dc24f846..0000000000
--- a/source4/utils/smbcacls.c
+++ /dev/null
@@ -1,937 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- ACL get/set utility
-
- Copyright (C) Andrew Tridgell 2000
- Copyright (C) Tim Potter 2000
- Copyright (C) Jeremy Allison 2000
-
- 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"
-
-static fstring password;
-static pstring username;
-static pstring owner_username;
-static fstring server;
-static int got_pass;
-static int test_args;
-static TALLOC_CTX *ctx;
-
-#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
-#define CREATE_ACCESS_WRITE (WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS)
-
-/* numeric is set when the user wants numeric SIDs and ACEs rather
- than going via LSA calls to resolve them */
-static int numeric;
-
-enum acl_mode {SMB_ACL_SET, SMB_ACL_DELETE, SMB_ACL_MODIFY, SMB_ACL_ADD };
-enum chown_mode {REQUEST_NONE, REQUEST_CHOWN, REQUEST_CHGRP};
-enum exit_values {EXIT_OK, EXIT_FAILED, EXIT_PARSE_ERROR};
-
-struct perm_value {
- const char *perm;
- uint32 mask;
-};
-
-/* These values discovered by inspection */
-
-static const struct perm_value special_values[] = {
- { "R", 0x00120089 },
- { "W", 0x00120116 },
- { "X", 0x001200a0 },
- { "D", 0x00010000 },
- { "P", 0x00040000 },
- { "O", 0x00080000 },
- { NULL, 0 },
-};
-
-static const struct perm_value standard_values[] = {
- { "READ", 0x001200a9 },
- { "CHANGE", 0x001301bf },
- { "FULL", 0x001f01ff },
- { NULL, 0 },
-};
-
-static struct cli_state *global_hack_cli;
-static POLICY_HND pol;
-static BOOL got_policy_hnd;
-
-static struct cli_state *connect_one(const char *share);
-
-/* Open cli connection and policy handle */
-
-static BOOL cacls_open_policy_hnd(void)
-{
- /* Initialise cli LSA connection */
-
- if (!global_hack_cli) {
- global_hack_cli = connect_one("IPC$");
- if (!cli_nt_session_open (global_hack_cli, PI_LSARPC)) {
- return False;
- }
- }
-
- /* Open policy handle */
-
- if (!got_policy_hnd) {
-
- /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED,
- but NT sends 0x2000000 so we might as well do it too. */
-
- if (!NT_STATUS_IS_OK(cli_lsa_open_policy(global_hack_cli, global_hack_cli->mem_ctx, True,
- GENERIC_EXECUTE_ACCESS, &pol))) {
- return False;
- }
-
- got_policy_hnd = True;
- }
-
- return True;
-}
-
-/* convert a SID to a string, either numeric or username/group */
-static void SidToString(fstring str, DOM_SID *sid)
-{
- char **domains = NULL;
- char **names = NULL;
- uint32 *types = NULL;
-
- sid_to_string(str, sid);
-
- if (numeric) return;
-
- /* Ask LSA to convert the sid to a name */
-
- if (!cacls_open_policy_hnd() ||
- !NT_STATUS_IS_OK(cli_lsa_lookup_sids(global_hack_cli, global_hack_cli->mem_ctx,
- &pol, 1, sid, &domains,
- &names, &types)) ||
- !domains || !domains[0] || !names || !names[0]) {
- return;
- }
-
- /* Converted OK */
-
- slprintf(str, sizeof(fstring) - 1, "%s%s%s",
- domains[0], lp_winbind_separator(),
- names[0]);
-
-}
-
-/* convert a string to a SID, either numeric or username/group */
-static BOOL StringToSid(DOM_SID *sid, const char *str)
-{
- uint32 *types = NULL;
- DOM_SID *sids = NULL;
- BOOL result = True;
-
- if (strncmp(str, "S-", 2) == 0) {
- return string_to_sid(sid, str);
- }
-
- if (!cacls_open_policy_hnd() ||
- !NT_STATUS_IS_OK(cli_lsa_lookup_names(global_hack_cli, global_hack_cli->mem_ctx,
- &pol, 1, &str, &sids,
- &types))) {
- result = False;
- goto done;
- }
-
- sid_copy(sid, &sids[0]);
- done:
-
- return result;
-}
-
-
-/* print an ACE on a FILE, using either numeric or ascii representation */
-static void print_ace(FILE *f, SEC_ACE *ace)
-{
- const struct perm_value *v;
- fstring sidstr;
- int do_print = 0;
- uint32 got_mask;
-
- SidToString(sidstr, &ace->trustee);
-
- fprintf(f, "%s:", sidstr);
-
- if (numeric) {
- fprintf(f, "%d/%d/0x%08x",
- ace->type, ace->flags, ace->info.mask);
- return;
- }
-
- /* Ace type */
-
- if (ace->type == SEC_ACE_TYPE_ACCESS_ALLOWED) {
- fprintf(f, "ALLOWED");
- } else if (ace->type == SEC_ACE_TYPE_ACCESS_DENIED) {
- fprintf(f, "DENIED");
- } else {
- fprintf(f, "%d", ace->type);
- }
-
- /* Not sure what flags can be set in a file ACL */
-
- fprintf(f, "/%d/", ace->flags);
-
- /* Standard permissions */
-
- for (v = standard_values; v->perm; v++) {
- if (ace->info.mask == v->mask) {
- fprintf(f, "%s", v->perm);
- return;
- }
- }
-
- /* Special permissions. Print out a hex value if we have
- leftover bits in the mask. */
-
- got_mask = ace->info.mask;
-
- again:
- for (v = special_values; v->perm; v++) {
- if ((ace->info.mask & v->mask) == v->mask) {
- if (do_print) {
- fprintf(f, "%s", v->perm);
- }
- got_mask &= ~v->mask;
- }
- }
-
- if (!do_print) {
- if (got_mask != 0) {
- fprintf(f, "0x%08x", ace->info.mask);
- } else {
- do_print = 1;
- goto again;
- }
- }
-}
-
-
-/* parse an ACE in the same format as print_ace() */
-static BOOL parse_ace(SEC_ACE *ace, char *str)
-{
- char *p;
- const char *cp;
- fstring tok;
- unsigned atype, aflags, amask;
- DOM_SID sid;
- SEC_ACCESS mask;
- const struct perm_value *v;
-
- ZERO_STRUCTP(ace);
- p = strchr_m(str,':');
- if (!p) return False;
- *p = '\0';
- p++;
- /* Try to parse numeric form */
-
- if (sscanf(p, "%i/%i/%i", &atype, &aflags, &amask) == 3 &&
- StringToSid(&sid, str)) {
- goto done;
- }
-
- /* Try to parse text form */
-
- if (!StringToSid(&sid, str)) {
- return False;
- }
-
- cp = p;
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
- return False;
- }
-
- if (strncmp(tok, "ALLOWED", strlen("ALLOWED")) == 0) {
- atype = SEC_ACE_TYPE_ACCESS_ALLOWED;
- } else if (strncmp(tok, "DENIED", strlen("DENIED")) == 0) {
- atype = SEC_ACE_TYPE_ACCESS_DENIED;
- } else {
- return False;
- }
-
- /* Only numeric form accepted for flags at present */
-
- if (!(next_token(&cp, tok, "/", sizeof(fstring)) &&
- sscanf(tok, "%i", &aflags))) {
- return False;
- }
-
- if (!next_token(&cp, tok, "/", sizeof(fstring))) {
- return False;
- }
-
- if (strncmp(tok, "0x", 2) == 0) {
- if (sscanf(tok, "%i", &amask) != 1) {
- return False;
- }
- goto done;
- }
-
- for (v = standard_values; v->perm; v++) {
- if (strcmp(tok, v->perm) == 0) {
- amask = v->mask;
- goto done;
- }
- }
-
- p = tok;
-
- while(*p) {
- BOOL found = False;
-
- for (v = special_values; v->perm; v++) {
- if (v->perm[0] == *p) {
- amask |= v->mask;
- found = True;
- }
- }
-
- if (!found) return False;
- p++;
- }
-
- if (*p) {
- return False;
- }
-
- done:
- mask.mask = amask;
- init_sec_ace(ace, &sid, atype, mask, aflags);
- return True;
-}
-
-/* add an ACE to a list of ACEs in a SEC_ACL */
-static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
-{
- SEC_ACL *new;
- SEC_ACE *aces;
- if (! *the_acl) {
- (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
- return True;
- }
-
- aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE));
- memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
- memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
- new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
- SAFE_FREE(aces);
- (*the_acl) = new;
- return True;
-}
-
-/* parse a ascii version of a security descriptor */
-static SEC_DESC *sec_desc_parse(char *str)
-{
- const char *p = str;
- fstring tok;
- SEC_DESC *ret;
- size_t sd_size;
- DOM_SID *grp_sid=NULL, *owner_sid=NULL;
- SEC_ACL *dacl=NULL;
- int revision=1;
-
- while (next_token(&p, tok, "\t,\r\n", sizeof(tok))) {
-
- if (strncmp(tok,"REVISION:", 9) == 0) {
- revision = strtol(tok+9, NULL, 16);
- continue;
- }
-
- if (strncmp(tok,"OWNER:", 6) == 0) {
- owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
- if (!owner_sid ||
- !StringToSid(owner_sid, tok+6)) {
- printf("Failed to parse owner sid\n");
- return NULL;
- }
- continue;
- }
-
- if (strncmp(tok,"GROUP:", 6) == 0) {
- grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
- if (!grp_sid ||
- !StringToSid(grp_sid, tok+6)) {
- printf("Failed to parse group sid\n");
- return NULL;
- }
- continue;
- }
-
- if (strncmp(tok,"ACL:", 4) == 0) {
- SEC_ACE ace;
- if (!parse_ace(&ace, tok+4)) {
- printf("Failed to parse ACL %s\n", tok);
- return NULL;
- }
- if(!add_ace(&dacl, &ace)) {
- printf("Failed to add ACL %s\n", tok);
- return NULL;
- }
- continue;
- }
-
- printf("Failed to parse security descriptor\n");
- return NULL;
- }
-
- ret = make_sec_desc(ctx,revision, owner_sid, grp_sid,
- NULL, dacl, &sd_size);
-
- SAFE_FREE(grp_sid);
- SAFE_FREE(owner_sid);
-
- return ret;
-}
-
-
-/* print a ascii version of a security descriptor on a FILE handle */
-static void sec_desc_print(FILE *f, SEC_DESC *sd)
-{
- fstring sidstr;
- uint32 i;
-
- printf("REVISION:%d\n", sd->revision);
-
- /* Print owner and group sid */
-
- if (sd->owner_sid) {
- SidToString(sidstr, sd->owner_sid);
- } else {
- fstrcpy(sidstr, "");
- }
-
- printf("OWNER:%s\n", sidstr);
-
- if (sd->grp_sid) {
- SidToString(sidstr, sd->grp_sid);
- } else {
- fstrcpy(sidstr, "");
- }
-
- fprintf(f, "GROUP:%s\n", sidstr);
-
- /* Print aces */
- for (i = 0; sd->dacl && i < sd->dacl->num_aces; i++) {
- SEC_ACE *ace = &sd->dacl->ace[i];
- fprintf(f, "ACL:");
- print_ace(f, ace);
- fprintf(f, "\n");
- }
-
-}
-
-/*****************************************************
-dump the acls for a file
-*******************************************************/
-static int cacl_dump(struct cli_state *cli, char *filename)
-{
- int result = EXIT_FAILED;
- int fnum = -1;
- SEC_DESC *sd;
-
- if (test_args)
- return EXIT_OK;
-
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
- printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
- goto done;
- }
-
- sd = cli_query_secdesc(cli, fnum, ctx);
-
- if (!sd) {
- printf("ERROR: secdesc query failed: %s\n", cli_errstr(cli));
- goto done;
- }
-
- sec_desc_print(stdout, sd);
-
- result = EXIT_OK;
-
-done:
- if (fnum != -1)
- cli_close(cli, fnum);
-
- return result;
-}
-
-/*****************************************************
-Change the ownership or group ownership of a file. Just
-because the NT docs say this can't be done :-). JRA.
-*******************************************************/
-
-static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
- char *filename, char *new_username)
-{
- int fnum;
- DOM_SID sid;
- SEC_DESC *sd, *old;
- size_t sd_size;
-
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
- printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
- return EXIT_FAILED;
- }
-
- if (!StringToSid(&sid, new_username))
- return EXIT_PARSE_ERROR;
-
- old = cli_query_secdesc(cli, fnum, ctx);
-
- cli_close(cli, fnum);
-
- if (!old) {
- printf("owner_set: Failed to query old descriptor\n");
- return EXIT_FAILED;
- }
-
- sd = make_sec_desc(ctx,old->revision,
- (change_mode == REQUEST_CHOWN) ? &sid : old->owner_sid,
- (change_mode == REQUEST_CHGRP) ? &sid : old->grp_sid,
- NULL, old->dacl, &sd_size);
-
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_WRITE);
-
- if (fnum == -1) {
- printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
- return EXIT_FAILED;
- }
-
- if (!cli_set_secdesc(cli, fnum, sd)) {
- printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
- }
-
- cli_close(cli, fnum);
-
- return EXIT_OK;
-}
-
-
-/* The MSDN is contradictory over the ordering of ACE entries in an ACL.
- However NT4 gives a "The information may have been modified by a
- computer running Windows NT 5.0" if denied ACEs do not appear before
- allowed ACEs. */
-
-static int ace_compare(SEC_ACE *ace1, SEC_ACE *ace2)
-{
- if (sec_ace_equal(ace1, ace2))
- return 0;
-
- if (ace1->type != ace2->type)
- return ace2->type - ace1->type;
-
- if (sid_compare(&ace1->trustee, &ace2->trustee))
- return sid_compare(&ace1->trustee, &ace2->trustee);
-
- if (ace1->flags != ace2->flags)
- return ace1->flags - ace2->flags;
-
- if (ace1->info.mask != ace2->info.mask)
- return ace1->info.mask - ace2->info.mask;
-
- if (ace1->size != ace2->size)
- return ace1->size - ace2->size;
-
- return memcmp(ace1, ace2, sizeof(SEC_ACE));
-}
-
-static void sort_acl(SEC_ACL *the_acl)
-{
- uint32 i;
- if (!the_acl) return;
-
- qsort(the_acl->ace, the_acl->num_aces, sizeof(the_acl->ace[0]), QSORT_CAST ace_compare);
-
- for (i=1;i<the_acl->num_aces;) {
- if (sec_ace_equal(&the_acl->ace[i-1], &the_acl->ace[i])) {
- int j;
- for (j=i; j<the_acl->num_aces-1; j++) {
- the_acl->ace[j] = the_acl->ace[j+1];
- }
- the_acl->num_aces--;
- } else {
- i++;
- }
- }
-}
-
-/*****************************************************
-set the ACLs on a file given an ascii description
-*******************************************************/
-static int cacl_set(struct cli_state *cli, char *filename,
- char *the_acl, enum acl_mode mode)
-{
- int fnum;
- SEC_DESC *sd, *old;
- uint32 i, j;
- size_t sd_size;
- int result = EXIT_OK;
-
- sd = sec_desc_parse(the_acl);
-
- if (!sd) return EXIT_PARSE_ERROR;
- if (test_args) return EXIT_OK;
-
- /* The desired access below is the only one I could find that works
- with NT4, W2KP and Samba */
-
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_READ);
-
- if (fnum == -1) {
- printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
- return EXIT_FAILED;
- }
-
- old = cli_query_secdesc(cli, fnum, ctx);
-
- if (!old) {
- printf("calc_set: Failed to query old descriptor\n");
- return EXIT_FAILED;
- }
-
- cli_close(cli, fnum);
-
- /* the logic here is rather more complex than I would like */
- switch (mode) {
- case SMB_ACL_DELETE:
- for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
- BOOL found = False;
-
- for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
- if (sec_ace_equal(&sd->dacl->ace[i],
- &old->dacl->ace[j])) {
- uint32 k;
- for (k=j; k<old->dacl->num_aces-1;k++) {
- old->dacl->ace[k] = old->dacl->ace[k+1];
- }
- old->dacl->num_aces--;
- if (old->dacl->num_aces == 0) {
- SAFE_FREE(old->dacl->ace);
- SAFE_FREE(old->dacl);
- old->off_dacl = 0;
- }
- found = True;
- break;
- }
- }
-
- if (!found) {
- printf("ACL for ACE:");
- print_ace(stdout, &sd->dacl->ace[i]);
- printf(" not found\n");
- }
- }
- break;
-
- case SMB_ACL_MODIFY:
- for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
- BOOL found = False;
-
- for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
- if (sid_equal(&sd->dacl->ace[i].trustee,
- &old->dacl->ace[j].trustee)) {
- old->dacl->ace[j] = sd->dacl->ace[i];
- found = True;
- }
- }
-
- if (!found) {
- fstring str;
-
- SidToString(str, &sd->dacl->ace[i].trustee);
- printf("ACL for SID %s not found\n", str);
- }
- }
-
- break;
-
- case SMB_ACL_ADD:
- for (i=0;sd->dacl && i<sd->dacl->num_aces;i++) {
- add_ace(&old->dacl, &sd->dacl->ace[i]);
- }
- break;
-
- case SMB_ACL_SET:
- old = sd;
- break;
- }
-
- /* Denied ACE entries must come before allowed ones */
- sort_acl(old->dacl);
-
- /* Create new security descriptor and set it */
- sd = make_sec_desc(ctx,old->revision, old->owner_sid, old->grp_sid,
- NULL, old->dacl, &sd_size);
-
- fnum = cli_nt_create(cli, filename, CREATE_ACCESS_WRITE);
-
- if (fnum == -1) {
- printf("cacl_set failed to open %s: %s\n", filename, cli_errstr(cli));
- return EXIT_FAILED;
- }
-
- if (!cli_set_secdesc(cli, fnum, sd)) {
- printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
- result = EXIT_FAILED;
- }
-
- /* Clean up */
-
- cli_close(cli, fnum);
-
- return result;
-}
-
-
-/*****************************************************
-return a connection to a server
-*******************************************************/
-static struct cli_state *connect_one(const char *share)
-{
- struct cli_state *c;
- struct in_addr ip;
- NTSTATUS nt_status;
- zero_ip(&ip);
-
- if (!got_pass) {
- char *pass = getpass("Password: ");
- if (pass) {
- fstrcpy(password, pass);
- got_pass = True;
- }
- }
-
- if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, lp_netbios_name(), server,
- &ip, 0,
- share, "?????",
- username, lp_workgroup(),
- password, 0, NULL))) {
- return c;
- } else {
- DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
- return NULL;
- }
-}
-
-
-static void usage(void)
-{
- printf(
-"Usage: smbcacls //server1/share1 filename [options]\n\
-\n\
-\t-D <acls> delete an acl\n\
-\t-M <acls> modify an acl\n\
-\t-A <acls> add an acl\n\
-\t-S <acls> set acls\n\
-\t-C username change ownership of a file\n\
-\t-G username change group ownership of a file\n\
-\t-n don't resolve sids or masks to names\n\
-\t-h print help\n\
-\t-d debuglevel set debug output level\n\
-\t-U username user to autheticate as\n\
-\n\
-The username can be of the form username%%password or\n\
-workgroup\\username%%password.\n\n\
-An acl is of the form ACL:<SID>:type/flags/mask\n\
-You can string acls together with spaces, commas or newlines\n\
-");
-}
-
-/****************************************************************************
- main program
-****************************************************************************/
- int main(int argc,char *argv[])
-{
- char *share;
- pstring filename;
- extern char *optarg;
- extern int optind;
- int opt;
- char *p;
- enum acl_mode mode = SMB_ACL_SET;
- char *the_acl = NULL;
- enum chown_mode change_mode = REQUEST_NONE;
- int result;
-
- struct cli_state *cli;
-
- ctx=talloc_init("main");
-
- setlinebuf(stdout);
-
- dbf = x_stderr;
-
- if (argc < 3 || argv[1][0] == '-') {
- usage();
- talloc_destroy(ctx);
- exit(EXIT_PARSE_ERROR);
- }
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- share = argv[1];
- pstrcpy(filename, argv[2]);
- all_string_sub(share,"/","\\",0);
-
- argc -= 2;
- argv += 2;
-
- lp_load(dyn_CONFIGFILE,True,False,False);
- load_interfaces();
-
- if (getenv("USER")) {
- pstrcpy(username,getenv("USER"));
-
- if ((p=strchr_m(username,'%'))) {
- *p = 0;
- fstrcpy(password,p+1);
- got_pass = True;
- memset(strchr_m(getenv("USER"), '%') + 1, 'X',
- strlen(password));
- }
- }
-
- while ((opt = getopt(argc, argv, "U:nhS:D:A:M:C:G:td:")) != EOF) {
- switch (opt) {
- case 'U':
- pstrcpy(username,optarg);
- p = strchr_m(username,'%');
- if (p) {
- *p = 0;
- fstrcpy(password, p+1);
- got_pass = 1;
- }
- break;
-
- case 'S':
- the_acl = optarg;
- mode = SMB_ACL_SET;
- break;
-
- case 'D':
- the_acl = optarg;
- mode = SMB_ACL_DELETE;
- break;
-
- case 'M':
- the_acl = optarg;
- mode = SMB_ACL_MODIFY;
- break;
-
- case 'A':
- the_acl = optarg;
- mode = SMB_ACL_ADD;
- break;
-
- case 'C':
- pstrcpy(owner_username,optarg);
- change_mode = REQUEST_CHOWN;
- break;
-
- case 'G':
- pstrcpy(owner_username,optarg);
- change_mode = REQUEST_CHGRP;
- break;
-
- case 'n':
- numeric = 1;
- break;
-
- case 't':
- test_args = 1;
- break;
-
- case 'h':
- usage();
- talloc_destroy(ctx);
- exit(EXIT_PARSE_ERROR);
-
- case 'd':
- DEBUGLEVEL = atoi(optarg);
- break;
-
- default:
- printf("Unknown option %c (%d)\n", (char)opt, opt);
- talloc_destroy(ctx);
- exit(EXIT_PARSE_ERROR);
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc > 0) {
- usage();
- talloc_destroy(ctx);
- exit(EXIT_PARSE_ERROR);
- }
-
- /* Make connection to server */
-
- fstrcpy(server,share+2);
- share = strchr_m(server,'\\');
- if (!share) {
- share = strchr_m(server,'/');
- if (!share) {
- return -1;
- }
- }
-
- *share = 0;
- share++;
-
- if (!test_args) {
- cli = connect_one(share);
- if (!cli) {
- talloc_destroy(ctx);
- exit(EXIT_FAILED);
- }
- } else {
- exit(0);
- }
-
- all_string_sub(filename, "/", "\\", 0);
- if (filename[0] != '\\') {
- pstring s;
- s[0] = '\\';
- safe_strcpy(&s[1], filename, sizeof(pstring)-1);
- pstrcpy(filename, s);
- }
-
- /* Perform requested action */
-
- if (change_mode != REQUEST_NONE) {
- result = owner_set(cli, change_mode, filename, owner_username);
- } else if (the_acl) {
- result = cacl_set(cli, filename, the_acl, mode);
- } else {
- result = cacl_dump(cli, filename);
- }
-
- talloc_destroy(ctx);
-
- return result;
-}
-
diff --git a/source4/utils/smbcontrol.c b/source4/utils/smbcontrol.c
deleted file mode 100644
index d715163ebb..0000000000
--- a/source4/utils/smbcontrol.c
+++ /dev/null
@@ -1,714 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- program to send control messages to Samba processes
- Copyright (C) Andrew Tridgell 1994-1998
- Copyright (C) 2001, 2002 by Martin Pool
- Copyright (C) Simo Sorce 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"
-
-extern BOOL AllowDebugChange;
-
-static const struct {
- const char *name;
- int value;
-} msg_types[] = {
- {"debug", MSG_DEBUG},
- {"force-election", MSG_FORCE_ELECTION},
- {"ping", MSG_PING},
- {"profile", MSG_PROFILE},
- {"profilelevel", MSG_REQ_PROFILELEVEL},
- {"debuglevel", MSG_REQ_DEBUGLEVEL},
- {"printnotify", MSG_PRINTER_NOTIFY2 },
- {"close-share", MSG_SMB_FORCE_TDIS},
- {"samsync", MSG_SMB_SAM_SYNC},
- {"samrepl", MSG_SMB_SAM_REPL},
- {"pool-usage", MSG_REQ_POOL_USAGE },
- {"dmalloc-mark", MSG_REQ_DMALLOC_MARK },
- {"dmalloc-log-changed", MSG_REQ_DMALLOC_LOG_CHANGED },
- {"shutdown", MSG_SHUTDOWN },
- {"drvupgrade", MSG_PRINTER_DRVUPGRADE},
- {"tallocdump", MSG_REQ_TALLOC_USAGE},
- {NULL, -1}
-};
-
-time_t timeout_start;
-
-#define MAX_WAIT 10
-
-/* we need these because we link to printing*.o */
-
-void become_root(void) {}
-void unbecome_root(void) {}
-
-
-static void usage(BOOL doexit)
-{
- int i;
- if (doexit) {
- printf("Usage: smbcontrol -i -s configfile\n");
- printf(" smbcontrol <destination> <message-type> <parameters>\n\n");
- } else {
- printf("<destination> <message-type> <parameters>\n\n");
- }
- printf("\t<destination> is one of \"nmbd\", \"smbd\" or a process ID\n");
- printf("\t<message-type> is one of:\n");
- for (i=0; msg_types[i].name; i++)
- printf("\t\t%s\n", msg_types[i].name);
- printf("\n");
- if (doexit) exit(1);
-}
-
-static int pong_count;
-static BOOL got_level;
-static BOOL got_pool;
-static BOOL pong_registered = False;
-static BOOL debuglevel_registered = False;
-static BOOL poolusage_registered = False;
-static BOOL profilelevel_registered = False;
-
-
-/**
- * Wait for replies for up to @p *max_secs seconds, or until @p
- * max_replies are received. max_replies may be NULL in which case it
- * is ignored.
- *
- * @note This is a pretty lame timeout; all it means is that after
- * max_secs we won't look for any more messages.
- **/
-static void wait_for_replies(int max_secs, int *max_replies)
-{
- time_t timeout_end = time(NULL) + max_secs;
-
- while ((!max_replies || (*max_replies)-- > 0)
- && (time(NULL) < timeout_end)) {
- message_dispatch();
- }
-}
-
-
-/****************************************************************************
-a useful function for testing the message system
-****************************************************************************/
-void pong_function(int msg_type, pid_t src, void *buf, size_t len)
-{
- pong_count++;
- printf("PONG from PID %u\n",(unsigned int)src);
-}
-
-/****************************************************************************
- Prints out the current talloc list.
-****************************************************************************/
-void tallocdump_function(int msg_type, pid_t src, void *buf, size_t len)
-{
- char *info = (char *)buf;
-
- printf("Current talloc contexts for process %u\n", (unsigned int)src );
- if (len == 0)
- printf("None returned\n");
- else
- printf(info);
- printf("\n");
- got_pool = True;
-}
-
-/****************************************************************************
-Prints out the current Debug level returned by MSG_DEBUGLEVEL
-****************************************************************************/
-void debuglevel_function(int msg_type, pid_t src, void *buf, size_t len)
-{
- const char *levels = (char *)buf;
-
- printf("Current debug levels of PID %u are:\n",(unsigned int)src);
- printf("%s\n", levels);
-
- got_level = True;
-}
-
-/****************************************************************************
-Prints out the current Profile level returned by MSG_PROFILELEVEL
-****************************************************************************/
-void profilelevel_function(int msg_type, pid_t src, void *buf, size_t len)
-{
- int level;
- const char *s=NULL;
- memcpy(&level, buf, sizeof(int));
-
- if (level) {
- switch (level) {
- case 1:
- s = "off";
- break;
- case 3:
- s = "count only";
- break;
- case 7:
- s = "count and time";
- break;
- default:
- s = "BOGUS";
- break;
- }
- printf("Profiling %s on PID %u\n",s,(unsigned int)src);
- } else {
- printf("Profiling not available on PID %u\n",(unsigned int)src);
- }
- got_level = True;
-}
-
-/**
- * Handle reply from POOL_USAGE.
- **/
-static void pool_usage_cb(int msg_type, pid_t src_pid, void *buf, size_t len)
-{
- printf("Got POOL_USAGE reply from pid%u:\n%.*s",
- (unsigned int) src_pid, (int) len, (const char *) buf);
-}
-
-
-/**
- * Send a message to a named destination
- *
- * @return False if an error occurred.
- **/
-static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates)
-{
- pid_t pid;
- /* "smbd" is the only broadcast operation */
- if (strequal(dest,"smbd")) {
- TDB_CONTEXT *tdb;
- BOOL ret;
- int n_sent = 0;
-
- tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDWR, 0);
- if (!tdb) {
- fprintf(stderr,"Failed to open connections database in send_message.\n");
- return False;
- }
-
- ret = message_send_all(tdb,msg_type, buf, len, duplicates,
- &n_sent);
- DEBUG(10,("smbcontrol/send_message: broadcast message to "
- "%d processes\n", n_sent));
- tdb_close(tdb);
-
- return ret;
- } else if (strequal(dest,"nmbd")) {
- pid = pidfile_pid(dest);
- if (pid == 0) {
- fprintf(stderr,"Can't find pid for nmbd\n");
- return False;
- }
- } else if (strequal(dest,"self")) {
- pid = sys_getpid();
- } else {
- pid = atoi(dest);
- if (pid == 0) {
- fprintf(stderr,"Not a valid pid\n");
- return False;
- }
- }
-
- DEBUG(10,("smbcontrol/send_message: send message to pid%d\n", pid));
- return message_send_pid(pid, msg_type, buf, len, duplicates);
-}
-
-/****************************************************************************
-evaluate a message type string
-****************************************************************************/
-static int parse_type(char *mtype)
-{
- int i;
- for (i=0;msg_types[i].name;i++) {
- if (strequal(mtype, msg_types[i].name)) return msg_types[i].value;
- }
- return -1;
-}
-
-
-static void register_all(void)
-{
- message_register(MSG_POOL_USAGE, pool_usage_cb);
-}
-
-/* This guy is here so we can link printing/notify.c to the smbcontrol
- binary without having to pull in tons of other crap. */
-
-TDB_CONTEXT *conn_tdb_ctx(void)
-{
- static TDB_CONTEXT *tdb;
-
- if (tdb)
- return tdb;
-
- tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
-
- if (!tdb)
- DEBUG(3, ("Failed to open connections database in send_spoolss_notify2_msg\n"));
-
- return tdb;
-}
-
-/****************************************************************************
-do command
-****************************************************************************/
-static BOOL do_command(char *dest, char *msg_name, int iparams, char **params)
-{
- int i, n, v;
- int mtype;
- BOOL retval=False;
- BOOL check_notify_msgs = False;
-
- mtype = parse_type(msg_name);
- if (mtype == -1) {
- fprintf(stderr,"Couldn't resolve message type: %s\n", msg_name);
- return(False);
- }
-
- switch (mtype) {
- case MSG_DEBUG: {
- char *buf, *b;
- char **p;
- int dim = 0;
-
- if (!params || !params[0]) {
- fprintf(stderr,"MSG_DEBUG needs a parameter\n");
- return(False);
- }
-
- /* first pass retrieve total lenght */
- for (p = params; p && *p ; p++)
- dim += (strnlen(*p, 1024) +1); /* lenght + space */
- b = buf = malloc(dim);
- if (!buf) {
- fprintf(stderr, "Out of memory!");
- return(False);
- }
- /* now build a single string with all parameters */
- for(p = params; p && *p; p++) {
- int l = strnlen(*p, 1024);
- strncpy(b, *p, l);
- b[l] = ' ';
- b = b + l + 1;
- }
- b[-1] = '\0';
-
- send_message(dest, MSG_DEBUG, buf, dim, False);
-
- free(buf);
-
- break;
- }
-
- case MSG_PROFILE:
- if (!params || !params[0]) {
- fprintf(stderr,"MSG_PROFILE needs a parameter\n");
- return(False);
- }
- if (strequal(params[0], "off")) {
- v = 0;
- } else if (strequal(params[0], "count")) {
- v = 1;
- } else if (strequal(params[0], "on")) {
- v = 2;
- } else if (strequal(params[0], "flush")) {
- v = 3;
- } else {
- fprintf(stderr,
- "MSG_PROFILE parameter must be off, count, on, or flush\n");
- return(False);
- }
- send_message(dest, MSG_PROFILE, &v, sizeof(int), False);
- break;
-
- case MSG_FORCE_ELECTION:
- if (!strequal(dest, "nmbd")) {
- fprintf(stderr,"force-election can only be sent to nmbd\n");
- return(False);
- }
- send_message(dest, MSG_FORCE_ELECTION, NULL, 0, False);
- break;
-
- case MSG_REQ_PROFILELEVEL:
- if (!profilelevel_registered) {
- message_register(MSG_PROFILELEVEL, profilelevel_function);
- profilelevel_registered = True;
- }
- got_level = False;
- retval = send_message(dest, MSG_REQ_PROFILELEVEL, NULL, 0, True);
- if (retval) {
- timeout_start = time(NULL);
- while (!got_level) {
- message_dispatch();
- if ((time(NULL) - timeout_start) > MAX_WAIT) {
- fprintf(stderr,"profilelevel timeout\n");
- break;
- }
- }
- }
- break;
-
- case MSG_REQ_TALLOC_USAGE:
- if (!poolusage_registered) {
- message_register(MSG_TALLOC_USAGE, tallocdump_function);
- poolusage_registered = True;
- }
- got_pool = False;
- retval = send_message(dest, MSG_REQ_TALLOC_USAGE, NULL, 0, True);
- if (retval) {
- timeout_start = time(NULL);
- while (!got_pool) {
- message_dispatch();
- if ((time(NULL) - timeout_start) > MAX_WAIT) {
- fprintf(stderr,"tallocdump timeout\n");
- break;
- }
- }
- }
- break;
-
- case MSG_REQ_DEBUGLEVEL:
- if (!debuglevel_registered) {
- message_register(MSG_DEBUGLEVEL, debuglevel_function);
- debuglevel_registered = True;
- }
- got_level = False;
- retval = send_message(dest, MSG_REQ_DEBUGLEVEL, NULL, 0, True);
- if (retval) {
- timeout_start = time(NULL);
- while (!got_level) {
- message_dispatch();
- if ((time(NULL) - timeout_start) > MAX_WAIT) {
- fprintf(stderr,"debuglevel timeout\n");
- break;
- }
- }
- }
- break;
-
- /* Send a notification message to a printer */
-
- case MSG_PRINTER_NOTIFY2: {
- char *cmd;
-
- /* Read subcommand */
-
- if (!params || !params[0]) {
- fprintf(stderr, "Must specify subcommand:\n");
- fprintf(stderr, "\tqueuepause <printername>\n");
- fprintf(stderr, "\tqueueresume <printername>\n");
- fprintf(stderr, "\tjobpause <printername> <unix jobid>\n");
- fprintf(stderr, "\tjobresume <printername> <unix jobid>\n");
- fprintf(stderr, "\tjobdelete <printername> <unix jobid>\n");
- fprintf(stderr, "\tprinter <printername> <comment|port|driver> <new value>\n");
- return False;
- }
-
- cmd = params[0];
-
- check_notify_msgs = True;
-
- /* Pause a print queue */
-
- if (strequal(cmd, "queuepause")) {
-
- if (!params[1]) {
- fprintf(stderr, "queuepause command requires a printer name\n");
- return False;
- }
-
- //TODL: notify_printer_status_byname(params[1], PRINTER_STATUS_PAUSED);
- break;
- }
-
- /* Resume a print queue */
-
- if (strequal(cmd, "queueresume")) {
-
- if (!params[1]) {
- fprintf(stderr, "queueresume command requires a printer name\n");
- return False;
- }
-
- //TODL: notify_printer_status_byname(params[1], PRINTER_STATUS_OK);
- break;
- }
-
- /* Pause a print job */
-
- if (strequal(cmd, "jobpause")) {
- int jobid;
-
- if (!params[1] || !params[2]) {
- fprintf(stderr, "jobpause command requires a printer name and a jobid\n");
- return False;
- }
-
- jobid = atoi(params[2]);
-
- //TODL: notify_job_status_byname(
- //TODL: params[1], jobid, JOB_STATUS_PAUSED,
- //TODL: SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
- break;
- }
-
- /* Resume a print job */
-
- if (strequal(cmd, "jobresume")) {
- int jobid;
-
- if (!params[1] || !params[2]) {
- fprintf(stderr, "jobresume command requires a printer name and a jobid\n");
- return False;
- }
-
- jobid = atoi(params[2]);
-
- //TODL: notify_job_status_byname(
- //TODL: params[1], jobid, JOB_STATUS_QUEUED,
- //TODL: SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
- break;
- }
-
- /* Delete a print job */
-
- if (strequal(cmd, "jobdelete")) {
- int jobid;
-
- if (!params[1] || !params[2]) {
- fprintf(stderr, "jobdelete command requires a printer name and a jobid\n");
- return False;
- }
-
- jobid = atoi(params[2]);
-
- //TODL: notify_job_status_byname(
- //TODL: params[1], jobid, JOB_STATUS_DELETING,
- //TODL: SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
-
- //TODL: notify_job_status_byname(
- //TODL: params[1], jobid, JOB_STATUS_DELETING|
- //TODL: JOB_STATUS_DELETED,
- //TODL: SPOOLSS_NOTIFY_MSG_UNIX_JOBID);
- }
-
- /* printer change notify */
-
- if (strequal(cmd, "printer")) {
- int attribute = -1;
-
- if (!params[1] || !params[2] || !params[3]) {
- fprintf(stderr, "printer command requires an and attribute name and value!\n");
- fprintf(stderr, "supported attributes:\n");
- fprintf(stderr, "\tcomment:\n");
- fprintf(stderr, "\tport:\n");
- fprintf(stderr, "\tdriver:\n");
- return False;
- }
- if ( strequal(params[2], "comment") )
- attribute = PRINTER_NOTIFY_COMMENT;
- else if ( strequal(params[2], "port") )
- attribute = PRINTER_NOTIFY_PORT_NAME;
- else if ( strequal(params[2], "driver") )
- attribute = PRINTER_NOTIFY_DRIVER_NAME;
-
- if ( attribute == -1 ) {
- fprintf(stderr, "bad attribute!\n");
- return False;
- }
-
- //TODL: notify_printer_byname( params[1], attribute, params[3]);
-
- break;
- }
-
- break;
- }
-
-
- case MSG_SMB_FORCE_TDIS:
- if (!strequal(dest, "smbd")) {
- fprintf(stderr,"close-share can only be sent to smbd\n");
- return(False);
- }
- if (!params || !params[0]) {
- fprintf(stderr, "close-share needs a share name or '*'\n");
- return (False);
- }
- retval = send_message(dest, MSG_SMB_FORCE_TDIS, params[0],
- strlen(params[0]) + 1, False);
- break;
-
- case MSG_SMB_SAM_SYNC:
- if (!strequal(dest, "smbd")) {
- fprintf(stderr, "samsync can only be sent to smbd\n");
- return False;
- }
-
- if (params) {
- fprintf(stderr, "samsync does not take any parameters\n");
- return False;
- }
-
- retval = send_message(dest, MSG_SMB_SAM_SYNC, NULL, 0, False);
-
- break;
-
- case MSG_SMB_SAM_REPL: {
- uint32 seqnum;
-
- if (!strequal(dest, "smbd")) {
- fprintf(stderr, "sam repl can only be sent to smbd\n");
- return False;
- }
-
- if (!params || !params[0]) {
- fprintf(stderr, "SAM_REPL needs a parameter\n");
- return False;
- }
-
- seqnum = atoi(params[0]);
-
- retval = send_message(dest, MSG_SMB_SAM_SYNC,
- (char *)&seqnum, sizeof(uint32), False);
-
- break;
- }
-
- case MSG_PING:
- if (!pong_registered) {
- message_register(MSG_PONG, pong_function);
- pong_registered = True;
- }
- if (!params || !params[0]) {
- fprintf(stderr,"MSG_PING needs a parameter\n");
- return(False);
- }
- n = atoi(params[0]);
- pong_count = 0;
- for (i=0;i<n;i++) {
- if (iparams > 1)
- retval = send_message(dest, MSG_PING, params[1], strlen(params[1]) + 1, True);
- else
- retval = send_message(dest, MSG_PING, NULL, 0, True);
- if (retval == False)
- return False;
- }
- wait_for_replies(MAX_WAIT, &n);
- if (n > 0) {
- fprintf(stderr,"PING timeout\n");
- }
- break;
-
- case MSG_REQ_POOL_USAGE:
- if (!send_message(dest, MSG_REQ_POOL_USAGE, NULL, 0, True))
- return False;
- wait_for_replies(MAX_WAIT, NULL);
-
- break;
-
- case MSG_REQ_DMALLOC_LOG_CHANGED:
- case MSG_REQ_DMALLOC_MARK:
- if (!send_message(dest, mtype, NULL, 0, False))
- return False;
- break;
-
- case MSG_SHUTDOWN:
- if (!send_message(dest, MSG_SHUTDOWN, NULL, 0, False))
- return False;
- break;
- case MSG_PRINTER_DRVUPGRADE:
- if (!send_message(dest, MSG_PRINTER_DRVUPGRADE, params[0], 0, False))
- return False;
- break;
- }
-
- /* check if we have any pending print notify messages */
-
- if ( check_notify_msgs )
- ;//TODO: print_notify_send_messages(0);
-
- return (True);
-}
-
- int main(int argc, char *argv[])
-{
- int opt;
- char temp[255];
- extern int optind;
- BOOL interactive = False;
-
- AllowDebugChange = False;
- DEBUGLEVEL = 0;
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- if (argc < 2) usage(True);
-
- while ((opt = getopt(argc, argv,"is:")) != EOF) {
- switch (opt) {
- case 'i':
- interactive = True;
- break;
- case 's':
- pstrcpy(dyn_CONFIGFILE, optarg);
- break;
- default:
- printf("Unknown option %c (%d)\n", (char)opt, opt);
- usage(True);
- }
- }
-
- lp_load(dyn_CONFIGFILE,False,False,False);
-
- if (!message_init()) exit(1);
-
- argc -= optind;
- argv = &argv[optind];
-
- register_all();
-
- if (!interactive) {
- if (argc < 2) usage(True);
- /* Need to invert sense of return code -- samba
- * routines mostly return True==1 for success, but
- * shell needs 0. */
- return ! do_command(argv[0],argv[1], argc-2, argc > 2 ? &argv[2] : 0);
- }
-
- while (True) {
- char *myargv[4];
- int myargc;
-
- printf("smbcontrol> ");
- if (!fgets(temp, sizeof(temp)-1, stdin)) break;
- myargc = 0;
- while ((myargc < 4) &&
- (myargv[myargc] = strtok(myargc?NULL:temp," \t\n"))) {
- myargc++;
- }
- if (!myargc) break;
- if (strequal(myargv[0],"q")) break;
- if (myargc < 2)
- usage(False);
- else if (!do_command(myargv[0],myargv[1],myargc-2,myargc > 2 ? &myargv[2] : 0))
- usage(False);
- }
- return(0);
-}
-
diff --git a/source4/utils/smbfilter.c b/source4/utils/smbfilter.c
deleted file mode 100644
index 9f240c31ca..0000000000
--- a/source4/utils/smbfilter.c
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- SMB filter/socket plugin
- Copyright (C) Andrew Tridgell 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"
-
-#define SECURITY_MASK 0
-#define SECURITY_SET 0
-
-/* this forces non-unicode */
-#define CAPABILITY_MASK 0
-#define CAPABILITY_SET 0
-
-/* and non-unicode for the client too */
-#define CLI_CAPABILITY_MASK 0
-#define CLI_CAPABILITY_SET 0
-
-static char *netbiosname;
-static char packet[BUFFER_SIZE];
-
-static void save_file(const char *fname, void *packet, size_t length)
-{
- int fd;
- fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (fd == -1) {
- perror(fname);
- return;
- }
- if (write(fd, packet, length) != length) {
- fprintf(stderr,"Failed to write %s\n", fname);
- return;
- }
- close(fd);
- printf("Wrote %d bytes to %s\n", length, fname);
-}
-
-static void filter_reply(char *buf)
-{
- int msg_type = CVAL(buf,0);
- int type = CVAL(buf,smb_com);
- unsigned x;
-
- if (msg_type) return;
-
- switch (type) {
-
- case SMBnegprot:
- /* force the security bits */
- x = CVAL(buf, smb_vwv1);
- x = (x | SECURITY_SET) & ~SECURITY_MASK;
- SCVAL(buf, smb_vwv1, x);
-
- /* force the capabilities */
- x = IVAL(buf,smb_vwv9+1);
- x = (x | CAPABILITY_SET) & ~CAPABILITY_MASK;
- SIVAL(buf, smb_vwv9+1, x);
- break;
-
- }
-}
-
-static void filter_request(char *buf)
-{
- int msg_type = CVAL(buf,0);
- int type = CVAL(buf,smb_com);
- pstring name1,name2;
- unsigned x;
-
- if (msg_type) {
- /* it's a netbios special */
- switch (msg_type) {
- case 0x81:
- /* session request */
- name_extract(buf,4,name1);
- name_extract(buf,4 + name_len(buf + 4),name2);
- d_printf("sesion_request: %s -> %s\n",
- name1, name2);
- if (netbiosname) {
- /* replace the destination netbios name */
- name_mangle(netbiosname, buf+4, 0x20);
- }
- }
- return;
- }
-
- /* it's an ordinary SMB request */
- switch (type) {
- case SMBsesssetupX:
- /* force the client capabilities */
- x = IVAL(buf,smb_vwv11);
- d_printf("SMBsesssetupX cap=0x%08x\n", x);
- d_printf("pwlen=%d/%d\n", SVAL(buf, smb_vwv7), SVAL(buf, smb_vwv8));
- system("mv sessionsetup.dat sessionsetup1.dat");
- save_file("sessionsetup.dat", smb_buf(buf), SVAL(buf, smb_vwv7));
- x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK;
- SIVAL(buf, smb_vwv11, x);
- break;
- }
-
-}
-
-
-static void filter_child(int c, struct in_addr dest_ip)
-{
- int s;
-
- /* we have a connection from a new client, now connect to the server */
- s = open_socket_out(SOCK_STREAM, &dest_ip, 445, LONG_CONNECT_TIMEOUT);
-
- if (s == -1) {
- d_printf("Unable to connect to %s\n", inet_ntoa(dest_ip));
- exit(1);
- }
-
- while (c != -1 || s != -1) {
- fd_set fds;
- int num;
-
- FD_ZERO(&fds);
- if (s != -1) FD_SET(s, &fds);
- if (c != -1) FD_SET(c, &fds);
-
- num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL);
- if (num <= 0) continue;
-
- if (c != -1 && FD_ISSET(c, &fds)) {
- if (!receive_smb(c, packet, 0)) {
- d_printf("client closed connection\n");
- exit(0);
- }
- filter_request(packet);
- if (!send_smb(s, packet)) {
- d_printf("server is dead\n");
- exit(1);
- }
- }
- if (s != -1 && FD_ISSET(s, &fds)) {
- if (!receive_smb(s, packet, 0)) {
- d_printf("server closed connection\n");
- exit(0);
- }
- filter_reply(packet);
- if (!send_smb(c, packet)) {
- d_printf("client is dead\n");
- exit(1);
- }
- }
- }
- d_printf("Connection closed\n");
- exit(0);
-}
-
-
-static void start_filter(char *desthost)
-{
- int s, c;
- struct in_addr dest_ip;
-
- CatchChild();
-
- /* start listening on port 445 locally */
- s = open_socket_in(SOCK_STREAM, 445, 0, 0, True);
-
- if (s == -1) {
- d_printf("bind failed\n");
- exit(1);
- }
-
- if (listen(s, 5) == -1) {
- d_printf("listen failed\n");
- }
-
- if (!resolve_name(desthost, &dest_ip, 0x20)) {
- d_printf("Unable to resolve host %s\n", desthost);
- exit(1);
- }
-
- while (1) {
- fd_set fds;
- int num;
- struct sockaddr addr;
- socklen_t in_addrlen = sizeof(addr);
-
- FD_ZERO(&fds);
- FD_SET(s, &fds);
-
- num = sys_select_intr(s+1,&fds,NULL,NULL,NULL);
- if (num > 0) {
- c = accept(s, &addr, &in_addrlen);
- if (c != -1) {
- if (fork() == 0) {
- close(s);
- filter_child(c, dest_ip);
- exit(0);
- } else {
- close(c);
- }
- }
- }
- }
-}
-
-
-int main(int argc, char *argv[])
-{
- char *desthost;
- pstring configfile;
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- pstrcpy(configfile,dyn_CONFIGFILE);
-
- if (argc < 2) {
- fprintf(stderr,"smbfilter <desthost> <netbiosname>\n");
- exit(1);
- }
-
- desthost = argv[1];
- if (argc > 2) {
- netbiosname = argv[2];
- }
-
- if (!lp_load(configfile,True,False,False)) {
- d_printf("Unable to load config file\n");
- }
-
- start_filter(desthost);
- return 0;
-}
diff --git a/source4/utils/smbgroupedit.c b/source4/utils/smbgroupedit.c
deleted file mode 100644
index edbee6cef2..0000000000
--- a/source4/utils/smbgroupedit.c
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * RPC Pipe client / server routines
- * Copyright (C) Andrew Tridgell 1992-2000,
- * Copyright (C) Jean François Micouleau 1998-2001.
- *
- * 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"
-
-/*
- * Next two lines needed for SunOS and don't
- * hurt anything else...
- */
-extern char *optarg;
-extern int optind;
-
-/*********************************************************
- Print command usage on stderr and die.
-**********************************************************/
-static void usage(void)
-{
- if (getuid() == 0) {
- printf("smbgroupedit options\n");
- } else {
- printf("You need to be root to use this tool!\n");
- }
- printf("options:\n");
- printf(" -a group create new group\n");
- printf(" -n group NT group name\n");
- printf(" -p privilege only local\n");
- printf(" -d description group description\n");
- printf(" -v list groups\n");
- printf(" -l long list (include details)\n");
- printf(" -s short list (default)\n");
- printf(" -c SID change group\n");
- printf(" -u unix group\n");
- printf(" -d description group description\n");
- printf(" -r rid RID of new group\n");
- printf(" -x group delete this group\n");
- printf("\n");
- printf(" -t[b|d|l] type: builtin, domain, local \n");
- exit(1);
-}
-
-/*********************************************************
- Figure out if the input was an NT group or a SID string.
- Return the SID.
-**********************************************************/
-static BOOL get_sid_from_input(DOM_SID *sid, char *input)
-{
- GROUP_MAP map;
-
- if (StrnCaseCmp( input, "S-", 2)) {
- /* Perhaps its the NT group name? */
- if (!pdb_getgrnam(&map, input, MAPPING_WITHOUT_PRIV)) {
- printf("NT Group %s doesn't exist in mapping DB\n", input);
- return False;
- } else {
- *sid = map.sid;
- }
- } else {
- if (!string_to_sid(sid, input)) {
- printf("converting sid %s from a string failed!\n", input);
- return False;
- }
- }
- return True;
-}
-
-/*********************************************************
- add a group.
-**********************************************************/
-static int addgroup(gid_t gid, enum SID_NAME_USE sid_type, char *ntgroup, char *ntcomment, char *privilege, uint32 rid)
-{
- PRIVILEGE_SET se_priv;
- DOM_SID sid;
- fstring string_sid;
- fstring comment;
-
- sid_copy(&sid, get_global_sam_sid());
- sid_append_rid(&sid, rid);
-
- sid_to_string(string_sid, &sid);
-
- if (ntcomment==NULL)
- fstrcpy(comment, "Local Unix group");
- else
- fstrcpy(comment, ntcomment);
-
- init_privilege(&se_priv);
- if (privilege!=NULL)
- convert_priv_from_text(&se_priv, privilege);
-
- if(!add_initial_entry(gid, string_sid, sid_type, ntgroup,
- comment, se_priv, PR_ACCESS_FROM_NETWORK)) {
- printf("adding entry for group %s failed!\n", ntgroup);
- free_privilege(&se_priv);
- return -1;
- }
-
- free_privilege(&se_priv);
- return 0;
-}
-
-/*********************************************************
- Change a group.
-**********************************************************/
-static int changegroup(char *sid_string, char *group, enum SID_NAME_USE sid_type, char *ntgroup, char *groupdesc, char *privilege)
-{
- DOM_SID sid;
- GROUP_MAP map;
- gid_t gid;
-
- if (!get_sid_from_input(&sid, sid_string)) {
- return -1;
- }
-
- /* Get the current mapping from the database */
- if(!pdb_getgrsid(&map, sid, MAPPING_WITH_PRIV)) {
- printf("This SID does not exist in the database\n");
- return -1;
- }
-
- /* If a new Unix group is specified, check and change */
- if (group!=NULL) {
- gid=nametogid(group);
- if (gid==-1) {
- printf("The UNIX group does not exist\n");
- return -1;
- } else
- map.gid=gid;
- }
-
- /*
- * Allow changing of group type only between domain and local
- * We disallow changing Builtin groups !!! (SID problem)
- */
- if (sid_type==SID_NAME_ALIAS
- || sid_type==SID_NAME_DOM_GRP
- || sid_type==SID_NAME_UNKNOWN) {
- if (map.sid_name_use==SID_NAME_ALIAS
- || map.sid_name_use==SID_NAME_DOM_GRP
- || map.sid_name_use==SID_NAME_UNKNOWN) {
- map.sid_name_use=sid_type;
- } else {
- printf("cannot change group type to builtin\n");
- };
- } else {
- printf("cannot change group type from builtin\n");
- }
-
- if (ntgroup!=NULL)
- fstrcpy(map.nt_name, ntgroup);
-
- /* Change comment if new one */
- if (groupdesc!=NULL)
- fstrcpy(map.comment, groupdesc);
-
- /* Change the privilege if new one */
- if (privilege!=NULL)
- convert_priv_from_text(&map.priv_set, privilege);
-
- if (!pdb_update_group_mapping_entry(&map)) {
- printf("Could not update group database\n");
- free_privilege(&map.priv_set);
- return -1;
- }
-
- free_privilege(&map.priv_set);
- return 0;
-}
-
-/*********************************************************
- Delete the group.
-**********************************************************/
-static int deletegroup(char *group)
-{
- DOM_SID sid;
-
- if (!get_sid_from_input(&sid, group)) {
- return -1;
- }
-
- if(!pdb_delete_group_mapping_entry(sid)) {
- printf("removing group %s from the mapping db failed!\n", group);
- return -1;
- }
-
- return 0;
-}
-
-/*********************************************************
- List the groups.
-**********************************************************/
-static int listgroup(enum SID_NAME_USE sid_type, BOOL long_list)
-{
- int entries,i;
- TALLOC_CTX *mem_ctx;
- GROUP_MAP *map=NULL;
- fstring string_sid;
- fstring group_type;
- fstring priv_text;
-
- if (!long_list)
- printf("NT group (SID) -> Unix group\n");
-
- if (!pdb_enum_group_mapping(sid_type, &map, &entries, ENUM_ALL_MAPPED, MAPPING_WITH_PRIV))
- return -1;
-
- mem_ctx = talloc_init("smbgroupedit talloc");
- if (!mem_ctx) return -1;
- for (i=0; i<entries; i++) {
- decode_sid_name_use(group_type, (map[i]).sid_name_use);
- sid_to_string(string_sid, &map[i].sid);
- convert_priv_to_text(&(map[i].priv_set), priv_text);
- free_privilege(&(map[i].priv_set));
-
- if (!long_list)
- printf("%s (%s) -> %s\n", map[i].nt_name, string_sid,
- gidtoname(mem_ctx, map[i].gid));
- else {
- printf("%s\n", map[i].nt_name);
- printf("\tSID : %s\n", string_sid);
- printf("\tUnix group: %s\n", gidtoname(mem_ctx, map[i].gid));
- printf("\tGroup type: %s\n", group_type);
- printf("\tComment : %s\n", map[i].comment);
- printf("\tPrivilege : %s\n\n", priv_text);
- }
- }
- talloc_destroy(mem_ctx);
-
- return 0;
-}
-
-/*********************************************************
- Start here.
-**********************************************************/
-int main (int argc, char **argv)
-{
- int ch;
- BOOL add_group = False;
- BOOL view_group = False;
- BOOL change_group = False;
- BOOL delete_group = False;
- BOOL nt_group = False;
- BOOL priv = False;
- BOOL group_type = False;
- BOOL long_list = False;
-
- char *group = NULL;
- char *sid = NULL;
- char *ntgroup = NULL;
- char *privilege = NULL;
- char *groupt = NULL;
- char *group_desc = NULL;
-
- enum SID_NAME_USE sid_type;
- uint32 rid = -1;
-
- setup_logging("groupedit", DEBUG_STDOUT);
-
- if (argc < 2) {
- usage();
- return 0;
- }
-
- if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n",
- dyn_CONFIGFILE);
- exit(1);
- }
-
- if (!init_names())
- exit(1);
-
- if(!initialize_password_db(True)) {
- fprintf(stderr, "Can't setup password database vectors.\n");
- exit(1);
- }
-
- if(get_global_sam_sid()==False) {
- fprintf(stderr, "Can not read machine SID\n");
- return 0;
- }
-
- while ((ch = getopt(argc, argv, "a:c:d:ln:p:r:st:u:vx:")) != EOF) {
- switch(ch) {
- case 'a':
- add_group = True;
- group=optarg;
- break;
- case 'c':
- change_group = True;
- sid=optarg;
- break;
- case 'd':
- group_desc=optarg;
- break;
- case 'l':
- long_list = True;
- break;
- case 'n':
- nt_group = True;
- ntgroup=optarg;
- break;
- case 'p':
- priv = True;
- privilege=optarg;
- break;
- case 'r':
- rid = atoi(optarg);
- break;
- case 's':
- long_list = False;
- break;
- case 't':
- group_type = True;
- groupt=optarg;
- break;
- case 'u':
- group=optarg;
- break;
- case 'v':
- view_group = True;
- break;
- case 'x':
- delete_group = True;
- group=optarg;
- break;
- /*default:
- usage();*/
- }
- }
-
-
- if (((add_group?1:0) + (view_group?1:0) + (change_group?1:0) + (delete_group?1:0)) > 1) {
- fprintf (stderr, "Incompatible options on command line!\n");
- usage();
- exit(1);
- }
-
- /* no option on command line -> list groups */
- if (((add_group?1:0) + (view_group?1:0) + (change_group?1:0) + (delete_group?1:0)) == 0)
- view_group = True;
-
-
- if (group_type==False)
- sid_type=SID_NAME_UNKNOWN;
- else {
- switch (groupt[0]) {
- case 'l':
- case 'L':
- sid_type=SID_NAME_ALIAS;
- break;
- case 'd':
- case 'D':
- sid_type=SID_NAME_DOM_GRP;
- break;
- case 'b':
- case 'B':
- sid_type=SID_NAME_WKN_GRP;
- break;
- default:
- sid_type=SID_NAME_UNKNOWN;
- break;
- }
- }
-
- if (add_group) {
- gid_t gid=nametogid(group);
- if (gid==-1) {
- printf("unix group %s doesn't exist!\n", group);
- return -1;
- }
-
- if (rid == -1) {
- rid = pdb_gid_to_group_rid(gid);
- }
- return addgroup(gid, sid_type, ntgroup?ntgroup:group,
- group_desc, privilege, rid);
- }
-
- if (view_group)
- return listgroup(sid_type, long_list);
-
- if (delete_group)
- return deletegroup(group);
-
- if (change_group) {
- return changegroup(sid, group, sid_type, ntgroup, group_desc, privilege);
- }
-
- usage();
-
- return 0;
-}
diff --git a/source4/utils/smbpasswd.c b/source4/utils/smbpasswd.c
deleted file mode 100644
index 743023afd7..0000000000
--- a/source4/utils/smbpasswd.c
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * Copyright (C) Jeremy Allison 1995-1998
- * Copyright (C) Tim Potter 2001
- *
- * 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"
-
-extern BOOL AllowDebugChange;
-
-/*
- * Next two lines needed for SunOS and don't
- * hurt anything else...
- */
-extern char *optarg;
-extern int optind;
-
-/* forced running in root-mode */
-static BOOL got_pass = False, got_username = False;
-static BOOL stdin_passwd_get = False;
-static fstring user_name, user_password;
-static char *new_passwd = NULL;
-static const char *remote_machine = NULL;
-
-static fstring ldap_secret;
-
-/*********************************************************
- Print command usage on stderr and die.
-**********************************************************/
-static void usage(void)
-{
- printf("When run by root:\n");
- printf(" smbpasswd [options] [username] [password]\n");
- printf("otherwise:\n");
- printf(" smbpasswd [options] [password]\n\n");
-
- printf("options:\n");
- printf(" -L local mode (must be first option)\n");
- printf(" -h print this usage message\n");
- printf(" -s use stdin for password prompt\n");
- printf(" -c smb.conf file Use the given path to the smb.conf file\n");
- printf(" -D LEVEL debug level\n");
- printf(" -r MACHINE remote machine\n");
- printf(" -U USER remote username\n");
-
- printf("extra options when run by root or in local mode:\n");
- printf(" -a add user\n");
- printf(" -d disable user\n");
- printf(" -e enable user\n");
- printf(" -i interdomain trust account\n");
- printf(" -m machine trust account\n");
- printf(" -n set no password\n");
- printf(" -w ldap admin password\n");
- printf(" -x delete user\n");
- printf(" -R ORDER name resolve order\n");
-
- exit(1);
-}
-
-static void set_line_buffering(FILE *f)
-{
- setvbuf(f, NULL, _IOLBF, 0);
-}
-
-/*******************************************************************
- Process command line options
- ******************************************************************/
-static int process_options(int argc, char **argv, int local_flags)
-{
- int ch;
- pstring configfile;
- pstrcpy(configfile, dyn_CONFIGFILE);
-
- local_flags |= LOCAL_SET_PASSWORD;
-
- ZERO_STRUCT(user_name);
- ZERO_STRUCT(user_password);
-
- user_name[0] = '\0';
-
- while ((ch = getopt(argc, argv, "c:axdehminjr:sw:R:D:U:L")) != EOF) {
- switch(ch) {
- case 'L':
- local_flags |= LOCAL_AM_ROOT;
- break;
- case 'c':
- pstrcpy(configfile,optarg);
- break;
- case 'a':
- local_flags |= LOCAL_ADD_USER;
- break;
- case 'x':
- local_flags |= LOCAL_DELETE_USER;
- local_flags &= ~LOCAL_SET_PASSWORD;
- break;
- case 'd':
- local_flags |= LOCAL_DISABLE_USER;
- local_flags &= ~LOCAL_SET_PASSWORD;
- break;
- case 'e':
- local_flags |= LOCAL_ENABLE_USER;
- local_flags &= ~LOCAL_SET_PASSWORD;
- break;
- case 'm':
- local_flags |= LOCAL_TRUST_ACCOUNT;
- break;
- case 'i':
- local_flags |= LOCAL_INTERDOM_ACCOUNT;
- break;
- case 'j':
- d_printf("See 'net join' for this functionality\n");
- exit(1);
- break;
- case 'n':
- local_flags |= LOCAL_SET_NO_PASSWORD;
- local_flags &= ~LOCAL_SET_PASSWORD;
- new_passwd = smb_xstrdup("NO PASSWORD");
- break;
- case 'r':
- remote_machine = optarg;
- break;
- case 's':
- set_line_buffering(stdin);
- set_line_buffering(stdout);
- set_line_buffering(stderr);
- stdin_passwd_get = True;
- break;
- case 'w':
- local_flags |= LOCAL_SET_LDAP_ADMIN_PW;
- fstrcpy(ldap_secret, optarg);
- break;
- case 'R':
- lp_set_name_resolve_order(optarg);
- break;
- case 'D':
- DEBUGLEVEL = atoi(optarg);
- break;
- case 'U': {
- char *lp;
-
- got_username = True;
- fstrcpy(user_name, optarg);
-
- if ((lp = strchr(user_name, '%'))) {
- *lp = 0;
- fstrcpy(user_password, lp + 1);
- got_pass = True;
- memset(strchr_m(optarg, '%') + 1, 'X',
- strlen(user_password));
- }
-
- break;
- }
- case 'h':
- default:
- usage();
- }
- }
-
- argc -= optind;
- argv += optind;
-
- switch(argc) {
- case 0:
- if (!got_username)
- fstrcpy(user_name, "");
- break;
- case 1:
- if (!(local_flags & LOCAL_AM_ROOT)) {
- new_passwd = argv[0];
- } else {
- if (got_username) {
- usage();
- } else {
- fstrcpy(user_name, argv[0]);
- }
- }
- break;
- case 2:
- if (!(local_flags & LOCAL_AM_ROOT) || got_username || got_pass) {
- usage();
- }
-
- fstrcpy(user_name, argv[0]);
- new_passwd = smb_xstrdup(argv[1]);
- break;
- default:
- usage();
- }
-
- if (!lp_load(configfile,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n",
- dyn_CONFIGFILE);
- exit(1);
- }
-
- return local_flags;
-}
-
-/*************************************************************
- Utility function to prompt for passwords from stdin. Each
- password entered must end with a newline.
-*************************************************************/
-static char *stdin_new_passwd(void)
-{
- static fstring new_pw;
- size_t len;
-
- ZERO_ARRAY(new_pw);
-
- /*
- * if no error is reported from fgets() and string at least contains
- * the newline that ends the password, then replace the newline with
- * a null terminator.
- */
- if ( fgets(new_pw, sizeof(new_pw), stdin) != NULL) {
- if ((len = strlen(new_pw)) > 0) {
- if(new_pw[len-1] == '\n')
- new_pw[len - 1] = 0;
- }
- }
- return(new_pw);
-}
-
-
-/*************************************************************
- Utility function to get passwords via tty or stdin
- Used if the '-s' option is set to silently get passwords
- to enable scripting.
-*************************************************************/
-static char *get_pass( const char *prompt, BOOL stdin_get)
-{
- char *p;
- if (stdin_get) {
- p = stdin_new_passwd();
- } else {
- p = getpass(prompt);
- }
- return smb_xstrdup(p);
-}
-
-/*************************************************************
- Utility function to prompt for new password.
-*************************************************************/
-static char *prompt_for_new_password(BOOL stdin_get)
-{
- char *p;
- fstring new_pw;
-
- ZERO_ARRAY(new_pw);
-
- p = get_pass("New SMB password:", stdin_get);
-
- fstrcpy(new_pw, p);
- SAFE_FREE(p);
-
- p = get_pass("Retype new SMB password:", stdin_get);
-
- if (strcmp(p, new_pw)) {
- fprintf(stderr, "Mismatch - password unchanged.\n");
- ZERO_ARRAY(new_pw);
- SAFE_FREE(p);
- return NULL;
- }
-
- return p;
-}
-
-
-/*************************************************************
- Change a password either locally or remotely.
-*************************************************************/
-
-static BOOL password_change(const char *remote_mach, char *username,
- char *old_passwd, char *new_pw, int local_flags)
-{
- BOOL ret;
- pstring err_str;
- pstring msg_str;
-
- if (remote_mach != NULL) {
- if (local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|
- LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) {
- /* these things can't be done remotely yet */
- return False;
- }
- ret = remote_password_change(remote_mach, username,
- old_passwd, new_pw, err_str, sizeof(err_str));
- if(*err_str)
- fprintf(stderr, err_str);
- return ret;
- }
-
- ret = local_password_change(username, local_flags, new_pw,
- err_str, sizeof(err_str), msg_str, sizeof(msg_str));
-
- if(*msg_str)
- printf(msg_str);
- if(*err_str)
- fprintf(stderr, err_str);
-
- return ret;
-}
-
-/*******************************************************************
- Store the LDAP admin password in secrets.tdb
- ******************************************************************/
-static BOOL store_ldap_admin_pw (char* pw)
-{
- if (!pw)
- return False;
-
- if (!secrets_init())
- return False;
-
- return secrets_store_ldap_pw(lp_ldap_admin_dn(), pw);
-}
-
-
-/*************************************************************
- Handle password changing for root.
-*************************************************************/
-
-static int process_root(int local_flags)
-{
- struct passwd *pwd;
- int result = 0;
- char *old_passwd = NULL;
-
- if (local_flags & LOCAL_SET_LDAP_ADMIN_PW)
- {
- printf("Setting stored password for \"%s\" in secrets.tdb\n",
- lp_ldap_admin_dn());
- if (!store_ldap_admin_pw(ldap_secret))
- DEBUG(0,("ERROR: Failed to store the ldap admin password!\n"));
- goto done;
- }
-
- /*
- * Ensure both add/delete user are not set
- * Ensure add/delete user and either remote machine or join domain are
- * not both set.
- */
- if(((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) == (LOCAL_ADD_USER|LOCAL_DELETE_USER)) ||
- ((local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER)) &&
- (remote_machine != NULL))) {
- usage();
- }
-
- /* Only load interfaces if we are doing network operations. */
-
- if (remote_machine) {
- load_interfaces();
- }
-
- if (!user_name[0] && (pwd = getpwuid_alloc(geteuid()))) {
- fstrcpy(user_name, pwd->pw_name);
- passwd_free(&pwd);
- }
-
- if (!user_name[0]) {
- fprintf(stderr,"You must specify a username\n");
- exit(1);
- }
-
- if (local_flags & LOCAL_TRUST_ACCOUNT) {
- /* add the $ automatically */
- static fstring buf;
-
- /*
- * Remove any trailing '$' before we
- * generate the initial machine password.
- */
-
- if (user_name[strlen(user_name)-1] == '$') {
- user_name[strlen(user_name)-1] = 0;
- }
-
- if (local_flags & LOCAL_ADD_USER) {
- SAFE_FREE(new_passwd);
- new_passwd = smb_xstrdup(user_name);
- strlower(new_passwd);
- }
-
- /*
- * Now ensure the username ends in '$' for
- * the machine add.
- */
-
- slprintf(buf, sizeof(buf)-1, "%s$", user_name);
- fstrcpy(user_name, buf);
- } else if (local_flags & LOCAL_INTERDOM_ACCOUNT) {
- static fstring buf;
-
- if (local_flags & LOCAL_ADD_USER) {
- /*
- * Prompt for trusting domain's account password
- */
- new_passwd = prompt_for_new_password(stdin_passwd_get);
- if(!new_passwd) {
- fprintf(stderr, "Unable to get newpassword.\n");
- exit(1);
- }
- }
-
- /* prepare uppercased and '$' terminated username */
- slprintf(buf, sizeof(buf) - 1, "%s$", user_name);
- fstrcpy(user_name, buf);
-
- } else {
-
- if (remote_machine != NULL) {
- old_passwd = get_pass("Old SMB password:",stdin_passwd_get);
- }
-
- if (!(local_flags & LOCAL_SET_PASSWORD)) {
-
- /*
- * If we are trying to enable a user, first we need to find out
- * if they are using a modern version of the smbpasswd file that
- * disables a user by just writing a flag into the file. If so
- * then we can re-enable a user without prompting for a new
- * password. If not (ie. they have a no stored password in the
- * smbpasswd file) then we need to prompt for a new password.
- */
-
- if(local_flags & LOCAL_ENABLE_USER) {
- SAM_ACCOUNT *sampass = NULL;
- BOOL ret;
-
- pdb_init_sam(&sampass);
- ret = pdb_getsampwnam(sampass, user_name);
- if((sampass != False) && (pdb_get_lanman_passwd(sampass) == NULL)) {
- local_flags |= LOCAL_SET_PASSWORD;
- }
- pdb_free_sam(&sampass);
- }
- }
-
- if(local_flags & LOCAL_SET_PASSWORD) {
- new_passwd = prompt_for_new_password(stdin_passwd_get);
-
- if(!new_passwd) {
- fprintf(stderr, "Unable to get new password.\n");
- exit(1);
- }
- }
- }
-
- if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) {
- fprintf(stderr,"Failed to modify password entry for user %s\n", user_name);
- result = 1;
- goto done;
- }
-
- if(remote_machine) {
- printf("Password changed for user %s on %s.\n", user_name, remote_machine );
- } else if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD|LOCAL_SET_PASSWORD))) {
- SAM_ACCOUNT *sampass = NULL;
- BOOL ret;
-
- pdb_init_sam(&sampass);
- ret = pdb_getsampwnam(sampass, user_name);
-
- printf("Password changed for user %s.", user_name );
- if( (ret != False) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) )
- printf(" User has disabled flag set.");
- if((ret != False) && (pdb_get_acct_ctrl(sampass) & ACB_PWNOTREQ) )
- printf(" User has no password flag set.");
- printf("\n");
- pdb_free_sam(&sampass);
- }
-
- done:
- SAFE_FREE(new_passwd);
- return result;
-}
-
-
-/*************************************************************
- Handle password changing for non-root.
-*************************************************************/
-
-static int process_nonroot(int local_flags)
-{
- struct passwd *pwd = NULL;
- int result = 0;
- char *old_pw = NULL;
- char *new_pw = NULL;
-
- if (local_flags & ~(LOCAL_AM_ROOT | LOCAL_SET_PASSWORD)) {
- /* Extra flags that we can't honor non-root */
- usage();
- }
-
- if (!user_name[0]) {
- pwd = getpwuid_alloc(getuid());
- if (pwd) {
- fstrcpy(user_name,pwd->pw_name);
- passwd_free(&pwd);
- } else {
- fprintf(stderr, "smbpasswd: you don't exist - go away\n");
- exit(1);
- }
- }
-
- /*
- * A non-root user is always setting a password
- * via a remote machine (even if that machine is
- * localhost).
- */
-
- load_interfaces(); /* Delayed from main() */
-
- if (remote_machine == NULL) {
- remote_machine = "127.0.0.1";
- }
-
- if (remote_machine != NULL) {
- old_pw = get_pass("Old SMB password:",stdin_passwd_get);
- }
-
- if (!new_passwd) {
- new_pw = prompt_for_new_password(stdin_passwd_get);
- }
- else
- new_pw = smb_xstrdup(new_passwd);
-
- if (!new_pw) {
- fprintf(stderr, "Unable to get new password.\n");
- exit(1);
- }
-
- if (!password_change(remote_machine, user_name, old_pw, new_pw, 0)) {
- fprintf(stderr,"Failed to change password for %s\n", user_name);
- result = 1;
- goto done;
- }
-
- printf("Password changed for user %s\n", user_name);
-
- done:
- SAFE_FREE(old_pw);
- SAFE_FREE(new_pw);
-
- return result;
-}
-
-
-
-/*********************************************************
- Start here.
-**********************************************************/
-int main(int argc, char **argv)
-{
- int local_flags = 0;
-
- AllowDebugChange = False;
-
-#if defined(HAVE_SET_AUTH_PARAMETERS)
- set_auth_parameters(argc, argv);
-#endif /* HAVE_SET_AUTH_PARAMETERS */
-
- if (getuid() == 0) {
- local_flags = LOCAL_AM_ROOT;
- }
-
- local_flags = process_options(argc, argv, local_flags);
-
- setup_logging("smbpasswd", DEBUG_STDOUT);
-
- /*
- * Set the machine NETBIOS name if not already
- * set from the config file.
- */
-
- if (!init_names())
- return 1;
-
- /* Check the effective uid - make sure we are not setuid */
- if (is_setuid_root()) {
- fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n");
- exit(1);
- }
-
- if (local_flags & LOCAL_AM_ROOT) {
- secrets_init();
- return process_root(local_flags);
- }
-
- return process_nonroot(local_flags);
-}
diff --git a/source4/utils/smbtree.c b/source4/utils/smbtree.c
deleted file mode 100644
index eeb7b318cb..0000000000
--- a/source4/utils/smbtree.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Network neighbourhood browser.
-
- Copyright (C) Tim Potter 2000
-
- 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"
-
-static BOOL use_bcast;
-
-struct user_auth_info {
- pstring username;
- pstring password;
- pstring workgroup;
-};
-
-/* How low can we go? */
-
-enum tree_level {LEV_WORKGROUP, LEV_SERVER, LEV_SHARE};
-static enum tree_level level = LEV_SHARE;
-
-static void usage(void)
-{
- printf(
-"Usage: smbtree [options]\n\
-\n\
-\t-d debuglevel set debug output level\n\
-\t-U username user to autheticate as\n\
-\t-W workgroup workgroup of user to authenticate as\n\
-\t-D list only domains (workgroups) of tree\n\
-\t-S list domains and servers of tree\n\
-\t-b use bcast instead of using the master browser\n\
-\n\
-The username can be of the form username%%password or\n\
-workgroup\\username%%password.\n\n\
-");
-}
-
-/* Holds a list of workgroups or servers */
-
-struct name_list {
- struct name_list *prev, *next;
- pstring name, comment;
- uint32 server_type;
-};
-
-static struct name_list *workgroups, *servers, *shares;
-
-static void free_name_list(struct name_list *list)
-{
- while(list)
- DLIST_REMOVE(list, list);
-}
-
-static void add_name(const char *machine_name, uint32 server_type,
- const char *comment, void *state)
-{
- struct name_list **name_list = (struct name_list **)state;
- struct name_list *new_name;
-
- new_name = (struct name_list *)malloc(sizeof(struct name_list));
-
- if (!new_name)
- return;
-
- ZERO_STRUCTP(new_name);
-
- pstrcpy(new_name->name, machine_name);
- pstrcpy(new_name->comment, comment);
- new_name->server_type = server_type;
-
- DLIST_ADD(*name_list, new_name);
-}
-
-/* Return a cli_state pointing at the IPC$ share for the given server */
-
-static struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip,
- struct user_auth_info *user_info)
-{
- struct cli_state *cli;
- char *myname;
- NTSTATUS nt_status;
-
- myname = get_myname();
-
- nt_status = cli_full_connection(&cli, myname, server, server_ip, 0, "IPC$", "IPC",
- user_info->username, lp_workgroup(), user_info->password,
- CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK, NULL);
-
- free(myname);
- if (NT_STATUS_IS_OK(nt_status)) {
- return cli;
- } else {
- return NULL;
- }
-}
-
-/* Return the IP address and workgroup of a master browser on the
- network. */
-
-static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip)
-{
- struct in_addr *ip_list;
- int i, count;
-
- /* Go looking for workgroups by broadcasting on the local network */
-
- if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) {
- return False;
- }
-
- for (i = 0; i < count; i++) {
- static fstring name;
-
- if (!name_status_find("*", 0, 0x1d, ip_list[i], name))
- continue;
-
- if (!find_master_ip(name, server_ip))
- continue;
-
- pstrcpy(workgroup, name);
-
- DEBUG(4, ("found master browser %s, %s\n",
- name, inet_ntoa(ip_list[i])));
-
- return True;
- }
-
- return False;
-}
-
-/****************************************************************************
- display tree of smb workgroups, servers and shares
-****************************************************************************/
-static BOOL get_workgroups(struct user_auth_info *user_info)
-{
- struct cli_state *cli;
- struct in_addr server_ip;
- pstring master_workgroup;
-
- /* Try to connect to a #1d name of our current workgroup. If that
- doesn't work broadcast for a master browser and then jump off
- that workgroup. */
-
- pstrcpy(master_workgroup, lp_workgroup());
-
- if (use_bcast || !find_master_ip(lp_workgroup(), &server_ip)) {
- DEBUG(4, ("Unable to find master browser for workgroup %s\n",
- master_workgroup));
- if (!find_master_ip_bcast(master_workgroup, &server_ip)) {
- DEBUG(4, ("Unable to find master browser by "
- "broadcast\n"));
- return False;
- }
- }
-
- if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
- return False;
-
- if (!cli_NetServerEnum(cli, master_workgroup,
- SV_TYPE_DOMAIN_ENUM, add_name, &workgroups))
- return False;
-
- return True;
-}
-
-/* Retrieve the list of servers for a given workgroup */
-
-static BOOL get_servers(char *workgroup, struct user_auth_info *user_info)
-{
- struct cli_state *cli;
- struct in_addr server_ip;
-
- /* Open an IPC$ connection to the master browser for the workgroup */
-
- if (!find_master_ip(workgroup, &server_ip)) {
- DEBUG(4, ("Cannot find master browser for workgroup %s\n",
- workgroup));
- return False;
- }
-
- if (!(cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info)))
- return False;
-
- if (!cli_NetServerEnum(cli, workgroup, SV_TYPE_ALL, add_name,
- &servers))
- return False;
-
- return True;
-}
-
-static BOOL get_shares(char *server_name, struct user_auth_info *user_info)
-{
- struct cli_state *cli;
-
- if (!(cli = get_ipc_connect(server_name, NULL, user_info)))
- return False;
-
- if (!cli_RNetShareEnum(cli, add_name, &shares))
- return False;
-
- return True;
-}
-
-static BOOL print_tree(struct user_auth_info *user_info)
-{
- struct name_list *wg, *sv, *sh;
-
- /* List workgroups */
-
- if (!get_workgroups(user_info))
- return False;
-
- for (wg = workgroups; wg; wg = wg->next) {
-
- printf("%s\n", wg->name);
-
- /* List servers */
-
- free_name_list(servers);
- servers = NULL;
-
- if (level == LEV_WORKGROUP ||
- !get_servers(wg->name, user_info))
- continue;
-
- for (sv = servers; sv; sv = sv->next) {
-
- printf("\t\\\\%-15s\t\t%s\n",
- sv->name, sv->comment);
-
- /* List shares */
-
- free_name_list(shares);
- shares = NULL;
-
- if (level == LEV_SERVER ||
- !get_shares(sv->name, user_info))
- continue;
-
- for (sh = shares; sh; sh = sh->next) {
- printf("\t\t\\\\%s\\%-15s\t%s\n",
- sv->name, sh->name, sh->comment);
- }
- }
- }
-
- return True;
-}
-
-/****************************************************************************
- main program
-****************************************************************************/
- int main(int argc,char *argv[])
-{
- extern char *optarg;
- extern int optind;
- int opt;
- char *p;
- struct user_auth_info user_info;
- BOOL got_pass = False;
-
- /* Initialise samba stuff */
-
- setlinebuf(stdout);
-
- dbf = x_stderr;
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- lp_load(dyn_CONFIGFILE,True,False,False);
- load_interfaces();
-
- if (getenv("USER")) {
- pstrcpy(user_info.username, getenv("USER"));
-
- if ((p=strchr(user_info.username, '%'))) {
- *p = 0;
- pstrcpy(user_info.password, p+1);
- got_pass = True;
- memset(strchr(getenv("USER"), '%') + 1, 'X',
- strlen(user_info.password));
- }
- }
-
- pstrcpy(user_info.workgroup, lp_workgroup());
-
- /* Parse command line args */
-
- while ((opt = getopt(argc, argv, "U:hd:W:DSb")) != EOF) {
- switch (opt) {
- case 'U':
- pstrcpy(user_info.username,optarg);
- p = strchr(user_info.username,'%');
- if (p) {
- *p = 0;
- pstrcpy(user_info.password, p+1);
- got_pass = 1;
- }
- break;
-
- case 'b':
- use_bcast = True;
- break;
-
- case 'h':
- usage();
- exit(1);
-
- case 'd':
- DEBUGLEVEL = atoi(optarg);
- break;
-
- case 'W':
- pstrcpy(user_info.workgroup, optarg);
- break;
-
- case 'D':
- level = LEV_WORKGROUP;
- break;
-
- case 'S':
- level = LEV_SERVER;
- break;
-
- default:
- printf("Unknown option %c (%d)\n", (char)opt, opt);
- exit(1);
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc > 0) {
- usage();
- exit(1);
- }
-
- if (!got_pass) {
- char *pass = getpass("Password: ");
- if (pass) {
- pstrcpy(user_info.password, pass);
- }
- got_pass = True;
- }
-
- /* Now do our stuff */
-
- if (!print_tree(&user_info))
- return 1;
-
- return 0;
-}
diff --git a/source4/utils/smbw_sample.c b/source4/utils/smbw_sample.c
deleted file mode 100644
index 5cd792df7a..0000000000
--- a/source4/utils/smbw_sample.c
+++ /dev/null
@@ -1,94 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-static void usage(void)
-{
- printf("
-smbw_sample - a sample program that uses smbw
-
-smbw_sample <options> path
-
- options:
- -W workgroup
- -l logfile
- -P prefix
- -d debuglevel
- -U username%%password
- -R resolve order
-
-note that path must start with /smb/
-");
-}
-
-int main(int argc, char *argv[])
-{
- DIR *dir;
- struct dirent *dent;
- int opt;
- char *p;
- extern char *optarg;
- extern int optind;
- char *path;
-
- lp_load(dyn_CONFIGFILE,1,0,0);
- smbw_setup_shared();
-
- while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
- switch (opt) {
- case 'W':
- smbw_setshared("WORKGROUP", optarg);
- break;
- case 'l':
- smbw_setshared("LOGFILE", optarg);
- break;
- case 'P':
- smbw_setshared("PREFIX", optarg);
- break;
- case 'd':
- smbw_setshared("DEBUG", optarg);
- break;
- case 'U':
- p = strchr_m(optarg,'%');
- if (p) {
- *p=0;
- smbw_setshared("PASSWORD",p+1);
- }
- smbw_setshared("USER", optarg);
- break;
- case 'R':
- smbw_setshared("RESOLVE_ORDER",optarg);
- break;
- case 'h':
- default:
- usage();
- exit(1);
- }
- }
-
- argc -= optind;
- argv += optind;
-
- if (argc < 1) {
- usage();
- exit(1);
- }
-
- path = argv[0];
-
- smbw_init();
-
- dir = smbw_opendir(path);
- if (!dir) {
- printf("failed to open %s\n", path);
- exit(1);
- }
-
- while ((dent = smbw_readdir(dir))) {
- printf("%s\n", dent->d_name);
- }
- smbw_closedir(dir);
- return 0;
-}
diff --git a/source4/utils/status.c b/source4/utils/status.c
deleted file mode 100644
index 71a5f78db8..0000000000
--- a/source4/utils/status.c
+++ /dev/null
@@ -1,665 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- status reporting
- Copyright (C) Andrew Tridgell 1994-1998
-
- 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.
-
- Revision History:
-
- 12 aug 96: Erik.Devriendt@te6.siemens.be
- added support for shared memory implementation of share mode locking
-
- 21-Jul-1998: rsharpe@ns.aus.com (Richard Sharpe)
- Added -L (locks only) -S (shares only) flags and code
-
-*/
-
-/*
- * This program reports current SMB connections
- */
-
-#include "includes.h"
-
-static pstring Ucrit_username = ""; /* added by OH */
-static pid_t Ucrit_pid[100]; /* Ugly !!! */ /* added by OH */
-static int Ucrit_MaxPid=0; /* added by OH */
-static unsigned int Ucrit_IsActive = 0; /* added by OH */
-static int verbose, brief;
-static int shares_only = 0; /* Added by RJS */
-static int locks_only = 0; /* Added by RJS */
-static BOOL processes_only=False;
-static int show_brl;
-
-/* we need these because we link to locking*.o */
- void become_root(void) {}
- void unbecome_root(void) {}
-
-
-/* added by OH */
-static void Ucrit_addUsername(const char *username)
-{
- pstrcpy(Ucrit_username, username);
- if(strlen(Ucrit_username) > 0)
- Ucrit_IsActive = 1;
-}
-
-static unsigned int Ucrit_checkUsername(const char *username)
-{
- if ( !Ucrit_IsActive) return 1;
- if (strcmp(Ucrit_username,username) ==0) return 1;
- return 0;
-}
-
-static unsigned int Ucrit_checkPid(pid_t pid)
-{
- int i;
- if ( !Ucrit_IsActive) return 1;
- for (i=0;i<Ucrit_MaxPid;i++)
- if( pid == Ucrit_pid[i] ) return 1;
- return 0;
-}
-
-
-static void print_share_mode(share_mode_entry *e, char *fname)
-{
- static int count;
- if (count==0) {
- d_printf("Locked files:\n");
- d_printf("Pid DenyMode Access R/W Oplock Name\n");
- d_printf("--------------------------------------------------------------\n");
- }
- count++;
-
- if (Ucrit_checkPid(e->pid)) {
- d_printf("%-5d ",(int)e->pid);
- switch (GET_DENY_MODE(e->share_mode)) {
- case DENY_NONE: d_printf("DENY_NONE "); break;
- case DENY_ALL: d_printf("DENY_ALL "); break;
- case DENY_DOS: d_printf("DENY_DOS "); break;
- case DENY_READ: d_printf("DENY_READ "); break;
- case DENY_WRITE:printf("DENY_WRITE "); break;
- case DENY_FCB: d_printf("DENY_FCB "); break;
- }
- d_printf("0x%-8x ",(unsigned int)e->desired_access);
- switch (e->share_mode&0xF) {
- case 0: d_printf("RDONLY "); break;
- case 1: d_printf("WRONLY "); break;
- case 2: d_printf("RDWR "); break;
- }
-
- if((e->op_type &
- (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
- (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
- d_printf("EXCLUSIVE+BATCH ");
- else if (e->op_type & EXCLUSIVE_OPLOCK)
- d_printf("EXCLUSIVE ");
- else if (e->op_type & BATCH_OPLOCK)
- d_printf("BATCH ");
- else if (e->op_type & LEVEL_II_OPLOCK)
- d_printf("LEVEL_II ");
- else
- d_printf("NONE ");
-
- d_printf(" %s %s",fname,
- asctime(localtime((time_t *)&e->time.tv_sec)));
- }
-}
-
-static void print_brl(SMB_DEV_T dev, SMB_INO_T ino, int pid,
- enum brl_type lock_type,
- br_off start, br_off size)
-{
- static int count;
- if (count==0) {
- d_printf("Byte range locks:\n");
- d_printf(" Pid dev:inode R/W start size\n");
- d_printf("------------------------------------------------\n");
- }
- count++;
-
- d_printf("%6d %05x:%05x %s %9.0f %9.0f\n",
- (int)pid, (int)dev, (int)ino,
- lock_type==READ_LOCK?"R":"W",
- (double)start, (double)size);
-}
-
-
-/*******************************************************************
- dump the elements of the profile structure
- ******************************************************************/
-static int profile_dump(void)
-{
-#ifdef WITH_PROFILE
- if (!profile_setup(True)) {
- fprintf(stderr,"Failed to initialise profile memory\n");
- return -1;
- }
-
- d_printf("smb_count: %u\n", profile_p->smb_count);
- d_printf("uid_changes: %u\n", profile_p->uid_changes);
- d_printf("************************ System Calls ****************************\n");
- d_printf("opendir_count: %u\n", profile_p->syscall_opendir_count);
- d_printf("opendir_time: %u\n", profile_p->syscall_opendir_time);
- d_printf("readdir_count: %u\n", profile_p->syscall_readdir_count);
- d_printf("readdir_time: %u\n", profile_p->syscall_readdir_time);
- d_printf("mkdir_count: %u\n", profile_p->syscall_mkdir_count);
- d_printf("mkdir_time: %u\n", profile_p->syscall_mkdir_time);
- d_printf("rmdir_count: %u\n", profile_p->syscall_rmdir_count);
- d_printf("rmdir_time: %u\n", profile_p->syscall_rmdir_time);
- d_printf("closedir_count: %u\n", profile_p->syscall_closedir_count);
- d_printf("closedir_time: %u\n", profile_p->syscall_closedir_time);
- d_printf("open_count: %u\n", profile_p->syscall_open_count);
- d_printf("open_time: %u\n", profile_p->syscall_open_time);
- d_printf("close_count: %u\n", profile_p->syscall_close_count);
- d_printf("close_time: %u\n", profile_p->syscall_close_time);
- d_printf("read_count: %u\n", profile_p->syscall_read_count);
- d_printf("read_time: %u\n", profile_p->syscall_read_time);
- d_printf("read_bytes: %u\n", profile_p->syscall_read_bytes);
- d_printf("write_count: %u\n", profile_p->syscall_write_count);
- d_printf("write_time: %u\n", profile_p->syscall_write_time);
- d_printf("write_bytes: %u\n", profile_p->syscall_write_bytes);
-#ifdef WITH_SENDFILE
- d_printf("sendfile_count: %u\n", profile_p->syscall_sendfile_count);
- d_printf("sendfile_time: %u\n", profile_p->syscall_sendfile_time);
- d_printf("sendfile_bytes: %u\n", profile_p->syscall_sendfile_bytes);
-#endif
- d_printf("lseek_count: %u\n", profile_p->syscall_lseek_count);
- d_printf("lseek_time: %u\n", profile_p->syscall_lseek_time);
- d_printf("rename_count: %u\n", profile_p->syscall_rename_count);
- d_printf("rename_time: %u\n", profile_p->syscall_rename_time);
- d_printf("fsync_count: %u\n", profile_p->syscall_fsync_count);
- d_printf("fsync_time: %u\n", profile_p->syscall_fsync_time);
- d_printf("stat_count: %u\n", profile_p->syscall_stat_count);
- d_printf("stat_time: %u\n", profile_p->syscall_stat_time);
- d_printf("fstat_count: %u\n", profile_p->syscall_fstat_count);
- d_printf("fstat_time: %u\n", profile_p->syscall_fstat_time);
- d_printf("lstat_count: %u\n", profile_p->syscall_lstat_count);
- d_printf("lstat_time: %u\n", profile_p->syscall_lstat_time);
- d_printf("unlink_count: %u\n", profile_p->syscall_unlink_count);
- d_printf("unlink_time: %u\n", profile_p->syscall_unlink_time);
- d_printf("chmod_count: %u\n", profile_p->syscall_chmod_count);
- d_printf("chmod_time: %u\n", profile_p->syscall_chmod_time);
- d_printf("fchmod_count: %u\n", profile_p->syscall_fchmod_count);
- d_printf("fchmod_time: %u\n", profile_p->syscall_fchmod_time);
- d_printf("chown_count: %u\n", profile_p->syscall_chown_count);
- d_printf("chown_time: %u\n", profile_p->syscall_chown_time);
- d_printf("fchown_count: %u\n", profile_p->syscall_fchown_count);
- d_printf("fchown_time: %u\n", profile_p->syscall_fchown_time);
- d_printf("chdir_count: %u\n", profile_p->syscall_chdir_count);
- d_printf("chdir_time: %u\n", profile_p->syscall_chdir_time);
- d_printf("getwd_count: %u\n", profile_p->syscall_getwd_count);
- d_printf("getwd_time: %u\n", profile_p->syscall_getwd_time);
- d_printf("utime_count: %u\n", profile_p->syscall_utime_count);
- d_printf("utime_time: %u\n", profile_p->syscall_utime_time);
- d_printf("ftruncate_count: %u\n", profile_p->syscall_ftruncate_count);
- d_printf("ftruncate_time: %u\n", profile_p->syscall_ftruncate_time);
- d_printf("fcntl_lock_count: %u\n", profile_p->syscall_fcntl_lock_count);
- d_printf("fcntl_lock_time: %u\n", profile_p->syscall_fcntl_lock_time);
- d_printf("readlink_count: %u\n", profile_p->syscall_readlink_count);
- d_printf("readlink_time: %u\n", profile_p->syscall_readlink_time);
- d_printf("symlink_count: %u\n", profile_p->syscall_symlink_count);
- d_printf("symlink_time: %u\n", profile_p->syscall_symlink_time);
- d_printf("************************ Statcache *******************************\n");
- d_printf("lookups: %u\n", profile_p->statcache_lookups);
- d_printf("misses: %u\n", profile_p->statcache_misses);
- d_printf("hits: %u\n", profile_p->statcache_hits);
- d_printf("************************ Writecache ******************************\n");
- d_printf("read_hits: %u\n", profile_p->writecache_read_hits);
- d_printf("abutted_writes: %u\n", profile_p->writecache_abutted_writes);
- d_printf("total_writes: %u\n", profile_p->writecache_total_writes);
- d_printf("non_oplock_writes: %u\n", profile_p->writecache_non_oplock_writes);
- d_printf("direct_writes: %u\n", profile_p->writecache_direct_writes);
- d_printf("init_writes: %u\n", profile_p->writecache_init_writes);
- d_printf("flushed_writes[SEEK]: %u\n", profile_p->writecache_flushed_writes[SEEK_FLUSH]);
- d_printf("flushed_writes[READ]: %u\n", profile_p->writecache_flushed_writes[READ_FLUSH]);
- d_printf("flushed_writes[WRITE]: %u\n", profile_p->writecache_flushed_writes[WRITE_FLUSH]);
- d_printf("flushed_writes[READRAW]: %u\n", profile_p->writecache_flushed_writes[READRAW_FLUSH]);
- d_printf("flushed_writes[OPLOCK_RELEASE]: %u\n", profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH]);
- d_printf("flushed_writes[CLOSE]: %u\n", profile_p->writecache_flushed_writes[CLOSE_FLUSH]);
- d_printf("flushed_writes[SYNC]: %u\n", profile_p->writecache_flushed_writes[SYNC_FLUSH]);
- d_printf("flushed_writes[SIZECHANGE]: %u\n", profile_p->writecache_flushed_writes[SIZECHANGE_FLUSH]);
- d_printf("num_perfect_writes: %u\n", profile_p->writecache_num_perfect_writes);
- d_printf("num_write_caches: %u\n", profile_p->writecache_num_write_caches);
- d_printf("allocated_write_caches: %u\n", profile_p->writecache_allocated_write_caches);
- d_printf("************************ SMB Calls *******************************\n");
- d_printf("mkdir_count: %u\n", profile_p->SMBmkdir_count);
- d_printf("mkdir_time: %u\n", profile_p->SMBmkdir_time);
- d_printf("rmdir_count: %u\n", profile_p->SMBrmdir_count);
- d_printf("rmdir_time: %u\n", profile_p->SMBrmdir_time);
- d_printf("open_count: %u\n", profile_p->SMBopen_count);
- d_printf("open_time: %u\n", profile_p->SMBopen_time);
- d_printf("create_count: %u\n", profile_p->SMBcreate_count);
- d_printf("create_time: %u\n", profile_p->SMBcreate_time);
- d_printf("close_count: %u\n", profile_p->SMBclose_count);
- d_printf("close_time: %u\n", profile_p->SMBclose_time);
- d_printf("flush_count: %u\n", profile_p->SMBflush_count);
- d_printf("flush_time: %u\n", profile_p->SMBflush_time);
- d_printf("unlink_count: %u\n", profile_p->SMBunlink_count);
- d_printf("unlink_time: %u\n", profile_p->SMBunlink_time);
- d_printf("mv_count: %u\n", profile_p->SMBmv_count);
- d_printf("mv_time: %u\n", profile_p->SMBmv_time);
- d_printf("getatr_count: %u\n", profile_p->SMBgetatr_count);
- d_printf("getatr_time: %u\n", profile_p->SMBgetatr_time);
- d_printf("setatr_count: %u\n", profile_p->SMBsetatr_count);
- d_printf("setatr_time: %u\n", profile_p->SMBsetatr_time);
- d_printf("read_count: %u\n", profile_p->SMBread_count);
- d_printf("read_time: %u\n", profile_p->SMBread_time);
- d_printf("write_count: %u\n", profile_p->SMBwrite_count);
- d_printf("write_time: %u\n", profile_p->SMBwrite_time);
- d_printf("lock_count: %u\n", profile_p->SMBlock_count);
- d_printf("lock_time: %u\n", profile_p->SMBlock_time);
- d_printf("unlock_count: %u\n", profile_p->SMBunlock_count);
- d_printf("unlock_time: %u\n", profile_p->SMBunlock_time);
- d_printf("ctemp_count: %u\n", profile_p->SMBctemp_count);
- d_printf("ctemp_time: %u\n", profile_p->SMBctemp_time);
- d_printf("mknew_count: %u\n", profile_p->SMBmknew_count);
- d_printf("mknew_time: %u\n", profile_p->SMBmknew_time);
- d_printf("chkpth_count: %u\n", profile_p->SMBchkpth_count);
- d_printf("chkpth_time: %u\n", profile_p->SMBchkpth_time);
- d_printf("exit_count: %u\n", profile_p->SMBexit_count);
- d_printf("exit_time: %u\n", profile_p->SMBexit_time);
- d_printf("lseek_count: %u\n", profile_p->SMBlseek_count);
- d_printf("lseek_time: %u\n", profile_p->SMBlseek_time);
- d_printf("lockread_count: %u\n", profile_p->SMBlockread_count);
- d_printf("lockread_time: %u\n", profile_p->SMBlockread_time);
- d_printf("writeunlock_count: %u\n", profile_p->SMBwriteunlock_count);
- d_printf("writeunlock_time: %u\n", profile_p->SMBwriteunlock_time);
- d_printf("readbraw_count: %u\n", profile_p->SMBreadbraw_count);
- d_printf("readbraw_time: %u\n", profile_p->SMBreadbraw_time);
- d_printf("readBmpx_count: %u\n", profile_p->SMBreadBmpx_count);
- d_printf("readBmpx_time: %u\n", profile_p->SMBreadBmpx_time);
- d_printf("readBs_count: %u\n", profile_p->SMBreadBs_count);
- d_printf("readBs_time: %u\n", profile_p->SMBreadBs_time);
- d_printf("writebraw_count: %u\n", profile_p->SMBwritebraw_count);
- d_printf("writebraw_time: %u\n", profile_p->SMBwritebraw_time);
- d_printf("writeBmpx_count: %u\n", profile_p->SMBwriteBmpx_count);
- d_printf("writeBmpx_time: %u\n", profile_p->SMBwriteBmpx_time);
- d_printf("writeBs_count: %u\n", profile_p->SMBwriteBs_count);
- d_printf("writeBs_time: %u\n", profile_p->SMBwriteBs_time);
- d_printf("writec_count: %u\n", profile_p->SMBwritec_count);
- d_printf("writec_time: %u\n", profile_p->SMBwritec_time);
- d_printf("setattrE_count: %u\n", profile_p->SMBsetattrE_count);
- d_printf("setattrE_time: %u\n", profile_p->SMBsetattrE_time);
- d_printf("getattrE_count: %u\n", profile_p->SMBgetattrE_count);
- d_printf("getattrE_time: %u\n", profile_p->SMBgetattrE_time);
- d_printf("lockingX_count: %u\n", profile_p->SMBlockingX_count);
- d_printf("lockingX_time: %u\n", profile_p->SMBlockingX_time);
- d_printf("trans_count: %u\n", profile_p->SMBtrans_count);
- d_printf("trans_time: %u\n", profile_p->SMBtrans_time);
- d_printf("transs_count: %u\n", profile_p->SMBtranss_count);
- d_printf("transs_time: %u\n", profile_p->SMBtranss_time);
- d_printf("ioctl_count: %u\n", profile_p->SMBioctl_count);
- d_printf("ioctl_time: %u\n", profile_p->SMBioctl_time);
- d_printf("ioctls_count: %u\n", profile_p->SMBioctls_count);
- d_printf("ioctls_time: %u\n", profile_p->SMBioctls_time);
- d_printf("copy_count: %u\n", profile_p->SMBcopy_count);
- d_printf("copy_time: %u\n", profile_p->SMBcopy_time);
- d_printf("move_count: %u\n", profile_p->SMBmove_count);
- d_printf("move_time: %u\n", profile_p->SMBmove_time);
- d_printf("echo_count: %u\n", profile_p->SMBecho_count);
- d_printf("echo_time: %u\n", profile_p->SMBecho_time);
- d_printf("writeclose_count: %u\n", profile_p->SMBwriteclose_count);
- d_printf("writeclose_time: %u\n", profile_p->SMBwriteclose_time);
- d_printf("openX_count: %u\n", profile_p->SMBopenX_count);
- d_printf("openX_time: %u\n", profile_p->SMBopenX_time);
- d_printf("readX_count: %u\n", profile_p->SMBreadX_count);
- d_printf("readX_time: %u\n", profile_p->SMBreadX_time);
- d_printf("writeX_count: %u\n", profile_p->SMBwriteX_count);
- d_printf("writeX_time: %u\n", profile_p->SMBwriteX_time);
- d_printf("trans2_count: %u\n", profile_p->SMBtrans2_count);
- d_printf("trans2_time: %u\n", profile_p->SMBtrans2_time);
- d_printf("transs2_count: %u\n", profile_p->SMBtranss2_count);
- d_printf("transs2_time: %u\n", profile_p->SMBtranss2_time);
- d_printf("findclose_count: %u\n", profile_p->SMBfindclose_count);
- d_printf("findclose_time: %u\n", profile_p->SMBfindclose_time);
- d_printf("findnclose_count: %u\n", profile_p->SMBfindnclose_count);
- d_printf("findnclose_time: %u\n", profile_p->SMBfindnclose_time);
- d_printf("tcon_count: %u\n", profile_p->SMBtcon_count);
- d_printf("tcon_time: %u\n", profile_p->SMBtcon_time);
- d_printf("tdis_count: %u\n", profile_p->SMBtdis_count);
- d_printf("tdis_time: %u\n", profile_p->SMBtdis_time);
- d_printf("negprot_count: %u\n", profile_p->SMBnegprot_count);
- d_printf("negprot_time: %u\n", profile_p->SMBnegprot_time);
- d_printf("sesssetupX_count: %u\n", profile_p->SMBsesssetupX_count);
- d_printf("sesssetupX_time: %u\n", profile_p->SMBsesssetupX_time);
- d_printf("ulogoffX_count: %u\n", profile_p->SMBulogoffX_count);
- d_printf("ulogoffX_time: %u\n", profile_p->SMBulogoffX_time);
- d_printf("tconX_count: %u\n", profile_p->SMBtconX_count);
- d_printf("tconX_time: %u\n", profile_p->SMBtconX_time);
- d_printf("dskattr_count: %u\n", profile_p->SMBdskattr_count);
- d_printf("dskattr_time: %u\n", profile_p->SMBdskattr_time);
- d_printf("search_count: %u\n", profile_p->SMBsearch_count);
- d_printf("search_time: %u\n", profile_p->SMBsearch_time);
- d_printf("ffirst_count: %u\n", profile_p->SMBffirst_count);
- d_printf("ffirst_time: %u\n", profile_p->SMBffirst_time);
- d_printf("funique_count: %u\n", profile_p->SMBfunique_count);
- d_printf("funique_time: %u\n", profile_p->SMBfunique_time);
- d_printf("fclose_count: %u\n", profile_p->SMBfclose_count);
- d_printf("fclose_time: %u\n", profile_p->SMBfclose_time);
- d_printf("nttrans_count: %u\n", profile_p->SMBnttrans_count);
- d_printf("nttrans_time: %u\n", profile_p->SMBnttrans_time);
- d_printf("nttranss_count: %u\n", profile_p->SMBnttranss_count);
- d_printf("nttranss_time: %u\n", profile_p->SMBnttranss_time);
- d_printf("ntcreateX_count: %u\n", profile_p->SMBntcreateX_count);
- d_printf("ntcreateX_time: %u\n", profile_p->SMBntcreateX_time);
- d_printf("ntcancel_count: %u\n", profile_p->SMBntcancel_count);
- d_printf("ntcancel_time: %u\n", profile_p->SMBntcancel_time);
- d_printf("splopen_count: %u\n", profile_p->SMBsplopen_count);
- d_printf("splopen_time: %u\n", profile_p->SMBsplopen_time);
- d_printf("splwr_count: %u\n", profile_p->SMBsplwr_count);
- d_printf("splwr_time: %u\n", profile_p->SMBsplwr_time);
- d_printf("splclose_count: %u\n", profile_p->SMBsplclose_count);
- d_printf("splclose_time: %u\n", profile_p->SMBsplclose_time);
- d_printf("splretq_count: %u\n", profile_p->SMBsplretq_count);
- d_printf("splretq_time: %u\n", profile_p->SMBsplretq_time);
- d_printf("sends_count: %u\n", profile_p->SMBsends_count);
- d_printf("sends_time: %u\n", profile_p->SMBsends_time);
- d_printf("sendb_count: %u\n", profile_p->SMBsendb_count);
- d_printf("sendb_time: %u\n", profile_p->SMBsendb_time);
- d_printf("fwdname_count: %u\n", profile_p->SMBfwdname_count);
- d_printf("fwdname_time: %u\n", profile_p->SMBfwdname_time);
- d_printf("cancelf_count: %u\n", profile_p->SMBcancelf_count);
- d_printf("cancelf_time: %u\n", profile_p->SMBcancelf_time);
- d_printf("getmac_count: %u\n", profile_p->SMBgetmac_count);
- d_printf("getmac_time: %u\n", profile_p->SMBgetmac_time);
- d_printf("sendstrt_count: %u\n", profile_p->SMBsendstrt_count);
- d_printf("sendstrt_time: %u\n", profile_p->SMBsendstrt_time);
- d_printf("sendend_count: %u\n", profile_p->SMBsendend_count);
- d_printf("sendend_time: %u\n", profile_p->SMBsendend_time);
- d_printf("sendtxt_count: %u\n", profile_p->SMBsendtxt_count);
- d_printf("sendtxt_time: %u\n", profile_p->SMBsendtxt_time);
- d_printf("invalid_count: %u\n", profile_p->SMBinvalid_count);
- d_printf("invalid_time: %u\n", profile_p->SMBinvalid_time);
- d_printf("************************ Pathworks Calls *************************\n");
- d_printf("setdir_count: %u\n", profile_p->pathworks_setdir_count);
- d_printf("setdir_time: %u\n", profile_p->pathworks_setdir_time);
- d_printf("************************ Trans2 Calls ****************************\n");
- d_printf("open_count: %u\n", profile_p->Trans2_open_count);
- d_printf("open_time: %u\n", profile_p->Trans2_open_time);
- d_printf("findfirst_count: %u\n", profile_p->Trans2_findfirst_count);
- d_printf("findfirst_time: %u\n", profile_p->Trans2_findfirst_time);
- d_printf("findnext_count: %u\n", profile_p->Trans2_findnext_count);
- d_printf("findnext_time: %u\n", profile_p->Trans2_findnext_time);
- d_printf("qfsinfo_count: %u\n", profile_p->Trans2_qfsinfo_count);
- d_printf("qfsinfo_time: %u\n", profile_p->Trans2_qfsinfo_time);
- d_printf("setfsinfo_count: %u\n", profile_p->Trans2_setfsinfo_count);
- d_printf("setfsinfo_time: %u\n", profile_p->Trans2_setfsinfo_time);
- d_printf("qpathinfo_count: %u\n", profile_p->Trans2_qpathinfo_count);
- d_printf("qpathinfo_time: %u\n", profile_p->Trans2_qpathinfo_time);
- d_printf("setpathinfo_count: %u\n", profile_p->Trans2_setpathinfo_count);
- d_printf("setpathinfo_time: %u\n", profile_p->Trans2_setpathinfo_time);
- d_printf("qfileinfo_count: %u\n", profile_p->Trans2_qfileinfo_count);
- d_printf("qfileinfo_time: %u\n", profile_p->Trans2_qfileinfo_time);
- d_printf("setfileinfo_count: %u\n", profile_p->Trans2_setfileinfo_count);
- d_printf("setfileinfo_time: %u\n", profile_p->Trans2_setfileinfo_time);
- d_printf("fsctl_count: %u\n", profile_p->Trans2_fsctl_count);
- d_printf("fsctl_time: %u\n", profile_p->Trans2_fsctl_time);
- d_printf("ioctl_count: %u\n", profile_p->Trans2_ioctl_count);
- d_printf("ioctl_time: %u\n", profile_p->Trans2_ioctl_time);
- d_printf("findnotifyfirst_count: %u\n", profile_p->Trans2_findnotifyfirst_count);
- d_printf("findnotifyfirst_time: %u\n", profile_p->Trans2_findnotifyfirst_time);
- d_printf("findnotifynext_count: %u\n", profile_p->Trans2_findnotifynext_count);
- d_printf("findnotifynext_time: %u\n", profile_p->Trans2_findnotifynext_time);
- d_printf("mkdir_count: %u\n", profile_p->Trans2_mkdir_count);
- d_printf("mkdir_time: %u\n", profile_p->Trans2_mkdir_time);
- d_printf("session_setup_count: %u\n", profile_p->Trans2_session_setup_count);
- d_printf("session_setup_time: %u\n", profile_p->Trans2_session_setup_time);
- d_printf("get_dfs_referral_count: %u\n", profile_p->Trans2_get_dfs_referral_count);
- d_printf("get_dfs_referral_time: %u\n", profile_p->Trans2_get_dfs_referral_time);
- d_printf("report_dfs_inconsistancy_count: %u\n", profile_p->Trans2_report_dfs_inconsistancy_count);
- d_printf("report_dfs_inconsistancy_time: %u\n", profile_p->Trans2_report_dfs_inconsistancy_time);
- d_printf("************************ NT Transact Calls ***********************\n");
- d_printf("create_count: %u\n", profile_p->NT_transact_create_count);
- d_printf("create_time: %u\n", profile_p->NT_transact_create_time);
- d_printf("ioctl_count: %u\n", profile_p->NT_transact_ioctl_count);
- d_printf("ioctl_time: %u\n", profile_p->NT_transact_ioctl_time);
- d_printf("set_security_desc_count: %u\n", profile_p->NT_transact_set_security_desc_count);
- d_printf("set_security_desc_time: %u\n", profile_p->NT_transact_set_security_desc_time);
- d_printf("notify_change_count: %u\n", profile_p->NT_transact_notify_change_count);
- d_printf("notify_change_time: %u\n", profile_p->NT_transact_notify_change_time);
- d_printf("rename_count: %u\n", profile_p->NT_transact_rename_count);
- d_printf("rename_time: %u\n", profile_p->NT_transact_rename_time);
- d_printf("query_security_desc_count: %u\n", profile_p->NT_transact_query_security_desc_count);
- d_printf("query_security_desc_time: %u\n", profile_p->NT_transact_query_security_desc_time);
- d_printf("************************ ACL Calls *******************************\n");
- d_printf("get_nt_acl_count: %u\n", profile_p->get_nt_acl_count);
- d_printf("get_nt_acl_time: %u\n", profile_p->get_nt_acl_time);
- d_printf("fget_nt_acl_count: %u\n", profile_p->fget_nt_acl_count);
- d_printf("fget_nt_acl_time: %u\n", profile_p->fget_nt_acl_time);
- d_printf("set_nt_acl_count: %u\n", profile_p->set_nt_acl_count);
- d_printf("set_nt_acl_time: %u\n", profile_p->set_nt_acl_time);
- d_printf("fset_nt_acl_count: %u\n", profile_p->fset_nt_acl_count);
- d_printf("fset_nt_acl_time: %u\n", profile_p->fset_nt_acl_time);
- d_printf("chmod_acl_count: %u\n", profile_p->chmod_acl_count);
- d_printf("chmod_acl_time: %u\n", profile_p->chmod_acl_time);
- d_printf("fchmod_acl_count: %u\n", profile_p->fchmod_acl_count);
- d_printf("fchmod_acl_time: %u\n", profile_p->fchmod_acl_time);
- d_printf("************************ NMBD Calls ****************************\n");
- d_printf("name_release_count: %u\n", profile_p->name_release_count);
- d_printf("name_release_time: %u\n", profile_p->name_release_time);
- d_printf("name_refresh_count: %u\n", profile_p->name_refresh_count);
- d_printf("name_refresh_time: %u\n", profile_p->name_refresh_time);
- d_printf("name_registration_count: %u\n", profile_p->name_registration_count);
- d_printf("name_registration_time: %u\n", profile_p->name_registration_time);
- d_printf("node_status_count: %u\n", profile_p->node_status_count);
- d_printf("node_status_time: %u\n", profile_p->node_status_time);
- d_printf("name_query_count: %u\n", profile_p->name_query_count);
- d_printf("name_query_time: %u\n", profile_p->name_query_time);
- d_printf("host_announce_count: %u\n", profile_p->host_announce_count);
- d_printf("host_announce_time: %u\n", profile_p->host_announce_time);
- d_printf("workgroup_announce_count: %u\n", profile_p->workgroup_announce_count);
- d_printf("workgroup_announce_time: %u\n", profile_p->workgroup_announce_time);
- d_printf("local_master_announce_count: %u\n", profile_p->local_master_announce_count);
- d_printf("local_master_announce_time: %u\n", profile_p->local_master_announce_time);
- d_printf("master_browser_announce_count: %u\n", profile_p->master_browser_announce_count);
- d_printf("master_browser_announce_time: %u\n", profile_p->master_browser_announce_time);
- d_printf("lm_host_announce_count: %u\n", profile_p->lm_host_announce_count);
- d_printf("lm_host_announce_time: %u\n", profile_p->lm_host_announce_time);
- d_printf("get_backup_list_count: %u\n", profile_p->get_backup_list_count);
- d_printf("get_backup_list_time: %u\n", profile_p->get_backup_list_time);
- d_printf("reset_browser_count: %u\n", profile_p->reset_browser_count);
- d_printf("reset_browser_time: %u\n", profile_p->reset_browser_time);
- d_printf("announce_request_count: %u\n", profile_p->announce_request_count);
- d_printf("announce_request_time: %u\n", profile_p->announce_request_time);
- d_printf("lm_announce_request_count: %u\n", profile_p->lm_announce_request_count);
- d_printf("lm_announce_request_time: %u\n", profile_p->lm_announce_request_time);
- d_printf("domain_logon_count: %u\n", profile_p->domain_logon_count);
- d_printf("domain_logon_time: %u\n", profile_p->domain_logon_time);
- d_printf("sync_browse_lists_count: %u\n", profile_p->sync_browse_lists_count);
- d_printf("sync_browse_lists_time: %u\n", profile_p->sync_browse_lists_time);
- d_printf("run_elections_count: %u\n", profile_p->run_elections_count);
- d_printf("run_elections_time: %u\n", profile_p->run_elections_time);
- d_printf("election_count: %u\n", profile_p->election_count);
- d_printf("election_time: %u\n", profile_p->election_time);
-#else /* WITH_PROFILE */
- fprintf(stderr, "Profile data unavailable\n");
-#endif /* WITH_PROFILE */
-
- return 0;
-}
-
-
-static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
-{
- struct connections_data crec;
-
- if (dbuf.dsize != sizeof(crec))
- return 0;
-
- memcpy(&crec, dbuf.dptr, sizeof(crec));
-
- if (crec.cnum == -1)
- return 0;
-
- if (!process_exists(crec.pid) || !Ucrit_checkUsername(uidtoname(crec.uid))) {
- return 0;
- }
-
- d_printf("%-10.10s %5d %-12s %s",
- crec.name,(int)crec.pid,
- crec.machine,
- asctime(localtime(&crec.start)));
-
- return 0;
-}
-
-static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
-{
- struct sessionid sessionid;
- TALLOC_CTX *mem_ctx;
-
- if (dbuf.dsize != sizeof(sessionid))
- return 0;
-
- memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
-
- if (!process_exists(sessionid.pid) || !Ucrit_checkUsername(uidtoname(sessionid.uid))) {
- return 0;
- }
-
- mem_ctx = talloc_init("smbgroupedit talloc");
- if (!mem_ctx) return -1;
- d_printf("%5d %-12s %-12s %-12s (%s)\n",
- (int)sessionid.pid, uidtoname(sessionid.uid),
- gidtoname(mem_ctx, sessionid.gid),
- sessionid.remote_machine, sessionid.hostname);
- talloc_destroy(mem_ctx);
- return 0;
-}
-
-
-
-
- int main(int argc, char *argv[])
-{
- int c;
- static int profile_only = 0;
- TDB_CONTEXT *tdb;
- poptContext pc;
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- {"processes", 'p', POPT_ARG_NONE, &processes_only, 'p', "Show processes only" },
- {"verbose", 'v', POPT_ARG_NONE, &verbose, 'v', "Be verbose" },
- {"locks", 'L', POPT_ARG_NONE, &locks_only, 'L', "Show locks only" },
- {"shares", 'S', POPT_ARG_NONE, &shares_only, 'S', "Show shares only" },
- {"user", 'u', POPT_ARG_STRING, 0, 'u', "Switch to user" },
- {"brief", 'b', POPT_ARG_NONE, &brief, 'b', "Be brief" },
-#ifdef WITH_PROFILE
- {"profile", 'P', POPT_ARG_NONE, &profile_only, 'P', "Do profiling" },
-#endif /* WITH_PROFILE */
- {"byterange", 'B', POPT_ARG_NONE, &show_brl, 'B', "Include byte range locks"},
- POPT_COMMON_SAMBA
- POPT_COMMON_CONNECTION
- POPT_COMMON_CREDENTIALS
- POPT_TABLEEND
- };
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- dbf = x_stderr;
-
- if (getuid() != geteuid()) {
- d_printf("smbstatus should not be run setuid\n");
- return(1);
- }
-
- pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
-
- while ((c = poptGetNextOpt(pc)) != EOF) {
- switch (c) {
- case 'u':
- Ucrit_addUsername(poptGetOptArg(pc));
- break;
- }
- }
-
- if (verbose) {
- d_printf("using configfile = %s\n", dyn_CONFIGFILE);
- }
-
- if (!lp_load(dyn_CONFIGFILE,False,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- return (-1);
- }
-
- if (profile_only) {
- return profile_dump();
- }
-
- tdb = tdb_open_log(lock_path("sessionid.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
- if (!tdb) {
- d_printf("sessionid.tdb not initialised\n");
- } else {
- if (locks_only) goto locks;
-
- d_printf("\nSamba version %s\n",SAMBA_VERSION);
- d_printf("PID Username Group Machine \n");
- d_printf("-------------------------------------------------------------------\n");
-
- tdb_traverse(tdb, traverse_sessionid, NULL);
- tdb_close(tdb);
- }
-
- tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
- if (!tdb) {
- d_printf("%s not initialised\n", lock_path("connections.tdb"));
- d_printf("This is normal if an SMB client has never connected to your server.\n");
- } else {
- if (verbose) {
- d_printf("Opened %s\n", lock_path("connections.tdb"));
- }
-
- if (brief)
- exit(0);
-
- d_printf("\nService pid machine Connected at\n");
- d_printf("-------------------------------------------------------\n");
-
- tdb_traverse(tdb, traverse_fn1, NULL);
- tdb_close(tdb);
- }
-
- locks:
- if (processes_only) exit(0);
-
- if (!shares_only) {
- int ret;
-
- if (!locking_init(1)) {
- d_printf("Can't initialise locking module - exiting\n");
- exit(1);
- }
-
- ret = share_mode_forall(print_share_mode);
-
- if (ret == 0) {
- d_printf("No locked files\n");
- } else if (ret == -1) {
- d_printf("locked file list truncated\n");
- }
-
- d_printf("\n");
-
- if (show_brl) {
- brl_forall(print_brl);
- }
-
- locking_end();
- }
-
- return (0);
-}
diff --git a/source4/utils/testparm.c b/source4/utils/testparm.c
deleted file mode 100644
index fdfb6cb426..0000000000
--- a/source4/utils/testparm.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Test validity of smb.conf
- Copyright (C) Karl Auer 1993, 1994-1998
-
- Extensively modified by Andrew Tridgell, 1995
- Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 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.
-*/
-
-/*
- * Testbed for loadparm.c/params.c
- *
- * This module simply loads a specified configuration file and
- * if successful, dumps it's contents to stdout. Note that the
- * operation is performed with DEBUGLEVEL at 3.
- *
- * Useful for a quick 'syntax check' of a configuration file.
- *
- */
-
-#include "includes.h"
-
-extern BOOL AllowDebugChange;
-
-/***********************************************
- Here we do a set of 'hard coded' checks for bad
- configuration settings.
-************************************************/
-
-static int do_global_checks(void)
-{
- int ret = 0;
- SMB_STRUCT_STAT st;
-
- if (lp_security() >= SEC_DOMAIN && !lp_encrypted_passwords()) {
- printf("ERROR: in 'security=domain' mode the 'encrypt passwords' parameter must always be set to 'true'.\n");
- ret = 1;
- }
-
- if (lp_wins_support() && lp_wins_server_list()) {
- printf("ERROR: both 'wins support = true' and 'wins server = <server list>' \
-cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
- ret = 1;
- }
-
- if (!directory_exist(lp_lockdir(), &st)) {
- printf("ERROR: lock directory %s does not exist\n",
- lp_lockdir());
- ret = 1;
- } else if ((st.st_mode & 0777) != 0755) {
- printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
- lp_lockdir());
- ret = 1;
- }
-
- if (!directory_exist(lp_piddir(), &st)) {
- printf("ERROR: pid directory %s does not exist\n",
- lp_piddir());
- ret = 1;
- }
-
- /*
- * Password server sanity checks.
- */
-
- if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !lp_passwordserver()) {
- pstring sec_setting;
- if(lp_security() == SEC_SERVER)
- pstrcpy(sec_setting, "server");
- else if(lp_security() == SEC_DOMAIN)
- pstrcpy(sec_setting, "domain");
-
- printf("ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
-to a valid password server.\n", sec_setting );
- ret = 1;
- }
-
-
- /*
- * Check 'hosts equiv' and 'use rhosts' compatibility with 'hostname lookup' value.
- */
-
- if(*lp_hosts_equiv() && !lp_hostname_lookups()) {
- printf("ERROR: The setting 'hosts equiv = %s' requires that 'hostname lookups = yes'.\n", lp_hosts_equiv());
- ret = 1;
- }
-
- /*
- * Password chat sanity checks.
- */
-
- if(lp_security() == SEC_USER && lp_unix_password_sync()) {
-
- /*
- * Check that we have a valid lp_passwd_program() if not using pam.
- */
-
-#ifdef WITH_PAM
- if (!lp_pam_password_change()) {
-#endif
-
- if(lp_passwd_program() == NULL) {
- printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd program' \
-parameter.\n" );
- ret = 1;
- } else {
- pstring passwd_prog;
- pstring truncated_prog;
- const char *p;
-
- pstrcpy( passwd_prog, lp_passwd_program());
- p = passwd_prog;
- *truncated_prog = '\0';
- next_token(&p, truncated_prog, NULL, sizeof(pstring));
-
- if(access(truncated_prog, F_OK) == -1) {
- printf("ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \
-cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
- ret = 1;
- }
- }
-
-#ifdef WITH_PAM
- }
-#endif
-
- if(lp_passwd_chat() == NULL) {
- printf("ERROR: the 'unix password sync' parameter is set and there is no valid 'passwd chat' \
-parameter.\n");
- ret = 1;
- }
-
- /*
- * Check that we have a valid script and that it hasn't
- * been written to expect the old password.
- */
-
- if(lp_encrypted_passwords()) {
- if(strstr( lp_passwd_chat(), "%o")!=NULL) {
- printf("ERROR: the 'passwd chat' script [%s] expects to use the old plaintext password \
-via the %%o substitution. With encrypted passwords this is not possible.\n", lp_passwd_chat() );
- ret = 1;
- }
- }
- }
-
- if (strlen(lp_winbind_separator()) != 1) {
- printf("ERROR: the 'winbind separator' parameter must be a single character.\n");
- ret = 1;
- }
-
- if (*lp_winbind_separator() == '+') {
- printf("'winbind separator = +' might cause problems with group membership.\n");
- }
-
- if (lp_algorithmic_rid_base() < BASE_RID) {
- /* Try to prevent admin foot-shooting, we can't put algorithmic
- rids below 1000, that's the 'well known RIDs' on NT */
- printf("'algorithmic rid base' must be equal to or above %lu\n", BASE_RID);
- }
-
- if (lp_algorithmic_rid_base() & 1) {
- printf("'algorithmic rid base' must be even.\n");
- }
-
-#ifndef HAVE_DLOPEN
- if (lp_preload_modules()) {
- printf("WARNING: 'preload modules = ' set while loading plugins not supported.\n");
- }
-#endif
-
- return ret;
-}
-
-int main(int argc, const char *argv[])
-{
- extern char *optarg;
- extern int optind;
- const char *config_file = dyn_CONFIGFILE;
- int s;
- static BOOL silent_mode = False;
- int ret = 0;
- int opt;
- poptContext pc;
- static const char *term_code = "";
- static char *new_local_machine = NULL;
- const char *cname;
- const char *caddr;
- static int show_defaults;
-
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"},
- {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"},
- {"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
- {"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters with encoding"},
- {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version},
- {0,0,0,0}
- };
-
- pc = poptGetContext(NULL, argc, argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
- poptSetOtherOptionHelp(pc, "[OPTION...] <config-file> [host-name] [host-ip]");
-
- while((opt = poptGetNextOpt(pc)) != -1);
-
- setup_logging(poptGetArg(pc), DEBUG_STDOUT);
-
- if (poptPeekArg(pc))
- config_file = poptGetArg(pc);
-
- cname = poptGetArg(pc);
- caddr = poptGetArg(pc);
-
- if (new_local_machine) {
- set_local_machine_name(new_local_machine);
- }
-
- dbf = x_stdout;
- DEBUGLEVEL = 2;
- AllowDebugChange = False;
-
- printf("Load smb config files from %s\n",config_file);
-
- if (!lp_load(config_file,False,True,False)) {
- printf("Error loading services.\n");
- return(1);
- }
-
- printf("Loaded services file OK.\n");
-
- ret = do_global_checks();
-
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s))
- if (strlen(lp_servicename(s)) > 8) {
- printf("WARNING: You have some share names that are longer than 8 chars\n");
- printf("These may give errors while browsing or may not be accessible\nto some older clients\n");
- break;
- }
- }
-
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s)) {
- const char **deny_list = lp_hostsdeny(s);
- const char **allow_list = lp_hostsallow(s);
- int i;
- if(deny_list) {
- for (i=0; deny_list[i]; i++) {
- char *hasstar = strchr_m(deny_list[i], '*');
- char *hasquery = strchr_m(deny_list[i], '?');
- if(hasstar || hasquery) {
- printf("Invalid character %c in hosts deny list (%s) for service %s.\n",
- hasstar ? *hasstar : *hasquery, deny_list[i], lp_servicename(s) );
- }
- }
- }
-
- if(allow_list) {
- for (i=0; allow_list[i]; i++) {
- char *hasstar = strchr_m(allow_list[i], '*');
- char *hasquery = strchr_m(allow_list[i], '?');
- if(hasstar || hasquery) {
- printf("Invalid character %c in hosts allow list (%s) for service %s.\n",
- hasstar ? *hasstar : *hasquery, allow_list[i], lp_servicename(s) );
- }
- }
- }
-
- if(lp_level2_oplocks(s) && !lp_oplocks(s)) {
- printf("Invalid combination of parameters for service %s. \
- Level II oplocks can only be set if oplocks are also set.\n",
- lp_servicename(s) );
- }
- }
- }
-
-
- if (!silent_mode) {
- printf("Server role: ");
- switch(lp_server_role()) {
- case ROLE_STANDALONE:
- printf("ROLE_STANDALONE\n");
- break;
- case ROLE_DOMAIN_MEMBER:
- printf("ROLE_DOMAIN_MEMBER\n");
- break;
- case ROLE_DOMAIN_BDC:
- printf("ROLE_DOMAIN_BDC\n");
- break;
- case ROLE_DOMAIN_PDC:
- printf("ROLE_DOMAIN_PDC\n");
- break;
- default:
- printf("Unknown -- internal error?\n");
- break;
- }
- }
-
- if (!cname) {
- if (!silent_mode) {
- printf("Press enter to see a dump of your service definitions\n");
- fflush(stdout);
- getc(stdin);
- }
- lp_dump(stdout, show_defaults, lp_numservices());
- }
-
- if(cname && caddr){
- /* this is totally ugly, a real `quick' hack */
- for (s=0;s<1000;s++) {
- if (VALID_SNUM(s)) {
- if (allow_access(lp_hostsdeny(s), lp_hostsallow(s), cname, caddr)) {
- printf("Allow connection from %s (%s) to %s\n",
- cname,caddr,lp_servicename(s));
- } else {
- printf("Deny connection from %s (%s) to %s\n",
- cname,caddr,lp_servicename(s));
- }
- }
- }
- }
- return(ret);
-}
diff --git a/source4/utils/testprns.c b/source4/utils/testprns.c
deleted file mode 100644
index 07c4498038..0000000000
--- a/source4/utils/testprns.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- test printer setup
- Copyright (C) Karl Auer 1993, 1994-1998
-
- 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.
-*/
-
-/*
- * Testbed for pcap.c
- *
- * This module simply checks a given printer name against the compiled-in
- * printcap file.
- *
- * The operation is performed with DEBUGLEVEL at 3.
- *
- * Useful for a quick check of a printcap file.
- *
- */
-
-#include "includes.h"
-
-int main(int argc, char *argv[])
-{
- const char *pszTemp;
-
- setup_logging(argv[0], DEBUG_STDOUT);
-
- if (argc < 2 || argc > 3)
- printf("Usage: testprns printername [printcapfile]\n");
- else
- {
- dbf = x_fopen("test.log", O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (dbf == NULL) {
- printf("Unable to open logfile.\n");
- } else {
- DEBUGLEVEL = 3;
- pszTemp = (argc < 3) ? PRINTCAP_NAME : argv[2];
- printf("Looking for printer %s in printcap file %s\n",
- argv[1], pszTemp);
- if (!pcap_printername_ok(argv[1], pszTemp))
- printf("Printer name %s is not valid.\n", argv[1]);
- else
- printf("Printer name %s is valid.\n", argv[1]);
- x_fclose(dbf);
- }
- }
- return (0);
-}