From 5a32a8491df9d81d54c3eb12e7b86abac7091bba Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 18 Feb 2003 05:08:09 +0000 Subject: We don't use mkproto stuff for the python extensions anymore. (This used to be commit 8d166ae093655a5a14a7478c7a84474b43e8ee97) --- source3/Makefile.in | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index c3b70f9986..bd41d9636c 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1067,35 +1067,6 @@ PYTHON_OBJS = $(LIB_OBJ) $(LIBSMB_OBJ) $(RPC_PARSE_OBJ) $(UBIQX_OBJ) \ $(PARAM_OBJ) $(LIBMSRPC_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) \ $(SECRETS_OBJ) $(KRBCLIENT_OBJ) -PY_SPOOLSS_PROTO_OBJ = python/py_spoolss.o \ - python/py_spoolss_printers.o python/py_spoolss_printers_conv.o\ - python/py_spoolss_forms.o python/py_spoolss_forms_conv.o \ - python/py_spoolss_ports.o python/py_spoolss_ports_conv.o \ - python/py_spoolss_drivers.o python/py_spoolss_drivers_conv.o \ - python/py_spoolss_jobs.o python/py_spoolss_jobs_conv.o \ - python/py_spoolss_printerdata.o - -PY_LSA_PROTO_OBJ = python/py_lsa.o - -PY_COMMON_PROTO_OBJ = python/py_common.c python/py_ntsec.c - -python_proto: python_spoolss_proto python_lsa_proto python_common_proto - -python_spoolss_proto: - @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ - -h _PY_SPOOLSS_PROTO_H python/py_spoolss_proto.h \ - $(PY_SPOOLSS_PROTO_OBJ) - -python_lsa_proto: - @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ - -h _PY_LSA_PROTO_H python/py_lsa_proto.h \ - $(PY_LSA_PROTO_OBJ) - -python_common_proto: - @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ - -h _PY_COMMON_PROTO_H python/py_common_proto.h \ - $(PY_COMMON_PROTO_OBJ) - python_ext: $(PYTHON_OBJS) @if test -z "$(PYTHON)"; then \ echo Use the option --with-python to configure python; \ -- cgit From 030beddfb3c5208256c08b3cd2620332113f6308 Mon Sep 17 00:00:00 2001 From: Rafal Szczesniak Date: Tue, 18 Feb 2003 14:59:21 +0000 Subject: Fix of two warnings. pull_ucs2_talloc function takes char** pointer, not (here explicitly casted) void** one. Rafal (This used to be commit e77c44efd95d42a8194f5c3d36c043f8e84dfd1d) --- source3/libads/ldap_printer.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source3') diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 87ea058896..f5cd4f2885 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -85,8 +85,7 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, return False; if (value->size && *((smb_ucs2_t *) value->data_p)) { - pull_ucs2_talloc(ctx, (void **) &str_value, - (const smb_ucs2_t *) value->data_p); + pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p); status = ads_mod_str(ctx, mods, value->valuename, str_value); return ADS_ERR_OK(status); } @@ -155,9 +154,8 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, cur_str = (smb_ucs2_t *) value->data_p; for (i=0; i < num_vals; i++) - cur_str += pull_ucs2_talloc(ctx, - (void **) &str_values[i], - cur_str); + cur_str += pull_ucs2_talloc(ctx, &str_values[i], + cur_str); status = ads_mod_strlist(ctx, mods, value->valuename, (const char **) str_values); -- cgit From c536b88b2b71c264a1e31ada51e463fee5cb949b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 18 Feb 2003 18:34:48 +0000 Subject: Use the new modules stuff to load dynrpc modules. Basically this means: - calling the initialization function in the module init_module() instead of rpc_pipe_init() - calling smb_load_module() to do the dlopen(), dlsym() and init_module() calls I'll merge this to 3.0, together with the smb_load_module() function. Discussed with Anthony. (This used to be commit 3757ed8df06ca2b306bef336bdb9c7671f5e6a65) --- source3/rpc_server/srv_dfs.c | 2 +- source3/rpc_server/srv_lsa.c | 2 +- source3/rpc_server/srv_netlog.c | 2 +- source3/rpc_server/srv_pipe.c | 31 ++++++------------------------- source3/rpc_server/srv_reg.c | 2 +- source3/rpc_server/srv_samr.c | 2 +- source3/rpc_server/srv_spoolss.c | 2 +- source3/rpc_server/srv_srvsvc.c | 2 +- source3/rpc_server/srv_wkssvc.c | 2 +- 9 files changed, 14 insertions(+), 33 deletions(-) (limited to 'source3') diff --git a/source3/rpc_server/srv_dfs.c b/source3/rpc_server/srv_dfs.c index f6e9ca3d56..14c1cb4088 100644 --- a/source3/rpc_server/srv_dfs.c +++ b/source3/rpc_server/srv_dfs.c @@ -159,7 +159,7 @@ static BOOL api_dfs_enum(pipes_struct *p) ********************************************************************/ #ifdef RPC_DFS_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_dfs_init(void) #endif diff --git a/source3/rpc_server/srv_lsa.c b/source3/rpc_server/srv_lsa.c index fad8f5641a..0e4039326b 100644 --- a/source3/rpc_server/srv_lsa.c +++ b/source3/rpc_server/srv_lsa.c @@ -772,7 +772,7 @@ static BOOL api_lsa_remove_acct_rights(pipes_struct *p) ***************************************************************************/ #ifdef RPC_LSA_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_lsa_init(void) #endif diff --git a/source3/rpc_server/srv_netlog.c b/source3/rpc_server/srv_netlog.c index f377d3952b..c9e4fc1b1f 100644 --- a/source3/rpc_server/srv_netlog.c +++ b/source3/rpc_server/srv_netlog.c @@ -322,7 +322,7 @@ static BOOL api_net_logon_ctrl(pipes_struct *p) ********************************************************************/ #ifdef RPC_NETLOG_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_net_init(void) #endif diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 50127005a1..0b8b7b229a 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -794,42 +794,23 @@ int rpc_pipe_register_commands(const char *clnt, const char *srv, const struct a /******************************************************************* Register commands to an RPC pipe *******************************************************************/ -int rpc_load_module(const char *module) +NTSTATUS rpc_load_module(const char *module) { -#ifdef HAVE_DLOPEN - void *handle; - int (*module_init)(void); pstring full_path; - char *error; + NTSTATUS status; pstrcpy(full_path, lib_path("rpc")); pstrcat(full_path, "/librpc_"); pstrcat(full_path, module); pstrcat(full_path, "."); pstrcat(full_path, shlib_ext()); - - handle = sys_dlopen(full_path, RTLD_LAZY); - if (!handle) { + + if (!NT_STATUS_IS_OK(status = smb_load_module(full_path))) { DEBUG(0, ("Could not load requested pipe %s as %s\n", module, full_path)); - DEBUG(0, (" Error: %s\n", dlerror())); - return 0; } - DEBUG(3, ("Module '%s' loaded\n", full_path)); - - module_init = sys_dlsym(handle, "rpc_pipe_init"); - if ((error = sys_dlerror()) != NULL) { - DEBUG(0, ("Error trying to resolve symbol 'rpc_pipe_init' in %s: %s\n", - full_path, error)); - return 0; - } - - return module_init(); -#else - DEBUG(0,("Attempting to load a dynamic RPC pipe when dlopen isn't available\n")); - return 0; -#endif + return status; } /******************************************************************* @@ -877,7 +858,7 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p) } } - if (!api_fd_commands[i].name && !rpc_load_module(p->name)) { + if (!api_fd_commands[i].name && !NT_STATUS_IS_OK(rpc_load_module(p->name))) { DEBUG(3,("api_pipe_bind_req: Unknown pipe name %s in bind request.\n", p->name )); if(!setup_bind_nak(p)) diff --git a/source3/rpc_server/srv_reg.c b/source3/rpc_server/srv_reg.c index 04960f8e3a..8fc1d42b2f 100644 --- a/source3/rpc_server/srv_reg.c +++ b/source3/rpc_server/srv_reg.c @@ -374,7 +374,7 @@ static BOOL api_reg_save_key(pipes_struct *p) ********************************************************************/ #ifdef RPC_REG_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_reg_init(void) #endif diff --git a/source3/rpc_server/srv_samr.c b/source3/rpc_server/srv_samr.c index 3a31ec82e1..b75195ceef 100644 --- a/source3/rpc_server/srv_samr.c +++ b/source3/rpc_server/srv_samr.c @@ -1444,7 +1444,7 @@ static BOOL api_samr_set_dom_info(pipes_struct *p) ********************************************************************/ #ifdef RPC_SAMR_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_samr_init(void) #endif diff --git a/source3/rpc_server/srv_spoolss.c b/source3/rpc_server/srv_spoolss.c index 5832ae876b..3023922a5b 100755 --- a/source3/rpc_server/srv_spoolss.c +++ b/source3/rpc_server/srv_spoolss.c @@ -1581,7 +1581,7 @@ static BOOL api_spoolss_replycloseprinter(pipes_struct *p) ********************************************************************/ #ifdef RPC_SPOOLSS_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_spoolss_init(void) #endif diff --git a/source3/rpc_server/srv_srvsvc.c b/source3/rpc_server/srv_srvsvc.c index 983c660965..7c5e317c87 100644 --- a/source3/rpc_server/srv_srvsvc.c +++ b/source3/rpc_server/srv_srvsvc.c @@ -527,7 +527,7 @@ static BOOL api_srv_net_file_set_secdesc(pipes_struct *p) ********************************************************************/ #ifdef RPC_SVC_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_srv_init(void) #endif diff --git a/source3/rpc_server/srv_wkssvc.c b/source3/rpc_server/srv_wkssvc.c index 1fed2cc6db..e0d662ea80 100644 --- a/source3/rpc_server/srv_wkssvc.c +++ b/source3/rpc_server/srv_wkssvc.c @@ -61,7 +61,7 @@ static BOOL api_wks_query_info(pipes_struct *p) ********************************************************************/ #ifdef RPC_WKS_DYNAMIC -int rpc_pipe_init(void) +int init_module(void) #else int rpc_wks_init(void) #endif -- cgit From 5eb7b6113b8d4b59de5177e8b1485dc0c3ae19db Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 18 Feb 2003 18:43:59 +0000 Subject: Add -V option (to print out version) to utilities where possible (pdbedit already has a -V option..) (This used to be commit 5de622968d95c1436dbd34edc8d0a9bbff68916b) --- source3/Makefile.in | 2 +- source3/nsswitch/wbinfo.c | 1 + source3/rpcclient/rpcclient.c | 1 + source3/rpcclient/samsync.c | 1 + source3/torture/samtest.c | 1 + source3/torture/vfstest.c | 1 + source3/utils/net.c | 1 + source3/utils/ntlm_auth.c | 1 + source3/utils/status.c | 1 + 9 files changed, 9 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index bd41d9636c..e04550cf21 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -597,7 +597,7 @@ WINBINDD_OBJ = \ $(PROFILE_OBJ) $(UNIGRP_OBJ) \ $(SECRETS_OBJ) $(LIBADS_OBJ) $(KRBCLIENT_OBJ) -WBINFO_OBJ = nsswitch/wbinfo.o libsmb/smbencrypt.o libsmb/smbdes.o +WBINFO_OBJ = nsswitch/wbinfo.o libsmb/smbencrypt.o libsmb/smbdes.o $(POPT_LIB_OBJ) WINBIND_NSS_OBJ = nsswitch/winbind_nss.o nsswitch/wb_common.o @WINBIND_NSS_EXTRA_OBJS@ diff --git a/source3/nsswitch/wbinfo.c b/source3/nsswitch/wbinfo.c index f03b0493de..68dc178bcd 100644 --- a/source3/nsswitch/wbinfo.c +++ b/source3/nsswitch/wbinfo.c @@ -711,6 +711,7 @@ int main(int argc, char **argv) { "set-auth-user", 'A', POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" }, { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL }, { "ping", 'p', POPT_ARG_NONE, 0, 'p', "'ping' winbindd to see if it is alive" }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { 0, 0, 0, 0 } }; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 81bb62486a..37ce597d4e 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -585,6 +585,7 @@ out_free: {"dest-ip", 'I', POPT_ARG_STRING, &opt_ipaddr, 'I', "Specify destination IP address", "IP"}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { NULL } }; diff --git a/source3/rpcclient/samsync.c b/source3/rpcclient/samsync.c index f941d70e5e..a4061d2a87 100644 --- a/source3/rpcclient/samsync.c +++ b/source3/rpcclient/samsync.c @@ -632,6 +632,7 @@ struct poptOption popt_common_interactive[] = { "Replicate SAM changes" }, { "serial", 0, POPT_ARG_INT, &serial, 0, "SAM serial number" }, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_auth_info }, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_interactive }, POPT_AUTOHELP diff --git a/source3/torture/samtest.c b/source3/torture/samtest.c index 17444c0757..a1ccec098b 100644 --- a/source3/torture/samtest.c +++ b/source3/torture/samtest.c @@ -369,6 +369,7 @@ int main(int argc, char *argv[]) {"command", 'e', POPT_ARG_STRING, &cmdstr, 'e', "Execute semicolon seperated cmds"}, {"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l', "Logfile to use instead of stdout"}, {"configfile", 'c', POPT_ARG_STRING, &config_file, 0,"use different configuration file",NULL}, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { 0, 0, 0, 0} }; diff --git a/source3/torture/vfstest.c b/source3/torture/vfstest.c index 78d22a07ac..fef189844b 100644 --- a/source3/torture/vfstest.c +++ b/source3/torture/vfstest.c @@ -495,6 +495,7 @@ int main(int argc, char *argv[]) {"command", 'c', POPT_ARG_STRING, &cmdstr, 0, "Execute specified list of commands" }, {"logfile", 'l', POPT_ARG_STRING, &opt_logfile, 'l', "Write output to specified logfile" }, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { 0, 0, 0, 0} }; diff --git a/source3/utils/net.c b/source3/utils/net.c index 33195375f5..ada0ed53e1 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -537,6 +537,7 @@ static struct functable net_func[] = { {"timeout", 't', POPT_ARG_INT, &opt_timeout}, {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass}, {"debuglevel", 'd', POPT_ARG_STRING, &debuglevel}, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { 0, 0, 0, 0} }; diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index 9e4318def3..b76308c55f 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -466,6 +466,7 @@ int main(int argc, const char **argv) { "password", 0, POPT_ARG_STRING, &password, OPT_PASSWORD, "User's plaintext password"}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { 0, 0, 0, 0 } }; diff --git a/source3/utils/status.c b/source3/utils/status.c index 094dc0ff1c..8014b133d9 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -560,6 +560,7 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo #endif /* WITH_PROFILE */ {"byterange", 'B', POPT_ARG_NONE, &show_brl, 'B', "Include byte range locks"}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, { 0, 0, 0, 0} }; -- cgit From 1d278baf06a0560b1e069a945b6db4af1c4f6f5e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 19 Feb 2003 00:13:23 +0000 Subject: Remove reference to obsolete samba-bugs address. (This used to be commit 8e5f2ac3ca0b4cfb910f38532efb63526f28b579) --- source3/change-log | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/change-log b/source3/change-log index 1f7798b541..71f5012484 100644 --- a/source3/change-log +++ b/source3/change-log @@ -2,7 +2,7 @@ SUPERCEDED Change Log for Samba ^^^^^^^^^^ Unless otherwise attributed, all changes were made by -Andrew.Tridgell@anu.edu.au. All bugs to samba-bugs@samba.org. +Andrew.Tridgell@anu.edu.au. NOTE: THIS LOG IS IN CHRONOLOGICAL ORDER -- cgit From a0913929ef6f1e34ff2654e8773c8bf45c6230af Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 00:27:38 +0000 Subject: base64_decode() with heimdal libs, so I've renamed it base64_decode_inplace(). (This used to be commit 8c69212eeb4a0ec144b960d76319fd4940b8c239) --- source3/lib/util_str.c | 2 +- source3/web/cgi.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 8fe04f0f58..cc4b6fe5c5 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1585,7 +1585,7 @@ DATA_BLOB base64_decode_data_blob(const char *s) /** * Decode a base64 string in-place - wrapper for the above **/ -void base64_decode(char *s) +void base64_decode_inplace(char *s) { DATA_BLOB decoded = base64_decode_data_blob(s); memcpy(s, decoded.data, decoded.length); diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 46f33789bf..8abc2f0bd5 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -306,7 +306,7 @@ static BOOL cgi_handle_authorization(char *line) } line += 6; while (line[0] == ' ') line++; - base64_decode(line); + base64_decode_inplace(line); if (!(p=strchr_m(line,':'))) { /* * Always give the same error so a cracker -- cgit From e354fd27cb05f9d6259ca480831e325d17cfefea Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 00:50:38 +0000 Subject: Add support for detecting method of listing encryption types (MIT v Heimdal) (This used to be commit 48dcf5b97f2d53617c41237e09369ec678ab65e9) --- source3/configure.in | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3') diff --git a/source3/configure.in b/source3/configure.in index 77553cf5b7..b90d99bf3d 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -2194,6 +2194,9 @@ fi AC_CHECK_LIB(krb5, krb5_auth_con_setkey, [AC_DEFINE(HAVE_KRB5_AUTH_CON_SETKEY,1,[Whether krb5_auth_con_setkey is available])]) AC_CHECK_LIB(krb5, krb5_auth_con_setuseruserkey, [AC_DEFINE(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY,1,[Whether krb5_auth_con_setuseruserkey is available])]) AC_CHECK_LIB(krb5, krb5_locate_kdc, [AC_DEFINE(HAVE_KRB5_LOCATE_KDC,1,[Whether krb5_locate_kdc is available])]) + AC_CHECK_LIB(krb5, krb5_get_permitted_enctypes, [AC_DEFINE(HAVE_KRB5_GET_PERMITTED_ENCTYPES,1,[Whether krb5_get_permitted_enctypes is available])]) + AC_CHECK_LIB(krb5, krb5_get_default_in_tkt_etypes, [AC_DEFINE(HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES,1,[Whether krb5_get_default_in_tkt_etypes is available])]) + AC_CHECK_LIB(krb5, krb5_free_ktypes, [AC_DEFINE(HAVE_KRB5_FREE_KTYPES,1,[Whether krb5_free_ktypes is available])]) AC_CACHE_CHECK([for addrtype in krb5_address],samba_cv_HAVE_ADDRTYPE_IN_KRB5_ADDRESS,[ AC_TRY_COMPILE([#include ], -- cgit From adfefcdcb6e9d8ea0458a11b6f684a5cf231c3ba Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 01:16:40 +0000 Subject: Try to get heimdal working with HEAD. - Provide generic functions for - get valid encryption types - free encryption types - Add encryption type parm to generic function create_kerberos_key_from_string() - Try to merge the two versions (between HEAD and SAMBA_3_0) of kerberos_verify.c I think this should work for both MIT and heimdal, in HEAD. If all goes smooth, I'll move it over to 3.0 soon... (This used to be commit 45e409fc8da9f26cf888e13d004392660d7c55d4) --- source3/include/includes.h | 5 +++-- source3/libads/kerberos_verify.c | 27 +++++++-------------------- source3/libsmb/clikrb5.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 26 deletions(-) (limited to 'source3') diff --git a/source3/include/includes.h b/source3/include/includes.h index 988913d16c..c5738f0a61 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1224,11 +1224,12 @@ krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_con /* Samba wrapper function for krb5 functionality. */ void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr); -int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key); +int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype); void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt); krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt); krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters); - +krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes); +void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); #endif /* HAVE_KRB5 */ #endif /* _INCLUDES_H */ diff --git a/source3/libads/kerberos_verify.c b/source3/libads/kerberos_verify.c index c1402b1370..17fecf60c8 100644 --- a/source3/libads/kerberos_verify.c +++ b/source3/libads/kerberos_verify.c @@ -36,8 +36,6 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, krb5_keytab keytab = NULL; krb5_data packet; krb5_ticket *tkt = NULL; - krb5_data salt; - krb5_encrypt_block eblock; int ret, i; krb5_keyblock * key; krb5_principal host_princ; @@ -92,17 +90,11 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, return NT_STATUS_LOGON_FAILURE; } - ret = krb5_principal2salt(context, host_princ, &salt); - if (ret) { - DEBUG(1,("krb5_principal2salt failed (%s)\n", error_message(ret))); - return NT_STATUS_LOGON_FAILURE; - } - if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) { return NT_STATUS_NO_MEMORY; } - if ((ret = krb5_get_permitted_enctypes(context, &enctypes))) { + if ((ret = get_kerberos_allowed_etypes(context, &enctypes))) { DEBUG(1,("krb5_get_permitted_enctypes failed (%s)\n", error_message(ret))); return NT_STATUS_LOGON_FAILURE; @@ -110,10 +102,7 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, /* we need to setup a auth context with each possible encoding type in turn */ for (i=0;enctypes[i];i++) { - krb5_use_enctype(context, &eblock, enctypes[i]); - - ret = krb5_string_to_key(context, &eblock, key, &password, &salt); - if (ret) { + if (create_kerberos_key_from_string(context, host_princ, &password, key, enctypes[i])) { continue; } @@ -124,7 +113,7 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, if (!(ret = krb5_rd_req(context, &auth_context, &packet, NULL, keytab, NULL, &tkt))) { - krb5_free_ktypes(context, enctypes); + free_kerberos_etypes(context, enctypes); auth_ok = True; break; } @@ -133,6 +122,7 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, if (!auth_ok) { DEBUG(3,("krb5_rd_req with auth failed (%s)\n", error_message(ret))); + SAFE_FREE(key); return NT_STATUS_LOGON_FAILURE; } @@ -140,11 +130,7 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, file_save("/tmp/ticket.dat", ticket->data, ticket->length); #endif - - if (tkt->enc_part2) { - *auth_data = data_blob(tkt->enc_part2->authorization_data[0]->contents, - tkt->enc_part2->authorization_data[0]->length); - } + get_auth_data_from_tkt(auth_data, tkt); #if 0 if (tkt->enc_part2) { @@ -154,7 +140,8 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, } #endif - if ((ret = krb5_unparse_name(context, tkt->enc_part2->client, principal))) { + if ((ret = krb5_unparse_name(context, get_principal_from_tkt(tkt), + principal))) { DEBUG(3,("krb5_unparse_name failed (%s)\n", error_message(ret))); return NT_STATUS_LOGON_FAILURE; diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index e380d80bcc..c13f663381 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -74,7 +74,8 @@ int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, - krb5_keyblock *key) + krb5_keyblock *key, + krb5_enctype enctype) { int ret; krb5_data salt; @@ -85,14 +86,15 @@ DEBUG(1,("krb5_principal2salt failed (%s)\n", error_message(ret))); return ret; } - krb5_use_enctype(context, &eblock, ENCTYPE_DES_CBC_MD5); + krb5_use_enctype(context, &eblock, enctype); return krb5_string_to_key(context, &eblock, key, password, &salt); } #elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT) int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, - krb5_keyblock *key) + krb5_keyblock *key, + krb5_enctype enctype) { int ret; krb5_salt salt; @@ -102,13 +104,41 @@ DEBUG(1,("krb5_get_pw_salt failed (%s)\n", error_message(ret))); return ret; } - return krb5_string_to_key_salt(context, ENCTYPE_DES_CBC_MD5, password->data, + return krb5_string_to_key_salt(context, enctype, password->data, salt, key); } #else __ERROR_XX_UNKNOWN_CREATE_KEY_FUNCTIONS #endif +#if defined(HAVE_KRB5_GET_PERMITTED_ENCTYPES) +krb5_error_code get_kerberos_allowed_etypes(krb5_context context, + krb5_enctype **enctypes) +{ + return krb5_get_permitted_enctypes(context, enctypes); +} +#elif defined(HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES) +krb5_error_code get_kerberos_allowed_etypes(krb5_context context, + krb5_enctype **enctypes) +{ + return krb5_get_default_in_tkt_etypes(context, enctypes); +} +#else + __ERROR_XX_UNKNOWN_GET_ENCTYPES_FUNCTIONS +#endif + +#if defined(HAVE_KRB5_FREE_KTYPES) +void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes) +{ + return krb5_free_ktypes(context, enctypes); +} +#else +void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes) +{ + return free(enctypes); +} +#endif + #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY) krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, -- cgit From e7b5d059c2af0ffb71e3d6b12a35a1dcd3295942 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Feb 2003 01:38:12 +0000 Subject: Bit of a hack job to prevent smbprn.XXX jobs appearing in the queue if the jobid is below the UNIX_JOB_START number. Jeremy. (This used to be commit e8a9bf67cbe5b3e33f99e6793fe4ec445d6e8819) --- source3/printing/printing.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'source3') diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 3bf992ad69..c9612ab3a9 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -579,11 +579,13 @@ static uint32 print_parse_jobid(char *fname) List a unix job in the print database. ****************************************************************************/ -static void print_unix_job(int snum, print_queue_struct *q) +static void print_unix_job(int snum, print_queue_struct *q, uint32 jobid) { - uint32 jobid = q->job + UNIX_JOB_START; struct printjob pj, *old_pj; + if (jobid == (uint32)-1) + jobid = q->job + UNIX_JOB_START; + /* Preserve the timestamp on an existing unix print job */ old_pj = print_job_find(snum, jobid); @@ -597,11 +599,14 @@ static void print_unix_job(int snum, print_queue_struct *q) pj.status = q->status; pj.size = q->size; pj.spooled = True; - pj.smbjob = False; - fstrcpy(pj.filename, ""); - fstrcpy(pj.jobname, q->fs_file); - fstrcpy(pj.user, q->fs_user); - fstrcpy(pj.queuename, lp_const_servicename(snum)); + pj.smbjob = (old_pj != NULL ? True : False); + fstrcpy(pj.filename, old_pj ? old_pj->filename : ""); + if (jobid < UNIX_JOB_START) + fstrcpy(pj.jobname, old_pj ? old_pj->jobname : "Remote Downlevel Document"); + else + fstrcpy(pj.jobname, old_pj ? old_pj->jobname : q->fs_file); + fstrcpy(pj.user, old_pj ? old_pj->user : q->fs_user); + fstrcpy(pj.queuename, old_pj ? old_pj->queuename : lp_const_servicename(snum)); pjob_store(snum, jobid, &pj); } @@ -879,7 +884,7 @@ static void print_queue_update(int snum) if (jobid == (uint32)-1) { /* assume its a unix print job */ - print_unix_job(snum, &queue[i]); + print_unix_job(snum, &queue[i], jobid); continue; } @@ -889,7 +894,7 @@ static void print_queue_update(int snum) /* err, somethings wrong. Probably smbd was restarted with jobs in the queue. All we can do is treat them like unix jobs. Pity. */ - print_unix_job(snum, &queue[i]); + print_unix_job(snum, &queue[i], jobid); continue; } -- cgit From b63edf9a28cf81536d45fbbe8021683262ff07a2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Feb 2003 02:34:33 +0000 Subject: Fix from Corny.Bondad@hp.com for missing if (setting_acls) on default perms. Jeremy. (This used to be commit ac96fa173cc3bd1c3226634154d6f99e4034179f) --- source3/smbd/posix_acls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c index 2739f73b0a..a40fb4042f 100644 --- a/source3/smbd/posix_acls.c +++ b/source3/smbd/posix_acls.c @@ -699,11 +699,11 @@ static BOOL ensure_canon_entry_valid(canon_ace **pp_ace, pace->unix_ug.world = -1; pace->trustee = global_sid_World; pace->attr = ALLOW_ACE; - if (setting_acl) + if (setting_acl) { pace->perms = 0; - else + apply_default_perms(fsp, pace, S_IROTH); + } else pace->perms = unix_perms_to_acl_perms(pst->st_mode, S_IROTH, S_IWOTH, S_IXOTH); - apply_default_perms(fsp, pace, S_IROTH); DLIST_ADD(*pp_ace, pace); } -- cgit From 3b541bdcfe14d30d961a5de20d382af179c381ee Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 03:19:30 +0000 Subject: Get non-krb systems to compile. How the heck do I keep something from being sucked into proto.h? (This used to be commit 7e84497882df5bf933ab7ae7fe9af3728393202c) --- source3/include/includes.h | 2 +- source3/libsmb/clikrb5.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'source3') diff --git a/source3/include/includes.h b/source3/include/includes.h index c5738f0a61..bb78ae0780 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1229,7 +1229,7 @@ void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt); krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt); krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters); krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes); -void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); +krb5_error_code free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); #endif /* HAVE_KRB5 */ #endif /* _INCLUDES_H */ diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index c13f663381..2e07dfdb66 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -127,17 +127,18 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, __ERROR_XX_UNKNOWN_GET_ENCTYPES_FUNCTIONS #endif -#if defined(HAVE_KRB5_FREE_KTYPES) -void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes) + /* the following is defined as krb5_error_code to keep it from + being sucked into proto.h */ +krb5_error_code free_kerberos_etypes(krb5_context context, + krb5_enctype *enctypes) { - return krb5_free_ktypes(context, enctypes); -} +#if defined(HAVE_KRB5_FREE_KTYPES) + krb5_free_ktypes(context, enctypes); #else -void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes) -{ - return free(enctypes); -} + SAFE_FREE(enctypes); #endif + return 0; +} #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY) krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, -- cgit From f145c2e350db43e401cd477eff89fdef136e7f6c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 10:12:14 +0000 Subject: Only do a kinit if we got told to use kerberos. Andrew Bartlett (This used to be commit 6af9ec50e010d171cf5287f40ec774e79e4a93fe) --- source3/libsmb/cliconnect.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3') diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 487b184dd6..c57f92eea9 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -630,19 +630,19 @@ static BOOL cli_session_setup_spnego(struct cli_state *cli, const char *user, /* If password is set we reauthenticate to kerberos server * and do not store results */ - if (*pass) { - int ret; - - use_in_memory_ccache(); - ret = kerberos_kinit_password(user, pass, 0 /* no time correction for now */); - - if (ret){ - DEBUG(0, ("Kinit failed: %s\n", error_message(ret))); - return False; - } - } - if (got_kerberos_mechanism && cli->use_kerberos) { + if (*pass) { + int ret; + + use_in_memory_ccache(); + ret = kerberos_kinit_password(user, pass, 0 /* no time correction for now */); + + if (ret){ + DEBUG(0, ("Kinit failed: %s\n", error_message(ret))); + return False; + } + } + return cli_session_setup_kerberos(cli, principal, workgroup); } #endif -- cgit From 9e3198cca7068c5125542d661013c7ea48fb7106 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 11:30:09 +0000 Subject: Fix logfile formatting, we were missing a "\n" (This used to be commit 53b8f8a44141a9f6d36ed1b237ff65c67119edd0) --- source3/smbd/service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/smbd/service.c b/source3/smbd/service.c index f9d84872d7..1c7e4017b0 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -364,14 +364,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser, } else if (vuser) { if (vuser->guest) { if (!lp_guest_ok(snum)) { - DEBUG(2, ("guest user (from session setup) not permitted to access this share (%s)", lp_servicename(snum))); + DEBUG(2, ("guest user (from session setup) not permitted to access this share (%s)\n", lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; return NULL; } } else { if (!user_ok(vuser->user.unix_name, snum, vuser->groups, vuser->n_groups)) { - DEBUG(2, ("user '%s' (from session setup) not permitted to access this share (%s)", vuser->user.unix_name, lp_servicename(snum))); + DEBUG(2, ("user '%s' (from session setup) not permitted to access this share (%s)\n", vuser->user.unix_name, lp_servicename(snum))); conn_free(conn); *status = NT_STATUS_ACCESS_DENIED; return NULL; -- cgit From 231f7375590110046ed67b7b337ac2e12d257736 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 11:30:52 +0000 Subject: After a talloc_zero(), we don't need to ZERO_STRUCTP too.. (This used to be commit 4fe8066394143c64c79c052c00f0d747e872103a) --- source3/libsmb/ntlmssp.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3') diff --git a/source3/libsmb/ntlmssp.c b/source3/libsmb/ntlmssp.c index e4398dad17..e1509f6b63 100644 --- a/source3/libsmb/ntlmssp.c +++ b/source3/libsmb/ntlmssp.c @@ -307,8 +307,6 @@ NTSTATUS ntlmssp_server_start(NTLMSSP_STATE **ntlmssp_state) return NT_STATUS_NO_MEMORY; } - ZERO_STRUCTP(*ntlmssp_state); - (*ntlmssp_state)->mem_ctx = mem_ctx; (*ntlmssp_state)->get_challenge = get_challenge; @@ -552,8 +550,6 @@ NTSTATUS ntlmssp_client_start(NTLMSSP_CLIENT_STATE **ntlmssp_state) return NT_STATUS_NO_MEMORY; } - ZERO_STRUCTP(*ntlmssp_state); - (*ntlmssp_state)->mem_ctx = mem_ctx; (*ntlmssp_state)->get_global_myname = global_myname; -- cgit From 1f1125577c000ab72754af00cd83c57fadcc85f1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 11:33:35 +0000 Subject: Move to a in-memory ccache for winbind, and replace setenv() properly. (According to the manpages, you cannot put a stack variable into putenv()). Yes, this leaks memory. Andrew Bartlett (This used to be commit 50bced1e26434ecc7474964062746e2831e5f433) --- source3/include/includes.h | 4 ++++ source3/lib/replace.c | 18 ++++++++++++++++++ source3/nsswitch/winbindd.h | 14 -------------- source3/nsswitch/winbindd_ads.c | 4 +--- 4 files changed, 23 insertions(+), 17 deletions(-) (limited to 'source3') diff --git a/source3/include/includes.h b/source3/include/includes.h index bb78ae0780..731d94996c 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -966,6 +966,10 @@ size_t strnlen(const char *s, size_t n); unsigned long strtoul(const char *nptr, char **endptr, int base); #endif +#ifndef HAVE_SETENV +int setenv(const char *name, const char *value, int overwrite); +#endif + #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL)) /* stupid glibc */ int setresuid(uid_t ruid, uid_t euid, uid_t suid); diff --git a/source3/lib/replace.c b/source3/lib/replace.c index cd48b8d160..0c62ec9bfa 100644 --- a/source3/lib/replace.c +++ b/source3/lib/replace.c @@ -447,3 +447,21 @@ char *rep_inet_ntoa(struct in_addr ip) return t; } #endif + +#ifndef HAVE_SETENV + int setenv(const char *name, const char *value, int overwrite) +{ + char *p = NULL; + int ret = -1; + + asprintf(&p, "%s=%s", name, value); + + if (overwrite || getenv(name)) { + if (p) ret = putenv(p); + } else { + ret = 0; + } + + return ret; +} +#endif diff --git a/source3/nsswitch/winbindd.h b/source3/nsswitch/winbindd.h index e8bcf76bd3..164b7ffda7 100644 --- a/source3/nsswitch/winbindd.h +++ b/source3/nsswitch/winbindd.h @@ -205,18 +205,4 @@ typedef struct { #define DOM_SEQUENCE_NONE ((uint32)-1) -/* SETENV */ -#if HAVE_SETENV -#define SETENV(name, value, overwrite) setenv(name,value,overwrite) -#elif HAVE_PUTENV -#define SETENV(name, value, overwrite) \ -{ \ - fstring envvar; \ - slprintf(envvar, sizeof(fstring), "%s=%s", name, value); \ - putenv(envvar); \ -} -#else -#define SETENV(name, value, overwrite) ; -#endif - #endif /* _WINBINDD_H */ diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 7cea4aa716..be4ed1c667 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -46,9 +46,7 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) } /* we don't want this to affect the users ccache */ - ccache = lock_path("winbindd_ccache"); - SETENV("KRB5CCNAME", ccache, 1); - unlink(ccache); + setenv("KRB5CCNAME", "MEMORY:winbind_ccache", 1); ads = ads_init(domain->alt_name, domain->name, NULL); if (!ads) { -- cgit From 39daab943dbf2f24d3d74fba5a8d76ef58b7dabf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 11:35:02 +0000 Subject: Check return values of various join-related functions, and ensure we always compare push_* returns with (size_t)-1, not < 0. Andrew Bartlett (This used to be commit 63f5e92536c6bcac54b796d6e91b755e7d328f66) --- source3/libads/ldap.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'source3') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index c92e481078..b7cfc8d84c 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -426,10 +426,10 @@ ADS_STATUS ads_do_paged_search(ADS_STRUCT *ads, const char *bind_path, return ADS_ERROR(LDAP_NO_MEMORY); /* 0 means the conversion worked but the result was empty - so we only fail if it's negative. In any case, it always + so we only fail if it's -1. In any case, it always at least nulls out the dest */ - if ((push_utf8_talloc(ctx, &utf8_exp, exp) < 0) || - (push_utf8_talloc(ctx, &utf8_path, bind_path) < 0)) { + if ((push_utf8_talloc(ctx, &utf8_exp, exp) == (size_t)-1) || + (push_utf8_talloc(ctx, &utf8_path, bind_path) == (size_t)-1)) { rc = LDAP_NO_MEMORY; goto done; } @@ -652,8 +652,8 @@ ADS_STATUS ads_do_search(ADS_STRUCT *ads, const char *bind_path, int scope, /* 0 means the conversion worked but the result was empty so we only fail if it's negative. In any case, it always at least nulls out the dest */ - if ((push_utf8_talloc(ctx, &utf8_exp, exp) < 0) || - (push_utf8_talloc(ctx, &utf8_path, bind_path) < 0)) { + if ((push_utf8_talloc(ctx, &utf8_exp, exp) == (size_t)-1) || + (push_utf8_talloc(ctx, &utf8_path, bind_path) == (size_t)-1)) { DEBUG(1,("ads_do_search: push_utf8_talloc() failed!")); rc = LDAP_NO_MEMORY; goto done; @@ -1432,8 +1432,8 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) NTSTATUS status; ADS_STATUS ret; DOM_SID sid; - SEC_DESC *psd = 0; - TALLOC_CTX *ctx = 0; + SEC_DESC *psd = NULL; + TALLOC_CTX *ctx = NULL; /* Avoid segmentation fault in prs_mem_free if * we have to bail out before prs_init */ @@ -1464,7 +1464,11 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) goto ads_set_sd_error; } - ads_pull_sid(ads, msg, attrs[1], &sid); + if (!ads_pull_sid(ads, msg, attrs[1], &sid)) { + ret = ADS_ERROR_NT(NT_STATUS_INVALID_PARAMETER); + goto ads_set_sd_error; + } + if (!(ctx = talloc_init("sec_io_desc"))) { ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; @@ -1482,7 +1486,10 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) goto ads_set_sd_error; } - prs_init(&ps_wire, sd_size, ctx, MARSHALL); + if (!prs_init(&ps_wire, sd_size, ctx, MARSHALL)) { + ret = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + } + if (!sec_io_desc("sd_wire", &psd, &ps_wire, 1)) { ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; -- cgit From 51521fab16c9982200c3c5cd829629a541eb6e29 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 12:05:21 +0000 Subject: Now we have setenv() in replace.c, we don't need a seperate copy here. Andrew Bartlett (This used to be commit c4834c46902380455d2ea1dd62661224e8d4eb11) --- source3/smbwrapper/smbsh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3') diff --git a/source3/smbwrapper/smbsh.c b/source3/smbwrapper/smbsh.c index f9697223c4..d853aa1afc 100644 --- a/source3/smbwrapper/smbsh.c +++ b/source3/smbwrapper/smbsh.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) smbw_setshared("PASSWORD", p); } - smbw_setenv("PS1", "smbsh$ "); + setenv("PS1", "smbsh$ "); sys_getwd(wd); @@ -101,18 +101,18 @@ int main(int argc, char *argv[]) smbw_setshared(line, wd); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd); - smbw_setenv("LD_PRELOAD", line); + etenv("LD_PRELOAD", line); slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); if (file_exist(line, NULL)) { slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); - smbw_setenv("_RLD_LIST", line); + setenv("_RLD_LIST", line); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); - smbw_setenv("_RLDN32_LIST", line); + setenv("_RLDN32_LIST", line); } else { slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); - smbw_setenv("_RLD_LIST", line); + setenv("_RLD_LIST", line); } { -- cgit From 6540693fea3a61795801cfccd988b5552b8b307f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 12:19:52 +0000 Subject: Missed one use of SETENV. (Compat macro no longer needed, as we have a replace.c function). (This used to be commit adad4c66fcfe756277de8c325ac9f8010f9d6f9c) --- source3/nsswitch/winbindd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index ddda2d5f8b..09b89462ec 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -790,7 +790,7 @@ static void usage(void) /* Set environment variable so we don't recursively call ourselves. This may also be useful interactively. */ - SETENV(WINBINDD_DONT_ENV, "1", 1); + setenv(WINBINDD_DONT_ENV, "1", 1); /* Initialise samba/rpc client stuff */ -- cgit From 02cb49bffae34d0f373f5d400077a7a8b7e809b2 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Wed, 19 Feb 2003 13:24:06 +0000 Subject: Improve detection of iconv(3) for various platforms. M4 code is similar to what I use in Midgard for past few years, modified for Samba needs. (This used to be commit 747d2d70a9eb4d9222d7b63e5fcec269eda76672) --- source3/aclocal.m4 | 92 ++++++++++++++++++++++++++++++++++++++++++++++ source3/configure.in | 60 +++++++++++++++++++++--------- source3/include/includes.h | 5 +++ 3 files changed, 140 insertions(+), 17 deletions(-) (limited to 'source3') diff --git a/source3/aclocal.m4 b/source3/aclocal.m4 index 5b1500106c..345be73aed 100644 --- a/source3/aclocal.m4 +++ b/source3/aclocal.m4 @@ -485,3 +485,95 @@ AC_DEFUN(LIB_REMOVE_USR_LIB,[ done $1=[$]ac_new_flags ]) + +dnl From Bruno Haible. + +AC_DEFUN(jm_ICONV, +[ + dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and + dnl those with the standalone portable libiconv installed). + AC_MSG_CHECKING(for iconv in $1) + jm_cv_func_iconv="no" + jm_cv_lib_iconv=no + jm_cv_giconv=no + AC_TRY_LINK([#include +#include ], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + jm_cv_func_iconv=yes + jm_cv_giconv=yes) + + if test "$jm_cv_func_iconv" != yes; then + AC_TRY_LINK([#include +#include ], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + jm_cv_func_iconv=yes) + + if test "$jm_cv_lib_iconv" != yes; then + jm_save_LIBS="$LIBS" + LIBS="$LIBS -lgiconv" + AC_TRY_LINK([#include +#include ], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + jm_cv_lib_iconv=yes + jm_cv_func_iconv=yes + jm_cv_giconv=yes) + LIBS="$jm_save_LIBS" + + if test "$jm_cv_func_iconv" != yes; then + jm_save_LIBS="$LIBS" + LIBS="$LIBS -liconv" + AC_TRY_LINK([#include +#include ], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + jm_cv_lib_iconv=yes + jm_cv_func_iconv=yes) + LIBS="$jm_save_LIBS" + fi + fi + fi + + if test "$jm_cv_func_iconv" = yes; then + if test "$jm_cv_giconv" = yes; then + AC_DEFINE(HAVE_GICONV, 1, [What header to include for iconv() function: giconv.h]) + AC_MSG_RESULT(yes) + ICONV_FOUND=yes + else + AC_DEFINE(HAVE_ICONV, 1, [What header to include for iconv() function: iconv.h]) + AC_MSG_RESULT(yes) + ICONV_FOUND=yes + fi + else + AC_MSG_RESULT(no) + fi + if test "$jm_cv_lib_iconv" = yes; then + if test "$jm_cv_giconv" = yes; then + LIBS="$LIBS -lgiconv" + else + LIBS="$LIBS -liconv" + fi + fi +]) + +dnl CFLAGS_ADD_DIR(CFLAGS, $INCDIR) +dnl This function doesn't add -I/usr/include into CFLAGS +AC_DEFUN(CFLAGS_ADD_DIR,[ +if test "$2" != "/usr/include" ; then + $1="$$1 -I$2" +fi +]) + +dnl LIB_ADD_DIR(LDFLAGS, $LIBDIR) +dnl This function doesn't add -L/usr/lib into LDFLAGS +AC_DEFUN(LIB_ADD_DIR,[ +if test "$2" != "/usr/lib" ; then + $1="$$1 -L$2" +fi +]) diff --git a/source3/configure.in b/source3/configure.in index b90d99bf3d..dfd97bc42f 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -1482,26 +1482,47 @@ if test x"$samba_cv_HAVE_UX_UT_SYSLEN" = x"yes"; then fi -################################################# -# check for libiconv support -AC_MSG_CHECKING(whether to use libiconv) +ICONV_LOCATION=standard +LOOK_DIRS="/usr /usr/local /sw" AC_ARG_WITH(libiconv, [ --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto) ], -[ case "$withval" in - no) - AC_MSG_RESULT(no) - ;; - *) - AC_MSG_RESULT(yes) - CFLAGS="$CFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" - AC_CHECK_LIB(iconv, iconv_open) - AC_DEFINE_UNQUOTED(WITH_LIBICONV, "${withval}",[Path to iconv]) - ;; - esac ], - AC_MSG_RESULT(no) -) +[ + if test "$withval" = "no" ; then + AC_MSG_ERROR(I won't take no for an answer) + else + if test "$withval" != "yes" ; then + LOOK_DIRS="$withval $LOOK_DIRS" + fi + fi +]) +ICONV_FOUND="no" +for i in $LOOK_DIRS ; do + save_LIBS=$LIBS + save_LDFLAGS=$LDFLAGS + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="-I$i/include" + LDFLAGS="-L$i/lib" + LIBS= + export LDFLAGS LIBS CPPFLAGS +dnl Try to find iconv(3) + jm_ICONV($i) + + CPPFLAGS=$save_CPPFLAGS + if test -n "$ICONV_FOUND" ; then + LDFLAGS=$save_LDFLAGS + LIB_ADD_DIR(LDFLAGS, "$i/lib") + CFLAGS_ADD_DIR(CPPFLAGS, "$i/include") + LIBS="$save_LIBS $LIBS" + ICONV_LOCATION=$i + export LDFLAGS LIBS CPPFLAGS + break + else + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + export LDFLAGS LIBS CPPFLAGS + fi +done ############ # check for iconv in libc @@ -1519,6 +1540,11 @@ if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv]) fi +if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then + AC_MSG_WARN([Sufficient support for iconv function was not found. + Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!]) +fi + AC_CACHE_CHECK([for Linux kernel oplocks],samba_cv_HAVE_KERNEL_OPLOCKS_LINUX,[ AC_TRY_RUN([ diff --git a/source3/include/includes.h b/source3/include/includes.h index 731d94996c..0d1c72cf1c 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -393,8 +393,13 @@ #endif /* HAVE_SYS_SHM_H */ #ifdef HAVE_NATIVE_ICONV +#ifdef HAVE_ICONV #include #endif +#ifdef HAVE_GICONV +#include +#endif +#endif #if HAVE_KRB5_H #include -- cgit From ad03d0a4f885a87b5dbe7c88e507b302cf06ece2 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 15:03:04 +0000 Subject: Fix segv in net ads join...an extra & was the culprit (This used to be commit 9874b233d55a0b1aea7eb033848f4b63a531833b) --- source3/libads/ldap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index b7cfc8d84c..67669fc078 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1506,7 +1506,7 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; } - prs_copy_all_data_out((char *)&bval.bv_val, &ps_wire); + prs_copy_all_data_out(bval.bv_val, &ps_wire); ads_mod_ber(ctx, &mods, attrs[0], &bval); ret = ads_gen_mod(ads, dn, mods); -- cgit From ffcee0c95e05f652f4eebf9b9d46bd51d059891b Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 15:22:46 +0000 Subject: Correct way to keep fucntion from proto.h (This used to be commit 762b072efb0d6801775a874494cb19ea3d61fa97) --- source3/include/includes.h | 2 +- source3/libsmb/clikrb5.c | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'source3') diff --git a/source3/include/includes.h b/source3/include/includes.h index 0d1c72cf1c..5b4c5a695f 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1238,7 +1238,7 @@ void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt); krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt); krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters); krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes); -krb5_error_code free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); +void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); #endif /* HAVE_KRB5 */ #endif /* _INCLUDES_H */ diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index 2e07dfdb66..da120622ea 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -127,17 +127,14 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, __ERROR_XX_UNKNOWN_GET_ENCTYPES_FUNCTIONS #endif - /* the following is defined as krb5_error_code to keep it from - being sucked into proto.h */ -krb5_error_code free_kerberos_etypes(krb5_context context, - krb5_enctype *enctypes) + void free_kerberos_etypes(krb5_context context, + krb5_enctype *enctypes) { #if defined(HAVE_KRB5_FREE_KTYPES) - krb5_free_ktypes(context, enctypes); + return krb5_free_ktypes(context, enctypes); #else - SAFE_FREE(enctypes); + return SAFE_FREE(enctypes); #endif - return 0; } #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY) -- cgit From f15ed71fbba9d3762f4e8a1382b65d6291a2a065 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 15:46:15 +0000 Subject: Can't return SAFE_FREE...put on its own line. (This used to be commit 9f1a4809b503f050189d5f87a294b7d8675b1e95) --- source3/libsmb/clikrb5.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index da120622ea..96e737166c 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -133,7 +133,8 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, #if defined(HAVE_KRB5_FREE_KTYPES) return krb5_free_ktypes(context, enctypes); #else - return SAFE_FREE(enctypes); + SAFE_FREE(enctypes); + return; #endif } -- cgit From de88e704ceb74e4811f14845556d65449f9d592b Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 20:37:34 +0000 Subject: libads/krb5_setpw.c (This used to be commit 4c52d7bd933f61bdba3d4159a204fe16db3d4f0f) --- source3/libads/krb5_setpw.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/libads/krb5_setpw.c b/source3/libads/krb5_setpw.c index c3ec754e39..9d8fb8d24c 100644 --- a/source3/libads/krb5_setpw.c +++ b/source3/libads/krb5_setpw.c @@ -327,7 +327,8 @@ static krb5_error_code parse_setpw_reply(krb5_context context, return KRB5KDC_ERR_BADOPTION; break; case KRB5_KPASSWD_INITIAL_FLAG_NEEDED: - return KV5M_ALT_METHOD; + return KRB5KDC_ERR_BADOPTION; + /* return KV5M_ALT_METHOD; MIT-only define */ break; case KRB5_KPASSWD_ETYPE_NOSUPP: return KRB5KDC_ERR_ETYPE_NOSUPP; -- cgit From 29b94266df3df046bc545a466a9b505edd8b7ca8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 19 Feb 2003 22:26:19 +0000 Subject: correct init for vfs.conn, thanks Stefan (This used to be commit 162683d2b5c15016fe1423876589573b48b9f5a6) --- source3/torture/vfstest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/torture/vfstest.c b/source3/torture/vfstest.c index fef189844b..fd1f83109e 100644 --- a/source3/torture/vfstest.c +++ b/source3/torture/vfstest.c @@ -546,7 +546,8 @@ int main(int argc, char *argv[]) } /* some basic initialization stuff */ - vfs.conn = (struct connection_struct *)malloc(sizeof(struct connection_struct)); + conn_init(); + vfs.conn = conn_new(); vfs.conn->user = "vfstest"; for (i=0; i < 1024; i++) vfs.files[i] = NULL; -- cgit From 673cdea310f8447b138cd0c30b5c2313f5c9afe9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Feb 2003 22:30:57 +0000 Subject: Fix inspired by Stefan (metze) Metzmacher - cache the sidtype also. Jeremy. (This used to be commit 634f20dff63d255c317f9dcc9f4caf4e8e79123c) --- source3/smbd/uid.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'source3') diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 4ebee75a15..6ac3528b1a 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -551,19 +551,21 @@ static struct uid_sid_cache { struct uid_sid_cache *next, *prev; uid_t uid; DOM_SID sid; + enum SID_NAME_USE sidtype; } *uid_sid_cache_head; static struct gid_sid_cache { struct gid_sid_cache *next, *prev; gid_t gid; DOM_SID sid; + enum SID_NAME_USE sidtype; } *gid_sid_cache_head; /***************************************************************** Find a SID given a uid. *****************************************************************/ -static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid) +static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, enum SID_NAME_USE *psidtype, uid_t uid) { struct uid_sid_cache *pc; @@ -571,6 +573,7 @@ static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid) if (pc->uid == uid) { fstring sid; *psid = pc->sid; + *psidtype = pc->sidtype; DEBUG(3,("fetch sid from uid cache %u -> %s\n", (unsigned int)uid, sid_to_string(sid, psid))); DLIST_PROMOTE(uid_sid_cache_head, pc); @@ -584,7 +587,7 @@ static BOOL fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid) Find a uid given a SID. *****************************************************************/ -static BOOL fetch_uid_from_cache(uid_t *puid, const DOM_SID *psid) +static BOOL fetch_uid_from_cache(uid_t *puid, const DOM_SID *psid, enum SID_NAME_USE sidtype) { struct uid_sid_cache *pc; @@ -605,7 +608,7 @@ static BOOL fetch_uid_from_cache(uid_t *puid, const DOM_SID *psid) Store uid to SID mapping in cache. *****************************************************************/ -static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid) +static void store_uid_sid_cache(const DOM_SID *psid, const enum SID_NAME_USE sidtype, uid_t uid) { struct uid_sid_cache *pc; @@ -629,6 +632,7 @@ static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid) return; pc->uid = uid; sid_copy(&pc->sid, psid); + pc->sidtype = sidtype; DLIST_ADD(uid_sid_cache_head, pc); n_uid_sid_cache++; } @@ -637,7 +641,7 @@ static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid) Find a SID given a gid. *****************************************************************/ -static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid) +static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, enum SID_NAME_USE *psidtype, gid_t gid) { struct gid_sid_cache *pc; @@ -645,6 +649,7 @@ static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid) if (pc->gid == gid) { fstring sid; *psid = pc->sid; + *psidtype = pc->sidtype; DEBUG(3,("fetch sid from gid cache %u -> %s\n", (unsigned int)gid, sid_to_string(sid, psid))); DLIST_PROMOTE(gid_sid_cache_head, pc); @@ -658,7 +663,7 @@ static BOOL fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid) Find a gid given a SID. *****************************************************************/ -static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid) +static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid, enum SID_NAME_USE sidtype) { struct gid_sid_cache *pc; @@ -679,7 +684,7 @@ static BOOL fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid) Store gid to SID mapping in cache. *****************************************************************/ -static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid) +static void store_gid_sid_cache(const DOM_SID *psid, const enum SID_NAME_USE sidtype, gid_t gid) { struct gid_sid_cache *pc; @@ -703,6 +708,7 @@ static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid) return; pc->gid = gid; sid_copy(&pc->sid, psid); + pc->sidtype = sidtype; DLIST_ADD(gid_sid_cache_head, pc); n_gid_sid_cache++; } @@ -717,9 +723,10 @@ static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid) DOM_SID *uid_to_sid(DOM_SID *psid, uid_t uid) { uid_t low, high; + enum SID_NAME_USE sidtype; fstring sid; - if (fetch_sid_from_uid_cache(psid, uid)) + if (fetch_sid_from_uid_cache(psid, &sidtype, uid)) return psid; if (lp_winbind_uid(&low, &high) && uid >= low && uid <= high) { @@ -729,7 +736,7 @@ DOM_SID *uid_to_sid(DOM_SID *psid, uid_t uid) (unsigned int)uid, sid_to_string(sid, psid))); if (psid) - store_uid_sid_cache(psid, uid); + store_uid_sid_cache(psid, SID_NAME_USER, uid); return psid; } } @@ -741,7 +748,7 @@ DOM_SID *uid_to_sid(DOM_SID *psid, uid_t uid) DEBUG(10,("uid_to_sid: local %u -> %s\n", (unsigned int)uid, sid_to_string(sid, psid))); if (psid) - store_uid_sid_cache(psid, uid); + store_uid_sid_cache(psid, SID_NAME_USER, uid); return psid; } @@ -755,9 +762,10 @@ DOM_SID *uid_to_sid(DOM_SID *psid, uid_t uid) DOM_SID *gid_to_sid(DOM_SID *psid, gid_t gid) { gid_t low, high; + enum SID_NAME_USE sidtype; fstring sid; - if (fetch_sid_from_gid_cache(psid, gid)) + if (fetch_sid_from_gid_cache(psid, &sidtype, gid)) return psid; if (lp_winbind_gid(&low, &high) && gid >= low && gid <= high) { @@ -767,7 +775,7 @@ DOM_SID *gid_to_sid(DOM_SID *psid, gid_t gid) (unsigned int)gid, sid_to_string(sid, psid))); if (psid) - store_gid_sid_cache(psid, gid); + store_gid_sid_cache(psid, SID_NAME_DOM_GRP, gid); return psid; } } @@ -776,7 +784,7 @@ DOM_SID *gid_to_sid(DOM_SID *psid, gid_t gid) psid = local_gid_to_sid(psid, gid); DEBUG(10,("gid_to_sid: local %u -> %s\n", (unsigned int)gid, sid_to_string(sid, psid))); if (psid) - store_gid_sid_cache(psid, gid); + store_gid_sid_cache(psid, SID_NAME_DOM_GRP, gid); return psid; } @@ -792,7 +800,7 @@ BOOL sid_to_uid(const DOM_SID *psid, uid_t *puid, enum SID_NAME_USE *sidtype) { fstring sid_str; - if (fetch_uid_from_cache(puid, psid)) + if (fetch_uid_from_cache(puid, psid, *sidtype)) return True; /* if we know its local then don't try winbindd */ @@ -802,7 +810,7 @@ BOOL sid_to_uid(const DOM_SID *psid, uid_t *puid, enum SID_NAME_USE *sidtype) result = local_sid_to_uid(puid, psid, sidtype); unbecome_root(); if (result) - store_uid_sid_cache(psid, *puid); + store_uid_sid_cache(psid, *sidtype, *puid); return result; } @@ -853,7 +861,7 @@ BOOL sid_to_uid(const DOM_SID *psid, uid_t *puid, enum SID_NAME_USE *sidtype) result = local_sid_to_uid(puid, psid, sidtype); unbecome_root(); if (result) - store_uid_sid_cache(psid, *puid); + store_uid_sid_cache(psid, *sidtype, *puid); return result; } @@ -861,7 +869,7 @@ BOOL sid_to_uid(const DOM_SID *psid, uid_t *puid, enum SID_NAME_USE *sidtype) sid_to_string(sid_str, psid), (unsigned int)*puid )); - store_uid_sid_cache(psid, *puid); + store_uid_sid_cache(psid, *sidtype, *puid); return True; } @@ -879,7 +887,7 @@ BOOL sid_to_gid(const DOM_SID *psid, gid_t *pgid, enum SID_NAME_USE *sidtype) *sidtype = SID_NAME_UNKNOWN; - if (fetch_gid_from_cache(pgid, psid)) + if (fetch_gid_from_cache(pgid, psid, *sidtype)) return True; /* @@ -893,7 +901,7 @@ BOOL sid_to_gid(const DOM_SID *psid, gid_t *pgid, enum SID_NAME_USE *sidtype) result = local_sid_to_gid(pgid, psid, sidtype); unbecome_root(); if (result) - store_gid_sid_cache(psid, *pgid); + store_gid_sid_cache(psid, *sidtype, *pgid); return result; } @@ -932,7 +940,7 @@ BOOL sid_to_gid(const DOM_SID *psid, gid_t *pgid, enum SID_NAME_USE *sidtype) sid_to_string(sid_str, psid), (unsigned int)*pgid )); - store_gid_sid_cache(psid, *pgid); + store_gid_sid_cache(psid, *sidtype, *pgid); return True; } -- cgit From 9061aae9b4bfed051b4c08b971561297710ef369 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 20 Feb 2003 03:33:20 +0000 Subject: (Merge from APPLIANCE_HEAD) CR1829: Fix memory leak when unpacking 'B' buffers in Python. (PyList_Append creates a new reference to the added object, and so we have to release the existing one.) (This used to be commit 55e114f596e0edfdf176cabdbcfe7f01fae6f8aa) --- source3/python/py_tdbpack.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3') diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index 6181a4918e..8aa4ee316a 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -638,6 +638,9 @@ pytdbunpack_buffer(char **pbuf, int *plen, PyObject *val_list) if (PyList_Append(val_list, str_obj) == -1) goto failed; + Py_DECREF(len_obj); + Py_DECREF(str_obj); + return val_list; failed: -- cgit From f8d9cf27266d9ce563011e44281483a4dfd0708f Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 20 Feb 2003 04:01:25 +0000 Subject: Doc (This used to be commit 5d7d400d6c49b195a1174ef40c7bf95065427fbd) --- source3/python/py_tdbpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index 8aa4ee316a..243cb44683 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -1,7 +1,7 @@ /* -*- c-file-style: "python"; indent-tabs-mode: nil; -*- Python wrapper for Samba tdb pack/unpack functions - Copyright (C) Martin Pool 2002 + Copyright (C) Martin Pool 2002, 2003 NOTE PYTHON STYLE GUIDE -- cgit From 215ff67a039d3dea516d70d538083db8833f7b7e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Feb 2003 10:43:21 +0000 Subject: for some (very weird) reason, the domain I was testing aginst would not return a DN for the user. Make sure we don't segfault. Andrew Bartlett (This used to be commit 9fdedeff6a3a9f8e8d048e6afd7001ad676c4e91) --- source3/nsswitch/winbindd_ads.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index be4ed1c667..9560a53fa0 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -490,6 +490,10 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, } user_dn = ads_pull_string(ads, mem_ctx, msg, "distinguishedName"); + if (!user_dn) { + DEBUG(1,("lookup_usergroups(rid=%d) ads_search did not return a a distinguishedName!\n", user_rid)); + goto done; + } if (msg) ads_msgfree(ads, msg); -- cgit From 512405321ac60ae8b1d6dd80139ff9a50add8714 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Feb 2003 10:50:09 +0000 Subject: Like for NTLM logins, lookup the 'winbind' user first, then the 'local' user. This needs to change, to be a SID->UID lookup from the PAC. Andrew Bartlett (This used to be commit 4071ed06a051f87f27e10510427a69fcdf45ddac) --- source3/smbd/sesssetup.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'source3') diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c index e408cc88e9..3a3209f172 100644 --- a/source3/smbd/sesssetup.c +++ b/source3/smbd/sesssetup.c @@ -148,6 +148,7 @@ static int reply_spnego_kerberos(connection_struct *conn, DATA_BLOB auth_data; auth_serversupplied_info *server_info = NULL; ADS_STRUCT *ads; + BOOL foreign = False; if (!spnego_parse_krb5_wrap(*secblob, &ticket)) { return ERROR_NT(NT_STATUS_LOGON_FAILURE); @@ -185,12 +186,20 @@ static int reply_spnego_kerberos(connection_struct *conn, if (!lp_allow_trusted_domains()) { return ERROR_NT(NT_STATUS_LOGON_FAILURE); } - /* this gives a fully qualified user name (ie. with full realm). - that leads to very long usernames, but what else can we do? */ - asprintf(&user, "%s%s%s", p+1, lp_winbind_separator(), client); - } else { - user = strdup(client); + foreign = True; + } + + /* this gives a fully qualified user name (ie. with full realm). + that leads to very long usernames, but what else can we do? */ + asprintf(&user, "%s%s%s", p+1, lp_winbind_separator(), client); + + pw = Get_Pwnam(user); + if (!pw && !foreign) { + pw = Get_Pwnam(client); + SAFE_FREE(user); + user = smb_xstrdup(client); } + ads_destroy(&ads); /* setup the string used by %U */ @@ -198,19 +207,6 @@ static int reply_spnego_kerberos(connection_struct *conn, reload_services(True); - /* the password is good - let them in */ - pw = Get_Pwnam(user); - if (!pw && !strstr(user, lp_winbind_separator())) { - char *user2; - /* try it with a winbind domain prefix */ - asprintf(&user2, "%s%s%s", lp_workgroup(), lp_winbind_separator(), user); - pw = Get_Pwnam(user2); - if (pw) { - free(user); - user = user2; - } - } - if (!pw) { DEBUG(1,("Username %s is invalid on this system\n",user)); return ERROR_NT(NT_STATUS_NO_SUCH_USER); -- cgit From d7b4f389e98e6b9cf32965e4ff41d39aa0d2cd4b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Feb 2003 12:01:39 +0000 Subject: For a number of months now, support for being a domain member without also running winbind has been broken. This fixes that, by removing assumptions about being able to call sid_to_uid() at will. This whole area needs revising when we get groups into the PDB. Andrew Bartlett (This used to be commit 980eda74b7df347c38b567ce976197826963324a) --- source3/auth/auth_util.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 5218467dab..352d058f20 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -641,34 +641,25 @@ NT_USER_TOKEN *create_nt_token(uid_t uid, gid_t gid, int ngroups, gid_t *groups, * of groups. ******************************************************************************/ -static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid, +static NTSTATUS get_user_groups_from_local_sam(SAM_ACCOUNT *sampass, int *n_groups, DOM_SID **groups, gid_t **unix_groups) { uid_t uid; - enum SID_NAME_USE snu; - fstring str; + gid_t gid; int n_unix_groups; int i; struct passwd *usr; - + *n_groups = 0; *groups = NULL; - - if (!sid_to_uid(user_sid, &uid, &snu)) { - DEBUG(2, ("get_user_groups_from_local_sam: Failed to convert user SID %s to a uid!\n", - sid_to_string(str, user_sid))); - /* This might be a non-unix account */ - return NT_STATUS_OK; - } - /* - * This is _essential_ to prevent occasional segfaults when - * winbind can't find uid -> username mapping - */ - if (!(usr = getpwuid_alloc(uid))) { - DEBUG(0, ("Couldn't find passdb structure for UID = %d ! Aborting.\n", uid)); + if (!IS_SAM_UNIX_USER(sampass)) { + DEBUG(1, ("user %s does not have a unix identity!\n", pdb_get_username(sampass))); return NT_STATUS_NO_SUCH_USER; - }; + } + + uid = pdb_get_uid(sampass); + gid = pdb_get_gid(sampass); n_unix_groups = groups_max(); if ((*unix_groups = malloc( sizeof(gid_t) * n_unix_groups ) ) == NULL) { @@ -677,7 +668,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid, return NT_STATUS_NO_MEMORY; } - if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) { + if (sys_getgrouplist(pdb_get_username(sampass), gid, *unix_groups, &n_unix_groups) == -1) { gid_t *groups_tmp; groups_tmp = Realloc(*unix_groups, sizeof(gid_t) * n_unix_groups); if (!groups_tmp) { @@ -687,7 +678,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid, } *unix_groups = groups_tmp; - if (sys_getgrouplist(usr->pw_name, usr->pw_gid, *unix_groups, &n_unix_groups) == -1) { + if (sys_getgrouplist(pdb_get_username(sampass), gid, *unix_groups, &n_unix_groups) == -1) { DEBUG(0, ("get_user_groups_from_local_sam: failed to get the unix group list\n")); SAFE_FREE(*unix_groups); passwd_free(&usr); @@ -695,9 +686,7 @@ static NTSTATUS get_user_groups_from_local_sam(const DOM_SID *user_sid, } } - debug_unix_user_token(DBGC_CLASS, 5, usr->pw_uid, usr->pw_gid, n_unix_groups, *unix_groups); - - passwd_free(&usr); + debug_unix_user_token(DBGC_CLASS, 5, uid, gid, n_unix_groups, *unix_groups); if (n_unix_groups > 0) { *groups = malloc(sizeof(DOM_SID) * n_unix_groups); @@ -763,7 +752,7 @@ NTSTATUS make_server_info_sam(auth_serversupplied_info **server_info, } if (!NT_STATUS_IS_OK(nt_status - = get_user_groups_from_local_sam(pdb_get_user_sid(sampass), + = get_user_groups_from_local_sam(sampass, &n_groupSIDs, &groupSIDs, &unix_groups))) { DEBUG(4,("get_user_groups_from_local_sam failed\n")); @@ -998,7 +987,7 @@ NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx, returned to the caller. */ if (!NT_STATUS_IS_OK(nt_status - = get_user_groups_from_local_sam(&user_sid, + = get_user_groups_from_local_sam(sam_account, &n_lgroupSIDs, &lgroupSIDs, &unix_groups))) -- cgit From 14401bb368464295936bd18fb011d551a36576ce Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Feb 2003 18:54:12 +0000 Subject: Ensure tdb error code is set for corrupt and i/o errors before calling the log function. This allows the log function to take action. Jeremy. (This used to be commit 0fa310cbc3f7ced0b15be0ffaeb70dc82e1d5d12) --- source3/tdb/tdb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source3') diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c index 8410538f01..097209ff7a 100644 --- a/source3/tdb/tdb.c +++ b/source3/tdb/tdb.c @@ -205,6 +205,11 @@ static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset, if (ret == -1) { if (!probe && lck_type != F_SETLK) { + /* Ensure error code is set for log fun to examine. */ + if (errno == EINTR && palarm_fired && *palarm_fired) + tdb->ecode = TDB_ERR_LOCK_TIMEOUT; + else + tdb->ecode = TDB_ERR_LOCK; TDB_LOG((tdb, 5,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d\n", tdb->fd, offset, rw_type, lck_type)); } @@ -312,6 +317,8 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe) return 0; if (tdb->flags & TDB_INTERNAL) { if (!probe) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, 0,"tdb_oob len %d beyond internal malloc size %d\n", (int)len, (int)tdb->map_size)); } @@ -323,6 +330,8 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off len, int probe) if (st.st_size < (size_t)len) { if (!probe) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, 0,"tdb_oob len %d beyond eof at %d\n", (int)len, (int)st.st_size)); } @@ -351,6 +360,8 @@ static int tdb_write(TDB_CONTEXT *tdb, tdb_off off, void *buf, tdb_len len) else if (lseek(tdb->fd, off, SEEK_SET) != off || write(tdb->fd, buf, len) != (ssize_t)len) { #endif + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, 0,"tdb_write failed at %d len=%d (%s)\n", off, len, strerror(errno))); return TDB_ERRCODE(TDB_ERR_IO, -1); @@ -372,6 +383,8 @@ static int tdb_read(TDB_CONTEXT *tdb,tdb_off off,void *buf,tdb_len len,int cv) else if (lseek(tdb->fd, off, SEEK_SET) != off || read(tdb->fd, buf, len) != (ssize_t)len) { #endif + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_IO; TDB_LOG((tdb, 0,"tdb_read failed at %d len=%d (%s)\n", off, len, strerror(errno))); return TDB_ERRCODE(TDB_ERR_IO, -1); @@ -387,6 +400,8 @@ static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len) char *buf; if (!(buf = malloc(len))) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_OOM; TDB_LOG((tdb, 0,"tdb_alloc_read malloc failed len=%d (%s)\n", len, strerror(errno))); return TDB_ERRCODE(TDB_ERR_OOM, buf); @@ -415,6 +430,8 @@ static int rec_read(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec) if (tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1) return -1; if (TDB_BAD_MAGIC(rec)) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_CORRUPT; TDB_LOG((tdb, 0,"rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset)); return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); } @@ -443,6 +460,8 @@ static int rec_free_read(TDB_CONTEXT *tdb, tdb_off off, struct list_struct *rec) } if (rec->magic != TDB_FREE_MAGIC) { + /* Ensure ecode is set for log fn. */ + tdb->ecode = TDB_ERR_CORRUPT; TDB_LOG((tdb, 0,"rec_free_read bad magic 0x%x at offset=%d\n", rec->magic, off)); return TDB_ERRCODE(TDB_ERR_CORRUPT, -1); -- cgit From 9d913a62ad8f4bac575a53c362d9d10fd6175c8c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Feb 2003 19:10:19 +0000 Subject: Remove obsolete files (This used to be commit f035cba2cf5764722318e9cd10dbe7bef56d0732) --- source3/rpcclient/display.c | 1338 ------------------------------------- source3/rpcclient/display_spool.c | 927 ------------------------- source3/rpcclient/samsync.c | 773 --------------------- 3 files changed, 3038 deletions(-) delete mode 100644 source3/rpcclient/display.c delete mode 100644 source3/rpcclient/display_spool.c delete mode 100644 source3/rpcclient/samsync.c (limited to 'source3') diff --git a/source3/rpcclient/display.c b/source3/rpcclient/display.c deleted file mode 100644 index d03465206e..0000000000 --- a/source3/rpcclient/display.c +++ /dev/null @@ -1,1338 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Luke Kenneth Casson Leighton 1996 - 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. -*/ - -#include "includes.h" - - -/**************************************************************************** -convert a share mode to a string -****************************************************************************/ -char *get_file_mode_str(uint32 share_mode) -{ - static fstring mode; - - switch (GET_DENY_MODE(share_mode)) - { - case DENY_NONE : fstrcpy(mode, "DENY_NONE "); break; - case DENY_ALL : fstrcpy(mode, "DENY_ALL "); break; - case DENY_DOS : fstrcpy(mode, "DENY_DOS "); break; - case DENY_READ : fstrcpy(mode, "DENY_READ "); break; - case DENY_WRITE: fstrcpy(mode, "DENY_WRITE "); break; - case DENY_FCB: fstrcpy(mode, "DENY_FCB "); break; - default : fstrcpy(mode, "DENY_???? "); break; - } - - switch (share_mode & 0xF) - { - case 0 : fstrcat(mode, "RDONLY"); break; - case 1 : fstrcat(mode, "WRONLY"); break; - case 2 : fstrcat(mode, "RDWR "); break; - default: fstrcat(mode, "R??W??"); break; - } - - return mode; -} - -/**************************************************************************** -convert an oplock mode to a string -****************************************************************************/ -char *get_file_oplock_str(uint32 op_type) -{ - static fstring oplock; - BOOL excl = ((op_type & EXCLUSIVE_OPLOCK) != 0); - BOOL batch = ((op_type & BATCH_OPLOCK ) != 0); - - oplock[0] = 0; - - if (excl ) fstrcat(oplock, "EXCLUSIVE"); - if (excl && batch) fstrcat(oplock, "+"); - if ( batch) fstrcat(oplock, "BATCH"); - if (!excl && !batch) fstrcat(oplock, "NONE"); - - return oplock; -} - -/**************************************************************************** -convert a share type enum to a string -****************************************************************************/ -char *get_share_type_str(uint32 type) -{ - static fstring typestr; - - switch (type) - { - case STYPE_DISKTREE: fstrcpy(typestr, "Disk" ); break; - case STYPE_PRINTQ : fstrcpy(typestr, "Printer"); break; - case STYPE_DEVICE : fstrcpy(typestr, "Device" ); break; - case STYPE_IPC : fstrcpy(typestr, "IPC" ); break; - default : fstrcpy(typestr, "????" ); break; - } - return typestr; -} - -/**************************************************************************** -convert a server type enum to a string -****************************************************************************/ -char *get_server_type_str(uint32 type) -{ - static fstring typestr; - - if (type == SV_TYPE_ALL) - { - fstrcpy(typestr, "All"); - } - else - { - int i; - typestr[0] = 0; - for (i = 0; i < 32; i++) - { - if (type & (1 << i)) - { - switch (((unsigned)1) << i) - { - case SV_TYPE_WORKSTATION : fstrcat(typestr, "Wk " ); break; - case SV_TYPE_SERVER : fstrcat(typestr, "Sv " ); break; - case SV_TYPE_SQLSERVER : fstrcat(typestr, "Sql "); break; - case SV_TYPE_DOMAIN_CTRL : fstrcat(typestr, "PDC "); break; - case SV_TYPE_DOMAIN_BAKCTRL : fstrcat(typestr, "BDC "); break; - case SV_TYPE_TIME_SOURCE : fstrcat(typestr, "Tim "); break; - case SV_TYPE_AFP : fstrcat(typestr, "AFP "); break; - case SV_TYPE_NOVELL : fstrcat(typestr, "Nov "); break; - case SV_TYPE_DOMAIN_MEMBER : fstrcat(typestr, "Dom "); break; - case SV_TYPE_PRINTQ_SERVER : fstrcat(typestr, "PrQ "); break; - case SV_TYPE_DIALIN_SERVER : fstrcat(typestr, "Din "); break; - case SV_TYPE_SERVER_UNIX : fstrcat(typestr, "Unx "); break; - case SV_TYPE_NT : fstrcat(typestr, "NT " ); break; - case SV_TYPE_WFW : fstrcat(typestr, "Wfw "); break; - case SV_TYPE_SERVER_MFPN : fstrcat(typestr, "Mfp "); break; - case SV_TYPE_SERVER_NT : fstrcat(typestr, "SNT "); break; - case SV_TYPE_POTENTIAL_BROWSER: fstrcat(typestr, "PtB "); break; - case SV_TYPE_BACKUP_BROWSER : fstrcat(typestr, "BMB "); break; - case SV_TYPE_MASTER_BROWSER : fstrcat(typestr, "LMB "); break; - case SV_TYPE_DOMAIN_MASTER : fstrcat(typestr, "DMB "); break; - case SV_TYPE_SERVER_OSF : fstrcat(typestr, "OSF "); break; - case SV_TYPE_SERVER_VMS : fstrcat(typestr, "VMS "); break; - case SV_TYPE_WIN95_PLUS : fstrcat(typestr, "W95 "); break; - case SV_TYPE_ALTERNATE_XPORT : fstrcat(typestr, "Xpt "); break; - case SV_TYPE_LOCAL_LIST_ONLY : fstrcat(typestr, "Dom "); break; - case SV_TYPE_DOMAIN_ENUM : fstrcat(typestr, "Loc "); break; - } - } - } - i = strlen(typestr)-1; - if (typestr[i] == ' ') typestr[i] = 0; - - } - return typestr; -} - -/**************************************************************************** -server info level 101 display function -****************************************************************************/ -void display_srv_info_101(FILE *out_hnd, enum action_type action, - SRV_INFO_101 *sv101) -{ - if (sv101 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Server Info Level 101:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring name; - fstring comment; - - rpcstr_pull(name, sv101->uni_name.buffer, sizeof(name), sv101->uni_name.uni_str_len*2, 0); - rpcstr_pull(comment, sv101->uni_comment.buffer, sizeof(comment), sv101->uni_comment.uni_str_len*2, 0); - - display_server(out_hnd, action, name, sv101->srv_type, comment); - - fprintf(out_hnd, "\tplatform_id : %d\n" , sv101->platform_id); - fprintf(out_hnd, "\tos version : %d.%d\n" , sv101->ver_major, sv101->ver_minor); - - break; - } - case ACTION_FOOTER: - { - break; - } - } - -} - -/**************************************************************************** -server info level 102 display function -****************************************************************************/ -void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *sv102) -{ - if (sv102 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Server Info Level 102:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring name; - fstring comment; - fstring usr_path; - - rpcstr_pull(name, sv102->uni_name.buffer, sizeof(name), sv102->uni_name.uni_str_len*2, 0); - rpcstr_pull(comment, sv102->uni_comment.buffer, sizeof(comment), sv102->uni_comment.uni_str_len*2, 0); - rpcstr_pull(usr_path, sv102->uni_usr_path.buffer, sizeof(usr_path), sv102->uni_usr_path.uni_str_len*2, 0); - - display_server(out_hnd, action, name, sv102->srv_type, comment); - - fprintf(out_hnd, "\tplatform_id : %d\n" , sv102->platform_id); - fprintf(out_hnd, "\tos version : %d.%d\n" , sv102->ver_major, sv102->ver_minor); - - fprintf(out_hnd, "\tusers : %x\n" , sv102->users ); - fprintf(out_hnd, "\tdisc, hidden : %x,%x\n" , sv102->disc , sv102->hidden ); - fprintf(out_hnd, "\tannounce, delta : %d, %d\n", sv102->announce , sv102->ann_delta); - fprintf(out_hnd, "\tlicenses : %d\n" , sv102->licenses ); - fprintf(out_hnd, "\tuser path : %s\n" , usr_path); - - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -server info container display function -****************************************************************************/ -void display_srv_info_ctr(FILE *out_hnd, enum action_type action,SRV_INFO_CTR *ctr) -{ - if (ctr == NULL || ctr->ptr_srv_ctr == 0) - { - fprintf(out_hnd, "Server Information: unavailable due to an error\n"); - return; - } - - switch (ctr->switch_value) - { - case 101: - { - display_srv_info_101(out_hnd, action, &(ctr->srv.sv101)); - break; - } - case 102: - { - display_srv_info_102(out_hnd, action, &(ctr->srv.sv102)); - break; - } - default: - { - fprintf(out_hnd, "Server Information: Unknown Info Level\n"); - break; - } - } -} - -/**************************************************************************** -connection info level 0 display function -****************************************************************************/ -void display_conn_info_0(FILE *out_hnd, enum action_type action, - CONN_INFO_0 *info0) -{ - if (info0 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Connection Info Level 0:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\tid: %d\n", info0->id); - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -connection info level 1 display function -****************************************************************************/ -void display_conn_info_1(FILE *out_hnd, enum action_type action, - CONN_INFO_1 *info1, CONN_INFO_1_STR *str1) -{ - if (info1 == NULL || str1 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Connection Info Level 1:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring usr_name; - fstring net_name; - - rpcstr_pull(usr_name, str1->uni_usr_name.buffer, sizeof(usr_name), str1->uni_usr_name.uni_str_len*2,0); - rpcstr_pull(net_name, str1->uni_net_name.buffer, sizeof(net_name), str1->uni_net_name.uni_str_len*2,0); - - fprintf(out_hnd, "\tid : %d\n", info1->id); - fprintf(out_hnd, "\ttype : %s\n", get_share_type_str(info1->type)); - fprintf(out_hnd, "\tnum_opens: %d\n", info1->num_opens); - fprintf(out_hnd, "\tnum_users: %d\n", info1->num_users); - fprintf(out_hnd, "\topen_time: %d\n", info1->open_time); - - fprintf(out_hnd, "\tuser name: %s\n", usr_name); - fprintf(out_hnd, "\tnet name: %s\n", net_name); - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -connection info level 0 container display function -****************************************************************************/ -void display_srv_conn_info_0_ctr(FILE *out_hnd, enum action_type action, - SRV_CONN_INFO_0 *ctr) -{ - if (ctr == NULL) - { - fprintf(out_hnd, "display_srv_conn_info_0_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < ctr->num_entries_read; i++) - { - display_conn_info_0(out_hnd, ACTION_HEADER , &(ctr->info_0[i])); - display_conn_info_0(out_hnd, ACTION_ENUMERATE, &(ctr->info_0[i])); - display_conn_info_0(out_hnd, ACTION_FOOTER , &(ctr->info_0[i])); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -void display_srv_conn_info_1_ctr(FILE *out_hnd, enum action_type action, - SRV_CONN_INFO_1 *ctr) -{ - if (ctr == NULL) - { - fprintf(out_hnd, "display_srv_conn_info_1_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < ctr->num_entries_read; i++) - { - display_conn_info_1(out_hnd, ACTION_HEADER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); - display_conn_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->info_1[i]), &(ctr->info_1_str[i])); - display_conn_info_1(out_hnd, ACTION_FOOTER , &(ctr->info_1[i]), &(ctr->info_1_str[i])); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_srv_conn_info_ctr(FILE *out_hnd, enum action_type action, - SRV_CONN_INFO_CTR *ctr) -{ - if (ctr == NULL || ctr->ptr_conn_ctr == 0) - { - fprintf(out_hnd, "display_srv_conn_info_ctr: unavailable due to an internal error\n"); - return; - } - - switch (ctr->switch_value) - { - case 0: - { - display_srv_conn_info_0_ctr(out_hnd, action, - &(ctr->conn.info0)); - break; - } - case 1: - { - display_srv_conn_info_1_ctr(out_hnd, action, - &(ctr->conn.info1)); - break; - } - default: - { - fprintf(out_hnd, "display_srv_conn_info_ctr: Unknown Info Level\n"); - break; - } - } -} - - -/**************************************************************************** -share info level 1 display function -****************************************************************************/ -void display_share_info_1(FILE *out_hnd, enum action_type action, - SRV_SHARE_INFO_1 *info1) -{ - if (info1 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Share Info Level 1:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring remark ; - fstring net_name; - - rpcstr_pull(net_name, info1->info_1_str.uni_netname.buffer, sizeof(net_name), info1->info_1_str.uni_netname.uni_str_len*2, 0); - rpcstr_pull(remark, info1->info_1_str.uni_remark.buffer, sizeof(remark), info1->info_1_str.uni_remark.uni_str_len*2, 0); - - display_share(out_hnd, action, net_name, info1->info_1.type, remark); - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -share info level 2 display function -****************************************************************************/ -void display_share_info_2(FILE *out_hnd, enum action_type action, - SRV_SHARE_INFO_2 *info2) -{ - if (info2 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "Share Info Level 2:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring remark ; - fstring net_name; - fstring path ; - fstring passwd ; - - rpcstr_pull(net_name, info2->info_2_str.uni_netname.buffer, sizeof(net_name), info2->info_2_str.uni_netname.uni_str_len*2, 0); - rpcstr_pull(remark, info2->info_2_str.uni_remark.buffer, sizeof(remark), info2->info_2_str.uni_remark.uni_str_len*2, 0); - rpcstr_pull(path, info2->info_2_str.uni_path.buffer, sizeof(path), info2->info_2_str.uni_path.uni_str_len*2, 0); - rpcstr_pull(passwd, info2->info_2_str.uni_passwd.buffer, sizeof(passwd), info2->info_2_str.uni_passwd.uni_str_len*2, 0); - - display_share2(out_hnd, action, net_name, - info2->info_2.type, remark, info2->info_2.perms, - info2->info_2.max_uses, info2->info_2.num_uses, - path, passwd); - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -share info container display function -****************************************************************************/ -void display_srv_share_info_ctr(FILE *out_hnd, enum action_type action, - SRV_SHARE_INFO_CTR *ctr) -{ - if (ctr == NULL) - { - fprintf(out_hnd, "display_srv_share_info_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < ctr->num_entries; i++) - { - switch (ctr->info_level) { - case 1: - display_share_info_1(out_hnd, ACTION_HEADER , &(ctr->share.info1[i])); - display_share_info_1(out_hnd, ACTION_ENUMERATE, &(ctr->share.info1[i])); - display_share_info_1(out_hnd, ACTION_FOOTER , &(ctr->share.info1[i])); - break; - case 2: - display_share_info_2(out_hnd, ACTION_HEADER , &(ctr->share.info2[i])); - display_share_info_2(out_hnd, ACTION_ENUMERATE, &(ctr->share.info2[i])); - display_share_info_2(out_hnd, ACTION_FOOTER , &(ctr->share.info2[i])); - break; - default: - fprintf(out_hnd, "display_srv_share_info_ctr: Unknown Info Level\n"); - break; - } - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -file info level 3 display function -****************************************************************************/ -void display_file_info_3(FILE *out_hnd, enum action_type action, - FILE_INFO_3 *info3, FILE_INFO_3_STR *str3) -{ - if (info3 == NULL || str3 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "File Info Level 3:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring path_name; - fstring user_name; - - rpcstr_pull(path_name, str3->uni_path_name.buffer, sizeof(path_name), str3->uni_path_name.uni_str_len*2, 0); - rpcstr_pull(user_name, str3->uni_user_name.buffer, sizeof(user_name), str3->uni_user_name.uni_str_len*2, 0); - - fprintf(out_hnd, "\tid : %d\n", info3->id); - fprintf(out_hnd, "\tperms : %s\n", get_file_mode_str(info3->perms)); - fprintf(out_hnd, "\tnum_locks: %d\n", info3->num_locks); - - fprintf(out_hnd, "\tpath name: %s\n", path_name); - fprintf(out_hnd, "\tuser name: %s\n", user_name); - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -file info level 3 container display function -****************************************************************************/ -void display_srv_file_info_3_ctr(FILE *out_hnd, enum action_type action, - SRV_FILE_INFO_3 *ctr) -{ - if (ctr == NULL) - { - fprintf(out_hnd, "display_srv_file_info_3_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < ctr->num_entries_read; i++) - { - display_file_info_3(out_hnd, ACTION_HEADER , &(ctr->info_3[i]), &(ctr->info_3_str[i])); - display_file_info_3(out_hnd, ACTION_ENUMERATE, &(ctr->info_3[i]), &(ctr->info_3_str[i])); - display_file_info_3(out_hnd, ACTION_FOOTER , &(ctr->info_3[i]), &(ctr->info_3_str[i])); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -file info container display function -****************************************************************************/ -void display_srv_file_info_ctr(FILE *out_hnd, enum action_type action, - SRV_FILE_INFO_CTR *ctr) -{ - if (ctr == NULL || ctr->ptr_file_ctr == 0) - { - fprintf(out_hnd, "display_srv_file_info_ctr: unavailable due to an internal error\n"); - return; - } - - switch (ctr->switch_value) - { - case 3: - { - display_srv_file_info_3_ctr(out_hnd, action, - &(ctr->file.info3)); - break; - } - default: - { - fprintf(out_hnd, "display_srv_file_info_ctr: Unknown Info Level\n"); - break; - } - } -} - -/**************************************************************************** - print browse connection on a host - ****************************************************************************/ -void display_server(FILE *out_hnd, enum action_type action, - char *sname, uint32 type, char *comment) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t%-15.15s%-20s %s\n", - sname, get_server_type_str(type), comment); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -print shares on a host -****************************************************************************/ -void display_share(FILE *out_hnd, enum action_type action, - char *sname, uint32 type, char *comment) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t%-15.15s%-10.10s%s\n", - sname, get_share_type_str(type), comment); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - - -/**************************************************************************** -print shares on a host, level 2 -****************************************************************************/ -void display_share2(FILE *out_hnd, enum action_type action, - char *sname, uint32 type, char *comment, - uint32 perms, uint32 max_uses, uint32 num_uses, - char *path, char *passwd) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t%-15.15s%-10.10s%s %x %x %x %s %s\n", - sname, get_share_type_str(type), comment, - perms, max_uses, num_uses, path, passwd); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - - -/**************************************************************************** -print name info -****************************************************************************/ -void display_name(FILE *out_hnd, enum action_type action, - char *sname) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t%-21.21s\n", sname); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - - -/**************************************************************************** - display group rid info - ****************************************************************************/ -void display_group_rid_info(FILE *out_hnd, enum action_type action, - uint32 num_gids, DOM_GID *gid) -{ - switch (action) - { - case ACTION_HEADER: - { - if (num_gids == 0) - { - fprintf(out_hnd, "\tNo Groups\n"); - } - else - { - fprintf(out_hnd, "\tGroup Info\n"); - fprintf(out_hnd, "\t----------\n"); - } - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < num_gids; i++) - { - fprintf(out_hnd, "\tGroup RID: %8x attr: %x\n", - gid[i].g_rid, gid[i].attr); - } - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - - -/**************************************************************************** - display alias name info - ****************************************************************************/ -void display_alias_name_info(FILE *out_hnd, enum action_type action, - uint32 num_aliases, fstring *alias_name, uint32 *num_als_usrs) -{ - switch (action) - { - case ACTION_HEADER: - { - if (num_aliases == 0) - { - fprintf(out_hnd, "\tNo Aliases\n"); - } - else - { - fprintf(out_hnd, "\tAlias Names\n"); - fprintf(out_hnd, "\t----------- \n"); - } - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < num_aliases; i++) - { - fprintf(out_hnd, "\tAlias Name: %s Attributes: %3d\n", - alias_name[i], num_als_usrs[i]); - } - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - - -/**************************************************************************** - display sam_user_info_21 structure - ****************************************************************************/ -void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_INFO_21 *usr) -{ - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "\tUser Info, Level 0x15\n"); - fprintf(out_hnd, "\t---------------------\n"); - - break; - } - case ACTION_ENUMERATE: - { - pstring tmp; - rpcstr_pull(tmp, usr->uni_user_name.buffer, sizeof(tmp),usr->uni_user_name.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tUser Name : %s\n", tmp); /* username unicode string */ - rpcstr_pull(tmp, usr->uni_full_name.buffer, sizeof(tmp),usr->uni_full_name.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tFull Name : %s\n", tmp); /* user's full name unicode string */ - rpcstr_pull(tmp, usr->uni_home_dir.buffer, sizeof(tmp),usr->uni_home_dir.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tHome Drive : %s\n", tmp); /* home directory unicode string */ - rpcstr_pull(tmp, usr->uni_dir_drive.buffer, sizeof(tmp),usr->uni_dir_drive.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tDir Drive : %s\n", tmp); /* home directory drive unicode string */ - rpcstr_pull(tmp, usr->uni_profile_path.buffer, sizeof(tmp),usr->uni_profile_path.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tProfile Path: %s\n", tmp); /* profile path unicode string */ - rpcstr_pull(tmp, usr->uni_logon_script.buffer, sizeof(tmp),usr->uni_logon_script.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tLogon Script: %s\n", tmp); /* logon script unicode string */ - rpcstr_pull(tmp, usr->uni_acct_desc.buffer, sizeof(tmp),usr->uni_acct_desc.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tDescription : %s\n", tmp); /* user description unicode string */ - rpcstr_pull(tmp, usr->uni_workstations.buffer, sizeof(tmp),usr->uni_workstations.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tWorkstations: %s\n", tmp); /* workstaions unicode string */ - rpcstr_pull(tmp, usr->uni_unknows_str.buffer, sizeof(tmp),usr->uni_unknown_str.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tUnknown Str : %s\n", tmp); /* unknown string unicode string */ - rpcstr_pull(tmp, usr->uni_munged_dial.buffer, sizeof(tmp),usr->uni_munged_dial.uni_str_len*2, 0); - fprintf(out_hnd, "\t\tRemote Dial : %s\n", tmp); /* munged remote access unicode string */ - - fprintf(out_hnd, "\t\tLogon Time : %s\n", http_timestring(nt_time_to_unix(&(usr->logon_time )))); - fprintf(out_hnd, "\t\tLogoff Time : %s\n", http_timestring(nt_time_to_unix(&(usr->logoff_time )))); - fprintf(out_hnd, "\t\tKickoff Time : %s\n", http_timestring(nt_time_to_unix(&(usr->kickoff_time )))); - fprintf(out_hnd, "\t\tPassword last set Time : %s\n", http_timestring(nt_time_to_unix(&(usr->pass_last_set_time )))); - fprintf(out_hnd, "\t\tPassword can change Time : %s\n", http_timestring(nt_time_to_unix(&(usr->pass_can_change_time )))); - fprintf(out_hnd, "\t\tPassword must change Time: %s\n", http_timestring(nt_time_to_unix(&(usr->pass_must_change_time)))); - - fprintf(out_hnd, "\t\tunknown_2[0..31]...\n"); /* user passwords? */ - - fprintf(out_hnd, "\t\tuser_rid : %x\n" , usr->user_rid ); /* User ID */ - fprintf(out_hnd, "\t\tgroup_rid: %x\n" , usr->group_rid); /* Group ID */ - fprintf(out_hnd, "\t\tacb_info : %04x\n", usr->acb_info ); /* Account Control Info */ - - fprintf(out_hnd, "\t\tunknown_3: %08x\n", usr->unknown_3); /* 0x00ff ffff */ - fprintf(out_hnd, "\t\tlogon_divs: %d\n", usr->logon_divs); /* 0x0000 00a8 which is 168 which is num hrs in a week */ - fprintf(out_hnd, "\t\tunknown_5: %08x\n", usr->unknown_5); /* 0x0002 0000 */ - - fprintf(out_hnd, "\t\tpadding1[0..7]...\n"); - - if (usr->ptr_logon_hrs) - { - fprintf(out_hnd, "\t\tlogon_hrs[0..%d]...\n", usr->logon_hrs.len); - } - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - - -/**************************************************************************** -convert a security permissions into a string -****************************************************************************/ -char *get_sec_mask_str(uint32 type) -{ - static fstring typestr; - int i; - - switch (type) - { - case SEC_RIGHTS_FULL_CONTROL: - { - fstrcpy(typestr, "Full Control"); - return typestr; - } - - case SEC_RIGHTS_READ: - { - fstrcpy(typestr, "Read"); - return typestr; - } - default: - { - break; - } - } - - typestr[0] = 0; - for (i = 0; i < 32; i++) - { - if (type & (1 << i)) - { - switch (((unsigned)1) << i) - { - case SEC_RIGHTS_QUERY_VALUE : fstrcat(typestr, "Query " ); break; - case SEC_RIGHTS_SET_VALUE : fstrcat(typestr, "Set " ); break; - case SEC_RIGHTS_CREATE_SUBKEY : fstrcat(typestr, "Create "); break; - case SEC_RIGHTS_ENUM_SUBKEYS : fstrcat(typestr, "Enum "); break; - case SEC_RIGHTS_NOTIFY : fstrcat(typestr, "Notify "); break; - case SEC_RIGHTS_CREATE_LINK : fstrcat(typestr, "CreateLink "); break; - case SEC_RIGHTS_DELETE : fstrcat(typestr, "Delete "); break; - case SEC_RIGHTS_READ_CONTROL : fstrcat(typestr, "ReadControl "); break; - case SEC_RIGHTS_WRITE_DAC : fstrcat(typestr, "WriteDAC "); break; - case SEC_RIGHTS_WRITE_OWNER : fstrcat(typestr, "WriteOwner "); break; - } - type &= ~(1 << i); - } - } - - /* remaining bits get added on as-is */ - if (type != 0) - { - fstring tmp; - slprintf(tmp, sizeof(tmp)-1, "[%08x]", type); - fstrcat(typestr, tmp); - } - - /* remove last space */ - i = strlen(typestr)-1; - if (typestr[i] == ' ') typestr[i] = 0; - - return typestr; -} - -/**************************************************************************** - display sec_access structure - ****************************************************************************/ -void display_sec_access(FILE *out_hnd, enum action_type action, SEC_ACCESS *info) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t\tPermissions: %s\n", - get_sec_mask_str(info->mask)); - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** - display sec_ace structure - ****************************************************************************/ -void display_sec_ace(FILE *out_hnd, enum action_type action, SEC_ACE *ace) -{ - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "\tACE\n"); - break; - } - case ACTION_ENUMERATE: - { - fstring sid_str; - - display_sec_access(out_hnd, ACTION_HEADER , &ace->info); - display_sec_access(out_hnd, ACTION_ENUMERATE, &ace->info); - display_sec_access(out_hnd, ACTION_FOOTER , &ace->info); - - sid_to_string(sid_str, &ace->sid); - fprintf(out_hnd, "\t\tSID: %s\n", sid_str); - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** - display sec_acl structure - ****************************************************************************/ -void display_sec_acl(FILE *out_hnd, enum action_type action, SEC_ACL *sec_acl) -{ - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "\tACL\tNum ACEs:\t%d\trevision:\t%x\n", - sec_acl->num_aces, sec_acl->revision); - fprintf(out_hnd, "\t---\n"); - - break; - } - case ACTION_ENUMERATE: - { - if (sec_acl->size != 0 && sec_acl->num_aces != 0) - { - int i; - for (i = 0; i < sec_acl->num_aces; i++) - { - display_sec_ace(out_hnd, ACTION_HEADER , &sec_acl->ace[i]); - display_sec_ace(out_hnd, ACTION_ENUMERATE, &sec_acl->ace[i]); - display_sec_ace(out_hnd, ACTION_FOOTER , &sec_acl->ace[i]); - } - } - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - -/**************************************************************************** - display sec_desc structure - ****************************************************************************/ -void display_sec_desc(FILE *out_hnd, enum action_type action, SEC_DESC *sec) -{ - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "\tSecurity Descriptor\trevision:\t%x\ttype:\t%x\n", - sec->revision, sec->type); - fprintf(out_hnd, "\t-------------------\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring sid_str; - - if (sec->off_sacl != 0) - { - display_sec_acl(out_hnd, ACTION_HEADER , sec->sacl); - display_sec_acl(out_hnd, ACTION_ENUMERATE, sec->sacl); - display_sec_acl(out_hnd, ACTION_FOOTER , sec->sacl); - } - if (sec->off_dacl != 0) - { - display_sec_acl(out_hnd, ACTION_HEADER , sec->dacl); - display_sec_acl(out_hnd, ACTION_ENUMERATE, sec->dacl); - display_sec_acl(out_hnd, ACTION_FOOTER , sec->dacl); - } - if (sec->off_owner_sid != 0) - { - sid_to_string(sid_str, sec->owner_sid); - fprintf(out_hnd, "\tOwner SID:\t%s\n", sid_str); - } - if (sec->off_grp_sid != 0) - { - sid_to_string(sid_str, sec->grp_sid); - fprintf(out_hnd, "\tParent SID:\t%s\n", sid_str); - } - - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - -/**************************************************************************** -convert a security permissions into a string -****************************************************************************/ -char *get_reg_val_type_str(uint32 type) -{ - static fstring typestr; - - switch (type) - { - case 0x01: - { - fstrcpy(typestr, "string"); - return typestr; - } - - case 0x03: - { - fstrcpy(typestr, "bytes"); - return typestr; - } - - case 0x04: - { - fstrcpy(typestr, "uint32"); - return typestr; - } - - case 0x07: - { - fstrcpy(typestr, "multi"); - return typestr; - } - default: - { - break; - } - } - slprintf(typestr, sizeof(typestr)-1, "[%d]", type); - return typestr; -} - - -static void print_reg_value(FILE *out_hnd, char *val_name, uint32 val_type, BUFFER2 *value) -{ - fstring type; - pstring intvalue; - fstrcpy(type, get_reg_val_type_str(val_type)); - - switch (val_type) - { - case 0x01: /* unistr */ - { - rpcstr_pull(intvalue, value->buffer, sizeof(intvalue), value->buf_len, 0); - /*fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, dos_buffer2_to_str(value));*/ - fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, value); - break; - } - - default: /* unknown */ - case 0x03: /* bytes */ - { - if (value->buf_len <= 8) - { - fprintf(out_hnd,"\t%s:\t%s:\t", val_name, type); - out_data(out_hnd, (char*)value->buffer, value->buf_len, 8); - } - else - { - fprintf(out_hnd,"\t%s:\t%s:\n", val_name, type); - out_data(out_hnd, (char*)value->buffer, value->buf_len, 16); - } - break; - } - - case 0x04: /* uint32 */ - { - fprintf(out_hnd,"\t%s:\t%s: 0x%08x\n", val_name, type, buffer2_to_uint32(value)); - break; - } - - case 0x07: /* multiunistr */ - { - fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, dos_buffer2_to_multistr(value)); - break; - } - } -} - -/**************************************************************************** - display structure - ****************************************************************************/ -void display_reg_value_info(FILE *out_hnd, enum action_type action, - char *val_name, uint32 val_type, BUFFER2 *value) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - print_reg_value(out_hnd, val_name, val_type, value); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** - display structure - ****************************************************************************/ -void display_reg_key_info(FILE *out_hnd, enum action_type action, - char *key_name, time_t key_mod_time) -{ - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - fprintf(out_hnd, "\t%s\t(%s)\n", - key_name, http_timestring(key_mod_time)); - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -#if COPY_THIS_TEMPLATE -/**************************************************************************** - display structure - ****************************************************************************/ - void display_(FILE *out_hnd, enum action_type action, *) -{ - switch (action) - { - case ACTION_HEADER: - { - fprintf(out_hnd, "\t\n"); - fprintf(out_hnd, "\t-------------------\n"); - - break; - } - case ACTION_ENUMERATE: - { - break; - } - case ACTION_FOOTER: - { - fprintf(out_hnd, "\n"); - break; - } - } -} - -#endif diff --git a/source3/rpcclient/display_spool.c b/source3/rpcclient/display_spool.c deleted file mode 100644 index b4baf570f1..0000000000 --- a/source3/rpcclient/display_spool.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1992-1999 - Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -/**************************************************************************** -printer info level 0 display function -****************************************************************************/ -static void display_print_info_0(FILE *out_hnd, PRINTER_INFO_0 *i1) -{ - fstring name; - fstring server; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->printername.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(server, i1->servername.buffer, sizeof(server), 0, STR_TERMINATE); - - report(out_hnd, "\tprintername:[%s]\n", name); - report(out_hnd, "\tservername:[%s]\n", server); - report(out_hnd, "\tcjobs:[%x]\n", i1->cjobs); - report(out_hnd, "\ttotal_jobs:[%x]\n", i1->total_jobs); - - report(out_hnd, "\t:date: [%d]-[%d]-[%d] (%d)\n", i1->year, i1->month, i1->day, i1->dayofweek); - report(out_hnd, "\t:time: [%d]-[%d]-[%d]-[%d]\n", i1->hour, i1->minute, i1->second, i1->milliseconds); - - report(out_hnd, "\tglobal_counter:[%x]\n", i1->global_counter); - report(out_hnd, "\ttotal_pages:[%x]\n", i1->total_pages); - - report(out_hnd, "\tmajorversion:[%x]\n", i1->major_version); - report(out_hnd, "\tbuildversion:[%x]\n", i1->build_version); - - report(out_hnd, "\tunknown7:[%x]\n", i1->unknown7); - report(out_hnd, "\tunknown8:[%x]\n", i1->unknown8); - report(out_hnd, "\tunknown9:[%x]\n", i1->unknown9); - report(out_hnd, "\tsession_counter:[%x]\n", i1->session_counter); - report(out_hnd, "\tunknown11:[%x]\n", i1->unknown11); - report(out_hnd, "\tprinter_errors:[%x]\n", i1->printer_errors); - report(out_hnd, "\tunknown13:[%x]\n", i1->unknown13); - report(out_hnd, "\tunknown14:[%x]\n", i1->unknown14); - report(out_hnd, "\tunknown15:[%x]\n", i1->unknown15); - report(out_hnd, "\tunknown16:[%x]\n", i1->unknown16); - report(out_hnd, "\tchange_id:[%x]\n", i1->change_id); - report(out_hnd, "\tunknown18:[%x]\n", i1->unknown18); - report(out_hnd, "\tstatus:[%x]\n", i1->status); - report(out_hnd, "\tunknown20:[%x]\n", i1->unknown20); - report(out_hnd, "\tc_setprinter:[%x]\n", i1->c_setprinter); - report(out_hnd, "\tunknown22:[%x]\n", i1->unknown22); - report(out_hnd, "\tunknown23:[%x]\n", i1->unknown23); - report(out_hnd, "\tunknown24:[%x]\n", i1->unknown24); - report(out_hnd, "\tunknown25:[%x]\n", i1->unknown25); - report(out_hnd, "\tunknown26:[%x]\n", i1->unknown26); - report(out_hnd, "\tunknown27:[%x]\n", i1->unknown27); - report(out_hnd, "\tunknown28:[%x]\n", i1->unknown28); - report(out_hnd, "\tunknown29:[%x]\n", i1->unknown29); -} - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_print_info_1(FILE *out_hnd, PRINTER_INFO_1 *i1) -{ - fstring desc; - fstring name; - fstring comm; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(desc, i1->description.buffer, sizeof(desc), 0, STR_TERMINATE); - rpcstr_pull(comm, i1->comment.buffer, sizeof(comm), 0, STR_TERMINATE); - - report(out_hnd, "\tflags:[%x]\n", i1->flags); - report(out_hnd, "\tname:[%s]\n", name); - report(out_hnd, "\tdescription:[%s]\n", desc); - report(out_hnd, "\tcomment:[%s]\n\n", comm); -} - -/**************************************************************************** -printer info level 2 display function -****************************************************************************/ -static void display_print_info_2(FILE *out_hnd, PRINTER_INFO_2 *i2) -{ - fstring servername; - fstring printername; - fstring sharename; - fstring portname; - fstring drivername; - fstring comment; - fstring location; - fstring sepfile; - fstring printprocessor; - fstring datatype; - fstring parameters; - - if (i2 == NULL) - return; - - rpcstr_pull(servername, i2->servername.buffer,sizeof(servername), 0, STR_TERMINATE); - rpcstr_pull(printername, i2->printername.buffer,sizeof(printername), 0, STR_TERMINATE); - rpcstr_pull(sharename, i2->sharename.buffer,sizeof(sharename), 0, STR_TERMINATE); - rpcstr_pull(portname, i2->portname.buffer,sizeof(portname), 0, STR_TERMINATE); - rpcstr_pull(drivername, i2->drivername.buffer,sizeof(drivername), 0, STR_TERMINATE); - rpcstr_pull(comment, i2->comment.buffer,sizeof(comment), 0, STR_TERMINATE); - rpcstr_pull(location, i2->location.buffer,sizeof(location), 0, STR_TERMINATE); - rpcstr_pull(sepfile, i2->sepfile.buffer,sizeof(sepfile), 0, STR_TERMINATE); - rpcstr_pull(printprocessor, i2->printprocessor.buffer,sizeof(printprocessor), 0, STR_TERMINATE); - rpcstr_pull(datatype, i2->datatype.buffer,sizeof(datatype), 0, STR_TERMINATE); - rpcstr_pull(parameters, i2->parameters.buffer,sizeof(parameters), 0, STR_TERMINATE); - - report(out_hnd, "\tservername:[%s]\n", servername); - report(out_hnd, "\tprintername:[%s]\n", printername); - report(out_hnd, "\tsharename:[%s]\n", sharename); - report(out_hnd, "\tportname:[%s]\n", portname); - report(out_hnd, "\tdrivername:[%s]\n", drivername); - report(out_hnd, "\tcomment:[%s]\n", comment); - report(out_hnd, "\tlocation:[%s]\n", location); - report(out_hnd, "\tsepfile:[%s]\n", sepfile); - report(out_hnd, "\tprintprocessor:[%s]\n", printprocessor); - report(out_hnd, "\tdatatype:[%s]\n", datatype); - report(out_hnd, "\tparameters:[%s]\n", parameters); - report(out_hnd, "\tattributes:[%x]\n", i2->attributes); - report(out_hnd, "\tpriority:[%x]\n", i2->priority); - report(out_hnd, "\tdefaultpriority:[%x]\n", i2->defaultpriority); - report(out_hnd, "\tstarttime:[%x]\n", i2->starttime); - report(out_hnd, "\tuntiltime:[%x]\n", i2->untiltime); - report(out_hnd, "\tstatus:[%x]\n", i2->status); - report(out_hnd, "\tcjobs:[%x]\n", i2->cjobs); - report(out_hnd, "\taverageppm:[%x]\n\n", i2->averageppm); - - if (i2->secdesc != NULL) - { - display_sec_desc(out_hnd, ACTION_HEADER , i2->secdesc); - display_sec_desc(out_hnd, ACTION_ENUMERATE, i2->secdesc); - display_sec_desc(out_hnd, ACTION_FOOTER , i2->secdesc); - } -} - -/**************************************************************************** -printer info level 3 display function -****************************************************************************/ -static void display_print_info_3(FILE *out_hnd, PRINTER_INFO_3 *i3) -{ - if (i3 == NULL) - return; - - report(out_hnd, "\tflags:[%x]\n", i3->flags); - - display_sec_desc(out_hnd, ACTION_HEADER , i3->secdesc); - display_sec_desc(out_hnd, ACTION_ENUMERATE, i3->secdesc); - display_sec_desc(out_hnd, ACTION_FOOTER , i3->secdesc); -} - -/**************************************************************************** -connection info level 0 container display function -****************************************************************************/ -static void display_printer_info_0_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_0 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 0:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_0; - display_print_info_0(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printer_info_1_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_1 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_1; - display_print_info_1(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -static void display_printer_info_2_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_2 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_2; - display_print_info_2(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_printer_info_3_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_INFO_CTR ctr) -{ - int i; - PRINTER_INFO_3 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer Info Level 3:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.printers_3; - display_print_info_3(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PRINTER_INFO_CTR ctr) -{ - switch (level) { - case 0: - display_printer_info_0_ctr(out_hnd, action, count, ctr); - break; - case 1: - display_printer_info_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_printer_info_2_ctr(out_hnd, action, count, ctr); - break; - case 3: - display_printer_info_3_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_printer_info_ctr: Unknown Info Level\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_port_info_1_ctr(FILE *out_hnd, enum action_type action, - uint32 count, PORT_INFO_CTR *ctr) -{ - uint32 i = 0; - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i=0; iport.info_1[i]); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_port_info_2_ctr(FILE *out_hnd, enum action_type action, - uint32 count, PORT_INFO_CTR *ctr) -{ - uint32 i = 0; - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port Info Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i=0; iport.info_2[i]); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PORT_INFO_CTR *ctr) -{ - switch (level) { - case 1: - display_port_info_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_port_info_2_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_port_info_ctr: Unknown Info Level\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_1(FILE *out_hnd, enum action_type action, PORT_INFO_1 *i1) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port:\n"); - break; - case ACTION_ENUMERATE: - rpcstr_pull(buffer, i1->port_name.buffer, sizeof(bufferi), 0, STR_TERMINATE); - fprintf (out_hnd, "\tPort Name:\t[%s]\n\n", buffer); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_port_info_2(FILE *out_hnd, enum action_type action, PORT_INFO_2 *i2) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Port:\n"); - break; - case ACTION_ENUMERATE: - rpcstr_pull(buffer, i2->port_name.buffer, sizeof(buffer), 0, STR_TERMINATE); - fprintf (out_hnd, "\tPort Name:\t[%s]\n", buffer); - rpcstr_pull(buffer, i2->monitor_name.buffer, sizeof(buffer), 0, STR_TERMINATE); - - fprintf (out_hnd, "\tMonitor Name:\t[%s]\n", buffer); - rpcstr_pull(buffer, i2->description.buffer, sizeof(buffer), 0, STR_TERMINATE); - fprintf (out_hnd, "\tDescription:\t[%s]\n", buffer); - fprintf (out_hnd, "\tPort Type:\t[%d]\n", i2->port_type); - fprintf (out_hnd, "\tReserved:\t[%d]\n", i2->reserved); - fprintf (out_hnd, "\n"); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_enumdata(FILE *out_hnd, enum action_type action, uint32 idx, - uint32 valuelen, uint16 *value, uint32 rvaluelen, - uint32 type, - uint32 datalen, uint8 *data, uint32 rdatalen) -{ - fstring buffer; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer enum data:\n"); - report(out_hnd, "index\tvaluelen\tvalue\t\trvaluelen"); - report(out_hnd, "\ttype\tdatalen\tdata\trdatalen\n"); - break; - case ACTION_ENUMERATE: - report(out_hnd, "[%d]", idx); - report(out_hnd, "\t[%d]", valuelen); - rpcstr_pull(buffer, value, sizeof(buffer), 0, STR_TERMINATE); - report(out_hnd, "\t[%s]", buffer); - report(out_hnd, "\t[%d]", rvaluelen); - report(out_hnd, "\t\t[%d]", type); - report(out_hnd, "\t[%d]", datalen); -/* report(out_hnd, "\t[%s]", data);*/ - report(out_hnd, "\t[%d]\n", rdatalen); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -job info level 2 display function -****************************************************************************/ -void display_job_info_2(FILE *out_hnd, enum action_type action, - JOB_INFO_2 *const i2) -{ - if (i2 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - report(out_hnd, "Job Info Level 2:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring tmp; - - report(out_hnd, "\tjob id:\t%d\n", i2->jobid); - rpcstr_pull(tmp, i2->printername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprinter name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->machinename.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tmachine name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->username.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tusername:\t%s\n", tmp); - rpcstr_pull(tmp, i2->document.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdocument:\t%s\n", tmp); - rpcstr_pull(tmp, i2->notifyname.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tnotify name:\t%s\n", tmp); - rpcstr_pull(tmp, i2->datatype.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdata type:\t%s\n", tmp); - rpcstr_pull(tmp, i2->printprocessor.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprint processor:\t%s\n", tmp); - rpcstr_pull(tmp, i2->parameters.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tparameters:\t%s\n", tmp); - rpcstr_pull(tmp, i2->drivername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdriver name:\t%s\n", tmp); - report(out_hnd, "\tDevice Mode:\tNOT DISPLAYED YET\n"); - - rpcstr_pull(tmp, i2->text_status.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\ttext status:\t%s\n", tmp); - /* SEC_DESC sec_desc;*/ - report(out_hnd, "\tstatus:\t%d\n", i2->status); - report(out_hnd, "\tpriority:\t%d\n", i2->priority); - report(out_hnd, "\tposition:\t%d\n", i2->position); - report(out_hnd, "\tstarttime:\t%d\n", i2->starttime); - report(out_hnd, "\tuntiltime:\t%d\n", i2->untiltime); - report(out_hnd, "\ttotalpages:\t%d\n", i2->totalpages); - report(out_hnd, "\tsize:\t%d\n", i2->size); -/* - SYSTEMTIME submitted; -*/ - report(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); - report(out_hnd, "\ttimeelapsed:\t%d\n", i2->timeelapsed); - report(out_hnd, "\tpagesprinted:\t%d\n", i2->pagesprinted); - } - case ACTION_FOOTER: - { - report(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -job info level 1 display function -****************************************************************************/ -void display_job_info_1(FILE *out_hnd, enum action_type action, - JOB_INFO_1 *const i1) -{ - if (i1 == NULL) - { - return; - } - - switch (action) - { - case ACTION_HEADER: - { - report(out_hnd, "Job Info Level 1:\n"); - - break; - } - case ACTION_ENUMERATE: - { - fstring tmp; - - report(out_hnd, "\tjob id:\t%d\n", i1->jobid); - rpcstr_pull(tmp, i1->printername.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tprinter name:\t%s\n", tmp); - rpcstr_pull(tmp, i1->machinename.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tmachine name:\t%s\n", tmp); - rpcstr_pull(tmp, i1->username.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tusername:\t%s\n", tmp); - rpcstr_pull(tmp, i1->document.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdocument:\t%s\n", tmp); - rpcstr_pull(tmp, i1->datatype.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\tdata type:\t%s\n", tmp); - rpcstr_pull(tmp, i1->text_status.buffer, sizeof(tmp), 0, STR_TERMINATE); - report(out_hnd, "\ttext status:\t%s\n", tmp); - report(out_hnd, "\tstatus:\t%d\n", i1->status); - report(out_hnd, "\tpriority:\t%d\n", i1->priority); - report(out_hnd, "\tposition:\t%d\n", i1->position); - report(out_hnd, "\ttotalpages:\t%d\n", i1->totalpages); -/* - SYSTEMTIME submitted; -*/ - report(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); - report(out_hnd, "\tpagesprinted:\t%d\n", i1->pagesprinted); - - break; - } - case ACTION_FOOTER: - { - report(out_hnd, "\n"); - break; - } - } - -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -void display_job_info_2_ctr(FILE *out_hnd, enum action_type action, - uint32 count, JOB_INFO_2 *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_2_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < count; i++) - { - display_job_info_2(out_hnd, ACTION_HEADER , ctr[i]); - display_job_info_2(out_hnd, ACTION_ENUMERATE, ctr[i]); - display_job_info_2(out_hnd, ACTION_FOOTER , ctr[i]); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -void display_job_info_1_ctr(FILE *out_hnd, enum action_type action, - uint32 count, JOB_INFO_1 *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_1_ctr: unavailable due to an internal error\n"); - return; - } - - switch (action) - { - case ACTION_HEADER: - { - break; - } - case ACTION_ENUMERATE: - { - int i; - - for (i = 0; i < count; i++) - { - display_job_info_1(out_hnd, ACTION_HEADER , ctr[i]); - display_job_info_1(out_hnd, ACTION_ENUMERATE, ctr[i]); - display_job_info_1(out_hnd, ACTION_FOOTER , ctr[i]); - } - break; - } - case ACTION_FOOTER: - { - break; - } - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_job_info_ctr(FILE *out_hnd, enum action_type action, - uint32 level, uint32 count, - void *const *const ctr) -{ - if (ctr == NULL) - { - report(out_hnd, "display_job_info_ctr: unavailable due to an internal error\n"); - return; - } - - switch (level) - { - case 1: - { - display_job_info_1_ctr(out_hnd, action, - count, (JOB_INFO_1*const*const)ctr); - break; - } - case 2: - { - display_job_info_2_ctr(out_hnd, action, - count, (JOB_INFO_2*const*const)ctr); - break; - } - default: - { - report(out_hnd, "display_job_info_ctr: Unknown Info Level\n"); - break; - } - } -} - -/**************************************************************************** -printer info level 0 display function -****************************************************************************/ -static void display_print_driver_1(FILE *out_hnd, DRIVER_INFO_1 *i1) -{ - fstring name; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - - report(out_hnd, "\tname:[%s]\n", name); -} - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_print_driver_2(FILE *out_hnd, DRIVER_INFO_2 *i1) -{ - fstring name; - fstring architecture; - fstring driverpath; - fstring datafile; - fstring configfile; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), 0, STR_TERMINATE); - rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), 0, STR_TERMINATE); - rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), 0, STR_TERMINATE); - rpcstr_pull(configfile, i1->conigfile.buffer, sizeof(configfile), 0, STR_TERMINATE); - - report(out_hnd, "\tversion:[%x]\n", i1->version); - report(out_hnd, "\tname:[%s]\n", name); - report(out_hnd, "\tarchitecture:[%s]\n", architecture); - report(out_hnd, "\tdriverpath:[%s]\n", driverpath); - report(out_hnd, "\tdatafile:[%s]\n", datafile); - report(out_hnd, "\tconfigfile:[%s]\n", configfile); -} - -/**************************************************************************** -printer info level 2 display function -****************************************************************************/ -static void display_print_driver_3(FILE *out_hnd, DRIVER_INFO_3 *i1) -{ - fstring name; - fstring architecture; - fstring driverpath; - fstring datafile; - fstring configfile; - fstring helpfile; - fstring dependentfiles; - fstring monitorname; - fstring defaultdatatype; - - int length=0; - BOOL valid = True; - - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), 0, STR_TERMINATE); - rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), 0, STR_TERMINATE); - rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), 0, STR_TERMINATE); - rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), 0, STR_TERMINATE); - rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), 0, STR_TERMINATE); - rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), 0, STR_TERMINATE); - rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), 0, STR_TERMINATE); - - report(out_hnd, "\tversion:[%x]\n", i1->version); - report(out_hnd, "\tname:[%s]\n",name); - report(out_hnd, "\tarchitecture:[%s]\n", architecture); - report(out_hnd, "\tdriverpath:[%s]\n", driverpath); - report(out_hnd, "\tdatafile:[%s]\n", datafile); - report(out_hnd, "\tconfigfile:[%s]\n", configfile); - report(out_hnd, "\thelpfile:[%s]\n\n", helpfile); - - while (valid) - { - rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), 0, STR_TERMINATE); - length+=strlen(dependentfiles)+1; - - if (strlen(dependentfiles) > 0) - { - report(out_hnd, "\tdependentfiles:[%s]\n", dependentfiles); - } - else - { - valid = False; - } - } - - report(out_hnd, "\n\tmonitorname:[%s]\n", monitorname); - report(out_hnd, "\tdefaultdatatype:[%s]\n", defaultdatatype); - -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printer_driver_1_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_1 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 1:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info1; - display_print_driver_1(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 2 container display function -****************************************************************************/ -static void display_printer_driver_2_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_2 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 2:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info2; - display_print_driver_2(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info level 3 container display function -****************************************************************************/ -static void display_printer_driver_3_ctr(FILE *out_hnd, enum action_type action, uint32 count, PRINTER_DRIVER_CTR ctr) -{ - int i; - DRIVER_INFO_3 *in; - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver Level 3:\n"); - break; - case ACTION_ENUMERATE: - for (i = 0; i < count; i++) { - in=ctr.info3; - display_print_driver_3(out_hnd, &(in[i]) ); - } - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printer_driver_ctr(FILE *out_hnd, enum action_type action, uint32 level, - uint32 count, PRINTER_DRIVER_CTR ctr) -{ - switch (level) { - case 1: - display_printer_driver_1_ctr(out_hnd, action, count, ctr); - break; - case 2: - display_printer_driver_2_ctr(out_hnd, action, count, ctr); - break; - case 3: - display_printer_driver_3_ctr(out_hnd, action, count, ctr); - break; - default: - report(out_hnd, "display_printer_driver_ctr: Unknown Info Level\n"); - break; - } -} - - -/**************************************************************************** -printer info level 1 display function -****************************************************************************/ -static void display_printdriverdir_info_1(FILE *out_hnd, DRIVER_DIRECTORY_1 *i1) -{ - fstring name; - if (i1 == NULL) - return; - - rpcstr_pull(name, i1->name.buffer, sizeof(name), 0, STR_TERMINATE); - - report(out_hnd, "\tname:[%s]\n", name); -} - -/**************************************************************************** -connection info level 1 container display function -****************************************************************************/ -static void display_printerdriverdir_info_1_ctr(FILE *out_hnd, enum action_type action, DRIVER_DIRECTORY_CTR ctr) -{ - - switch (action) - { - case ACTION_HEADER: - report(out_hnd, "Printer driver dir Info Level 1:\n"); - break; - case ACTION_ENUMERATE: - display_printdriverdir_info_1(out_hnd, &(ctr.driver.info_1) ); - break; - case ACTION_FOOTER: - report(out_hnd, "\n"); - break; - } -} - -/**************************************************************************** -connection info container display function -****************************************************************************/ -void display_printerdriverdir_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, - DRIVER_DIRECTORY_CTR ctr) -{ - switch (level) { - case 1: - display_printerdriverdir_info_1_ctr(out_hnd, action, ctr); - break; - default: - report(out_hnd, "display_printerdriverdir_info_ctr: Unknown Info Level\n"); - break; - } -} diff --git a/source3/rpcclient/samsync.c b/source3/rpcclient/samsync.c deleted file mode 100644 index a4061d2a87..0000000000 --- a/source3/rpcclient/samsync.c +++ /dev/null @@ -1,773 +0,0 @@ -/* - Unix SMB/CIFS implementation. - SAM synchronisation and replication - - Copyright (C) Tim Potter 2001,2002 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -DOM_SID domain_sid; - -static void decode_domain_info(SAM_DOMAIN_INFO *a) -{ - fstring temp; - printf("Domain Information\n"); - printf("------------------\n"); - - unistr2_to_ascii(temp, &a->uni_dom_name, sizeof(temp)-1); - printf("\tDomain :%s\n", temp); - printf("\tMin password len :%d\n", a->min_pwd_len); - printf("\tpassword history len:%d\n", a->pwd_history_len); - printf("\tcreation time :%s\n", http_timestring(nt_time_to_unix(&a->creation_time))); -} - -static void decode_sam_group_info(SAM_GROUP_INFO *a) -{ - fstring temp; - printf("\nDomain Group Information\n"); - printf("------------------------\n"); - - unistr2_to_ascii(temp, &a->uni_grp_name, sizeof(temp)-1); - printf("\tGroup name :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_grp_desc, sizeof(temp)-1); - printf("\tGroup description :%s\n", temp); - printf("\trid :%d\n", a->gid.g_rid); - printf("\tattribute :%d\n", a->gid.attr); -} - -static void decode_sam_account_info(SAM_ACCOUNT_INFO *a) -{ - fstring temp; - printf("\nUser Information\n"); - printf("----------------\n"); - - unistr2_to_ascii(temp, &a->uni_acct_name, sizeof(temp)-1); - printf("\tUser name :%s\n", temp); - printf("\tuser's rid :%d\n", a->user_rid); - printf("\tuser's primary gid :%d\n", a->group_rid); - unistr2_to_ascii(temp, &a->uni_full_name, sizeof(temp)-1); - printf("\tfull name :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_home_dir, sizeof(temp)-1); - printf("\thome directory :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_dir_drive, sizeof(temp)-1); - printf("\tdrive :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_logon_script, sizeof(temp)-1); - printf("\tlogon script :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_acct_desc, sizeof(temp)-1); - printf("\tdescription :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_workstations, sizeof(temp)-1); - printf("\tworkstations :%s\n", temp); -} - -static void decode_sam_grp_mem_info(SAM_GROUP_MEM_INFO *a) -{ - int i; - printf("\nGroup members information\n"); - printf("-------------------------\n"); - printf("\tnum members :%d\n", a->num_members); - - for (i=0; inum_members; i++) { - printf("\trid, attr:%d, %d\n", a->rids[i], a->attribs[i]); - } -} - -static void decode_sam_alias_info(SAM_ALIAS_INFO *a) -{ - fstring temp; - printf("\nAlias Information\n"); - printf("-----------------\n"); - - unistr2_to_ascii(temp, &a->uni_als_name, sizeof(temp)-1); - printf("\tname :%s\n", temp); - unistr2_to_ascii(temp, &a->uni_als_desc, sizeof(temp)-1); - printf("\tdescription :%s\n", temp); - printf("\trid :%d\n", a->als_rid); -} - -static void decode_sam_als_mem_info(SAM_ALIAS_MEM_INFO *a) -{ - int i; - fstring temp; - printf("\nAlias members Information\n"); - printf("-------------------------\n"); - printf("\tnum members :%d\n", a->num_members); - printf("\tnum sids :%d\n", a->num_sids); - for (i=0; inum_sids; i++) { - printf("\tsid :%s\n", sid_to_string(temp, &a->sids[i].sid)); - } - - -} - -static void decode_sam_dom_info(SAM_DELTA_DOM *a) -{ - fstring temp; - printf("\nDomain information\n"); - printf("------------------\n"); - - unistr2_to_ascii(temp, &a->domain_name, sizeof(temp)-1); - printf("\tdomain name :%s\n", temp); - printf("\tsid :%s\n", sid_to_string(temp, &a->domain_sid.sid)); -} - -static void decode_sam_unk0e_info(SAM_DELTA_UNK0E *a) -{ - fstring temp; - printf("\nTrust information\n"); - printf("-----------------\n"); - - unistr2_to_ascii(temp, &a->domain, sizeof(temp)-1); - printf("\tdomain name :%s\n", temp); - printf("\tsid :%s\n", sid_to_string(temp, &a->sid.sid)); - display_sec_desc(a->sec_desc); -} - -static void decode_sam_privs_info(SAM_DELTA_PRIVS *a) -{ - int i; - fstring temp; - printf("\nSID and privileges information\n"); - printf("------------------------------\n"); - printf("\tsid :%s\n", sid_to_string(temp, &a->sid.sid)); - display_sec_desc(a->sec_desc); - printf("\tprivileges count :%d\n", a->privlist_count); - for (i=0; iprivlist_count; i++) { - unistr2_to_ascii(temp, &a->uni_privslist[i], sizeof(temp)-1); - printf("\tprivilege name :%s\n", temp); - printf("\tattribute :%d\n", a->attributes[i]); - } -} - -static void decode_sam_unk12_info(SAM_DELTA_UNK12 *a) -{ - fstring temp; - printf("\nTrusted information\n"); - printf("-------------------\n"); - - unistr2_to_ascii(temp, &a->secret, sizeof(temp)-1); - printf("\tsecret name :%s\n", temp); - display_sec_desc(a->sec_desc); - - printf("\ttime 1 :%s\n", http_timestring(nt_time_to_unix(&a->time1))); - printf("\ttime 2 :%s\n", http_timestring(nt_time_to_unix(&a->time2))); - - display_sec_desc(a->sec_desc2); -} - -static void decode_sam_stamp(SAM_DELTA_STAMP *a) -{ - printf("\nStamp information\n"); - printf("-----------------\n"); - printf("\tsequence number :%d\n", a->seqnum); -} - -static void decode_sam_deltas(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas, SAM_DELTA_CTR *deltas) -{ - int i; - for (i = 0; i < num_deltas; i++) { - switch (hdr_deltas[i].type) { - case SAM_DELTA_DOMAIN_INFO: { - SAM_DOMAIN_INFO *a; - a = &deltas[i].domain_info; - decode_domain_info(a); - break; - } - case SAM_DELTA_GROUP_INFO: { - SAM_GROUP_INFO *a; - a = &deltas[i].group_info; - decode_sam_group_info(a); - break; - } - case SAM_DELTA_ACCOUNT_INFO: { - SAM_ACCOUNT_INFO *a; - a = &deltas[i].account_info; - decode_sam_account_info(a); - break; - } - case SAM_DELTA_GROUP_MEM: { - SAM_GROUP_MEM_INFO *a; - a = &deltas[i].grp_mem_info; - decode_sam_grp_mem_info(a); - break; - } - case SAM_DELTA_ALIAS_INFO: { - SAM_ALIAS_INFO *a; - a = &deltas[i].alias_info; - decode_sam_alias_info(a); - break; - } - case SAM_DELTA_ALIAS_MEM: { - SAM_ALIAS_MEM_INFO *a; - a = &deltas[i].als_mem_info; - decode_sam_als_mem_info(a); - break; - } - case SAM_DELTA_POLICY_INFO: { - SAM_DELTA_POLICY *a; - a = &deltas[i].dom_info; - decode_sam_dom_info(a); - break; - } - case SAM_DELTA_UNK0E_INFO: { - SAM_DELTA_UNK0E *a; - a = &deltas[i].unk0e_info; - decode_sam_unk0e_info(a); - break; - } - case SAM_DELTA_PRIVS_INFO: { - SAM_DELTA_PRIVS *a; - a = &deltas[i].privs_info; - decode_sam_privs_info(a); - break; - } - case SAM_DELTA_UNK12_INFO: { - SAM_DELTA_UNK12 *a; - a = &deltas[i].unk12_info; - decode_sam_unk12_info(a); - break; - } - case SAM_DELTA_SAM_STAMP: { - SAM_DELTA_STAMP *a; - a = &deltas[i].stamp; - decode_sam_stamp(a); - break; - } - default: - DEBUG(0,("unknown delta type: %d\n", hdr_deltas[i].type)); - break; - } - } -} - -/* Convert a SAM_ACCOUNT_DELTA to a SAM_ACCOUNT. */ - -static void sam_account_from_delta(SAM_ACCOUNT *account, - SAM_ACCOUNT_INFO *delta) -{ - DOM_SID sid; - fstring s; - - /* Username, fullname, home dir, dir drive, logon script, acct - desc, workstations, profile. */ - - unistr2_to_ascii(s, &delta->uni_acct_name, sizeof(s) - 1); - pdb_set_nt_username(account, s); - - /* Unix username is the same - for sainity */ - pdb_set_username(account, s); - - unistr2_to_ascii(s, &delta->uni_full_name, sizeof(s) - 1); - pdb_set_fullname(account, s); - - unistr2_to_ascii(s, &delta->uni_home_dir, sizeof(s) - 1); - pdb_set_homedir(account, s, True); - - unistr2_to_ascii(s, &delta->uni_dir_drive, sizeof(s) - 1); - pdb_set_dir_drive(account, s, True); - - unistr2_to_ascii(s, &delta->uni_logon_script, sizeof(s) - 1); - pdb_set_logon_script(account, s, True); - - unistr2_to_ascii(s, &delta->uni_acct_desc, sizeof(s) - 1); - pdb_set_acct_desc(account, s); - - unistr2_to_ascii(s, &delta->uni_workstations, sizeof(s) - 1); - pdb_set_workstations(account, s); - - unistr2_to_ascii(s, &delta->uni_profile, sizeof(s) - 1); - pdb_set_profile_path(account, s, True); - - /* User and group sid */ - - sid_copy(&sid, &domain_sid); - sid_append_rid(&sid, delta->user_rid); - pdb_set_user_sid(account, &sid); - - sid_copy(&sid, &domain_sid); - sid_append_rid(&sid, delta->group_rid); - pdb_set_group_sid(account, &sid); - - /* Logon and password information */ - - pdb_set_logon_time(account, nt_time_to_unix(&delta->logon_time), True); - pdb_set_logoff_time(account, nt_time_to_unix(&delta->logoff_time), - True); - - pdb_set_logon_divs(account, delta->logon_divs); - - /* TODO: logon hours */ - /* TODO: bad password count */ - /* TODO: logon count */ - - pdb_set_pass_last_set_time( - account, nt_time_to_unix(&delta->pwd_last_set_time)); - - /* TODO: account expiry time */ - - pdb_set_acct_ctrl(account, delta->acb_info); -} - -static void apply_account_info(SAM_ACCOUNT_INFO *sam_acct_delta) -{ - SAM_ACCOUNT *sam_acct; - BOOL result; - - if (!NT_STATUS_IS_OK(pdb_init_sam(&sam_acct))) { - return; - } - - sam_account_from_delta(sam_acct, sam_acct_delta); - result = pdb_add_sam_account(sam_acct); -} - -/* Apply an array of deltas to the SAM database */ - -static void apply_deltas(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas, - SAM_DELTA_CTR *deltas) -{ - uint32 i; - - for (i = 0; i < num_deltas; i++) { - switch(hdr_deltas[i].type) { - case SAM_DELTA_ACCOUNT_INFO: - apply_account_info(&deltas[i].account_info); - break; - } - } -} - -/* Synchronise sam database */ - -static NTSTATUS sam_sync(struct cli_state *cli, unsigned char trust_passwd[16], - BOOL do_smbpasswd_output, BOOL verbose) -{ - TALLOC_CTX *mem_ctx; - SAM_DELTA_HDR *hdr_deltas_0, *hdr_deltas_2; - SAM_DELTA_CTR *deltas_0, *deltas_2; - uint32 num_deltas_0, num_deltas_2; - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - struct pdb_context *in; - uint32 neg_flags = 0x000001ff; - - DOM_CRED ret_creds; - - /* Initialise */ - - if (!NT_STATUS_IS_OK(make_pdb_context_list(&in, lp_passdb_backend()))){ - DEBUG(0, ("Can't initialize passdb backend.\n")); - return result; - } - - if (!(mem_ctx = talloc_init("sam_sync"))) { - DEBUG(0,("talloc_init failed\n")); - return result; - } - - if (!cli_nt_session_open (cli, PI_NETLOGON)) { - DEBUG(0, ("Could not initialize netlogon pipe!\n")); - goto done; - } - - /* Request a challenge */ - - if (!NT_STATUS_IS_OK(cli_nt_setup_creds(cli, SEC_CHAN_BDC, trust_passwd, &neg_flags, 2))) { - DEBUG(0, ("Error initialising session creds\n")); - goto done; - } - - /* on first call the returnAuthenticator is empty */ - memset(&ret_creds, 0, sizeof(ret_creds)); - - /* Do sam synchronisation on the SAM database*/ - - result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, 0, 0, - &num_deltas_0, &hdr_deltas_0, - &deltas_0); - - if (!NT_STATUS_IS_OK(result)) - goto done; - - - /* Update sam */ - - apply_deltas(num_deltas_0, hdr_deltas_0, deltas_0); - - - /* - * we can't yet do several sam_sync in a raw, it's a credential problem - * we must chain the credentials - */ - -#if 1 - /* Do sam synchronisation on the LSA database */ - - result = cli_netlogon_sam_sync(cli, mem_ctx, &ret_creds, 2, 0, &num_deltas_2, &hdr_deltas_2, &deltas_2); - - if (!NT_STATUS_IS_OK(result)) - goto done; - - /* verbose mode */ - if (verbose) - decode_sam_deltas(num_deltas_2, hdr_deltas_2, deltas_2); -#endif - - /* Produce smbpasswd output - good for migrating from NT! */ - - if (do_smbpasswd_output) { - int i; - - for (i = 0; i < num_deltas_0; i++) { - SAM_ACCOUNT_INFO *a; - fstring acct_name, hex_nt_passwd, hex_lm_passwd; - uchar lm_passwd[16], nt_passwd[16]; - - /* Skip non-user accounts */ - - if (hdr_deltas_0[i].type != SAM_DELTA_ACCOUNT_INFO) - continue; - - a = &deltas_0[i].account_info; - - unistr2_to_ascii(acct_name, &a->uni_acct_name, - sizeof(acct_name) - 1); - - /* Decode hashes from password hash */ - - sam_pwd_hash(a->user_rid, a->pass.buf_lm_pwd, - lm_passwd, 0); - sam_pwd_hash(a->user_rid, a->pass.buf_nt_pwd, - nt_passwd, 0); - - /* Encode as strings */ - - smbpasswd_sethexpwd(hex_lm_passwd, lm_passwd, - a->acb_info); - smbpasswd_sethexpwd(hex_nt_passwd, nt_passwd, - a->acb_info); - - /* Display user info */ - - printf("%s:%d:%s:%s:%s:LCT-0\n", acct_name, - a->user_rid, hex_lm_passwd, hex_nt_passwd, - smbpasswd_encode_acb_info(a->acb_info)); - } - - goto done; - } - - done: - cli_nt_session_close(cli); - talloc_destroy(mem_ctx); - - return result; -} - -/* Replicate sam deltas */ - -static NTSTATUS sam_repl(struct cli_state *cli, unsigned char trust_passwde[16], - uint32 low_serial) -{ - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - - return result; -} - -/* Connect to primary domain controller */ - -static struct cli_state *init_connection(struct cli_state **cli, - char *username, char *domain, - char *password) -{ - extern pstring global_myname; - struct in_addr pdc_ip; - fstring dest_host; - - /* Initialise myname */ - - if (!global_myname[0]) { - char *p; - - fstrcpy(global_myname, myhostname()); - p = strchr(global_myname, '.'); - if (p) - *p = 0; - } - - /* Look up name of PDC controller */ - - if (!get_pdc_ip(lp_workgroup(), &pdc_ip)) { - DEBUG(0, ("Cannot find domain controller for domain %s\n", - lp_workgroup())); - return NULL; - } - - if (!lookup_dc_name(global_myname, lp_workgroup(), pdc_ip, - dest_host)) { - DEBUG(0, ("Could not lookup up PDC name for domain %s\n", - lp_workgroup())); - return NULL; - } - - if (NT_STATUS_IS_OK(cli_full_connection(cli, global_myname, dest_host, - pdc_ip, 0, - "IPC$", "IPC", - username, domain, - password, 0))) { - return *cli; - } - - return NULL; -} - -/* Main function */ - -static fstring popt_username, popt_domain, popt_password; -static BOOL popt_got_pass; - -static void user_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - const char *p, *ch; - - if (!arg) - return; - - switch(opt->val) { - - /* Check for [DOMAIN\\]username[%password]*/ - - case 'U': - - p = arg; - - if ((ch = strchr(p, '\\'))) { - fstrcpy(popt_domain, p); - popt_domain[ch - p] = 0; - } - - fstrcpy(popt_username, p); - - if ((ch = strchr(p, '%'))) { - popt_username[ch - p] = 0; - fstrcpy(popt_password, ch + 1); - popt_got_pass = True; - } - - break; - - case 'W': - fstrcpy(popt_domain, arg); - break; - } -} - -/* Return domain, username and password passed in from cmd line */ - -void popt_common_get_auth_info(char **domain, char **username, char **password, - BOOL *got_pass) -{ - *domain = popt_domain; - *username = popt_username; - *password = popt_password; - *got_pass = popt_got_pass; -} - -struct poptOption popt_common_auth_info[] = { - { NULL, 0, POPT_ARG_CALLBACK, user_callback }, - { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set username", - "[DOMAIN\\]username[%password]" }, - { "domain", 'W', POPT_ARG_STRING, NULL, 'W', "Set domain name", - "DOMAIN"}, - { 0 } -}; - -static BOOL popt_interactive; - -BOOL popt_common_is_interactive(void) -{ - return popt_interactive; -} - -struct poptOption popt_common_interactive[] = { - { "interactive", 'i', POPT_ARG_NONE, &popt_interactive, 'i', - "Log to stdout" }, - { 0 } -}; - - int main(int argc, char **argv) -{ - BOOL do_sam_sync = False, do_sam_repl = False; - struct cli_state *cli; - NTSTATUS result; - pstring logfile; - BOOL do_smbpasswd_output = False; - BOOL verbose = True, got_pass = False; - uint32 serial = 0; - unsigned char trust_passwd[16]; - char *username, *domain, *password; - poptContext pc; - char c; - - struct poptOption popt_samsync_opts[] = { - { "synchronise", 'S', POPT_ARG_NONE, &do_sam_sync, 'S', - "Perform full SAM synchronisation" }, - { "replicate", 'R', POPT_ARG_NONE, &do_sam_repl, 'R', - "Replicate SAM changes" }, - { "serial", 0, POPT_ARG_INT, &serial, 0, "SAM serial number" }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version}, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_auth_info }, - { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_interactive }, - POPT_AUTOHELP - { 0 } - }; - - /* Read command line options */ - - pc = poptGetContext("samsync", argc, (const char **)argv, - popt_samsync_opts, 0); - - if (argc == 1) { - poptPrintUsage(pc, stdout, 0); - return 1; - } - - while ((c = poptGetNextOpt(pc)) != -1) { - - /* Argument processing error */ - - if (c < -1) { - fprintf(stderr, "samsync: %s: %s\n", - poptBadOption(pc, POPT_BADOPTION_NOALIAS), - poptStrerror(c)); - return 1; - } - - /* Handle arguments */ - - switch (c) { - case 'h': - poptPrintHelp(pc, stdout, 0); - return 1; - case 'u': - poptPrintUsage(pc, stdout, 0); - return 1; - } - } - - /* Bail out if any extra args were passed */ - - if (poptPeekArg(pc)) { - fprintf(stderr, "samsync: invalid argument %s\n", - poptPeekArg(pc)); - poptPrintUsage(pc, stdout, 0); - return 1; - } - - poptFreeContext(pc); - - /* Setup logging */ - - dbf = x_stdout; - - if (!lp_load(dyn_CONFIGFILE, True, False, False)) { - d_fprintf(stderr, "samsync: error opening config file %s. " - "Error was %s\n", dyn_CONFIGFILE, strerror(errno)); - return 1; - } - - slprintf(logfile, sizeof(logfile) - 1, "%s/log.%s", dyn_LOGFILEBASE, - "samsync"); - - lp_set_logfile(logfile); - - setup_logging("samsync", popt_common_is_interactive()); - - if (!popt_common_is_interactive()) - reopen_logs(); - - load_interfaces(); - - /* Check arguments make sense */ - - if (do_sam_sync && do_sam_repl) { - DEBUG(0, ("cannot specify both -S and -R\n")); - return 1; - - } - - if (!do_sam_sync && !do_sam_repl) { - DEBUG(0, ("samsync: you must either --synchronise or " - "--replicate the SAM database\n")); - return 1; - } - - if (do_sam_repl && serial == 0) { - DEBUG(0, ("samsync: must specify serial number\n")); - return 1; - } - - if (do_sam_sync && serial != 0) { - DEBUG(0, ("samsync: you can't specify a serial number when " - "synchonising the SAM database\n")); - return 1; - } - - /* BDC operations require the machine account password */ - - if (!secrets_init()) { - DEBUG(0, ("samsync: unable to initialise secrets database\n")); - return 1; - } - - if (!secrets_fetch_trust_account_password(lp_workgroup(), - trust_passwd, NULL)) { - DEBUG(0, ("samsync: could not fetch trust account password\n")); - return 1; - } - - /* I wish the domain sid wasn't stored in secrets.tdb */ - - if (!secrets_fetch_domain_sid(lp_workgroup(), &domain_sid)) { - DEBUG(0, ("samsync: could not retrieve domain sid\n")); - return 1; - } - - /* Perform sync or replication */ - - popt_common_get_auth_info(&domain, &username, &password, &got_pass); - - if (!init_connection(&cli, username, domain, password)) - return 1; - - if (do_sam_sync) - result = sam_sync(cli, trust_passwd, do_smbpasswd_output, - verbose); - - if (do_sam_repl) - result = sam_repl(cli, trust_passwd, serial); - - if (!NT_STATUS_IS_OK(result)) { - DEBUG(0, ("%s\n", nt_errstr(result))); - return 1; - } - - return 0; -} -- cgit From 1009ef3e37c82682e9c2c4c63bc7407420f20af8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Feb 2003 22:09:57 +0000 Subject: Added Volkers "print server role" patch. Jeremy. (This used to be commit e81d72ac221023ded9e0932be7dd303ad5280665) --- source3/utils/testparm.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3') diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 36b2bdfc6d..0fafd1b83d 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -283,6 +283,28 @@ int main(int argc, const char *argv[]) } } + + 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"); -- cgit From 8d8a8c9633ea04d269d70b1fa8f4393cc73f7bbd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Feb 2003 22:26:28 +0000 Subject: Make init_module() and thus smb_load_module() return an int. modules/developer.c: init_module() should return an int (This used to be commit 7f59703550378ff2333e3c851bf1a77037510abd) --- source3/include/smb.h | 2 +- source3/lib/module.c | 18 +++++++++--------- source3/modules/developer.c | 2 +- source3/rpc_server/srv_pipe.c | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'source3') diff --git a/source3/include/smb.h b/source3/include/smb.h index f96a19954a..71051e341e 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -1721,6 +1721,6 @@ extern struct poptOption popt_common_netbios_name[]; extern struct poptOption popt_common_log_base[]; /* Module support */ -typedef NTSTATUS (init_module_function) (void); +typedef int (init_module_function) (void); #endif /* _SMB_H */ diff --git a/source3/lib/module.c b/source3/lib/module.c index 6febe8a9f1..dd94f79950 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -22,11 +22,11 @@ #include "includes.h" #ifdef HAVE_DLOPEN -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) { void *handle; init_module_function *init; - NTSTATUS nt_status; + int status; const char *error; /* Always try to use LAZY symbol resolving; if the plugin has @@ -37,7 +37,7 @@ NTSTATUS smb_load_module(const char *module_name) if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); - return NT_STATUS_UNSUCCESSFUL; + return False; } init = sys_dlsym(handle, "init_module"); @@ -47,14 +47,14 @@ NTSTATUS smb_load_module(const char *module_name) error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); - return NT_STATUS_UNSUCCESSFUL; + return False; } - nt_status = init(); + status = init(); DEBUG(2, ("Module '%s' loaded\n", module_name)); - return nt_status; + return status; } /* Load all modules in list and return number of @@ -65,7 +65,7 @@ int smb_load_modules(const char **modules) int success = 0; for(i = 0; modules[i]; i++){ - if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { + if(smb_load_module(modules[i])) { success++; } } @@ -77,10 +77,10 @@ int smb_load_modules(const char **modules) #else /* HAVE_DLOPEN */ -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) { DEBUG(0,("This samba executable has not been build with plugin support")); - return NT_STATUS_NOT_SUPPORTED; + return False; } int smb_load_modules(const char **modules) diff --git a/source3/modules/developer.c b/source3/modules/developer.c index c12bbc562a..a697abcd22 100644 --- a/source3/modules/developer.c +++ b/source3/modules/developer.c @@ -128,5 +128,5 @@ struct charset_functions weird_functions = {"WEIRD", weird_pull, weird_push}; int init_module(void) { smb_register_charset(&weird_functions); - return 0; + return 1; } diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 0b8b7b229a..f6deac68f8 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -794,10 +794,10 @@ int rpc_pipe_register_commands(const char *clnt, const char *srv, const struct a /******************************************************************* Register commands to an RPC pipe *******************************************************************/ -NTSTATUS rpc_load_module(const char *module) +int rpc_load_module(const char *module) { pstring full_path; - NTSTATUS status; + int status; pstrcpy(full_path, lib_path("rpc")); pstrcat(full_path, "/librpc_"); @@ -805,7 +805,7 @@ NTSTATUS rpc_load_module(const char *module) pstrcat(full_path, "."); pstrcat(full_path, shlib_ext()); - if (!NT_STATUS_IS_OK(status = smb_load_module(full_path))) { + if (!(status = smb_load_module(full_path))) { DEBUG(0, ("Could not load requested pipe %s as %s\n", module, full_path)); } @@ -858,7 +858,7 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p) } } - if (!api_fd_commands[i].name && !NT_STATUS_IS_OK(rpc_load_module(p->name))) { + if (!api_fd_commands[i].name && !rpc_load_module(p->name)) { DEBUG(3,("api_pipe_bind_req: Unknown pipe name %s in bind request.\n", p->name )); if(!setup_bind_nak(p)) -- cgit From 5bec7f5fcac1a3e5a48b04f140b96f03b88f0965 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 20 Feb 2003 22:46:37 +0000 Subject: From aliguori@us.ibm.com: This patch adds the architecture for an IDMAP backend system including a new smb.conf parameter "winbind backend". Right now, the only valid value is "tdb" but I'm currently working on an LDAP backend. (This used to be commit 35e4448dcb2deb0d5d34d9e974a49f2fb31f1356) --- source3/Makefile.in | 1 + source3/nsswitch/winbindd.h | 25 ++ source3/nsswitch/winbindd_idmap.c | 625 ++++++++++------------------------ source3/nsswitch/winbindd_idmap_tdb.c | 519 ++++++++++++++++++++++++++++ source3/param/loadparm.c | 6 + 5 files changed, 738 insertions(+), 438 deletions(-) create mode 100644 source3/nsswitch/winbindd_idmap_tdb.c (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index e04550cf21..efc3b935b4 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -579,6 +579,7 @@ WINBINDD_OBJ1 = \ nsswitch/winbindd_user.o \ nsswitch/winbindd_group.o \ nsswitch/winbindd_idmap.o \ + nsswitch/winbindd_idmap_tdb.o \ nsswitch/winbindd_util.o \ nsswitch/winbindd_cache.o \ nsswitch/winbindd_pam.o \ diff --git a/source3/nsswitch/winbindd.h b/source3/nsswitch/winbindd.h index 164b7ffda7..a498b76626 100644 --- a/source3/nsswitch/winbindd.h +++ b/source3/nsswitch/winbindd.h @@ -4,6 +4,7 @@ Winbind daemon for ntdom nss module Copyright (C) Tim Potter 2000 + Copyright (C) Anthony Liguori 2003 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -195,6 +196,30 @@ typedef struct { POLICY_HND pol; } CLI_POLICY_HND; +/* Filled out by IDMAP backends */ +struct idmap_methods { + /* Called when backend is first loaded */ + BOOL (*init)(void); + + BOOL (*get_sid_from_uid)(uid_t uid, DOM_SID *sid); + BOOL (*get_sid_from_gid)(gid_t gid, DOM_SID *sid); + + BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid); + BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid); + + BOOL (*get_rid_from_uid)(uid_t uid, uint32 *user_rid, + struct winbindd_domain **domain); + BOOL (*get_rid_from_gid)(gid_t gid, uint32 *group_rid, + struct winbindd_domain **domain); + BOOL (*get_uid_from_rid)(const char *dom_name, uint32 rid, uid_t *uid); + BOOL (*get_gid_from_rid)(const char *dom_name, uint32 rid, gid_t *gid); + + /* Called when backend is unloaded */ + BOOL (*close)(void); + /* Called to dump backend status */ + void (*status)(void); +}; + #include "winbindd_proto.h" #include "rpc_parse.h" diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c index 6d184fec5f..d9448ef859 100644 --- a/source3/nsswitch/winbindd_idmap.c +++ b/source3/nsswitch/winbindd_idmap.c @@ -1,20 +1,19 @@ /* Unix SMB/CIFS implementation. - - Winbind daemon - user related function - + Winbind ID Mapping Copyright (C) Tim Potter 2000 - + Copyright (C) Anthony Liguori 2003 + 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. @@ -22,508 +21,258 @@ #include "winbindd.h" -#undef DBGC_CLASS -#define DBGC_CLASS DBGC_WINBIND - -/* High water mark keys */ - -#define HWM_GROUP "GROUP HWM" -#define HWM_USER "USER HWM" - -/* idmap version determines auto-conversion */ -#define IDMAP_VERSION 2 - -/* Globals */ - -static TDB_CONTEXT *idmap_tdb; - -/* Allocate either a user or group id from the pool */ - -static BOOL allocate_id(uid_t *id, BOOL isgroup) +static struct { + const char *name; + /* Function to create a member of the idmap_methods list */ + BOOL (*reg_meth)(struct idmap_methods **methods); + struct idmap_methods *methods; +} builtin_idmap_functions[] = { + { "tdb", winbind_idmap_reg_tdb, NULL }, + /* { "ldap", winbind_idmap_reg_ldap, NULL },*/ + { NULL, NULL, NULL } +}; + +/* singleton pattern: uberlazy evaluation */ +static struct idmap_methods *impl; + +static struct idmap_methods *get_impl(const char *name) { - int hwm; - - /* Get current high water mark */ - - if ((hwm = tdb_fetch_int32(idmap_tdb, - isgroup ? HWM_GROUP : HWM_USER)) == -1) { - return False; - } - - /* Return next available uid in list */ + int i = 0; + struct idmap_methods *ret = NULL; - if ((isgroup && (hwm > server_state.gid_high)) || - (!isgroup && (hwm > server_state.uid_high))) { - DEBUG(0, ("winbind %sid range full!\n", isgroup ? "g" : "u")); - return False; - } + while (builtin_idmap_functions[i].name && + strcmp(builtin_idmap_functions[i].name, name)) { + i++; + } - if (id) { - *id = hwm; + if (builtin_idmap_functions[i].name) { + if (!builtin_idmap_functions[i].methods) { + builtin_idmap_functions[i].reg_meth(&builtin_idmap_functions[i].methods); } - hwm++; + ret = builtin_idmap_functions[i].methods; + } - /* Store new high water mark */ - - tdb_store_int32(idmap_tdb, isgroup ? HWM_GROUP : HWM_USER, hwm); - - return True; + return ret; } -/* Get an id from a rid */ -static BOOL get_id_from_sid(DOM_SID *sid, uid_t *id, BOOL isgroup) +/* Initialize backend */ +BOOL winbindd_idmap_init(void) { - TDB_DATA data, key; - fstring keystr; - BOOL result = False; - - /* Check if sid is present in database */ - sid_to_string(keystr, sid); - - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; - - data = tdb_fetch(idmap_tdb, key); + BOOL ret = False; - if (data.dptr) { - fstring scanstr; - int the_id; + DEBUG(3, ("winbindd_idmap_init: using '%s' as backend\n", + lp_winbind_backend())); - /* Parse and return existing uid */ - fstrcpy(scanstr, isgroup ? "GID" : "UID"); - fstrcat(scanstr, " %d"); - - if (sscanf(data.dptr, scanstr, &the_id) == 1) { - /* Store uid */ - if (id) { - *id = the_id; - } - - result = True; - } - - SAFE_FREE(data.dptr); - } else { - - /* Allocate a new id for this sid */ + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } + } - if (id && allocate_id(id, isgroup)) { - fstring keystr2; + if (impl) { + ret = impl->init(); + } - /* Store new id */ - - slprintf(keystr2, sizeof(keystr2), "%s %d", isgroup ? "GID" : "UID", *id); + DEBUG(3, ("winbind_idmap_init: returning %s\n", ret ? "true" : "false")); - data.dptr = keystr2; - data.dsize = strlen(keystr2) + 1; + return ret; +} - tdb_store(idmap_tdb, key, data, TDB_REPLACE); - tdb_store(idmap_tdb, data, key, TDB_REPLACE); +/* Get UID from SID */ +BOOL winbindd_idmap_get_uid_from_sid(DOM_SID *sid, uid_t *uid) +{ + BOOL ret = False; - result = True; - } + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); } + } - return result; -} + if (impl) { + ret = impl->get_uid_from_sid(sid, uid); + } -/* Get a uid from a user sid */ -BOOL winbindd_idmap_get_uid_from_sid(DOM_SID *sid, uid_t *uid) -{ - return get_id_from_sid(sid, uid, False); + return ret; } -/* Get a gid from a group sid */ +/* Get GID from SID */ BOOL winbindd_idmap_get_gid_from_sid(DOM_SID *sid, gid_t *gid) { - return get_id_from_sid(sid, gid, True); -} - -/* Get a uid from a user rid */ -BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid, uid_t *uid) -{ - struct winbindd_domain *domain; - DOM_SID sid; + BOOL ret = False; - if (!(domain = find_domain_from_name(dom_name))) { - return False; - } + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } + } - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); + if (impl) { + ret = impl->get_gid_from_sid(sid, gid); + } - return get_id_from_sid(&sid, uid, False); + return ret; } -/* Get a gid from a group rid */ -BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid, gid_t *gid) +/* Get UID from RID */ +BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid, + uid_t *uid) { - struct winbindd_domain *domain; - DOM_SID sid; + BOOL ret = False; - if (!(domain = find_domain_from_name(dom_name))) { - return False; - } + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } + } - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); + if (impl) { + ret = impl->get_uid_from_rid(dom_name, rid, uid); + } - return get_id_from_sid(&sid, gid, True); + return ret; } - -BOOL get_sid_from_id(int id, DOM_SID *sid, BOOL isgroup) +/* Get GID From RID */ +BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid, + gid_t *gid) { - TDB_DATA key, data; - fstring keystr; - BOOL result = False; - - slprintf(keystr, sizeof(keystr), "%s %d", isgroup ? "GID" : "UID", id); - - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; + BOOL ret = False; - data = tdb_fetch(idmap_tdb, key); - - if (data.dptr) { - result = string_to_sid(sid, data.dptr); - SAFE_FREE(data.dptr); + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); } + } + + if (impl) { + ret = impl->get_gid_from_rid(dom_name, rid, gid); + } - return result; + return ret; } -/* Get a sid from a uid */ +/* Get SID from UID */ BOOL winbindd_idmap_get_sid_from_uid(uid_t uid, DOM_SID *sid) { - return get_sid_from_id((int)uid, sid, False); -} + BOOL ret = False; -/* Get a sid from a gid */ -BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid) -{ - return get_sid_from_id((int)gid, sid, True); + if (!impl) { + impl = get_impl(lp_winbind_backend()); + if (!impl) { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } + } + + if (impl) { + ret = impl->get_sid_from_uid(uid, sid); + } + + return ret; } -/* Get a user rid from a uid */ -BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid, - struct winbindd_domain **domain) +/* Get SID from GID */ +BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid) { - DOM_SID sid; + BOOL ret = False; - if (!get_sid_from_id((int)uid, &sid, False)) { - return False; - } + if (!impl) { + impl = get_impl(lp_winbind_backend()); + } - *domain = find_domain_from_sid(&sid); - if (! *domain) return False; + if (impl) { + ret = impl->get_sid_from_gid(gid, sid); + } else { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } - sid_split_rid(&sid, user_rid); - - return True; + return ret; } -/* Get a group rid from a gid */ - -BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid, +/* Get RID From UID */ +BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid, struct winbindd_domain **domain) { - DOM_SID sid; - - if (!get_sid_from_id((int)gid, &sid, True)) { - return False; - } + BOOL ret = False; - *domain = find_domain_from_sid(&sid); - if (! *domain) return False; + if (!impl) { + impl = get_impl(lp_winbind_backend()); + } - sid_split_rid(&sid, group_rid); + if (impl) { + ret = impl->get_rid_from_uid(uid, user_rid, domain); + } else { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } - return True; + return ret; } -/* convert one record to the new format */ -static int convert_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, void *ignored) +/* Get RID from GID */ +BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid, + struct winbindd_domain **domain) { - struct winbindd_domain *domain; - char *p; - DOM_SID sid; - uint32 rid; - fstring keystr; - fstring dom_name; - TDB_DATA key2; - - p = strchr(key.dptr, '/'); - if (!p) - return 0; - - *p = 0; - fstrcpy(dom_name, key.dptr); - *p++ = '/'; - - domain = find_domain_from_name(dom_name); - if (!domain) { - /* We must delete the old record. */ - DEBUG(0,("winbindd: convert_fn : Unable to find domain %s\n", dom_name )); - DEBUG(0,("winbindd: convert_fn : deleting record %s\n", key.dptr )); - tdb_delete(idmap_tdb, key); - return 0; - } - - rid = atoi(p); - - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); - - sid_to_string(keystr, &sid); - key2.dptr = keystr; - key2.dsize = strlen(keystr) + 1; - - if (tdb_store(idmap_tdb, key2, data, TDB_INSERT) != 0) { - /* not good! */ - DEBUG(0,("winbindd: convert_fn : Unable to update record %s\n", key2.dptr )); - DEBUG(0,("winbindd: convert_fn : conversion failed - idmap corrupt ?\n")); - return -1; - } - - if (tdb_store(idmap_tdb, data, key2, TDB_REPLACE) != 0) { - /* not good! */ - DEBUG(0,("winbindd: convert_fn : Unable to update record %s\n", data.dptr )); - DEBUG(0,("winbindd: convert_fn : conversion failed - idmap corrupt ?\n")); - return -1; - } - - tdb_delete(idmap_tdb, key); - - return 0; -} + BOOL ret = False; -#if 0 -/***************************************************************************** - Make a backup copy of the old idmap just to be safe.... JRA. -*****************************************************************************/ + if (!impl) { + impl = get_impl(lp_winbind_backend()); + } -static BOOL backup_old_idmap(const char *idmap_name) -{ - pstring new_name; - int outfd = -1; - SMB_OFF_T size; - struct stat st; - - pstrcpy(new_name, idmap_name); - pstrcat(new_name, ".bak"); - - DEBUG(10,("backup_old_idmap: backing up %s to %s before upgrade.\n", - idmap_name, new_name )); - - if (tdb_lockall(idmap_tdb) == -1) { - DEBUG(10,("backup_old_idmap: failed to lock %s. Error %s\n", - idmap_name, tdb_errorstr(idmap_tdb) )); - return False; - } - if ((outfd = open(new_name, O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) { - DEBUG(10,("backup_old_idmap: failed to open %s. Error %s\n", - new_name, strerror(errno) )); - goto fail; - } - - if (fstat(idmap_tdb->fd, &st) == -1) { - DEBUG(10,("backup_old_idmap: failed to fstat %s. Error %s\n", - idmap_name, strerror(errno) )); - goto fail; - } - - size = (SMB_OFF_T)st.st_size; - - if (transfer_file(idmap_tdb->fd, outfd, size) != size ) { - DEBUG(10,("backup_old_idmap: failed to copy %s. Error %s\n", - idmap_name, strerror(errno) )); - goto fail; - } - - if (close(outfd) == -1) { - DEBUG(10,("backup_old_idmap: failed to close %s. Error %s\n", - idmap_name, strerror(errno) )); - outfd = -1; - goto fail; - } - tdb_unlockall(idmap_tdb); - return True; - -fail: - - if (outfd != -1) - close(outfd); - tdb_unlockall(idmap_tdb); - return False; -} -#endif - -/***************************************************************************** - Convert the idmap database from an older version. -*****************************************************************************/ + if (impl) { + ret = impl->get_rid_from_gid(gid, group_rid, domain); + } else { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } -static BOOL idmap_convert(const char *idmap_name) -{ - int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION"); - BOOL bigendianheader = (idmap_tdb->flags & TDB_BIGENDIAN) ? True : False; - - if (vers == IDMAP_VERSION) - return True; - -#if 0 - /* Make a backup copy before doing anything else.... */ - if (!backup_old_idmap(idmap_name)) - return False; -#endif - - if (((vers == -1) && bigendianheader) || (IREV(vers) == IDMAP_VERSION)) { - /* Arrggghh ! Bytereversed or old big-endian - make order independent ! */ - /* - * high and low records were created on a - * big endian machine and will need byte-reversing. - */ - - int32 wm; - - wm = tdb_fetch_int32(idmap_tdb, HWM_USER); - - if (wm != -1) { - wm = IREV(wm); - } else - wm = server_state.uid_low; - - if (tdb_store_int32(idmap_tdb, HWM_USER, wm) == -1) { - DEBUG(0, ("idmap_convert: Unable to byteswap user hwm in idmap database\n")); - return False; - } - - wm = tdb_fetch_int32(idmap_tdb, HWM_GROUP); - if (wm != -1) { - wm = IREV(wm); - } else - wm = server_state.gid_low; - - if (tdb_store_int32(idmap_tdb, HWM_GROUP, wm) == -1) { - DEBUG(0, ("idmap_convert: Unable to byteswap group hwm in idmap database\n")); - return False; - } - } - - /* the old format stored as DOMAIN/rid - now we store the SID direct */ - tdb_traverse(idmap_tdb, convert_fn, NULL); - - if (tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION) == -1) { - DEBUG(0, ("idmap_convert: Unable to byteswap group hwm in idmap database\n")); - return False; - } - - return True; -} - -/***************************************************************************** - Initialise idmap database. -*****************************************************************************/ - -BOOL winbindd_idmap_init(void) -{ - /* Open tdb cache */ - - if (!(idmap_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, - TDB_DEFAULT, O_RDWR | O_CREAT, 0600))) { - DEBUG(0, ("winbindd_idmap_init: Unable to open idmap database\n")); - return False; - } - - /* possibly convert from an earlier version */ - if (!idmap_convert(lock_path("winbindd_idmap.tdb"))) { - DEBUG(0, ("winbindd_idmap_init: Unable to open idmap database\n")); - return False; - } - - /* Create high water marks for group and user id */ - - if (tdb_fetch_int32(idmap_tdb, HWM_USER) == -1) { - if (tdb_store_int32(idmap_tdb, HWM_USER, server_state.uid_low) == -1) { - DEBUG(0, ("winbindd_idmap_init: Unable to initialise user hwm in idmap database\n")); - return False; - } - } - - if (tdb_fetch_int32(idmap_tdb, HWM_GROUP) == -1) { - if (tdb_store_int32(idmap_tdb, HWM_GROUP, server_state.gid_low) == -1) { - DEBUG(0, ("winbindd_idmap_init: Unable to initialise group hwm in idmap database\n")); - return False; - } - } - - return True; + return ret; } +/* Close backend */ BOOL winbindd_idmap_close(void) { - if (idmap_tdb) - return (tdb_close(idmap_tdb) == 0); - return True; -} + BOOL ret = False; -/* Dump status information to log file. Display different stuff based on - the debug level: + if (!impl) { + impl = get_impl(lp_winbind_backend()); + } - Debug Level Information Displayed - ================================================================= - 0 Percentage of [ug]id range allocated - 0 High water marks (next allocated ids) -*/ + if (impl) { + ret = impl->close(); + } else { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } -#define DUMP_INFO 0 + return ret; +} +/* Dump backend status */ void winbindd_idmap_status(void) { - int user_hwm, group_hwm; - - DEBUG(0, ("winbindd idmap status:\n")); - - /* Get current high water marks */ - - if ((user_hwm = tdb_fetch_int32(idmap_tdb, HWM_USER)) == -1) { - DEBUG(DUMP_INFO, ("\tCould not get userid high water mark!\n")); - } - - if ((group_hwm = tdb_fetch_int32(idmap_tdb, HWM_GROUP)) == -1) { - DEBUG(DUMP_INFO, ("\tCould not get groupid high water mark!\n")); - } - - /* Display next ids to allocate */ - - if (user_hwm != -1) { - DEBUG(DUMP_INFO, ("\tNext userid to allocate is %d\n", user_hwm)); - } - - if (group_hwm != -1) { - DEBUG(DUMP_INFO, ("\tNext groupid to allocate is %d\n", group_hwm)); - } - - /* Display percentage of id range already allocated. */ - - if (user_hwm != -1) { - int num_users = user_hwm - server_state.uid_low; - int total_users = server_state.uid_high - server_state.uid_low; - - DEBUG(DUMP_INFO, ("\tUser id range is %d%% full (%d of %d)\n", - num_users * 100 / total_users, num_users, - total_users)); - } - - if (group_hwm != -1) { - int num_groups = group_hwm - server_state.gid_low; - int total_groups = server_state.gid_high - server_state.gid_low; - - DEBUG(DUMP_INFO, ("\tGroup id range is %d%% full (%d of %d)\n", - num_groups * 100 / total_groups, num_groups, - total_groups)); - } - - /* Display complete mapping of users and groups to rids */ + if (!impl) { + impl = get_impl(lp_winbind_backend()); + } + + if (impl) { + impl->status(); + } else { + DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", + lp_winbind_backend())); + } } + diff --git a/source3/nsswitch/winbindd_idmap_tdb.c b/source3/nsswitch/winbindd_idmap_tdb.c new file mode 100644 index 0000000000..f27c3c1b5f --- /dev/null +++ b/source3/nsswitch/winbindd_idmap_tdb.c @@ -0,0 +1,519 @@ +/* + Unix SMB/CIFS implementation. + + Winbind daemon - user related function + + Copyright (C) Tim Potter 2000 + Copyright (C) Anthony Liguori 2003 + + 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 "winbindd.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_WINBIND + +/* High water mark keys */ +#define HWM_GROUP "GROUP HWM" +#define HWM_USER "USER HWM" + +/* idmap version determines auto-conversion */ +#define IDMAP_VERSION 2 + +/* Globals */ +static TDB_CONTEXT *idmap_tdb; + +/* convert one record to the new format */ +static int tdb_convert_fn(TDB_CONTEXT * tdb, TDB_DATA key, TDB_DATA data, + void *ignored) +{ + struct winbindd_domain *domain; + char *p; + DOM_SID sid; + uint32 rid; + fstring keystr; + fstring dom_name; + TDB_DATA key2; + + p = strchr(key.dptr, '/'); + if (!p) + return 0; + + *p = 0; + fstrcpy(dom_name, key.dptr); + *p++ = '/'; + + domain = find_domain_from_name(dom_name); + if (!domain) { + /* We must delete the old record. */ + DEBUG(0, + ("winbindd: tdb_convert_fn : Unable to find domain %s\n", + dom_name)); + DEBUG(0, + ("winbindd: tdb_convert_fn : deleting record %s\n", + key.dptr)); + tdb_delete(idmap_tdb, key); + return 0; + } + + rid = atoi(p); + + sid_copy(&sid, &domain->sid); + sid_append_rid(&sid, rid); + + sid_to_string(keystr, &sid); + key2.dptr = keystr; + key2.dsize = strlen(keystr) + 1; + + if (tdb_store(idmap_tdb, key2, data, TDB_INSERT) != 0) { + /* not good! */ + DEBUG(0, + ("winbindd: tdb_convert_fn : Unable to update record %s\n", + key2.dptr)); + DEBUG(0, + ("winbindd: tdb_convert_fn : conversion failed - idmap corrupt ?\n")); + return -1; + } + + if (tdb_store(idmap_tdb, data, key2, TDB_REPLACE) != 0) { + /* not good! */ + DEBUG(0, + ("winbindd: tdb_convert_fn : Unable to update record %s\n", + data.dptr)); + DEBUG(0, + ("winbindd: tdb_convert_fn : conversion failed - idmap corrupt ?\n")); + return -1; + } + + tdb_delete(idmap_tdb, key); + + return 0; +} + +/***************************************************************************** + Convert the idmap database from an older version. +*****************************************************************************/ +static BOOL tdb_idmap_convert(const char *idmap_name) +{ + int32 vers = tdb_fetch_int32(idmap_tdb, "IDMAP_VERSION"); + BOOL bigendianheader = + (idmap_tdb->flags & TDB_BIGENDIAN) ? True : False; + + if (vers == IDMAP_VERSION) + return True; + + if (((vers == -1) && bigendianheader) + || (IREV(vers) == IDMAP_VERSION)) { + /* Arrggghh ! Bytereversed or old big-endian - make order independent ! */ + /* + * high and low records were created on a + * big endian machine and will need byte-reversing. + */ + + int32 wm; + + wm = tdb_fetch_int32(idmap_tdb, HWM_USER); + + if (wm != -1) { + wm = IREV(wm); + } else + wm = server_state.uid_low; + + if (tdb_store_int32(idmap_tdb, HWM_USER, wm) == -1) { + DEBUG(0, + ("tdb_idmap_convert: Unable to byteswap user hwm in idmap database\n")); + return False; + } + + wm = tdb_fetch_int32(idmap_tdb, HWM_GROUP); + if (wm != -1) { + wm = IREV(wm); + } else + wm = server_state.gid_low; + + if (tdb_store_int32(idmap_tdb, HWM_GROUP, wm) == -1) { + DEBUG(0, + ("tdb_idmap_convert: Unable to byteswap group hwm in idmap database\n")); + return False; + } + } + + /* the old format stored as DOMAIN/rid - now we store the SID direct */ + tdb_traverse(idmap_tdb, tdb_convert_fn, NULL); + + if (tdb_store_int32(idmap_tdb, "IDMAP_VERSION", IDMAP_VERSION) == + -1) { + DEBUG(0, + ("tdb_idmap_convert: Unable to byteswap group hwm in idmap database\n")); + return False; + } + + return True; +} + +/* Allocate either a user or group id from the pool */ +static BOOL tdb_allocate_id(uid_t * id, BOOL isgroup) +{ + int hwm; + + /* Get current high water mark */ + if ((hwm = tdb_fetch_int32(idmap_tdb, + isgroup ? HWM_GROUP : HWM_USER)) == + -1) { + return False; + } + + /* Return next available uid in list */ + if ((isgroup && (hwm > server_state.gid_high)) || + (!isgroup && (hwm > server_state.uid_high))) { + DEBUG(0, + ("winbind %sid range full!\n", isgroup ? "g" : "u")); + return False; + } + + if (id) { + *id = hwm; + } + + hwm++; + + /* Store new high water mark */ + tdb_store_int32(idmap_tdb, isgroup ? HWM_GROUP : HWM_USER, hwm); + + return True; +} + +/* Get a sid from an id */ +static BOOL tdb_get_sid_from_id(int id, DOM_SID * sid, BOOL isgroup) +{ + TDB_DATA key, data; + fstring keystr; + BOOL result = False; + + slprintf(keystr, sizeof(keystr), "%s %d", isgroup ? "GID" : "UID", + id); + + key.dptr = keystr; + key.dsize = strlen(keystr) + 1; + + data = tdb_fetch(idmap_tdb, key); + + if (data.dptr) { + result = string_to_sid(sid, data.dptr); + SAFE_FREE(data.dptr); + } + + return result; +} + +/* Get an id from a sid */ +static BOOL tdb_get_id_from_sid(DOM_SID * sid, uid_t * id, BOOL isgroup) +{ + TDB_DATA data, key; + fstring keystr; + BOOL result = False; + + /* Check if sid is present in database */ + sid_to_string(keystr, sid); + + key.dptr = keystr; + key.dsize = strlen(keystr) + 1; + + data = tdb_fetch(idmap_tdb, key); + + if (data.dptr) { + fstring scanstr; + int the_id; + + /* Parse and return existing uid */ + fstrcpy(scanstr, isgroup ? "GID" : "UID"); + fstrcat(scanstr, " %d"); + + if (sscanf(data.dptr, scanstr, &the_id) == 1) { + /* Store uid */ + if (id) { + *id = the_id; + } + + result = True; + } + + SAFE_FREE(data.dptr); + } else { + + /* Allocate a new id for this sid */ + if (id && tdb_allocate_id(id, isgroup)) { + fstring keystr2; + + /* Store new id */ + slprintf(keystr2, sizeof(keystr2), "%s %d", + isgroup ? "GID" : "UID", *id); + + data.dptr = keystr2; + data.dsize = strlen(keystr2) + 1; + + tdb_store(idmap_tdb, key, data, TDB_REPLACE); + tdb_store(idmap_tdb, data, key, TDB_REPLACE); + + result = True; + } + } + + return result; +} + +/***************************************************************************** + Initialise idmap database. +*****************************************************************************/ +static BOOL tdb_idmap_init(void) +{ + /* Open tdb cache */ + if (!(idmap_tdb = tdb_open_log(lock_path("winbindd_idmap.tdb"), 0, + TDB_DEFAULT, O_RDWR | O_CREAT, + 0600))) { + DEBUG(0, + ("winbindd_idmap_init: Unable to open idmap database\n")); + return False; + } + + /* possibly convert from an earlier version */ + if (!tdb_idmap_convert(lock_path("winbindd_idmap.tdb"))) { + DEBUG(0, + ("winbindd_idmap_init: Unable to open idmap database\n")); + return False; + } + + /* Create high water marks for group and user id */ + if (tdb_fetch_int32(idmap_tdb, HWM_USER) == -1) { + if (tdb_store_int32 + (idmap_tdb, HWM_USER, server_state.uid_low) == -1) { + DEBUG(0, + ("winbindd_idmap_init: Unable to initialise user hwm in idmap database\n")); + return False; + } + } + + if (tdb_fetch_int32(idmap_tdb, HWM_GROUP) == -1) { + if (tdb_store_int32 + (idmap_tdb, HWM_GROUP, server_state.gid_low) == -1) { + DEBUG(0, + ("winbindd_idmap_init: Unable to initialise group hwm in idmap database\n")); + return False; + } + } + + return True; +} + +/* Get a sid from a uid */ +static BOOL tdb_get_sid_from_uid(uid_t uid, DOM_SID * sid) +{ + return tdb_get_sid_from_id((int) uid, sid, False); +} + +/* Get a sid from a gid */ +static BOOL tdb_get_sid_from_gid(gid_t gid, DOM_SID * sid) +{ + return tdb_get_sid_from_id((int) gid, sid, True); +} + +/* Get a uid from a sid */ +static BOOL tdb_get_uid_from_sid(DOM_SID * sid, uid_t * uid) +{ + return tdb_get_id_from_sid(sid, uid, False); +} + +/* Get a gid from a group sid */ +static BOOL tdb_get_gid_from_sid(DOM_SID * sid, gid_t * gid) +{ + return tdb_get_id_from_sid(sid, gid, True); +} + +/* Get a uid from a user rid */ +static BOOL tdb_get_uid_from_rid(const char *dom_name, uint32 rid, + uid_t * uid) +{ + struct winbindd_domain *domain; + DOM_SID sid; + + if (!(domain = find_domain_from_name(dom_name))) { + return False; + } + + sid_copy(&sid, &domain->sid); + sid_append_rid(&sid, rid); + + return tdb_get_id_from_sid(&sid, uid, False); +} + +/* Get a gid from a group rid */ +static BOOL tdb_get_gid_from_rid(const char *dom_name, uint32 rid, + gid_t * gid) +{ + struct winbindd_domain *domain; + DOM_SID sid; + + if (!(domain = find_domain_from_name(dom_name))) { + return False; + } + + sid_copy(&sid, &domain->sid); + sid_append_rid(&sid, rid); + + return tdb_get_id_from_sid(&sid, gid, True); +} + +/* Get a user rid from a uid */ +static BOOL tdb_get_rid_from_uid(uid_t uid, uint32 * user_rid, + struct winbindd_domain **domain) +{ + DOM_SID sid; + + if (!tdb_get_sid_from_id((int) uid, &sid, False)) { + return False; + } + + *domain = find_domain_from_sid(&sid); + if (!*domain) + return False; + + sid_split_rid(&sid, user_rid); + + return True; +} + +/* Get a group rid from a gid */ +static BOOL tdb_get_rid_from_gid(gid_t gid, uint32 * group_rid, + struct winbindd_domain **domain) +{ + DOM_SID sid; + + if (!tdb_get_sid_from_id((int) gid, &sid, True)) { + return False; + } + + *domain = find_domain_from_sid(&sid); + if (!*domain) + return False; + + sid_split_rid(&sid, group_rid); + + return True; +} + +/* Close the tdb */ +static BOOL tdb_idmap_close(void) +{ + if (idmap_tdb) + return (tdb_close(idmap_tdb) == 0); + return True; +} + + +/* Dump status information to log file. Display different stuff based on + the debug level: + + Debug Level Information Displayed + ================================================================= + 0 Percentage of [ug]id range allocated + 0 High water marks (next allocated ids) +*/ + +#define DUMP_INFO 0 + +static void tdb_idmap_status(void) +{ + int user_hwm, group_hwm; + + DEBUG(0, ("winbindd idmap status:\n")); + + /* Get current high water marks */ + + if ((user_hwm = tdb_fetch_int32(idmap_tdb, HWM_USER)) == -1) { + DEBUG(DUMP_INFO, + ("\tCould not get userid high water mark!\n")); + } + + if ((group_hwm = tdb_fetch_int32(idmap_tdb, HWM_GROUP)) == -1) { + DEBUG(DUMP_INFO, + ("\tCould not get groupid high water mark!\n")); + } + + /* Display next ids to allocate */ + + if (user_hwm != -1) { + DEBUG(DUMP_INFO, + ("\tNext userid to allocate is %d\n", user_hwm)); + } + + if (group_hwm != -1) { + DEBUG(DUMP_INFO, + ("\tNext groupid to allocate is %d\n", group_hwm)); + } + + /* Display percentage of id range already allocated. */ + + if (user_hwm != -1) { + int num_users = user_hwm - server_state.uid_low; + int total_users = + server_state.uid_high - server_state.uid_low; + + DEBUG(DUMP_INFO, + ("\tUser id range is %d%% full (%d of %d)\n", + num_users * 100 / total_users, num_users, + total_users)); + } + + if (group_hwm != -1) { + int num_groups = group_hwm - server_state.gid_low; + int total_groups = + server_state.gid_high - server_state.gid_low; + + DEBUG(DUMP_INFO, + ("\tGroup id range is %d%% full (%d of %d)\n", + num_groups * 100 / total_groups, num_groups, + total_groups)); + } + + /* Display complete mapping of users and groups to rids */ +} + +struct idmap_methods tdb_idmap_methods = { + tdb_idmap_init, + + tdb_get_sid_from_uid, + tdb_get_sid_from_gid, + + tdb_get_uid_from_sid, + tdb_get_gid_from_sid, + + tdb_get_rid_from_uid, + tdb_get_rid_from_gid, + + tdb_get_uid_from_rid, + tdb_get_gid_from_rid, + + tdb_idmap_close, + + tdb_idmap_status +}; + +BOOL winbind_idmap_reg_tdb(struct idmap_methods **meth) +{ + *meth = &tdb_idmap_methods; + + return True; +} diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 398ae88b97..01b6980c8f 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -8,6 +8,7 @@ Copyright (C) Simo Sorce 2001 Copyright (C) Alexander Bokovoy 2002 Copyright (C) Stefan (metze) Metzmacher 2002 + Copyright (C) Anthony Liguori 2003 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 @@ -171,6 +172,7 @@ typedef struct BOOL bWinbindEnumUsers; BOOL bWinbindEnumGroups; BOOL bWinbindUseDefaultDomain; + char *szWinbindBackend; char *szAddShareCommand; char *szChangeShareCommand; char *szDeleteShareCommand; @@ -1118,6 +1120,7 @@ static struct parm_struct parm_table[] = { {"winbind enum users", P_BOOL, P_GLOBAL, &Globals.bWinbindEnumUsers, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"winbind enum groups", P_BOOL, P_GLOBAL, &Globals.bWinbindEnumGroups, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"winbind use default domain", P_BOOL, P_GLOBAL, &Globals.bWinbindUseDefaultDomain, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, + {"winbind backend", P_STRING, P_GLOBAL, &Globals.szWinbindBackend, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {NULL, P_BOOL, P_NONE, NULL, NULL, NULL, 0} }; @@ -1458,6 +1461,8 @@ static void init_globals(void) Globals.bWinbindEnumGroups = True; Globals.bWinbindUseDefaultDomain = False; + string_set(&Globals.szWinbindBackend, "tdb"); + Globals.name_cache_timeout = 660; /* In seconds */ Globals.bUseSpnego = True; @@ -1630,6 +1635,7 @@ FN_GLOBAL_STRING(lp_acl_compatibility, &Globals.szAclCompat) FN_GLOBAL_BOOL(lp_winbind_enum_users, &Globals.bWinbindEnumUsers) FN_GLOBAL_BOOL(lp_winbind_enum_groups, &Globals.bWinbindEnumGroups) FN_GLOBAL_BOOL(lp_winbind_use_default_domain, &Globals.bWinbindUseDefaultDomain) +FN_GLOBAL_STRING(lp_winbind_backend, &Globals.szWinbindBackend) #ifdef WITH_LDAP_SAMCONFIG FN_GLOBAL_STRING(lp_ldap_server, &Globals.szLdapServer) -- cgit From 1fc2976e14f8b79c85514d7947744bc495513670 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 21 Feb 2003 03:05:55 +0000 Subject: Doxygen janitor (This used to be commit 367997562998adb3f80602596c770d9ac319065b) --- source3/lib/util_unistr.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 5c9b4c783b..522ab7eb40 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -95,9 +95,14 @@ static int check_dos_char(smb_ucs2_t c) return (c == c2); } -/******************************************************************* -load the valid character map table -********************************************************************/ +/** + * Load the valid character map table from valid.dat or + * create from the configured codepage. + * + * This function is called whenever the configuration is reloaded. + * However, the valid character table is not changed if it's loaded + * from a file, because we can't unmap files. + **/ void init_valid_table(void) { static int initialised; @@ -114,6 +119,7 @@ void init_valid_table(void) return; } + /* Otherwise, using a dynamically loaded one. */ if (valid_table) free(valid_table); DEBUG(2,("creating default valid table\n")); @@ -128,6 +134,7 @@ void init_valid_table(void) } + /******************************************************************* Write a string in (little-endian) unicode format. src is in the current DOS codepage. len is the length in bytes of the -- cgit From 4834c61ebcc16397b496a8b37d5078021041b1c1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 04:25:04 +0000 Subject: Fix for only specifying one command with -c (This used to be commit 7418351427071edccb2e825ddbbf31fce8ef381e) --- source3/rpcclient/rpcclient.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 37ce597d4e..7a9c464cf6 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -170,7 +170,10 @@ static char* next_command (char** cmdstr) if (p) *p = '\0'; pstrcpy(command, *cmdstr); - *cmdstr = p + 1; + if (p) + *cmdstr = p + 1; + else + *cmdstr = NULL; return command; } -- cgit From ae8d3538c762af4d2b5672cc3c9dd11f1c2db59b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 04:26:58 +0000 Subject: Exit path cleanup for cli_samr_enum_dom_users() (This used to be commit 0bc1dfc68b0d411801a4209c9681c735cd7a73cc) --- source3/rpc_client/cli_samr.c | 52 +++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) (limited to 'source3') diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index f0035ca22e..08c68b7632 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -561,8 +561,8 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 size, char ***dom_users, uint32 **rids, uint32 *num_dom_users) { - prs_struct qdata; - prs_struct rdata; + prs_struct qbuf; + prs_struct rbuf; SAMR_Q_ENUM_DOM_USERS q; SAMR_R_ENUM_DOM_USERS r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -571,40 +571,24 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, ZERO_STRUCT(q); ZERO_STRUCT(r); - if (cli == NULL || pol == NULL) - return result; - - /* initialise parse structures */ - prs_init(&qdata, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rdata, 0, mem_ctx, UNMARSHALL); - - DEBUG(4, ("SAMR Enum Domain Users. start_idx: %d, acb: %d, size: %d\n", - *start_idx, acb_mask, size)); + /* Initialise parse structures */ + + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - /* fill query structure with parameters */ + /* Fill query structure with parameters */ + init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size); - /* prepare query stream */ - if (!samr_io_q_enum_dom_users("", &q, &qdata, 0)) { - prs_mem_free(&qdata); - prs_mem_free(&rdata); - return result; - } - - /* send rpc call over the pipe */ - if (!rpc_api_pipe_req(cli, SAMR_ENUM_DOM_USERS, &qdata, &rdata)) { - prs_mem_free(&qdata); - prs_mem_free(&rdata); - return result; + if (!samr_io_q_enum_dom_users("", &q, &qbuf, 0) || + !rpc_api_pipe_req(cli, SAMR_ENUM_DOM_USERS, &qbuf, &rbuf)) { + goto done; } - + /* unpack received stream */ - if(!samr_io_r_enum_dom_users("", &r, &rdata, 0)) { - prs_mem_free(&qdata); - prs_mem_free(&rdata); - result = r.status; - return result; - } + + if(!samr_io_r_enum_dom_users("", &r, &rbuf, 0)) + goto done; /* return the data obtained in response */ if (!NT_STATUS_IS_OK(r.status) && @@ -641,13 +625,13 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, } } - prs_mem_free(&qdata); - prs_mem_free(&rdata); +done: + prs_mem_free(&qbuf); + prs_mem_free(&rbuf); return result; }; - /* Enumerate domain groups */ NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, -- cgit From 696895d5b1c7749e7efa512330a970bbda74edab Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 04:28:32 +0000 Subject: Added enumdomusers command. (This used to be commit 30353da3e94f732e9f1b258e62da906f628e09d0) --- source3/rpcclient/cmd_samr.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'source3') diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c index 9e8d105c46..85aface7be 100644 --- a/source3/rpcclient/cmd_samr.c +++ b/source3/rpcclient/cmd_samr.c @@ -626,6 +626,80 @@ static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli, return result; } +/* Enumerate domain users */ + +static NTSTATUS cmd_samr_enum_dom_users(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + int argc, char **argv) +{ + POLICY_HND connect_pol, domain_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + uint32 start_idx, size, num_dom_users, i; + char **dom_users; + uint32 *dom_rids; + uint32 access_mask = MAXIMUM_ALLOWED_ACCESS; + uint16 acb_mask = ACB_NORMAL; + BOOL got_connect_pol = False, got_domain_pol = False; + + if ((argc < 1) || (argc > 2)) { + printf("Usage: %s [access_mask]\n", argv[0]); + return NT_STATUS_OK; + } + + if (argc > 1) + sscanf(argv[1], "%x", &access_mask); + + /* Get sam policy handle */ + + result = try_samr_connects(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, + &connect_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + got_connect_pol = True; + + /* Get domain policy handle */ + + result = cli_samr_open_domain(cli, mem_ctx, &connect_pol, + access_mask, + &domain_sid, &domain_pol); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + got_domain_pol = True; + + /* Enumerate domain users */ + + start_idx = 0; + size = 0xffff; + + do { + result = cli_samr_enum_dom_users( + cli, mem_ctx, &domain_pol, &start_idx, acb_mask, + size, &dom_users, &dom_rids, &num_dom_users); + + if (NT_STATUS_IS_OK(result) || + NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) { + + for (i = 0; i < num_dom_users; i++) + printf("group:[%s] rid:[0x%x]\n", + dom_users[i], dom_rids[i]); + } + + } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)); + + done: + if (got_domain_pol) + cli_samr_close(cli, mem_ctx, &domain_pol); + + if (got_connect_pol) + cli_samr_close(cli, mem_ctx, &connect_pol); + + return result; +} + /* Enumerate domain groups */ static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli, @@ -1428,6 +1502,7 @@ struct cmd_set samr_commands[] = { { "queryaliasmem", cmd_samr_query_aliasmem, PI_SAMR, "Query alias membership", "" }, { "querydispinfo", cmd_samr_query_dispinfo, PI_SAMR, "Query display info", "" }, { "querydominfo", cmd_samr_query_dominfo, PI_SAMR, "Query domain info", "" }, + { "enumdomusers", cmd_samr_enum_dom_users, PI_SAMR, "Enumerate domain users", "" }, { "enumdomgroups", cmd_samr_enum_dom_groups, PI_SAMR, "Enumerate domain groups", "" }, { "enumalsgroups", cmd_samr_enum_als_groups, PI_SAMR, "Enumerate alias groups", "" }, -- cgit From 9383d61f6c61ba8600ec73d22bd6f048c55a5261 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 04:47:24 +0000 Subject: Fixed compiler warning. (This used to be commit b3f9cf8c1c293e905a536dfa5bb6a827627b7024) --- source3/rpc_server/srv_lsa_nt.c | 2 +- source3/smbd/sesssetup.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/rpc_server/srv_lsa_nt.c b/source3/rpc_server/srv_lsa_nt.c index b230381d62..1b42c5f141 100644 --- a/source3/rpc_server/srv_lsa_nt.c +++ b/source3/rpc_server/srv_lsa_nt.c @@ -1280,7 +1280,7 @@ NTSTATUS _lsa_enum_acct_rights(pipes_struct *p, LSA_Q_ENUM_ACCT_RIGHTS *q_u, LSA r_u->status = privilege_enum_account_rights(&q_u->sid.sid, &num_rights, &rights); - init_r_enum_acct_rights(r_u, num_rights, rights); + init_r_enum_acct_rights(r_u, num_rights, (const char **)rights); for (i=0;i Date: Fri, 21 Feb 2003 04:53:39 +0000 Subject: Fixed another compiler warning. (This used to be commit d15b7425d408f17505c4f3a91ec68bcfc4472c16) --- source3/utils/net_ads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index d508320423..75bb29f213 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -110,7 +110,7 @@ static int net_ads_info(int argc, const char **argv) return 0; } -static void use_in_memory_ccache() { +static void use_in_memory_ccache(void) { /* Use in-memory credentials cache so we do not interfere with * existing credentials */ setenv(KRB5_ENV_CCNAME, "MEMORY:net_ads", 1); -- cgit From 7eff9dd5eff7656aa4b41ac0c413c28776b81b9e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 05:06:49 +0000 Subject: Fix another compiler warning. (This used to be commit 1ea27d7987d2c0f67977371a99efec3ded13c872) --- source3/nsswitch/winbindd_ads.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 9560a53fa0..9fd391870b 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -39,7 +39,6 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) { ADS_STRUCT *ads; ADS_STATUS status; - char *ccache; if (domain->private) { return (ADS_STRUCT *)domain->private; -- cgit From e1c987abf2c716e26d2484a89e23507d1d2a9c5e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 05:07:51 +0000 Subject: Doesn't anyone run ./configure.developer anymore? (This used to be commit 09be123c6c1b67621eaf6c8ffb3016eccd375e5b) --- source3/libsmb/cliconnect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index c57f92eea9..901daf4b09 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -453,7 +453,7 @@ static DATA_BLOB cli_session_setup_blob(struct cli_state *cli, DATA_BLOB blob) /**************************************************************************** Use in-memory credentials cache ****************************************************************************/ -static void use_in_memory_ccache() { +static void use_in_memory_ccache(void) { setenv(KRB5_ENV_CCNAME, "MEMORY:cliconnect", 1); } -- cgit From 6a46281dbb9c1f1f3278f199e812ba71bd0b45b8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 21 Feb 2003 05:51:10 +0000 Subject: Ignore errors on python_clean target. (This used to be commit 3805a9c5d5e98e089e1cd9e794f7204fc354a311) --- source3/Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index efc3b935b4..cbd8418a48 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -1085,7 +1085,7 @@ python_install: $(PYTHON_OBJS) $(PYTHON) python/setup.py install python_clean: - @if test -n "$(PYTHON)"; then $(PYTHON) python/setup.py clean; fi + @-if test -n "$(PYTHON)"; then $(PYTHON) python/setup.py clean; fi # revert to the previously installed version revert: -- cgit From 2935d153763ca3f40de974418c479c4ef6cd4ec0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 21 Feb 2003 06:25:39 +0000 Subject: Added comments to make it clearer when we're assigning a pointer that it must not be freed afterwards. Jeremy. (This used to be commit 80bad908c0235a57446c70b9632d3415c9d2fcf5) --- source3/smbd/posix_acls.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3') diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c index a40fb4042f..93a57925f1 100644 --- a/source3/smbd/posix_acls.c +++ b/source3/smbd/posix_acls.c @@ -1000,8 +1000,16 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name )); return False; } + /* + * We must not free current_ace here as its + * pointer is now owned by the dir_ace list. + */ current_ace = dup_ace; } else { + /* + * We must not free current_ace here as its + * pointer is now owned by the dir_ace list. + */ current_ace = NULL; } } @@ -1036,6 +1044,10 @@ Deny entry after Allow entry. Failing to set on file %s.\n", fsp->fsp_name )); print_canon_ace( current_ace, 0); } all_aces_are_inherit_only = False; + /* + * We must not free current_ace here as its + * pointer is now owned by the file_ace list. + */ current_ace = NULL; } -- cgit From db721d24c5ed337e2fd69860d0a4011a6c1f3e2d Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 21 Feb 2003 13:25:10 +0000 Subject: rename 'winbind backend' to 'idmap backend'. Put paramter in security section...does this make sense? (This used to be commit 822083f73e8ba4e096c53ff0f7578f47bc21b7b5) --- source3/nsswitch/winbindd_idmap.c | 46 +++++++++++++++++++-------------------- source3/param/loadparm.c | 8 +++---- 2 files changed, 27 insertions(+), 27 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c index d9448ef859..0a17fcd87f 100644 --- a/source3/nsswitch/winbindd_idmap.c +++ b/source3/nsswitch/winbindd_idmap.c @@ -62,13 +62,13 @@ BOOL winbindd_idmap_init(void) BOOL ret = False; DEBUG(3, ("winbindd_idmap_init: using '%s' as backend\n", - lp_winbind_backend())); + lp_idmap_backend())); if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -87,10 +87,10 @@ BOOL winbindd_idmap_get_uid_from_sid(DOM_SID *sid, uid_t *uid) BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -107,10 +107,10 @@ BOOL winbindd_idmap_get_gid_from_sid(DOM_SID *sid, gid_t *gid) BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -128,10 +128,10 @@ BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid, BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -149,10 +149,10 @@ BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid, BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -169,10 +169,10 @@ BOOL winbindd_idmap_get_sid_from_uid(uid_t uid, DOM_SID *sid) BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); if (!impl) { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } @@ -189,14 +189,14 @@ BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid) BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); } if (impl) { ret = impl->get_sid_from_gid(gid, sid); } else { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } return ret; @@ -209,14 +209,14 @@ BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid, BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); } if (impl) { ret = impl->get_rid_from_uid(uid, user_rid, domain); } else { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } return ret; @@ -229,14 +229,14 @@ BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid, BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); } if (impl) { ret = impl->get_rid_from_gid(gid, group_rid, domain); } else { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } return ret; @@ -248,14 +248,14 @@ BOOL winbindd_idmap_close(void) BOOL ret = False; if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); } if (impl) { ret = impl->close(); } else { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } return ret; @@ -265,14 +265,14 @@ BOOL winbindd_idmap_close(void) void winbindd_idmap_status(void) { if (!impl) { - impl = get_impl(lp_winbind_backend()); + impl = get_impl(lp_idmap_backend()); } if (impl) { impl->status(); } else { DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_winbind_backend())); + lp_idmap_backend())); } } diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 01b6980c8f..7aaae439b1 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -172,7 +172,7 @@ typedef struct BOOL bWinbindEnumUsers; BOOL bWinbindEnumGroups; BOOL bWinbindUseDefaultDomain; - char *szWinbindBackend; + char *szIDMapBackend; char *szAddShareCommand; char *szChangeShareCommand; char *szDeleteShareCommand; @@ -749,6 +749,7 @@ static struct parm_struct parm_table[] = { {"update encrypted", P_BOOL, P_GLOBAL, &Globals.bUpdateEncrypt, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_DEVELOPER}, {"allow trusted domains", P_BOOL, P_GLOBAL, &Globals.bAllowTrustedDomains, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"hosts equiv", P_STRING, P_GLOBAL, &Globals.szHostsEquiv, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, + {"idmap backend", P_STRING, P_GLOBAL, &Globals.szIDMapBackend, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"min passwd length", P_INTEGER, P_GLOBAL, &Globals.min_passwd_length, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"min password length", P_INTEGER, P_GLOBAL, &Globals.min_passwd_length, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"map to guest", P_ENUM, P_GLOBAL, &Globals.map_to_guest, NULL, enum_map_to_guest, FLAG_ADVANCED | FLAG_DEVELOPER}, @@ -1120,7 +1121,6 @@ static struct parm_struct parm_table[] = { {"winbind enum users", P_BOOL, P_GLOBAL, &Globals.bWinbindEnumUsers, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"winbind enum groups", P_BOOL, P_GLOBAL, &Globals.bWinbindEnumGroups, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {"winbind use default domain", P_BOOL, P_GLOBAL, &Globals.bWinbindUseDefaultDomain, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, - {"winbind backend", P_STRING, P_GLOBAL, &Globals.szWinbindBackend, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER}, {NULL, P_BOOL, P_NONE, NULL, NULL, NULL, 0} }; @@ -1461,7 +1461,7 @@ static void init_globals(void) Globals.bWinbindEnumGroups = True; Globals.bWinbindUseDefaultDomain = False; - string_set(&Globals.szWinbindBackend, "tdb"); + string_set(&Globals.szIDMapBackend, "tdb"); Globals.name_cache_timeout = 660; /* In seconds */ @@ -1635,7 +1635,7 @@ FN_GLOBAL_STRING(lp_acl_compatibility, &Globals.szAclCompat) FN_GLOBAL_BOOL(lp_winbind_enum_users, &Globals.bWinbindEnumUsers) FN_GLOBAL_BOOL(lp_winbind_enum_groups, &Globals.bWinbindEnumGroups) FN_GLOBAL_BOOL(lp_winbind_use_default_domain, &Globals.bWinbindUseDefaultDomain) -FN_GLOBAL_STRING(lp_winbind_backend, &Globals.szWinbindBackend) +FN_GLOBAL_STRING(lp_idmap_backend, &Globals.szIDMapBackend) #ifdef WITH_LDAP_SAMCONFIG FN_GLOBAL_STRING(lp_ldap_server, &Globals.szLdapServer) -- cgit From 23553b48e6bd21481ca32c4b3ee54fc1aded4174 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 21 Feb 2003 14:35:02 +0000 Subject: Fix IRIX build...void fn can't return another void fn (This used to be commit df3c7c9cbb275e9c35356b4f1cab1a741de6f500) --- source3/libsmb/clikrb5.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index 96e737166c..bef6998a49 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -131,7 +131,8 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype *enctypes) { #if defined(HAVE_KRB5_FREE_KTYPES) - return krb5_free_ktypes(context, enctypes); + krb5_free_ktypes(context, enctypes); + return; #else SAFE_FREE(enctypes); return; -- cgit From 193f9200aa4ea692e9126f3df68a5cb83e3a4056 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Feb 2003 16:15:30 +0000 Subject: patch from Hal Roberts check for a valid [f]chmod_acl function pointer before calling it. Fixes seg fault in audit VFS module (This used to be commit 5e115d43812021f9a16111fc7c05d750026cca1e) --- source3/modules/vfs_audit.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c index 92b78c1c32..1944c98e53 100644 --- a/source3/modules/vfs_audit.c +++ b/source3/modules/vfs_audit.c @@ -233,7 +233,12 @@ static int audit_chmod(struct connection_struct *conn, const char *path, mode_t static int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode) { - int result = default_vfs_ops.chmod_acl(conn, path, mode); + int result; + + if ( !default_vfs_ops.chmod_acl ) + return 0; + + result = default_vfs_ops.chmod_acl(conn, path, mode); syslog(SYSLOG_PRIORITY, "chmod_acl %s mode 0x%x %s%s\n", path, mode, @@ -257,7 +262,12 @@ static int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode) static int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode) { - int result = default_vfs_ops.fchmod_acl(fsp, fd, mode); + int result; + + if ( !default_vfs_ops.fchmod_acl ) + return 0; + + result = default_vfs_ops.fchmod_acl(fsp, fd, mode); syslog(SYSLOG_PRIORITY, "fchmod_acl %s mode 0x%x %s%s\n", fsp->fsp_name, mode, -- cgit From ab985b983f45a284b2ee9fdd08801989574edf4b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Feb 2003 17:08:43 +0000 Subject: couple of merges from APP_HEAD * performance optimization in enumprinterdataex() when keyname is empty * fix a few typos in comments * reload services after addprinter_command() dump registry data in ascii when the key is REG_SZ or REG_MULTI_SZ (This used to be commit fde6ef7cc62c58d512dc8053b214f0a3c59a78ab) --- source3/rpc_parse/parse_spoolss.c | 2 +- source3/rpc_server/srv_spoolss_nt.c | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c index cb3b2efd9d..fb2aaf71ec 100644 --- a/source3/rpc_parse/parse_spoolss.c +++ b/source3/rpc_parse/parse_spoolss.c @@ -1372,7 +1372,7 @@ BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, return False; } - if (!prs_uint8s(False,"data", ps, depth, r_u->data, r_u->size)) + if (!prs_uint8s( r_u->type&(REG_SZ|REG_MULTI_SZ), "data", ps, depth, r_u->data, r_u->size )) return False; if (!prs_align(ps)) diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d94bebf4c1..4c87d0f73d 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -615,7 +615,7 @@ static BOOL is_monitoring_event(Printer_entry *p, uint16 notify_type, /* * Flags should always be zero when the change notify - * is registered by the cliebnt's spooler. A user Win32 app + * is registered by the client's spooler. A user Win32 app * might use the flags though instead of the NOTIFY_OPTION_INFO * --jerry */ @@ -5936,6 +5936,13 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_ACCESS_DENIED; goto done; } + + /* + * make sure we actually reload the services after + * this as smb.conf could have a new section in it + * .... shouldn't .... but could + */ + reload_services(False); } /* @@ -8871,11 +8878,24 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ DEBUG(4,("_spoolss_enumprinterdataex\n")); if (!Printer) { - DEBUG(2,("_spoolss_enumprinterdata: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle))); + DEBUG(2,("_spoolss_enumprinterdataex: Invalid handle (%s:%u:%u1<).\n", OUR_HANDLE(handle))); return WERR_BADFID; } - /* first get the printer off of disk */ + /* + * first check for a keyname of NULL or "". Win2k seems to send + * this a lot and we should send back WERR_INVALID_PARAM + * no need to spend time looking up the printer in this case. + * --jerry + */ + + unistr2_to_dos(key, &q_u->key, sizeof(key) - 1); + if ( !strlen(key) ) { + result = WERR_INVALID_PARAM; + goto done; + } + + /* get the printer off of disk */ if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; @@ -8971,6 +8991,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ done: + if ( printer ) free_a_printer(&printer, 2); return result; -- cgit From 3d730f89cf3c30d8b17f0d35d2cdf28db53296e2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 21 Feb 2003 20:00:46 +0000 Subject: i patched the wrong branch! s/unistr2_to_dos/unistr2_to_ascii/ (This used to be commit 513fb2ddd85a74de7684a6cb09d57011af69161f) --- source3/rpc_server/srv_spoolss_nt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 4c87d0f73d..93566c2bb7 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8889,7 +8889,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ * --jerry */ - unistr2_to_dos(key, &q_u->key, sizeof(key) - 1); + unistr2_to_ascii(key, &q_u->key, sizeof(key) - 1); if ( !strlen(key) ) { result = WERR_INVALID_PARAM; goto done; -- cgit From 301ebd6324138b9628638c0020597227d0cbf959 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 00:54:08 +0000 Subject: Fix a DEBUG() formatting, add some more debug to our SID pulling code and inline the call to prs_copy_all_data_out() so that we can know we are not overrunning our buffer. Also check more return values. Andrew Bartlett (This used to be commit e3b73d5d658584428c81c9ef3ccf024687a56e2f) --- source3/libads/ldap.c | 51 +++++++++++++++++++++++++-------------- source3/nsswitch/winbindd_group.c | 2 +- 2 files changed, 34 insertions(+), 19 deletions(-) (limited to 'source3') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 67669fc078..bc90e90ea0 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -816,18 +816,18 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, { int curmod; LDAPMod **modlist = (LDAPMod **) *mods; - void **values; + struct berval **ber_values; + char **char_values; if (!invals) { - values = NULL; mod_op = LDAP_MOD_DELETE; } else { if (mod_op & LDAP_MOD_BVALUES) - values = (void **) ads_dup_values(ctx, - (const struct berval **)invals); + ber_values = ads_dup_values(ctx, + (const struct berval **)invals); else - values = (void **) ads_push_strvals(ctx, - (const char **) invals); + char_values = ads_push_strvals(ctx, + (const char **) invals); } /* find the first empty slot */ @@ -846,10 +846,14 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, if (!(modlist[curmod] = talloc_zero(ctx, sizeof(LDAPMod)))) return ADS_ERROR(LDAP_NO_MEMORY); modlist[curmod]->mod_type = talloc_strdup(ctx, name); - if (mod_op & LDAP_MOD_BVALUES) - modlist[curmod]->mod_bvalues = (struct berval **) values; - else - modlist[curmod]->mod_values = (char **) values; + if (mod_op & LDAP_MOD_BVALUES) { + modlist[curmod]->mod_bvalues = ber_values; + } else if (mod_op & LDAP_MOD_DELETE) { + modlist[curmod]->mod_values = NULL; + } else { + modlist[curmod]->mod_values = char_values; + } + modlist[curmod]->mod_op = mod_op; return ADS_ERROR(LDAP_SUCCESS); } @@ -1500,16 +1504,24 @@ ADS_STATUS ads_set_machine_sd(ADS_STRUCT *ads, const char *hostname, char *dn) #endif if (!(mods = ads_init_mods(ctx))) return ADS_ERROR(LDAP_NO_MEMORY); - bval.bv_len = sd_size; - bval.bv_val = talloc(ctx, sd_size); + bval.bv_len = prs_offset(&ps_wire); + bval.bv_val = talloc(ctx, bval.bv_len); if (!bval.bv_val) { ret = ADS_ERROR(LDAP_NO_MEMORY); goto ads_set_sd_error; } - prs_copy_all_data_out(bval.bv_val, &ps_wire); - ads_mod_ber(ctx, &mods, attrs[0], &bval); - ret = ads_gen_mod(ads, dn, mods); + prs_set_offset(&ps_wire, 0); + + if (!prs_copy_data_out(bval.bv_val, &ps_wire, bval.bv_len)) { + ret = ADS_ERROR(LDAP_NO_MEMORY); + goto ads_set_sd_error; + } + + ret = ads_mod_ber(ctx, &mods, attrs[0], &bval); + if (ADS_ERR_OK(ret)) { + ret = ads_gen_mod(ads, dn, mods); + } ads_set_sd_error: ads_msgfree(ads, res); @@ -1554,7 +1566,7 @@ char *ads_pull_string(ADS_STRUCT *ads, char **values; char *ret = NULL; char *ux_string; - int rc; + size_t rc; values = ldap_get_values(ads->ld, msg, field); if (!values) @@ -1563,7 +1575,7 @@ char *ads_pull_string(ADS_STRUCT *ads, if (values[0]) { rc = pull_utf8_talloc(mem_ctx, &ux_string, values[0]); - if (rc != -1) + if (rc != (size_t)-1) ret = ux_string; } @@ -1725,8 +1737,11 @@ int ads_pull_sids(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, count = 0; for (i=0; values[i]; i++) { ret = sid_parse(values[i]->bv_val, values[i]->bv_len, &(*sids)[count]); - if (ret) + if (ret) { + fstring sid; + DEBUG(10, ("pulling SID: %s\n", sid_to_string(sid, &(*sids)[count]))); count++; + } } ldap_value_free_len(values); diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c index 6b2f05f436..94a826fbbc 100644 --- a/source3/nsswitch/winbindd_group.c +++ b/source3/nsswitch/winbindd_group.c @@ -434,7 +434,7 @@ static BOOL get_sam_group_entries(struct getent_state *ent) status = domain->methods->enum_dom_groups(domain, mem_ctx, &num_entries, &sam_grp_entries); if (!NT_STATUS_IS_OK(status)) { - DEBUG(3, ("get_sam_group_entries: could not enumerate domain groups! Error: %s", nt_errstr(status))); + DEBUG(3, ("get_sam_group_entries: could not enumerate domain groups! Error: %s\n", nt_errstr(status))); result = False; goto done; } -- cgit From ca2e9955764fa0bec3ace1fc049f13bb8e2961ac Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 22 Feb 2003 01:08:19 +0000 Subject: New locktest7 code based on patch from "Srikanta Shivanna" Jeremy. (This used to be commit caf298c3808cbdd683e884b32b7a0538505a3066) --- source3/torture/torture.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) (limited to 'source3') diff --git a/source3/torture/torture.c b/source3/torture/torture.c index 97e864de96..fe53baae7e 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -1569,6 +1569,139 @@ static BOOL run_locktest6(int dummy) return True; } +static BOOL run_locktest7(int dummy) +{ + static struct cli_state cli1; + const char *fname = "\\lockt7.lck"; + int fnum1; + char buf[200]; + BOOL correct = False; + + if (!torture_open_connection(&cli1)) { + return False; + } + + cli_sockopt(&cli1, sockops); + + printf("starting locktest7\n"); + + cli_unlink(&cli1, fname); + + fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE); + + memset(buf, 0, sizeof(buf)); + + if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) { + printf("Failed to create file\n"); + goto fail; + } + + cli_setpid(&cli1, 1); + + if (!cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK)) { + printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(&cli1)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for READ\n"); + } + + if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1)); + if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid1 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli_setpid(&cli1, 2); + + if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1)); + } else { + printf("pid2 successfully read the range 130:4\n"); + } + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1)); + if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli_setpid(&cli1, 1); + cli_unlock(&cli1, fnum1, 130, 4); + + if (!cli_lock(&cli1, fnum1, 130, 4, 0, WRITE_LOCK)) { + printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(&cli1)); + goto fail; + } else { + printf("pid1 successfully locked range 130:4 for WRITE\n"); + } + + if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) { + printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1)); + goto fail; + } else { + printf("pid1 successfully read the range 130:4\n"); + } + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1)); + goto fail; + } else { + printf("pid1 successfully wrote to the range 130:4\n"); + } + + cli_setpid(&cli1, 2); + + if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) { + printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1)); + if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully read the range 130:4 (should be denied)\n"); + goto fail; + } + + if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) { + printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1)); + if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { + printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); + goto fail; + } + } else { + printf("pid2 successfully wrote to the range 130:4 (should be denied)\n"); + goto fail; + } + + cli_unlock(&cli1, fnum1, 130, 0); + correct = True; + +fail: + cli_close(&cli1, fnum1); + cli_unlink(&cli1, fname); + torture_close_connection(&cli1); + + printf("finished locktest7\n"); + return correct; +} + /* test whether fnums and tids open on one VC are available on another (a major security hole) @@ -3956,6 +4089,7 @@ static struct { {"LOCK4", run_locktest4, 0}, {"LOCK5", run_locktest5, 0}, {"LOCK6", run_locktest6, 0}, + {"LOCK7", run_locktest7, 0}, {"UNLINK", run_unlinktest, 0}, {"BROWSE", run_browsetest, 0}, {"ATTR", run_attrtest, 0}, -- cgit From 4fdb86eb3b9b7eb01a90e3f3a846fb9f223d7208 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 22 Feb 2003 01:09:42 +0000 Subject: When checking is_locked() new WRITE locks conflict with existing READ locks even if the context is the same. See LOCKTEST7 in smbtorture. Jeremy. (This used to be commit b362cc241b829f585a96b5d285ed12db50b21e2e) --- source3/locking/brlock.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index 8c22f7d7ab..9902c7bbd7 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -151,9 +151,16 @@ static BOOL brl_conflict_other(struct lock_struct *lck1, struct lock_struct *lck if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) return False; - if (brl_same_context(&lck1->context, &lck2->context) && - lck1->fnum == lck2->fnum) - return False; + /* + * Incoming WRITE locks conflict with existing READ locks even + * if the context is the same. JRA. See LOCKTEST7 in smbtorture. + */ + + if (!(lck2->lock_type == WRITE_LOCK && lck1->lock_type == READ_LOCK)) { + if (brl_same_context(&lck1->context, &lck2->context) && + lck1->fnum == lck2->fnum) + return False; + } if (lck1->start >= (lck2->start + lck2->size) || lck2->start >= (lck1->start + lck1->size)) return False; -- cgit From ab43a25b2893506d5de305626dfbbf98966f1f78 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 11:34:04 +0000 Subject: First check if the user is in the passdb, then check Get_Pwnam(). We check passdb becouse the user might have things like a logon script set, but we have to check the passdb becouse the user might not be in smbpasswd at all. This is in preperation for the removal of unixsam as an assuption. Andrew Bartlett (This used to be commit 61e3e2695860c58f9b0e8d1856972318666682c8) --- source3/auth/auth_rhosts.c | 62 +++++++++++++++++++++++----------------------- source3/auth/auth_util.c | 30 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 31 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth_rhosts.c b/source3/auth/auth_rhosts.c index 4ed0e6bbc4..d8e1b01942 100644 --- a/source3/auth/auth_rhosts.c +++ b/source3/auth/auth_rhosts.c @@ -129,23 +129,19 @@ static BOOL check_user_equiv(const char *user, const char *remote, const char *e return False; } - /**************************************************************************** check for a possible hosts equiv or rhosts entry for the user ****************************************************************************/ -static BOOL check_hosts_equiv(struct passwd *pass) +static BOOL check_hosts_equiv(SAM_ACCOUNT *account) { char *fname = NULL; - if (!pass) - return(False); - fname = lp_hosts_equiv(); /* note: don't allow hosts.equiv on root */ - if (fname && *fname && (pass->pw_uid != 0)) { - if (check_user_equiv(pass->pw_name,client_name(),fname)) + if (IS_SAM_UNIX_USER(account) && fname && *fname && (pdb_get_uid(account) != 0)) { + if (check_user_equiv(pdb_get_username(account),client_name(),fname)) return(True); } @@ -164,15 +160,15 @@ static NTSTATUS check_hostsequiv_security(const struct auth_context *auth_contex auth_serversupplied_info **server_info) { NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE; - struct passwd *pass = Get_Pwnam(user_info->internal_username.str); - - if (pass) { - if (check_hosts_equiv(pass)) { - nt_status = NT_STATUS_OK; - make_server_info_pw(server_info, pass); - } - } else { - nt_status = NT_STATUS_NO_SUCH_USER; + SAM_ACCOUNT *account = NULL; + if (!NT_STATUS_IS_OK(nt_status = + auth_get_sam_account(user_info->internal_username.str, + &account))) { + return nt_status; + } + + if (check_hosts_equiv(account)) { + nt_status = make_server_info_sam(server_info, account); } return nt_status; @@ -186,6 +182,7 @@ NTSTATUS auth_init_hostsequiv(struct auth_context *auth_context, const char* par } (*auth_method)->auth = check_hostsequiv_security; + (*auth_method)->name = "hostsequiv"; return NT_STATUS_OK; } @@ -201,24 +198,26 @@ static NTSTATUS check_rhosts_security(const struct auth_context *auth_context, auth_serversupplied_info **server_info) { NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE; - struct passwd *pass = Get_Pwnam(user_info->internal_username.str); - pstring rhostsfile; + SAM_ACCOUNT *account = NULL; - if (pass) { - char *home = pass->pw_dir; - if (home) { - slprintf(rhostsfile, sizeof(rhostsfile)-1, "%s/.rhosts", home); - become_root(); - if (check_user_equiv(pass->pw_name,client_name(),rhostsfile)) { - nt_status = NT_STATUS_OK; - make_server_info_pw(server_info, pass); - } - unbecome_root(); - } - } else { - nt_status = NT_STATUS_NO_SUCH_USER; + if (!NT_STATUS_IS_OK(nt_status = + auth_get_sam_account(user_info->internal_username.str, + &account))) { + return nt_status; } + pstring rhostsfile; + + char *home = pdb_get_unix_homedir(account); + if (home) { + slprintf(rhostsfile, sizeof(rhostsfile)-1, "%s/.rhosts", home); + become_root(); + if (check_user_equiv(pdb_get_username(account),client_name(),rhostsfile)) { + nt_status = make_server_info_sam(server_info, account); + } + unbecome_root(); + } + return nt_status; } @@ -230,5 +229,6 @@ NTSTATUS auth_init_rhosts(struct auth_context *auth_context, const char *param, } (*auth_method)->auth = check_rhosts_security; + (*auth_method)->name = "rhosts"; return NT_STATUS_OK; } diff --git a/source3/auth/auth_util.c b/source3/auth/auth_util.c index 352d058f20..7d85153bd0 100644 --- a/source3/auth/auth_util.c +++ b/source3/auth/auth_util.c @@ -77,6 +77,36 @@ void smb_user_control(const auth_usersupplied_info *user_info, auth_serversuppli } } +/**************************************************************************** + Create a SAM_ACCOUNT - either by looking in the pdb, or by faking it up from + unix info. +****************************************************************************/ + +NTSTATUS auth_get_sam_account(const char *user, SAM_ACCOUNT **account) +{ + BOOL pdb_ret; + NTSTATUS nt_status; + if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(account))) { + return nt_status; + } + + become_root(); + pdb_ret = pdb_getsampwnam(*account, user); + unbecome_root(); + + if (!pdb_ret) { + + struct passwd *pass = Get_Pwnam(user); + if (!pass) + return NT_STATUS_NO_SUCH_USER; + + if (!NT_STATUS_IS_OK(nt_status = pdb_fill_sam_pw(*account, pass))) { + return nt_status; + } + } + return NT_STATUS_OK; +} + /**************************************************************************** Create an auth_usersupplied_data structure ****************************************************************************/ -- cgit From 3e19eda335057ec47483c8567395b43d316485db Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:01:05 +0000 Subject: Remove 'unixsam' from the default passdb backends. The intention is to remove the muliple passdb backends, but we need the 'guest' account to always be there. If the admin adds the guest account to (say) LDAP, there will only be one backend required for operation. This helps remove some nasty behaviours with adding accounts to the system for both the RPC 'create user' and the SAMSYNC code. Users 'added' with an 'add user/machine' script won't magicly appear, and machine accounts 'pre-added' to unix, but not the smbpasswd file will not cause mayhem. This commit also implements somthing tridge discussed with me, the concept of 'default' passdb operation pointers - so that each backend does not need it's own stub funcitons wrapping the default tdb privilages/group mapping code. This also removes an implicit 'sid->name' and 'name->sid' mapping from our own local SID space, to winbind usernames. When adding mapping for NIS/LDAP non-sam users in future, we need to be careful. Andrew Bartlett (This used to be commit 6f32fa234961a525760a05418a08ec48d22d7617) --- source3/Makefile.in | 5 +- source3/groupdb/mapping.c | 55 ++++++++++++++++++ source3/param/loadparm.c | 4 +- source3/passdb/passdb.c | 6 +- source3/passdb/pdb_guest.c | 123 +++++++++++++++++++++++++++++++++++++++++ source3/passdb/pdb_interface.c | 63 +++++++++++++++++++++ source3/passdb/pdb_ldap.c | 59 -------------------- source3/passdb/pdb_smbpasswd.c | 85 +++++----------------------- source3/passdb/pdb_tdb.c | 59 -------------------- source3/passdb/pdb_unix.c | 88 ----------------------------- 10 files changed, 264 insertions(+), 283 deletions(-) create mode 100644 source3/passdb/pdb_guest.c (limited to 'source3') diff --git a/source3/Makefile.in b/source3/Makefile.in index cbd8418a48..7de4b0ae8f 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -286,8 +286,9 @@ PASSDB_GET_SET_OBJ = passdb/pdb_get_set.o PASSDB_OBJ = $(PASSDB_GET_SET_OBJ) passdb/passdb.o passdb/pdb_interface.o \ passdb/machine_sid.o passdb/pdb_smbpasswd.o \ passdb/pdb_tdb.o passdb/pdb_ldap.o \ - passdb/pdb_unix.o passdb/util_sam_sid.o \ - passdb/pdb_compat.o passdb/pdb_nisplus.o passdb/privileges.o + passdb/pdb_unix.o passdb/pdb_guest.o passdb/util_sam_sid.o \ + passdb/pdb_compat.o passdb/pdb_nisplus.o \ + passdb/privileges.o XML_OBJ = modules/xml.o MYSQL_OBJ = modules/mysql.o diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c index 272783608c..02fc23418f 100644 --- a/source3/groupdb/mapping.c +++ b/source3/groupdb/mapping.c @@ -841,6 +841,7 @@ BOOL enum_group_mapping(enum SID_NAME_USE sid_name_use, GROUP_MAP **rmap, } *num_entries=entries; + return True; } @@ -1276,3 +1277,57 @@ int smb_delete_user_group(const char *unix_group, const char *unix_user) DEBUG(3,("smb_delete_user_group: Running the command `%s' gave %d\n",del_script,ret)); return ret; } + + +NTSTATUS pdb_default_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, + DOM_SID sid, BOOL with_priv) +{ + return get_group_map_from_sid(sid, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, + gid_t gid, BOOL with_priv) +{ + return get_group_map_from_gid(gid, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, + char *name, BOOL with_priv) +{ + return get_group_map_from_ntname(name, map, with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_add_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map) +{ + return add_mapping_entry(map, TDB_INSERT) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_update_group_mapping_entry(struct pdb_methods *methods, + GROUP_MAP *map) +{ + return add_mapping_entry(map, TDB_REPLACE) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_delete_group_mapping_entry(struct pdb_methods *methods, + DOM_SID sid) +{ + return group_map_remove(sid) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS pdb_default_enum_group_mapping(struct pdb_methods *methods, + enum SID_NAME_USE sid_name_use, + GROUP_MAP **rmap, int *num_entries, + BOOL unix_only, BOOL with_priv) +{ + return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, + with_priv) ? + NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 7aaae439b1..b57b169adc 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -1408,9 +1408,9 @@ static void init_globals(void) #ifdef WITH_LDAP_SAMCONFIG string_set(&Globals.szLdapServer, "localhost"); Globals.ldap_port = 636; - Globals.szPassdbBackend = str_list_make("ldapsam unixsam", NULL); + Globals.szPassdbBackend = str_list_make("ldapsam guest", NULL); #else - Globals.szPassdbBackend = str_list_make("smbpasswd unixsam", NULL); + Globals.szPassdbBackend = str_list_make("smbpasswd guest", NULL); #endif /* WITH_LDAP_SAMCONFIG */ string_set(&Globals.szLdapSuffix, ""); diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 71a880d295..eff1ef4bcc 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -283,7 +283,7 @@ NTSTATUS pdb_init_sam_pw(SAM_ACCOUNT **new_sam_acct, const struct passwd *pwd) if (!pwd) { new_sam_acct = NULL; - return NT_STATUS_UNSUCCESSFUL; + return NT_STATUS_INVALID_PARAMETER; } if (!NT_STATUS_IS_OK(nt_status = pdb_init_sam(new_sam_acct))) { @@ -661,7 +661,7 @@ BOOL local_lookup_sid(DOM_SID *sid, char *name, enum SID_NAME_USE *psid_name_use pdb_free_sam(&sam_account); if (pdb_getgrsid(&map, *sid, MAPPING_WITHOUT_PRIV)) { - if (map.gid!=-1) { + if (map.gid!=(gid_t)-1) { DEBUG(5,("local_lookup_sid: mapped group %s to gid %u\n", map.nt_name, (unsigned int)map.gid)); } else { DEBUG(5,("local_lookup_sid: mapped group %s to no unix gid. Returning name.\n", map.nt_name)); @@ -950,7 +950,7 @@ BOOL local_sid_to_gid(gid_t *pgid, const DOM_SID *psid, enum SID_NAME_USE *name_ if (pdb_getgrsid(&map, *psid, MAPPING_WITHOUT_PRIV)) { /* the SID is in the mapping table but not mapped */ - if (map.gid==-1) + if (map.gid==(gid_t)-1) return False; *pgid = map.gid; diff --git a/source3/passdb/pdb_guest.c b/source3/passdb/pdb_guest.c new file mode 100644 index 0000000000..3f0f06d18d --- /dev/null +++ b/source3/passdb/pdb_guest.c @@ -0,0 +1,123 @@ +/* + * 'Guest' password backend for samba + * Copyright (C) Jelmer Vernooij 2002 + * Copyright (C) Andrew Bartlett 2003 + * + * 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" + +/****************************************************************** + Lookup a name in the SAM database + ******************************************************************/ + +static NTSTATUS guestsam_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +{ + NTSTATUS nt_status; + struct passwd *pass; + const char *guest_account = lp_guestaccount(); + if (!(guest_account && *guest_account)) { + DEBUG(1, ("NULL guest account!?!?\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!methods) { + DEBUG(0,("invalid methods\n")); + return NT_STATUS_UNSUCCESSFUL; + } + if (!sname) { + DEBUG(0,("invalid name specified")); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!strequal(guest_account, sname)) { + return NT_STATUS_NO_SUCH_USER; + } + + pass = getpwnam_alloc(guest_account); + + nt_status = pdb_fill_sam_pw(user, pass); + + passwd_free(&pass); + return nt_status; +} + + +/*************************************************************************** + Search by rid + **************************************************************************/ + +static NTSTATUS guestsam_getsampwrid (struct pdb_methods *methods, + SAM_ACCOUNT *user, uint32 rid) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + struct passwd *pass = NULL; + const char *guest_account = lp_guestaccount(); + if (!(guest_account && *guest_account)) { + DEBUG(1, ("NULL guest account!?!?\n")); + return nt_status; + } + + if (!methods) { + DEBUG(0,("invalid methods\n")); + return nt_status; + } + + if (rid == DOMAIN_USER_RID_GUEST) { + pass = getpwnam_alloc(guest_account); + if (!pass) { + DEBUG(1, ("guest account %s does not seem to exist...\n", guest_account)); + return NT_STATUS_NO_SUCH_USER; + } + } else { + return NT_STATUS_NO_SUCH_USER; + } + + nt_status = pdb_fill_sam_pw(user, pass); + passwd_free(&pass); + + return nt_status; +} + +static NTSTATUS guestsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) +{ + uint32 rid; + if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) + return NT_STATUS_NO_SUCH_USER; + return guestsam_getsampwrid(my_methods, user, rid); +} + +NTSTATUS pdb_init_guestsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) +{ + NTSTATUS nt_status; + + if (!pdb_context) { + DEBUG(0, ("invalid pdb_context specified\n")); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) { + return nt_status; + } + + (*pdb_method)->name = "guestsam"; + + (*pdb_method)->getsampwnam = guestsam_getsampwnam; + (*pdb_method)->getsampwsid = guestsam_getsampwsid; + + /* There's not very much to initialise here */ + return NT_STATUS_OK; +} diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index 778cb9425c..d465439dda 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -37,6 +37,7 @@ static const struct { { "ldapsam", pdb_init_ldapsam }, { "ldapsam_nua", pdb_init_ldapsam_nua }, { "unixsam", pdb_init_unixsam }, + { "guest", pdb_init_guestsam }, { "nisplussam", pdb_init_nisplussam }, { NULL, NULL} }; @@ -763,6 +764,51 @@ BOOL initialize_password_db(BOOL reload) } +/*************************************************************************** + Default implementations of some functions. + ****************************************************************************/ + +static NTSTATUS pdb_default_getsampwnam (struct pdb_methods *methods, SAM_ACCOUNT *user, const char *sname) +{ + return NT_STATUS_NO_SUCH_USER; +} + +static NTSTATUS pdb_default_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) +{ + return NT_STATUS_NO_SUCH_USER; +} + +static NTSTATUS pdb_default_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +{ + DEBUG(0,("this backend (%s) should not be listed as the first passdb backend! You can't add users to it.\n", methods->name)); + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS pdb_default_update_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS pdb_default_delete_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *pwd) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS pdb_default_setsampwent(struct pdb_methods *methods, BOOL update) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static NTSTATUS pdb_default_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +static void pdb_default_endsampwent(struct pdb_methods *methods) +{ + return; /* NT_STATUS_NOT_IMPLEMENTED; */ +} + NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods) { *methods = talloc(mem_ctx, sizeof(struct pdb_methods)); @@ -773,5 +819,22 @@ NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods) ZERO_STRUCTP(*methods); + (*methods)->setsampwent = pdb_default_setsampwent; + (*methods)->endsampwent = pdb_default_endsampwent; + (*methods)->getsampwent = pdb_default_getsampwent; + (*methods)->getsampwnam = pdb_default_getsampwnam; + (*methods)->getsampwsid = pdb_default_getsampwsid; + (*methods)->add_sam_account = pdb_default_add_sam_account; + (*methods)->update_sam_account = pdb_default_update_sam_account; + (*methods)->delete_sam_account = pdb_default_delete_sam_account; + + (*methods)->getgrsid = pdb_default_getgrsid; + (*methods)->getgrgid = pdb_default_getgrgid; + (*methods)->getgrnam = pdb_default_getgrnam; + (*methods)->add_group_mapping_entry = pdb_default_add_group_mapping_entry; + (*methods)->update_group_mapping_entry = pdb_default_update_group_mapping_entry; + (*methods)->delete_group_mapping_entry = pdb_default_delete_group_mapping_entry; + (*methods)->enum_group_mapping = pdb_default_enum_group_mapping; + return NT_STATUS_OK; } diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index e058d2d108..548d7bc60d 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -1965,58 +1965,6 @@ static NTSTATUS ldapsam_add_sam_account(struct pdb_methods *my_methods, SAM_ACCO return NT_STATUS_OK; } -static NTSTATUS ldapsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, - DOM_SID sid, BOOL with_priv) -{ - return get_group_map_from_sid(sid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, - gid_t gid, BOOL with_priv) -{ - return get_group_map_from_gid(gid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, - char *name, BOOL with_priv) -{ - return get_group_map_from_ntname(name, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_add_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_INSERT) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_update_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_REPLACE) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_delete_group_mapping_entry(struct pdb_methods *methods, - DOM_SID sid) -{ - return group_map_remove(sid) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods, - enum SID_NAME_USE sid_name_use, - GROUP_MAP **rmap, int *num_entries, - BOOL unix_only, BOOL with_priv) -{ - return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, - with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - static void free_private_data(void **vp) { struct ldapsam_privates **ldap_state = (struct ldapsam_privates **)vp; @@ -2056,13 +2004,6 @@ NTSTATUS pdb_init_ldapsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, co (*pdb_method)->add_sam_account = ldapsam_add_sam_account; (*pdb_method)->update_sam_account = ldapsam_update_sam_account; (*pdb_method)->delete_sam_account = ldapsam_delete_sam_account; - (*pdb_method)->getgrsid = ldapsam_getgrsid; - (*pdb_method)->getgrgid = ldapsam_getgrgid; - (*pdb_method)->getgrnam = ldapsam_getgrnam; - (*pdb_method)->add_group_mapping_entry = ldapsam_add_group_mapping_entry; - (*pdb_method)->update_group_mapping_entry = ldapsam_update_group_mapping_entry; - (*pdb_method)->delete_group_mapping_entry = ldapsam_delete_group_mapping_entry; - (*pdb_method)->enum_group_mapping = ldapsam_enum_group_mapping; /* TODO: Setup private data and free */ diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index 5fd6a828bf..b5a2bbbfe7 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -1222,7 +1222,6 @@ static BOOL build_sam_account(struct smbpasswd_privates *smbpasswd_state, return False; } } else { - if (!NT_STATUS_IS_OK(pdb_fill_sam_pw(sam_pass, pwfile))) { return False; } @@ -1380,14 +1379,19 @@ static NTSTATUS smbpasswd_getsampwnam(struct pdb_methods *my_methods, return NT_STATUS_OK; } -static NTSTATUS smbpasswd_getsampwrid(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_acct,uint32 rid) +static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT *sam_acct, const DOM_SID *sid) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data; struct smb_passwd *smb_pw; void *fp = NULL; + fstring sid_str; + uint32 rid; + + DEBUG(10, ("smbpasswd_getsampwrid: search by sid: %s\n", sid_to_string(sid_str, sid))); - DEBUG(10, ("smbpasswd_getsampwrid: search by rid: %d\n", rid)); + if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) + return NT_STATUS_UNSUCCESSFUL; /* More special case 'guest account' hacks... */ if (rid == DOMAIN_USER_RID_GUEST) { @@ -1431,18 +1435,18 @@ static NTSTATUS smbpasswd_getsampwrid(struct pdb_methods *my_methods, SAM_ACCOUN if (!build_sam_account (smbpasswd_state, sam_acct, smb_pw)) return nt_status; + /* build_sam_account might change the SID on us, if the name was for the guest account */ + if (NT_STATUS_IS_OK(nt_status) && !sid_equal(pdb_get_user_sid(sam_acct), sid)) { + fstring sid_string1, sid_string2; + DEBUG(1, ("looking for user with sid %s instead returned %s for account %s!?!\n", + sid_to_string(sid_string1, sid), sid_to_string(sid_string2, pdb_get_user_sid(sam_acct)), pdb_get_username(sam_acct))); + return NT_STATUS_NO_SUCH_USER; + } + /* success */ return NT_STATUS_OK; } -static NTSTATUS smbpasswd_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT * user, const DOM_SID *sid) -{ - uint32 rid; - if (!sid_peek_check_rid(get_global_sam_sid(), sid, &rid)) - return NT_STATUS_UNSUCCESSFUL; - return smbpasswd_getsampwrid(my_methods, user, rid); -} - static NTSTATUS smbpasswd_add_sam_account(struct pdb_methods *my_methods, SAM_ACCOUNT *sampass) { struct smbpasswd_privates *smbpasswd_state = (struct smbpasswd_privates*)my_methods->private_data; @@ -1493,58 +1497,6 @@ static NTSTATUS smbpasswd_delete_sam_account (struct pdb_methods *my_methods, SA return NT_STATUS_UNSUCCESSFUL; } -static NTSTATUS smbpasswd_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, - DOM_SID sid, BOOL with_priv) -{ - return get_group_map_from_sid(sid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, - gid_t gid, BOOL with_priv) -{ - return get_group_map_from_gid(gid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, - char *name, BOOL with_priv) -{ - return get_group_map_from_ntname(name, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_add_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_INSERT) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_update_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_REPLACE) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_delete_group_mapping_entry(struct pdb_methods *methods, - DOM_SID sid) -{ - return group_map_remove(sid) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS smbpasswd_enum_group_mapping(struct pdb_methods *methods, - enum SID_NAME_USE sid_name_use, - GROUP_MAP **rmap, int *num_entries, - BOOL unix_only, BOOL with_priv) -{ - return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, - with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - static void free_private_data(void **vp) { struct smbpasswd_privates **privates = (struct smbpasswd_privates**)vp; @@ -1575,13 +1527,6 @@ NTSTATUS pdb_init_smbpasswd(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, (*pdb_method)->add_sam_account = smbpasswd_add_sam_account; (*pdb_method)->update_sam_account = smbpasswd_update_sam_account; (*pdb_method)->delete_sam_account = smbpasswd_delete_sam_account; - (*pdb_method)->getgrsid = smbpasswd_getgrsid; - (*pdb_method)->getgrgid = smbpasswd_getgrgid; - (*pdb_method)->getgrnam = smbpasswd_getgrnam; - (*pdb_method)->add_group_mapping_entry = smbpasswd_add_group_mapping_entry; - (*pdb_method)->update_group_mapping_entry = smbpasswd_update_group_mapping_entry; - (*pdb_method)->delete_group_mapping_entry = smbpasswd_delete_group_mapping_entry; - (*pdb_method)->enum_group_mapping = smbpasswd_enum_group_mapping; /* Setup private data and free function */ diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index a1f786c8cd..c48c9567b1 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -896,58 +896,6 @@ static NTSTATUS tdbsam_add_sam_account (struct pdb_methods *my_methods, SAM_ACCO return NT_STATUS_UNSUCCESSFUL; } -static NTSTATUS tdbsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, - DOM_SID sid, BOOL with_priv) -{ - return get_group_map_from_sid(sid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, - gid_t gid, BOOL with_priv) -{ - return get_group_map_from_gid(gid, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, - char *name, BOOL with_priv) -{ - return get_group_map_from_ntname(name, map, with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_add_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_INSERT) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_update_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return add_mapping_entry(map, TDB_REPLACE) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_delete_group_mapping_entry(struct pdb_methods *methods, - DOM_SID sid) -{ - return group_map_remove(sid) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - -static NTSTATUS tdbsam_enum_group_mapping(struct pdb_methods *methods, - enum SID_NAME_USE sid_name_use, - GROUP_MAP **rmap, int *num_entries, - BOOL unix_only, BOOL with_priv) -{ - return enum_group_mapping(sid_name_use, rmap, num_entries, unix_only, - with_priv) ? - NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; -} - static void free_private_data(void **vp) { struct tdbsam_privates **tdb_state = (struct tdbsam_privates **)vp; @@ -985,13 +933,6 @@ NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, con (*pdb_method)->add_sam_account = tdbsam_add_sam_account; (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - (*pdb_method)->getgrsid = tdbsam_getgrsid; - (*pdb_method)->getgrgid = tdbsam_getgrgid; - (*pdb_method)->getgrnam = tdbsam_getgrnam; - (*pdb_method)->add_group_mapping_entry = tdbsam_add_group_mapping_entry; - (*pdb_method)->update_group_mapping_entry = tdbsam_update_group_mapping_entry; - (*pdb_method)->delete_group_mapping_entry = tdbsam_delete_group_mapping_entry; - (*pdb_method)->enum_group_mapping = tdbsam_enum_group_mapping; tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); diff --git a/source3/passdb/pdb_unix.c b/source3/passdb/pdb_unix.c index 8acc29b7a4..07acd08a4e 100644 --- a/source3/passdb/pdb_unix.c +++ b/source3/passdb/pdb_unix.c @@ -88,16 +88,6 @@ static NTSTATUS unixsam_getsampwsid(struct pdb_methods *my_methods, SAM_ACCOUNT return unixsam_getsampwrid(my_methods, user, rid); } -/*************************************************************************** - Adds an existing SAM_ACCOUNT - ****************************************************************************/ - -static NTSTATUS unixsam_add_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *newpwd) -{ - DEBUG(0,("pdb_unix should not be listed as the first passdb backend! You can't add users to it.\n")); - return NT_STATUS_NOT_IMPLEMENTED; -} - /*************************************************************************** Updates a SAM_ACCOUNT @@ -113,70 +103,6 @@ static NTSTATUS unixsam_update_sam_account (struct pdb_methods *methods, SAM_ACC return methods->parent->pdb_add_sam_account(methods->parent, newpwd); } -static NTSTATUS unixsam_delete_sam_account (struct pdb_methods *methods, SAM_ACCOUNT *pwd) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_setsampwent(struct pdb_methods *methods, BOOL update) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT *user) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static void unixsam_endsampwent(struct pdb_methods *methods) -{ - return; /* NT_STATUS_NOT_IMPLEMENTED; */ -} - -static NTSTATUS unixsam_getgrsid(struct pdb_methods *methods, GROUP_MAP *map, - DOM_SID sid, BOOL with_priv) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_getgrgid(struct pdb_methods *methods, GROUP_MAP *map, - gid_t gid, BOOL with_priv) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_getgrnam(struct pdb_methods *methods, GROUP_MAP *map, - char *name, BOOL with_priv) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_add_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_update_group_mapping_entry(struct pdb_methods *methods, - GROUP_MAP *map) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_delete_group_mapping_entry(struct pdb_methods *methods, - DOM_SID sid) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - -static NTSTATUS unixsam_enum_group_mapping(struct pdb_methods *methods, - enum SID_NAME_USE sid_name_use, - GROUP_MAP **rmap, int *num_entries, - BOOL unix_only, BOOL with_priv) -{ - return NT_STATUS_NOT_IMPLEMENTED; -} - NTSTATUS pdb_init_unixsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) { NTSTATUS nt_status; @@ -191,22 +117,8 @@ NTSTATUS pdb_init_unixsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, co } (*pdb_method)->name = "unixsam"; - - (*pdb_method)->setsampwent = unixsam_setsampwent; - (*pdb_method)->endsampwent = unixsam_endsampwent; - (*pdb_method)->getsampwent = unixsam_getsampwent; (*pdb_method)->getsampwnam = unixsam_getsampwnam; (*pdb_method)->getsampwsid = unixsam_getsampwsid; - (*pdb_method)->add_sam_account = unixsam_add_sam_account; - (*pdb_method)->update_sam_account = unixsam_update_sam_account; - (*pdb_method)->delete_sam_account = unixsam_delete_sam_account; - (*pdb_method)->getgrsid = unixsam_getgrsid; - (*pdb_method)->getgrgid = unixsam_getgrgid; - (*pdb_method)->getgrnam = unixsam_getgrnam; - (*pdb_method)->add_group_mapping_entry = unixsam_add_group_mapping_entry; - (*pdb_method)->update_group_mapping_entry = unixsam_update_group_mapping_entry; - (*pdb_method)->delete_group_mapping_entry = unixsam_delete_group_mapping_entry; - (*pdb_method)->enum_group_mapping = unixsam_enum_group_mapping; /* There's not very much to initialise here */ return NT_STATUS_OK; -- cgit From e22a1915fee466c2266361a7b956d1225ad86f56 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:14:08 +0000 Subject: With assuptions about unixsam gone, we can forget about looking up the user a second time now. Andrew Bartlett (This used to be commit a1e27a02f52315df0dd05ab8a94ae5a2bf398655) --- source3/utils/net_rpc_samsync.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/utils/net_rpc_samsync.c b/source3/utils/net_rpc_samsync.c index ac3b78fc7a..7d5c8681ad 100644 --- a/source3/utils/net_rpc_samsync.c +++ b/source3/utils/net_rpc_samsync.c @@ -317,10 +317,7 @@ fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta) "gave %d\n", add_script, add_ret)); } - if (!pdb_getsampwnam(sam_account, account)) { - try_add = True; - /* still not there, hope the backend likes NUAs */ - } + try_add = True; } sam_account_from_delta(sam_account, delta); -- cgit From ae2f064dc65762e32db10de1362e2cef782eb304 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:16:17 +0000 Subject: Add static (This used to be commit d0365f20c242bcfc4f5d8286c6c5654e310a9d45) --- source3/torture/masktest.c | 2 +- source3/utils/profiles.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3') diff --git a/source3/torture/masktest.c b/source3/torture/masktest.c index df0a047aff..7d751fb789 100644 --- a/source3/torture/masktest.c +++ b/source3/torture/masktest.c @@ -254,7 +254,7 @@ struct cli_state *connect_one(char *share) static char *resultp; static file_info *f_info; -void listfn(file_info *f, const char *s, void *state) +static void listfn(file_info *f, const char *s, void *state) { if (strcmp(f->name,".") == 0) { resultp[0] = '+'; diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c index 2ed102b677..b4087cf6cf 100644 --- a/source3/utils/profiles.c +++ b/source3/utils/profiles.c @@ -398,7 +398,7 @@ DOM_SID old_sid, new_sid; int change = 0, new = 0; /* Compare two SIDs for equality */ -int my_sid_equal(DOM_SID *s1, DOM_SID *s2) +static int my_sid_equal(DOM_SID *s1, DOM_SID *s2) { int sa1, sa2; @@ -417,7 +417,7 @@ int my_sid_equal(DOM_SID *s1, DOM_SID *s2) * Quick and dirty to read a SID in S-1-5-21-x-y-z-rid format and * construct a DOM_SID */ -int get_sid(DOM_SID *sid, char *sid_str) +static int get_sid(DOM_SID *sid, char *sid_str) { int i = 0, auth; char *lstr; @@ -460,7 +460,7 @@ int get_sid(DOM_SID *sid, char *sid_str) * This routine does not need to deal with endianism as * long as the incoming SIDs are both in the same (LE) format. */ -void change_sid(DOM_SID *s1, DOM_SID *s2) +static void change_sid(DOM_SID *s1, DOM_SID *s2) { int i; @@ -469,7 +469,7 @@ void change_sid(DOM_SID *s1, DOM_SID *s2) } } -void print_sid(DOM_SID *sid) +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]); @@ -482,7 +482,7 @@ void print_sid(DOM_SID *sid) fprintf(stdout, "\n"); } -void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) +static void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) { int i; if (my_sid_equal(sid, o_sid)) { @@ -496,7 +496,7 @@ void process_sid(DOM_SID *sid, DOM_SID *o_sid, DOM_SID *n_sid) } -void process_acl(ACL *acl, const char *prefix) +static void process_acl(ACL *acl, const char *prefix) { int ace_cnt, i; ACE *ace; @@ -514,7 +514,7 @@ void process_acl(ACL *acl, const char *prefix) } } -void usage(void) +static void usage(void) { fprintf(stderr, "usage: profiles [-c -n ] \n"); fprintf(stderr, "Version: %s\n", VERSION); -- cgit From db94beaa41d6c2c82ee9351a171f2a73a9e358da Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:17:02 +0000 Subject: Fix comment - the other bits of code don't call this any more. (This used to be commit 523d1429b1072c999d376d2b4e13a1c08349990a) --- source3/passdb/passdb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index eff1ef4bcc..5e6466ff0a 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -992,10 +992,7 @@ BOOL local_sid_to_gid(gid_t *pgid, const DOM_SID *psid, enum SID_NAME_USE *name_ /************************************************************* Change a password entry in the local smbpasswd file. - FIXME!! The function needs to be abstracted into the - passdb interface or something. It is currently being called - by _api_samr_create_user() in rpc_server/srv_samr.c, - in SWAT and by smbpasswd/pdbedit. +It is currently being called by SWAT and by smbpasswd. --jerry *************************************************************/ -- cgit From 0dde23a7b24edf1cbf4d7d7e5afea485e37498e5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:19:18 +0000 Subject: Fixes from Paul Green and vorlon@debian.org for building shared libraries (make it possible to build both shared and static) and -lcrypt handling. (This used to be commit 30510f50077fd157664c127ac0182ce26843d43f) --- source3/aclocal.m4 | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ source3/configure.in | 67 +++++++++++++++++++++++++++------------------------- 2 files changed, 99 insertions(+), 32 deletions(-) (limited to 'source3') diff --git a/source3/aclocal.m4 b/source3/aclocal.m4 index 345be73aed..7bec88dd87 100644 --- a/source3/aclocal.m4 +++ b/source3/aclocal.m4 @@ -577,3 +577,67 @@ if test "$2" != "/usr/lib" ; then $1="$$1 -L$2" fi ]) + +dnl AC_ENABLE_SHARED - implement the --enable-shared flag +dnl Usage: AC_ENABLE_SHARED[(DEFAULT)] +dnl Where DEFAULT is either `yes' or `no'. If omitted, it defaults to +dnl `yes'. +AC_DEFUN([AC_ENABLE_SHARED], +[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE(shared, +changequote(<<, >>)dnl +<< --enable-shared[=PKGS] build shared libraries [default=>>AC_ENABLE_SHARED_DEFAULT], +changequote([, ])dnl +[p=${PACKAGE-default} +case $enableval in +yes) enable_shared=yes ;; +no) enable_shared=no ;; +*) + enable_shared=no + # Look at the argument we got. We use all the common list separators. + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," + for pkg in $enableval; do + if test "X$pkg" = "X$p"; then + enable_shared=yes + fi + + done + IFS="$ac_save_ifs" + ;; +esac], +enable_shared=AC_ENABLE_SHARED_DEFAULT)dnl +]) + +dnl AC_ENABLE_STATIC - implement the --enable-static flag +dnl Usage: AC_ENABLE_STATIC[(DEFAULT)] +dnl Where DEFAULT is either `yes' or `no'. If omitted, it defaults to +dnl `yes'. +AC_DEFUN([AC_ENABLE_STATIC], +[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl +AC_ARG_ENABLE(static, +changequote(<<, >>)dnl +<< --enable-static[=PKGS] build static libraries [default=>>AC_ENABLE_STATIC_DEFAULT], +changequote([, ])dnl +[p=${PACKAGE-default} +case $enableval in +yes) enable_static=yes ;; +no) enable_static=no ;; +*) + enable_static=no + # Look at the argument we got. We use all the common list separators. + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:," + for pkg in $enableval; do + if test "X$pkg" = "X$p"; then + enable_static=yes + fi + done + IFS="$ac_save_ifs" + ;; +esac], +enable_static=AC_ENABLE_STATIC_DEFAULT)dnl +]) + +dnl AC_DISABLE_STATIC - set the default static flag to --disable-static +AC_DEFUN([AC_DISABLE_STATIC], +[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl +AC_ENABLE_STATIC(no)]) diff --git a/source3/configure.in b/source3/configure.in index dfd97bc42f..66bdf5edf1 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -6,6 +6,9 @@ AC_PREREQ(2.53) AC_INIT(include/includes.h) AC_CONFIG_HEADER(include/config.h) +AC_DISABLE_STATIC +AC_ENABLE_SHARED + ################################################# # Directory handling stuff to support both the # legacy SAMBA directories and FHS compliant @@ -726,11 +729,6 @@ fi AC_FUNC_MEMCMP -############################################### -# test for where we get crypt() from -AC_SEARCH_LIBS(crypt, [crypt], [AUTHLIBS="$AUTHLIBS -lcrypt"; - AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function])]) - ############################################### # Readline included by default unless explicitly asked not to test "${with_readline+set}" != "set" && with_readline=yes @@ -952,9 +950,8 @@ AC_LIBTESTFUNC(sec, bigcrypt) AC_LIBTESTFUNC(security, getprpwnam) AC_LIBTESTFUNC(sec, getprpwnam) -# this bit needs to be modified for each OS that is suported by -# smbwrapper. You need to specify how to created a shared library and -# how to compile C code to produce PIC object files +# Assume non-shared by default and override below +BLDSHARED="false" # these are the defaults, good for lots of systems HOST_OS="$host_os" @@ -965,12 +962,16 @@ PICFLAG="" PICSUFFIX="po" POBAD_CC="#" SHLIBEXT="so" -# Assume non-shared by default and override below -BLDSHARED="false" -AC_MSG_CHECKING([ability to build shared libraries]) -# and these are for particular systems -case "$host_os" in +if test "$enable_shared" = "yes"; then + # this bit needs to be modified for each OS that is suported by + # smbwrapper. You need to specify how to created a shared library and + # how to compile C code to produce PIC object files + + AC_MSG_CHECKING([ability to build shared libraries]) + + # and these are for particular systems + case "$host_os" in *linux*) AC_DEFINE(LINUX,1,[Whether the host os is linux]) BLDSHARED="true" LDSHFLAGS="-shared" @@ -1114,13 +1115,14 @@ case "$host_os" in *) AC_DEFINE(STAT_ST_BLOCKSIZE,512) ;; -esac -AC_SUBST(DYNEXP) -AC_MSG_RESULT($BLDSHARED) -AC_MSG_CHECKING([linker flags for shared libraries]) -AC_MSG_RESULT([$LDSHFLAGS]) -AC_MSG_CHECKING([compiler flags for position-independent code]) -AC_MSG_RESULT([$PICFLAGS]) + esac + AC_SUBST(DYNEXP) + AC_MSG_RESULT($BLDSHARED) + AC_MSG_CHECKING([linker flags for shared libraries]) + AC_MSG_RESULT([$LDSHFLAGS]) + AC_MSG_CHECKING([compiler flags for position-independent code]) + AC_MSG_RESULT([$PICFLAGS]) +fi ####################################################### # test whether building a shared library actually works @@ -2408,15 +2410,10 @@ AC_ARG_WITH(pam_smbpass, ############################################### -# test for where we get crypt() from, but only -# if not using PAM -if test x"$with_pam_for_crypt" = x"no"; then -AC_CHECK_FUNCS(crypt) -if test x"$ac_cv_func_crypt" = x"no"; then - AC_CHECK_LIB(crypt, crypt, [AUTHLIBS="$AUTHLIBS -lcrypt"; - AC_DEFINE(HAVE_CRYPT,1,[Whether crypt() is available])]) -fi -fi +# test for where we get crypt() from +AC_SEARCH_LIBS(crypt, [crypt], + [test "$ac_cv_search_crypt" = "none required" || AUTHLIBS="-lcrypt $AUTHLIBS" + AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function])]) ## ## moved after the check for -lcrypt in order to @@ -2673,9 +2670,12 @@ AC_ARG_WITH(libsmbclient, LIBSMBCLIENT=libsmbclient AC_MSG_RESULT(yes) else + enable_static=yes + AC_MSG_RESULT(no shared library support -- will supply static library) + fi + if test $enable_static = yes; then INSTALLCLIENTCMD_A="\$(INSTALLCMD)" LIBSMBCLIENT=libsmbclient - AC_MSG_RESULT(no shared library support -- will supply static library) fi ;; esac ], @@ -2686,10 +2686,13 @@ AC_ARG_WITH(libsmbclient, LIBSMBCLIENT_SHARED=bin/libsmbclient.$SHLIBEXT LIBSMBCLIENT=libsmbclient AC_MSG_RESULT(yes) - else + else + enable_static=yes + AC_MSG_RESULT(no shared library support -- will supply static library) + fi + if test $enable_static = yes; then INSTALLCLIENTCMD_A="\$(INSTALLCMD)" LIBSMBCLIENT=libsmbclient - AC_MSG_RESULT(no shared library support -- will supply static library) fi] ) -- cgit From 7e110f782a55d4dca1fb3fedd95bf059c9ec0638 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:22:06 +0000 Subject: More signed/unsigned fixes (yes, I run with funny compiler options) and make x_fwrite() match fwrite() in returning a size_t. Andrew Bartlett (This used to be commit 2943c695787b742e9a96b2eefe2d75f681bacf7c) --- source3/include/hash.h | 4 ++-- source3/lib/hash.c | 10 +++++----- source3/lib/pidfile.c | 2 +- source3/lib/time.c | 2 +- source3/lib/util_file.c | 2 +- source3/lib/util_seaccess.c | 2 +- source3/lib/xfile.c | 7 ++++--- source3/smbd/dosmode.c | 2 +- source3/smbd/mangle_hash2.c | 8 ++++---- 9 files changed, 20 insertions(+), 19 deletions(-) (limited to 'source3') diff --git a/source3/include/hash.h b/source3/include/hash.h index c327c971ab..40cc8b7cab 100644 --- a/source3/include/hash.h +++ b/source3/include/hash.h @@ -66,8 +66,8 @@ typedef struct hash_element { typedef struct hash_table { ubi_dlList *buckets; ubi_dlList lru_chain; - int num_elements; - int size; + unsigned num_elements; + unsigned size; compare_function comp_func; } hash_table; diff --git a/source3/lib/hash.c b/source3/lib/hash.c index 6b7a8476b1..95af485707 100644 --- a/source3/lib/hash.c +++ b/source3/lib/hash.c @@ -28,7 +28,7 @@ #include "includes.h" static BOOL enlarge_hash_table(hash_table *table); -static int primes[] = +static unsigned primes[] = {17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411}; /**************************************************************************** @@ -47,9 +47,9 @@ static int primes[] = **************************************************************************** */ -BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compare_func) +BOOL hash_table_init(hash_table *table, unsigned num_buckets, compare_function compare_func) { - int i; + unsigned i; ubi_dlList *bucket; table->num_elements = 0; @@ -118,7 +118,7 @@ static hash_element *hash_chain_find(hash_table *table, ubi_dlList *hash_chain, { hash_element *hash_elem; ubi_dlNodePtr lru_item; - int i = 0; + unsigned int i = 0; for (hash_elem = (hash_element *)(ubi_dlFirst(hash_chain)); i < hash_chain->count; i++, hash_elem = (hash_element *)(ubi_dlNext(hash_elem))) { @@ -299,7 +299,7 @@ static BOOL enlarge_hash_table(hash_table *table) void hash_clear(hash_table *table) { - int i; + unsigned int i; ubi_dlList *bucket = table->buckets; hash_element *hash_elem; for (i = 0; i < table->size; bucket++, i++) { diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 16a12656b3..1a462bf128 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -100,7 +100,7 @@ void pidfile_create(const char *name) memset(buf, 0, sizeof(buf)); slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid()); - if (write(fd, buf, strlen(buf)) != strlen(buf)) { + if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { DEBUG(0,("ERROR: can't write to file %s: %s\n", pidFile, strerror(errno))); exit(1); diff --git a/source3/lib/time.c b/source3/lib/time.c index ea5c6837bf..f76a1bdc0d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -479,7 +479,7 @@ check if it's a null mtime ****************************************************************************/ BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1) + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) return(True); return(False); } diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 4babab8931..02acbd4d7e 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -593,7 +593,7 @@ BOOL file_save(const char *fname, void *packet, size_t length) if (fd == -1) { return False; } - if (write(fd, packet, length) != length) { + if (write(fd, packet, length) != (size_t)length) { return False; } close(fd); diff --git a/source3/lib/util_seaccess.c b/source3/lib/util_seaccess.c index 21d7fe8599..eba8cab7fb 100644 --- a/source3/lib/util_seaccess.c +++ b/source3/lib/util_seaccess.c @@ -343,7 +343,7 @@ SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr, SEC_DESC *sd; SEC_ACL *new_dacl, *the_acl; SEC_ACE *new_ace_list = NULL; - int new_ace_list_ndx = 0, i; + unsigned int new_ace_list_ndx = 0, i; size_t size; /* Currently we only process the dacl when creating the child. The diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 57f3e27638..1534dd855e 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -140,9 +140,10 @@ int x_fclose(XFILE *f) } /* simulate fwrite() */ -int x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) +size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) { - int ret, total=0; + ssize_t ret; + size_t total=0; /* we might be writing unbuffered */ if (f->buftype == X_IONBF || @@ -154,7 +155,7 @@ int x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) while (total < size*nmemb) { - int n = f->bufsize - f->bufused; + size_t n = f->bufsize - f->bufused; n = MIN(n, (size*nmemb)-total); if (n == 0) { diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 77d8c9cc92..6c21dc04d0 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -181,7 +181,7 @@ uint32 dos_mode(connection_struct *conn,char *path,SMB_STRUCT_STAT *sbuf) /******************************************************************* chmod a file - but preserve some bits ********************************************************************/ -int file_chmod(connection_struct *conn,char *fname,int dosmode,SMB_STRUCT_STAT *st) +int file_chmod(connection_struct *conn,char *fname, uint32 dosmode,SMB_STRUCT_STAT *st) { SMB_STRUCT_STAT st1; int mask=0; diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c index bbc9020eab..eda509214d 100644 --- a/source3/smbd/mangle_hash2.c +++ b/source3/smbd/mangle_hash2.c @@ -203,7 +203,7 @@ static const char *cache_lookup(u32 hash) */ static BOOL is_mangled_component(const char *name) { - int len, i; + unsigned int len, i; M_DEBUG(10,("is_mangled_component %s ?\n", name)); @@ -368,7 +368,7 @@ static void mangle_reset(void) static BOOL check_cache(char *name) { u32 hash, multiplier; - int i; + unsigned int i; const char *prefix; char extension[4]; @@ -489,8 +489,8 @@ static void name_map(char *name, BOOL need83, BOOL cache83) char *dot_p; char lead_chars[7]; char extension[4]; - int extension_length, i; - int prefix_len; + unsigned int extension_length, i; + unsigned int prefix_len; u32 hash, v; char new_name[13]; -- cgit From fa26737f40607baa084f2fcc481894473add69d4 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 20:01:00 +0000 Subject: See if I can make this look slightly like C. It compiled locally, honest... Andrew Bartlett (This used to be commit cfc4cc776899da92a5c9a17f0ea36c7cb65d7a80) --- source3/auth/auth_rhosts.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth_rhosts.c b/source3/auth/auth_rhosts.c index d8e1b01942..8915acaecd 100644 --- a/source3/auth/auth_rhosts.c +++ b/source3/auth/auth_rhosts.c @@ -199,6 +199,8 @@ static NTSTATUS check_rhosts_security(const struct auth_context *auth_context, { NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE; SAM_ACCOUNT *account = NULL; + pstring rhostsfile; + const char *home; if (!NT_STATUS_IS_OK(nt_status = auth_get_sam_account(user_info->internal_username.str, @@ -206,9 +208,8 @@ static NTSTATUS check_rhosts_security(const struct auth_context *auth_context, return nt_status; } - pstring rhostsfile; - - char *home = pdb_get_unix_homedir(account); + home = pdb_get_unix_homedir(account); + if (home) { slprintf(rhostsfile, sizeof(rhostsfile)-1, "%s/.rhosts", home); become_root(); -- cgit From 1d1ad2db2e1f78ed16bd7c62b4d062aa128bb27d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 20:11:29 +0000 Subject: Make sure we set the error code to indicate failure... Andrew Bartlett (This used to be commit 5a472e2a3cffe175ac4341e19c153a931505a2e8) --- source3/auth/auth_rhosts.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth_rhosts.c b/source3/auth/auth_rhosts.c index 8915acaecd..5451f7d930 100644 --- a/source3/auth/auth_rhosts.c +++ b/source3/auth/auth_rhosts.c @@ -169,6 +169,9 @@ static NTSTATUS check_hostsequiv_security(const struct auth_context *auth_contex if (check_hosts_equiv(account)) { nt_status = make_server_info_sam(server_info, account); + } else { + pdb_free_sam(&account); + nt_status = NT_STATUS_LOGON_FAILURE; } return nt_status; @@ -215,10 +218,16 @@ static NTSTATUS check_rhosts_security(const struct auth_context *auth_context, become_root(); if (check_user_equiv(pdb_get_username(account),client_name(),rhostsfile)) { nt_status = make_server_info_sam(server_info, account); + } else { + pdb_free_sam(&account); + nt_status = NT_STATUS_LOGON_FAILURE; } unbecome_root(); - } - + } else { + pdb_free_sam(&account); + nt_status = NT_STATUS_LOGON_FAILURE; + } + return nt_status; } -- cgit From bfc5f0ba8e7fed1f95f83cb1ee43631e307927fb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 23 Feb 2003 17:40:43 +0000 Subject: move genparser to use talloc contexts instead of [m|c|re]alloc() and free()s (This used to be commit 70fce680c01fa1baa65fb3cbc83dfaf822fdadd7) --- source3/lib/genparser.c | 233 ++++++++++++++++++++++-------------------- source3/lib/genparser_samba.c | 82 +++++++-------- 2 files changed, 163 insertions(+), 152 deletions(-) (limited to 'source3') diff --git a/source3/lib/genparser.c b/source3/lib/genparser.c index 9fa9dbd33b..233050b432 100644 --- a/source3/lib/genparser.c +++ b/source3/lib/genparser.c @@ -34,12 +34,12 @@ static int all_zero(const char *ptr, unsigned size) } /* encode a buffer of bytes into a escaped string */ -static char *encode_bytes(const char *ptr, unsigned len) +static char *encode_bytes(TALLOC_CTX *mem_ctx, const char *ptr, unsigned len) { const char *hexdig = "0123456789abcdef"; char *ret, *p; unsigned i; - ret = malloc(len*3 + 1); /* worst case size */ + ret = talloc(mem_ctx, len*3 + 1); /* worst case size */ if (!ret) return NULL; for (p=ret,i=0;i 255) { - free(ret); return NULL; } *(unsigned char *)p = v; @@ -96,11 +100,11 @@ static char *decode_bytes(const char *s, unsigned *len) parse_string */ /* allocate more space if needed */ -static int addgen_alloc(struct parse_string *p, int n) +static int addgen_alloc(TALLOC_CTX *mem_ctx, struct parse_string *p, int n) { if (p->length + n <= p->allocated) return 0; p->allocated = p->length + n + 200; - p->s = realloc(p->s, p->allocated); + p->s = talloc_realloc(mem_ctx, p->s, p->allocated); if (!p->s) { errno = ENOMEM; return -1; @@ -109,9 +113,9 @@ static int addgen_alloc(struct parse_string *p, int n) } /* add a character to the buffer */ -static int addchar(struct parse_string *p, char c) +static int addchar(TALLOC_CTX *mem_ctx, struct parse_string *p, char c) { - if (addgen_alloc(p, 2) != 0) { + if (addgen_alloc(mem_ctx, p, 2) != 0) { return -1; } p->s[p->length++] = c; @@ -120,10 +124,10 @@ static int addchar(struct parse_string *p, char c) } /* add a string to the buffer */ -int addstr(struct parse_string *p, const char *s) +int addstr(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *s) { int len = strlen(s); - if (addgen_alloc(p, len+1) != 0) { + if (addgen_alloc(mem_ctx, p, len+1) != 0) { return -1; } memcpy(p->s + p->length, s, len+1); @@ -132,10 +136,10 @@ int addstr(struct parse_string *p, const char *s) } /* add a string to the buffer with a tab prefix */ -static int addtabbed(struct parse_string *p, const char *s, unsigned indent) +static int addtabbed(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *s, unsigned indent) { int len = strlen(s); - if (addgen_alloc(p, indent+len+1) != 0) { + if (addgen_alloc(mem_ctx, p, indent+len+1) != 0) { return -1; } while (indent--) { @@ -147,7 +151,7 @@ static int addtabbed(struct parse_string *p, const char *s, unsigned indent) } /* note! this can only be used for results up to 60 chars wide! */ -int addshort(struct parse_string *p, const char *fmt, ...) +int addshort(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *fmt, ...) { char buf[60]; int n; @@ -155,7 +159,7 @@ int addshort(struct parse_string *p, const char *fmt, ...) va_start(ap, fmt); n = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - if (addgen_alloc(p, n + 1) != 0) { + if (addgen_alloc(mem_ctx, p, n + 1) != 0) { return -1; } if (n != 0) { @@ -170,7 +174,7 @@ int addshort(struct parse_string *p, const char *fmt, ...) this is here to make it easier for people to write dump functions for their own types */ -int gen_addgen(struct parse_string *p, const char *fmt, ...) +int gen_addgen(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *fmt, ...) { char *buf = NULL; int n; @@ -178,7 +182,7 @@ int gen_addgen(struct parse_string *p, const char *fmt, ...) va_start(ap, fmt); n = vasprintf(&buf, fmt, ap); va_end(ap); - if (addgen_alloc(p, n + 1) != 0) { + if (addgen_alloc(mem_ctx, p, n + 1) != 0) { if (buf) free(buf); return -1; } @@ -192,7 +196,8 @@ int gen_addgen(struct parse_string *p, const char *fmt, ...) } /* dump a enumerated type */ -int gen_dump_enum(const struct enum_struct *einfo, +int gen_dump_enum(TALLOC_CTX *mem_ctx, + const struct enum_struct *einfo, struct parse_string *p, const char *ptr, unsigned indent) @@ -201,36 +206,37 @@ int gen_dump_enum(const struct enum_struct *einfo, int i; for (i=0;einfo[i].name;i++) { if (v == einfo[i].value) { - addstr(p, einfo[i].name); + addstr(mem_ctx, p, einfo[i].name); return 0; } } /* hmm, maybe we should just fail? */ - return gen_dump_unsigned(p, ptr, indent); + return gen_dump_unsigned(mem_ctx, p, ptr, indent); } /* dump a single non-array element, hanlding struct and enum */ -static int gen_dump_one(struct parse_string *p, - const struct parse_struct *pinfo, - const char *ptr, - unsigned indent) +static int gen_dump_one(TALLOC_CTX *mem_ctx, + struct parse_string *p, + const struct parse_struct *pinfo, + const char *ptr, + unsigned indent) { if (pinfo->dump_fn == gen_dump_char && pinfo->ptr_count == 1) { - char *s = encode_bytes(ptr, strlen(ptr)); - if (addchar(p,'{') || - addstr(p, s) || - addstr(p, "}")) { - free(s); + char *s = encode_bytes(mem_ctx, ptr, strlen(ptr)); + if (addchar(mem_ctx, p,'{') || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}")) { return -1; } return 0; } - return pinfo->dump_fn(p, ptr, indent); + return pinfo->dump_fn(mem_ctx, p, ptr, indent); } /* handle dumping of an array of arbitrary type */ -static int gen_dump_array(struct parse_string *p, +static int gen_dump_array(TALLOC_CTX *mem_ctx, + struct parse_string *p, const struct parse_struct *pinfo, const char *ptr, int array_len, @@ -242,13 +248,12 @@ static int gen_dump_array(struct parse_string *p, if (array_len != 0 && pinfo->ptr_count == 0 && pinfo->dump_fn == gen_dump_char) { - char *s = encode_bytes(ptr, array_len); + char *s = encode_bytes(mem_ctx, ptr, array_len); if (!s) return -1; - if (addtabbed(p, pinfo->name, indent) || - addstr(p, " = {") || - addstr(p, s) || - addstr(p, "}\n")) { - free(s); + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addstr(mem_ctx, p, " = {") || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}\n")) { return -1; } free(s); @@ -272,23 +277,23 @@ static int gen_dump_array(struct parse_string *p, continue; } if (count == 0) { - if (addtabbed(p, pinfo->name, indent) || - addshort(p, " = %u:", i)) { + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addshort(mem_ctx, p, " = %u:", i)) { return -1; } } else { - if (addshort(p, ", %u:", i) != 0) { + if (addshort(mem_ctx, p, ", %u:", i) != 0) { return -1; } } - if (gen_dump_one(p, pinfo, p2, indent) != 0) { + if (gen_dump_one(mem_ctx, p, pinfo, p2, indent) != 0) { return -1; } ptr += size; count++; } if (count) { - return addstr(p, "\n"); + return addstr(mem_ctx, p, "\n"); } return 0; } @@ -325,36 +330,35 @@ static int find_var(const struct parse_struct *pinfo, } -int gen_dump_struct(const struct parse_struct *pinfo, +int gen_dump_struct(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, struct parse_string *p, const char *ptr, unsigned indent) { - char *s = gen_dump(pinfo, ptr, indent+1); + char *s = gen_dump(mem_ctx, pinfo, ptr, indent+1); if (!s) return -1; - if (addstr(p, "{\n") || - addstr(p,s) || - addtabbed(p,"}", indent)) { - free(s); + if (addstr(mem_ctx, p, "{\n") || + addstr(mem_ctx, p, s) || + addtabbed(mem_ctx, p, "}", indent)) { return -1; } - free(s); return 0; } -static int gen_dump_string(struct parse_string *p, +static int gen_dump_string(TALLOC_CTX *mem_ctx, + struct parse_string *p, const struct parse_struct *pinfo, const char *data, unsigned indent) { const char *ptr = *(char **)data; - char *s = encode_bytes(ptr, strlen(ptr)); - if (addtabbed(p, pinfo->name, indent) || - addstr(p, " = ") || - addchar(p,'{') || - addstr(p, s) || - addstr(p, "}\n")) { - free(s); + char *s = encode_bytes(mem_ctx, ptr, strlen(ptr)); + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addstr(mem_ctx, p, " = ") || + addchar(mem_ctx, p, '{') || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}\n")) { return -1; } return 0; @@ -370,7 +374,7 @@ static int len_nullterm(const char *ptr, int size, int array_len) if (size == 1) { len = strnlen(ptr, array_len); } else { - for (len=0;lenparse_fn == gen_parse_char && pinfo->ptr_count==1) { unsigned len; - char *s = decode_bytes(str, &len); + char *s = decode_bytes(mem_ctx, str, &len); if (!s) return -1; *(char **)ptr = s; return 0; } if (pinfo->ptr_count) { + unsigned size = pinfo->ptr_count>1?sizeof(void *):pinfo->size; struct parse_struct p2 = *pinfo; - *(void **)ptr = calloc(1, pinfo->ptr_count>1?sizeof(void *):pinfo->size); + *(void **)ptr = talloc(mem_ctx, size); if (! *(void **)ptr) { return -1; } + memset(*(void **)ptr, 0, size); ptr = *(char **)ptr; p2.ptr_count--; - return gen_parse_base(&p2, ptr, str); + return gen_parse_base(mem_ctx, &p2, ptr, str); } - return pinfo->parse_fn(ptr, str); + return pinfo->parse_fn(mem_ctx, ptr, str); } /* parse a generic array */ -static int gen_parse_array(const struct parse_struct *pinfo, - char *ptr, - const char *str, - int array_len) +static int gen_parse_array(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, + char *ptr, + const char *str, + int array_len) { char *p, *p2; unsigned size = pinfo->size; @@ -564,11 +574,10 @@ static int gen_parse_array(const struct parse_struct *pinfo, pinfo->ptr_count == 0 && pinfo->dump_fn == gen_dump_char) { unsigned len = 0; - char *s = decode_bytes(str, &len); - if (!s) return -1; + char *s = decode_bytes(mem_ctx, str, &len); + if (!s || (len > array_len)) return -1; memset(ptr, 0, array_len); memcpy(ptr, s, len); - free(s); return 0; } @@ -593,7 +602,7 @@ static int gen_parse_array(const struct parse_struct *pinfo, p[strlen(p)-1] = 0; } - if (gen_parse_base(pinfo, ptr + idx*size, p) != 0) { + if (gen_parse_base(mem_ctx, pinfo, ptr + idx*size, p) != 0) { return -1; } @@ -605,7 +614,8 @@ static int gen_parse_array(const struct parse_struct *pinfo, } /* parse one element, hanlding dynamic and static arrays */ -static int gen_parse_one(const struct parse_struct *pinfo, +static int gen_parse_one(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, const char *name, char *data, const char *str) @@ -621,7 +631,8 @@ static int gen_parse_one(const struct parse_struct *pinfo, } if (pinfo[i].array_len) { - return gen_parse_array(&pinfo[i], data+pinfo[i].offset, + return gen_parse_array(mem_ctx, &pinfo[i], + data+pinfo[i].offset, str, pinfo[i].array_len); } @@ -632,33 +643,33 @@ static int gen_parse_one(const struct parse_struct *pinfo, return -1; } if (len > 0) { - unsigned size; struct parse_struct p2 = pinfo[i]; char *ptr; - size = pinfo[i].ptr_count>1?sizeof(void*):pinfo[i].size; - ptr = calloc(len, size); + unsigned size = pinfo[i].ptr_count>1?sizeof(void*):pinfo[i].size; + ptr = talloc(mem_ctx, len*size); if (!ptr) { errno = ENOMEM; return -1; } + memset(ptr, 0, len*size); *((char **)(data + pinfo[i].offset)) = ptr; p2.ptr_count--; p2.dynamic_len = NULL; - return gen_parse_array(&p2, ptr, str, len); + return gen_parse_array(mem_ctx, &p2, ptr, str, len); } return 0; } - return gen_parse_base(&pinfo[i], data + pinfo[i].offset, str); + return gen_parse_base(mem_ctx, &pinfo[i], data + pinfo[i].offset, str); } -int gen_parse_struct(const struct parse_struct *pinfo, char *ptr, const char *str) +int gen_parse_struct(TALLOC_CTX * mem_ctx, const struct parse_struct *pinfo, char *ptr, const char *str) { - return gen_parse(pinfo, ptr, str); + return gen_parse(mem_ctx, pinfo, ptr, str); } /* the main parse routine */ -int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) +int gen_parse(TALLOC_CTX *mem_ctx, const struct parse_struct *pinfo, char *data, const char *s) { char *str, *s0; @@ -694,7 +705,7 @@ int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) *str++ = 0; - if (gen_parse_one(pinfo, name, data, value) != 0) { + if (gen_parse_one(mem_ctx, pinfo, name, data, value) != 0) { free(s0); return -1; } @@ -708,68 +719,68 @@ int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) /* for convenience supply some standard dumpers and parsers here */ -int gen_parse_char(char *ptr, const char *str) +int gen_parse_char(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(unsigned char *)ptr = atoi(str); return 0; } -int gen_parse_int(char *ptr, const char *str) +int gen_parse_int(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(int *)ptr = atoi(str); return 0; } -int gen_parse_unsigned(char *ptr, const char *str) +int gen_parse_unsigned(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(unsigned *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_time_t(char *ptr, const char *str) +int gen_parse_time_t(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(time_t *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_double(char *ptr, const char *str) +int gen_parse_double(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(double *)ptr = atof(str); return 0; } -int gen_parse_float(char *ptr, const char *str) +int gen_parse_float(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(float *)ptr = atof(str); return 0; } -int gen_dump_char(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_char(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(unsigned char *)(ptr)); + return addshort(mem_ctx, p, "%u", *(unsigned char *)(ptr)); } -int gen_dump_int(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_int(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%d", *(int *)(ptr)); + return addshort(mem_ctx, p, "%d", *(int *)(ptr)); } -int gen_dump_unsigned(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_unsigned(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(unsigned *)(ptr)); + return addshort(mem_ctx, p, "%u", *(unsigned *)(ptr)); } -int gen_dump_time_t(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_time_t(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(time_t *)(ptr)); + return addshort(mem_ctx, p, "%u", *(time_t *)(ptr)); } -int gen_dump_double(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_double(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%lg", *(double *)(ptr)); + return addshort(mem_ctx, p, "%lg", *(double *)(ptr)); } -int gen_dump_float(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_float(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%g", *(float *)(ptr)); + return addshort(mem_ctx, p, "%g", *(float *)(ptr)); } diff --git a/source3/lib/genparser_samba.c b/source3/lib/genparser_samba.c index 6c700d1094..bece587747 100644 --- a/source3/lib/genparser_samba.c +++ b/source3/lib/genparser_samba.c @@ -22,25 +22,25 @@ /* PARSE functions */ -int gen_parse_uint8(char *ptr, const char *str) +int gen_parse_uint8(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint8 *)ptr = atoi(str); return 0; } -int gen_parse_uint16(char *ptr, const char *str) +int gen_parse_uint16(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint16 *)ptr = atoi(str); return 0; } -int gen_parse_uint32(char *ptr, const char *str) +int gen_parse_uint32(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint32 *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_NTTIME(char *ptr, const char *str) +int gen_parse_NTTIME(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(sscanf(str, "%u,%u", &(((NTTIME *)(ptr))->high), &(((NTTIME *)(ptr))->low)) != 2) { errno = EINVAL; @@ -49,19 +49,19 @@ int gen_parse_NTTIME(char *ptr, const char *str) return 0; } -int gen_parse_DOM_SID(char *ptr, const char *str) +int gen_parse_DOM_SID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(!string_to_sid((DOM_SID *)ptr, str)) return -1; return 0; } -int gen_parse_SEC_ACCESS(char *ptr, const char *str) +int gen_parse_SEC_ACCESS(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { ((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10); return 0; } -int gen_parse_GUID(char *ptr, const char *str) +int gen_parse_GUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { int info[GUID_SIZE]; int i; @@ -89,27 +89,27 @@ int gen_parse_GUID(char *ptr, const char *str) return 0; } -int gen_parse_SEC_ACE(char *ptr, const char *str) +int gen_parse_SEC_ACE(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_ace_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_ace_info, ptr, str); } -int gen_parse_SEC_ACL(char *ptr, const char *str) +int gen_parse_SEC_ACL(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_acl_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_acl_info, ptr, str); } -int gen_parse_SEC_DESC(char *ptr, const char *str) +int gen_parse_SEC_DESC(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_descriptor_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_descriptor_info, ptr, str); } -int gen_parse_LUID_ATTR(char *ptr, const char *str) +int gen_parse_LUID_ATTR(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_luid_attr_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_luid_attr_info, ptr, str); } -int gen_parse_LUID(char *ptr, const char *str) +int gen_parse_LUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(sscanf(str, "%u,%u", &(((LUID *)(ptr))->high), &(((LUID *)(ptr))->low)) != 2) { errno = EINVAL; @@ -122,79 +122,79 @@ int gen_parse_LUID(char *ptr, const char *str) /* DUMP functions */ -int gen_dump_uint8(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint8(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint8 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint8 *)(ptr)); } -int gen_dump_uint16(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint16(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint16 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint16 *)(ptr)); } -int gen_dump_uint32(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint32(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint32 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint32 *)(ptr)); } -int gen_dump_NTTIME(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_NTTIME(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { uint32 low, high; high = ((NTTIME *)(ptr))->high; low = ((NTTIME *)(ptr))->low; - return addshort(p, "%u,%u", high, low); + return addshort(mem_ctx, p, "%u,%u", high, low); } -int gen_dump_DOM_SID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_DOM_SID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { fstring sidstr; sid_to_string(sidstr, (DOM_SID *)ptr); - return addstr(p, sidstr); + return addstr(mem_ctx, p, sidstr); } -int gen_dump_SEC_ACCESS(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACCESS(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", ((SEC_ACCESS *)ptr)->mask); + return addshort(mem_ctx, p, "%u", ((SEC_ACCESS *)ptr)->mask); } -int gen_dump_GUID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_GUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { int i, r; for (i = 0; i < (GUID_SIZE - 1); i++) { - if (!(r = addshort(p, "%d,", ((GUID *)ptr)->info[i]))) return r; + if (!(r = addshort(mem_ctx, p, "%d,", ((GUID *)ptr)->info[i]))) return r; } - return addshort(p, "%d", ((GUID *)ptr)->info[i]); + return addshort(mem_ctx, p, "%d", ((GUID *)ptr)->info[i]); } -int gen_dump_SEC_ACE(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACE(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_ace_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_ace_info, p, ptr, indent); } -int gen_dump_SEC_ACL(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACL(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_acl_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_acl_info, p, ptr, indent); } -int gen_dump_SEC_DESC(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_DESC(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_descriptor_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_descriptor_info, p, ptr, indent); } -int gen_dump_LUID_ATTR(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_LUID_ATTR(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_luid_attr_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_luid_attr_info, p, ptr, indent); } -int gen_dump_LUID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_LUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { uint32 low, high; high = ((LUID *)(ptr))->high; low = ((LUID *)(ptr))->low; - return addshort(p, "%u,%u", high, low); + return addshort(mem_ctx, p, "%u,%u", high, low); } -- cgit From bd0bbde1bba4ad4e6e95f269912943d9d583dce4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 23 Feb 2003 18:08:07 +0000 Subject: forgot the altered include file (This used to be commit f3be08472b8b34d8921ff23c52dd2ba030c96f25) --- source3/include/genparser.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/include/genparser.h b/source3/include/genparser.h index 002d79f8f9..f28cd78249 100644 --- a/source3/include/genparser.h +++ b/source3/include/genparser.h @@ -46,8 +46,8 @@ struct parse_string { char *s; }; -typedef int (*gen_dump_fn)(struct parse_string *, const char *ptr, unsigned indent); -typedef int (*gen_parse_fn)(char *ptr, const char *str); +typedef int (*gen_dump_fn)(TALLOC_CTX *, struct parse_string *, const char *ptr, unsigned indent); +typedef int (*gen_parse_fn)(TALLOC_CTX *, char *ptr, const char *str); /* genstruct.pl generates arrays of these */ struct parse_struct { @@ -63,8 +63,8 @@ struct parse_struct { }; #define DUMP_PARSE_DECL(type) \ - int gen_dump_ ## type(struct parse_string *, const char *, unsigned); \ - int gen_parse_ ## type(char *, const char *); + int gen_dump_ ## type(TALLOC_CTX *, struct parse_string *, const char *, unsigned); \ + int gen_parse_ ## type(TALLOC_CTX *, char *, const char *); DUMP_PARSE_DECL(char) DUMP_PARSE_DECL(int) -- cgit From e68684aa65b579081163c175d681b7867a0828bf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 01:13:31 +0000 Subject: Fix 2 off-by-one bugs in the use of malloc()ed strings and safe_strcpy(). safe_strcpy() isn't particularly safe (this has been noted before) as it does not take the size of the buffer, but instead the size of the buffer *minus 1* The locking.c fix was causing segfaults on machines running with --enable-developer, and was tracked down thanks to the fact that vance's build farm machine runs with such an option, and smbtorture's DIR1 test hits this bug very well. (The --enable-developer code writes to the last byte of the string, to check for incorrect use of safe_strcpy()). Andrew Bartlett (This used to be commit e908fd164d1b11b6f76a6fdffb22e139813cb3c0) --- source3/lib/hash.c | 6 ++++-- source3/locking/locking.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/lib/hash.c b/source3/lib/hash.c index 95af485707..c7b1493b4c 100644 --- a/source3/lib/hash.c +++ b/source3/lib/hash.c @@ -171,6 +171,7 @@ hash_element *hash_insert(hash_table *table, char *value, char *key) hash_element *hash_elem; ubi_dlNodePtr lru_item; ubi_dlList *bucket; + size_t string_length; /* * If the hash table size has not reached the MAX_HASH_TABLE_SIZE, @@ -204,12 +205,13 @@ hash_element *hash_insert(hash_table *table, char *value, char *key) * string. */ - if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + strlen(key)))) { + string_length = strlen(key); + if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + string_length))) { DEBUG(0,("hash_insert: malloc fail !\n")); return (hash_element *)NULL; } - safe_strcpy((char *) hash_elem->key, key, strlen(key)+1); + safe_strcpy((char *) hash_elem->key, key, string_length); hash_elem->value = (char *)value; hash_elem->bucket = bucket; diff --git a/source3/locking/locking.c b/source3/locking/locking.c index d4794560f6..fdfd4d661c 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -630,7 +630,7 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type) fsp->fsp_name )); offset = sizeof(*data) + sizeof(share_mode_entry); - safe_strcpy(p + offset, fname, size - offset); + safe_strcpy(p + offset, fname, size - offset - 1); fill_share_mode(p + sizeof(*data), fsp, port, op_type); dbuf.dptr = p; dbuf.dsize = size; -- cgit From ded88da1ea1fdcd6da017de2e1378578971f7645 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 02:11:32 +0000 Subject: Add const (This used to be commit ffaa608be01d72075942ca3aff2325c6364e0556) --- source3/lib/util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/lib/util.c b/source3/lib/util.c index 13f5b17781..3958600cbd 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -309,9 +309,9 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, const gid_t *groups) Like atoi but gets the value up to the separator character. ****************************************************************************/ -static char *Atoic(char *p, int *n, char *c) +static const char *Atoic(const char *p, int *n, const char *c) { - if (!isdigit((int)*p)) { + if (!isdigit((const int)*p)) { DEBUG(5, ("Atoic: malformed number\n")); return NULL; } @@ -333,7 +333,7 @@ static char *Atoic(char *p, int *n, char *c) Reads a list of numbers. *************************************************************************/ -char *get_numlist(char *p, uint32 **num, int *count) +const char *get_numlist(const char *p, uint32 **num, int *count) { int val; @@ -2400,7 +2400,7 @@ static BOOL unix_do_match(char *regexp, char *str) Simple case insensitive interface to a UNIX wildcard matcher. *******************************************************************/ -BOOL unix_wild_match(char *pattern, char *string) +BOOL unix_wild_match(const char *pattern, const char *string) { pstring p2, s2; char *p; -- cgit From e25aa22a8ff46b3c29fc373a585d8a5e5cc37296 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 24 Feb 2003 02:12:39 +0000 Subject: Merge: > Exit path cleanup for cli_samr_enum_dom_users() (This used to be commit 655c1e03519d4fa174a85534c165bdd1ce163ae8) --- source3/rpc_client/cli_samr.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3') diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index 08c68b7632..c451ee2e42 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -590,16 +590,14 @@ NTSTATUS cli_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, if(!samr_io_r_enum_dom_users("", &r, &rbuf, 0)) goto done; - /* return the data obtained in response */ - if (!NT_STATUS_IS_OK(r.status) && - (NT_STATUS_EQUAL(r.status, STATUS_MORE_ENTRIES) || - NT_STATUS_EQUAL(r.status, NT_STATUS_NO_MORE_ENTRIES))) { - return r.status; - } + result = r.status; + + if (!NT_STATUS_IS_OK(result) && + NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) + goto done; *start_idx = r.next_idx; *num_dom_users = r.num_entries2; - result = r.status; if (r.num_entries2) { /* allocate memory needed to return received data */ -- cgit From 12f2ebf7f006369477824d9b4b917847d63a68af Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 03:45:02 +0000 Subject: Always initialise (This used to be commit ff2b5b2f85f2d9dade67077cea1b68719cf65352) --- source3/libads/ldap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index bc90e90ea0..29f44672f4 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -816,8 +816,8 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, { int curmod; LDAPMod **modlist = (LDAPMod **) *mods; - struct berval **ber_values; - char **char_values; + struct berval **ber_values = NULL; + char **char_values = NULL; if (!invals) { mod_op = LDAP_MOD_DELETE; -- cgit From 5b5453e6c799cbf3fa7638950825e3b1c276cdc2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 24 Feb 2003 04:42:24 +0000 Subject: Merge documentation from 3_0. (This used to be commit 5002555a9719987ccdc887ffff64ea8d02c9881d) --- source3/lib/charcnv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index bffa2a378c..a8df003f8b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,17 +22,24 @@ */ #include "includes.h" -static pstring cvtbuf; - -static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; - /** * @file * - * Character set conversion routines. + * @brief Character-set conversion routines built on our iconv. + * + * @note Samba's internal character set (at least in the 3.0 series) + * is always the same as the one for the Unix filesystem. It is + * not necessarily UTF-8 and may be different on machines that + * need i18n filenames to be compatible with Unix software. It does + * have to be a superset of ASCII. All multibyte sequences must start + * with a byte with the high bit set. * * @sa lib/iconv.c - **/ + */ + +static pstring cvtbuf; + +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /** -- cgit From 6fa6b607c9f97dca9850e2d5c5dc175497fbebd8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 24 Feb 2003 04:59:15 +0000 Subject: Quieten compiler warning. (This used to be commit eb5d1a72dc9dc35997d39f8778ee98163b8cce32) --- source3/python/py_tdbpack.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3') diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index 243cb44683..f0718b717e 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -25,6 +25,13 @@ #include "Python.h" +/* This symbol is used in both config.h and Python.h which causes an + annoying compiler warning. */ + +#ifdef HAVE_FSTAT +#undef HAVE_FSTAT +#endif + /* This module is supposed to be standalone, however for portability it would be good to use the FUNCTION_MACRO preprocessor define. */ -- cgit From 2295c0cf296090ed48d7e9bf47c4358de30eaec0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 09:10:41 +0000 Subject: Fix off-by-one bugs, and move to strdup() rather than malloc()/strcpy(). Andrew Bartlett (This used to be commit aa486355e282b891b299d63cc07431f32213b1b8) --- source3/modules/vfs_recycle.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'source3') diff --git a/source3/modules/vfs_recycle.c b/source3/modules/vfs_recycle.c index dcd83b7acd..a99a593caf 100644 --- a/source3/modules/vfs_recycle.c +++ b/source3/modules/vfs_recycle.c @@ -472,25 +472,21 @@ static void recycle_touch(connection_struct *conn, const char *fname) /** * Check if file should be recycled **/ -static int recycle_unlink(connection_struct *conn, const char *inname) +static int recycle_unlink(connection_struct *conn, const char *file_name) { recycle_bin_private_data *recdata; recycle_bin_connections *recconn; recycle_bin_struct *recbin; - char *file_name = NULL; char *path_name = NULL; char *temp_name = NULL; char *final_name = NULL; - char *base; + const char *base; int i; /* SMB_BIG_UINT dfree, dsize, bsize; */ SMB_OFF_T file_size; /* space_avail; */ BOOL exist; int rc = -1; - file_name = strdup(inname); - ALLOC_CHECK(file_name, done); - recbin = NULL; if (recycle_bin_private_handle) { recdata = (recycle_bin_private_data *)(recycle_bin_private_handle->data); @@ -560,14 +556,13 @@ static int recycle_unlink(connection_struct *conn, const char *inname) path_name = (char *)malloc(PATH_MAX); ALLOC_CHECK(path_name, done); *path_name = '\0'; - safe_strcpy(path_name, file_name, PATH_MAX); + safe_strcpy(path_name, file_name, PATH_MAX - 1); base = strrchr(path_name, '/'); if (base == NULL) { base = file_name; - safe_strcpy(path_name, "/", PATH_MAX); + safe_strcpy(path_name, "/", PATH_MAX - 1); } else { - *base = '\0'; base++; } @@ -591,14 +586,13 @@ static int recycle_unlink(connection_struct *conn, const char *inname) goto done; } - temp_name = (char *)malloc(PATH_MAX); + temp_name = (char *)strdup(recbin->repository); ALLOC_CHECK(temp_name, done); - safe_strcpy(temp_name, recbin->repository, PATH_MAX); /* see if we need to recreate the original directory structure in the recycle bin */ if (recbin->keep_dir_tree == True) { - safe_strcat(temp_name, "/", PATH_MAX); - safe_strcat(temp_name, path_name, PATH_MAX); + safe_strcat(temp_name, "/", PATH_MAX - 1); + safe_strcat(temp_name, path_name, PATH_MAX - 1); } exist = recycle_directory_exist(conn, temp_name); @@ -613,9 +607,9 @@ static int recycle_unlink(connection_struct *conn, const char *inname) } } - final_name = (char *)malloc(PATH_MAX); + final_name = NULL; + asprintf(&final_name, "%s/%s", temp_name, base); ALLOC_CHECK(final_name, done); - snprintf(final_name, PATH_MAX, "%s/%s", temp_name, base); DEBUG(10, ("recycle.bin: recycled file name%s\n", temp_name)); /* new filename with path */ /* check if we should delete file from recycle bin */ @@ -647,7 +641,6 @@ static int recycle_unlink(connection_struct *conn, const char *inname) recycle_touch(conn, final_name); done: - SAFE_FREE(file_name); SAFE_FREE(path_name); SAFE_FREE(temp_name); SAFE_FREE(final_name); -- cgit From 9c6d78c54c7f420903767f17659e9ce8d7002dbf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 09:46:01 +0000 Subject: If it's a pstring, use pstrcpy(). (This used to be commit 34fb5f0b1a6281b3aa7782edb3fcb82cc4ec4877) --- source3/msdfs/msdfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/msdfs/msdfs.c b/source3/msdfs/msdfs.c index 4df3145009..bf3b3cc213 100644 --- a/source3/msdfs/msdfs.c +++ b/source3/msdfs/msdfs.c @@ -266,7 +266,7 @@ static BOOL resolve_dfs_path(char* dfspath, struct dfs_path* dp, if (consumedcntp) { char *q; pstring buf; - safe_strcpy(buf, dfspath, sizeof(buf)); + pstrcpy(buf, dfspath); trim_string(buf, NULL, "\\"); q = strrchr(buf, '\\'); if (q) @@ -633,7 +633,7 @@ int setup_dfs_referral(char* pathname, int max_referral_level, char** ppdata) && pathnamep[1] == '\\') pathnamep++; - safe_strcpy(buf, pathnamep, sizeof(buf)); + pstrcpy(buf, pathnamep); if (!get_referred_path(buf, &junction, &consumedcnt, &self_referral)) return -1; -- cgit From 2f0c70efb2c4b5b01eb073f5d5217108b4ca438f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 10:35:24 +0000 Subject: setenv takes 3 arguments... (This used to be commit 6d18f64ef518cbb3d522cf1f92dc5cbc2e2cb642) --- source3/smbwrapper/smbsh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3') diff --git a/source3/smbwrapper/smbsh.c b/source3/smbwrapper/smbsh.c index d853aa1afc..845d1d5606 100644 --- a/source3/smbwrapper/smbsh.c +++ b/source3/smbwrapper/smbsh.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) smbw_setshared("PASSWORD", p); } - setenv("PS1", "smbsh$ "); + setenv("PS1", "smbsh$ ", 1); sys_getwd(wd); @@ -107,12 +107,12 @@ int main(int argc, char *argv[]) if (file_exist(line, NULL)) { slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so:DEFAULT", libd); - setenv("_RLD_LIST", line); + setenv("_RLD_LIST", line, 1); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); - setenv("_RLDN32_LIST", line); + setenv("_RLDN32_LIST", line, 1); } else { slprintf(line,sizeof(line)-1,"%s/smbwrapper.so:DEFAULT", libd); - setenv("_RLD_LIST", line); + setenv("_RLD_LIST", line, 1); } { -- cgit From eb64538dba772a9846c05e2712839dbaa12c39a1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 11:09:21 +0000 Subject: Patch from Luke Howard to add mutual kerberos authentication, and SMB session keys for kerberos authentication. Andrew Bartlett (This used to be commit 8b798f03dbbdd670ff9af4eb46f7b0845c611e0f) --- source3/configure.in | 16 ++++++++++++ source3/include/ads.h | 5 ++++ source3/include/asn_1.h | 7 +++++ source3/libads/kerberos_verify.c | 32 ++++++++++++++++++----- source3/libsmb/cliconnect.c | 2 +- source3/libsmb/clikrb5.c | 56 +++++++++++++++++++++++++++++++++------- source3/libsmb/clispnego.c | 29 +++++++++++---------- source3/smbd/sesssetup.c | 52 +++++++++++++++++++++++++++---------- 8 files changed, 157 insertions(+), 42 deletions(-) (limited to 'source3') diff --git a/source3/configure.in b/source3/configure.in index 66bdf5edf1..e3b5f2fe15 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -2250,6 +2250,22 @@ if test x"$samba_cv_HAVE_KRB5_TKT_ENC_PART2" = x"yes"; then AC_DEFINE(HAVE_KRB5_TKT_ENC_PART2,1,[Whether the krb5_ticket struct has a enc_part2 property]) fi +AC_CACHE_CHECK([for keyvalue in krb5_keyblock],samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE,[ +AC_TRY_COMPILE([#include ], +[krb5_keyblock key; key.keyvalue.data = NULL;], +samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=yes,samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE=no)]) +if test x"$samba_cv_HAVE_KRB5_KEYBLOCK_KEYVALUE" = x"yes"; then + AC_DEFINE(HAVE_KRB5_KEYBLOCK_KEYVALUE,1,[Whether the krb5_keyblock struct has a keyvalue property]) +fi + +AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC_MD5],samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,[ +AC_TRY_COMPILE([#include ], +[krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC_MD5;], +samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=yes,samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5=no)]) +if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes"; then + AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,1,[Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type is available]) +fi + ######################################################## # now see if we can find the krb5 libs in standard paths # or as specified above diff --git a/source3/include/ads.h b/source3/include/ads.h index 304a997b2c..f90983e405 100644 --- a/source3/include/ads.h +++ b/source3/include/ads.h @@ -208,3 +208,8 @@ typedef void **ADS_MODLIST; /* Kerberos environment variable names */ #define KRB5_ENV_CCNAME "KRB5CCNAME" + +/* Heimdal uses a slightly different name */ +#if defined(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5) +#define ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC_MD5 +#endif diff --git a/source3/include/asn_1.h b/source3/include/asn_1.h index ab7fa5d398..7d4da0db0c 100644 --- a/source3/include/asn_1.h +++ b/source3/include/asn_1.h @@ -59,4 +59,11 @@ typedef struct { #define SPNEGO_NEG_RESULT_INCOMPLETE 1 #define SPNEGO_NEG_RESULT_REJECT 2 +/* not really ASN.1, but RFC 1964 */ +#define TOK_ID_KRB_AP_REQ "\x01\x00" +#define TOK_ID_KRB_AP_REP "\x02\x00" +#define TOK_ID_KRB_ERROR "\x03\x00" +#define TOK_ID_GSS_GETMIC "\x01\x01" +#define TOK_ID_GSS_WRAP "\x02\x01" + #endif /* _ASN_1_H */ diff --git a/source3/libads/kerberos_verify.c b/source3/libads/kerberos_verify.c index 17fecf60c8..4d9a1bf765 100644 --- a/source3/libads/kerberos_verify.c +++ b/source3/libads/kerberos_verify.c @@ -3,7 +3,7 @@ kerberos utility library Copyright (C) Andrew Tridgell 2001 Copyright (C) Remus Koos 2001 - + Copyright (C) Luke Howard 2003 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 @@ -29,7 +29,9 @@ authorization_data if available */ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, - char **principal, DATA_BLOB *auth_data) + char **principal, DATA_BLOB *auth_data, + DATA_BLOB *ap_rep, + uint8 session_key[16]) { krb5_context context; krb5_auth_context auth_context = NULL; @@ -122,10 +124,24 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, if (!auth_ok) { DEBUG(3,("krb5_rd_req with auth failed (%s)\n", error_message(ret))); - SAFE_FREE(key); return NT_STATUS_LOGON_FAILURE; } + ret = krb5_mk_rep(context, auth_context, &packet); + if (ret) { + DEBUG(3,("Failed to generate mutual authentication reply (%s)\n", + error_message(ret))); + krb5_auth_con_free(context, auth_context); + return NT_STATUS_LOGON_FAILURE; + } + + *ap_rep = data_blob(packet.data, packet.length); + free(packet.data); + + krb5_get_smb_session_key(context, auth_context, session_key); + DEBUG(0,("SMB session key (from ticket) follows:\n")); + dump_data(0, session_key, 16); + #if 0 file_save("/tmp/ticket.dat", ticket->data, ticket->length); #endif @@ -134,20 +150,24 @@ NTSTATUS ads_verify_ticket(ADS_STRUCT *ads, const DATA_BLOB *ticket, #if 0 if (tkt->enc_part2) { - file_save("/tmp/authdata.dat", + file_save("/tmp/authdata.dat", tkt->enc_part2->authorization_data[0]->contents, tkt->enc_part2->authorization_data[0]->length); - } #endif if ((ret = krb5_unparse_name(context, get_principal_from_tkt(tkt), principal))) { DEBUG(3,("krb5_unparse_name failed (%s)\n", error_message(ret))); + data_blob_free(auth_data); + data_blob_free(ap_rep); + krb5_auth_con_free(context, auth_context); return NT_STATUS_LOGON_FAILURE; } + krb5_auth_con_free(context, auth_context); + return NT_STATUS_OK; } -#endif +#endif /* HAVE_KRB5 */ diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 901daf4b09..4962ffa3c9 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. client connect/disconnect routines Copyright (C) Andrew Tridgell 1994-1998 - Copyright (C) Andrew Barteltt 2001-2003 + Copyright (C) Andrew Bartlett 2001-2003 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 diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index bef6998a49..47dec1f171 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. simple kerberos5 routines for active directory Copyright (C) Andrew Tridgell 2001 - Copyright (C) Luke Howard 2002 + Copyright (C) Luke Howard 2002-2003 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 @@ -23,6 +23,16 @@ #ifdef HAVE_KRB5 +#ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE +#define KRB5_KEY_TYPE(k) ((k)->keytype) +#define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length) +#define KRB5_KEY_DATA(k) ((k)->keyvalue.data) +#else +#define KRB5_KEY_TYPE(k) ((k)->enctype) +#define KRB5_KEY_LENGTH(k) ((k)->length) +#define KRB5_KEY_DATA(k) ((k)->contents) +#endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */ + #ifndef HAVE_KRB5_SET_REAL_TIME /* * This function is not in the Heimdal mainline. @@ -124,7 +134,7 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, return krb5_get_default_in_tkt_etypes(context, enctypes); } #else - __ERROR_XX_UNKNOWN_GET_ENCTYPES_FUNCTIONS +#error UNKNOWN_GET_ENCTYPES_FUNCTIONS #endif void free_kerberos_etypes(krb5_context context, @@ -305,12 +315,12 @@ DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) DATA_BLOB ret; krb5_enctype enc_types[] = { #ifdef ENCTYPE_ARCFOUR_HMAC - ENCTYPE_ARCFOUR_HMAC, -#endif - ENCTYPE_DES_CBC_MD5, - ENCTYPE_DES_CBC_CRC, - ENCTYPE_NULL}; - + ENCTYPE_ARCFOUR_HMAC, +#endif + ENCTYPE_DES_CBC_MD5, + ENCTYPE_DES_CBC_CRC, + ENCTYPE_NULL}; + retval = krb5_init_context(&context); if (retval) { DEBUG(1,("krb5_init_context failed (%s)\n", @@ -355,11 +365,39 @@ failed: return data_blob(NULL, 0); } +BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) + { + krb5_keyblock *skey; + BOOL ret = False; + + memset(session_key, 0, 16); + +#ifdef ENCTYPE_ARCFOUR_HMAC + if (krb5_auth_con_getremotesubkey(context, auth_context, &skey) == 0 && skey != NULL) { + if (KRB5_KEY_TYPE(skey) == + ENCTYPE_ARCFOUR_HMAC + && KRB5_KEY_LENGTH(skey) == 16) { + memcpy(session_key, KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey)); + ret = True; + } + krb5_free_keyblock(context, skey); + } +#endif /* ENCTYPE_ARCFOUR_HMAC */ + + return ret; + } #else /* HAVE_KRB5 */ /* this saves a few linking headaches */ - DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) +DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) { DEBUG(0,("NO KERBEROS SUPPORT\n")); return data_blob(NULL, 0); } + +BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context ac, uint8 session_key[16]) + { + DEBUG(0,("NO KERBEROS SUPPORT\n")); + memset(session_key, 0, 16); + return False; + } #endif diff --git a/source3/libsmb/clispnego.c b/source3/libsmb/clispnego.c index e93f1855dd..dfa8f80146 100644 --- a/source3/libsmb/clispnego.c +++ b/source3/libsmb/clispnego.c @@ -3,6 +3,7 @@ simple kerberos5/SPNEGO routines Copyright (C) Andrew Tridgell 2001 Copyright (C) Jim McDonough 2002 + Copyright (C) Luke Howard 2003 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 @@ -259,7 +260,7 @@ BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se /* generate a krb5 GSS-API wrapper packet given a ticket */ -DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket) +DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, uint8 tok_id[2]) { ASN1_DATA data; DATA_BLOB ret; @@ -268,7 +269,8 @@ DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket) asn1_push_tag(&data, ASN1_APPLICATION(0)); asn1_write_OID(&data, OID_KERBEROS5); - asn1_write_BOOLEAN(&data, 0); + + asn1_write(&data, tok_id, 2); asn1_write(&data, ticket.data, ticket.length); asn1_pop_tag(&data); @@ -286,7 +288,7 @@ DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket) /* parse a krb5 GSS-API wrapper packet giving a ticket */ -BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket) +BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2]) { BOOL ret; ASN1_DATA data; @@ -295,15 +297,15 @@ BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket) asn1_load(&data, blob); asn1_start_tag(&data, ASN1_APPLICATION(0)); asn1_check_OID(&data, OID_KERBEROS5); - asn1_check_BOOLEAN(&data, 0); data_remaining = asn1_tag_remaining(&data); - if (data_remaining < 1) { + if (data_remaining < 3) { data.has_error = True; } else { - - *ticket = data_blob(data.data, data_remaining); + asn1_read(&data, tok_id, 2); + data_remaining -= 2; + *ticket = data_blob(NULL, data_remaining); asn1_read(&data, ticket->data, ticket->length); } @@ -330,7 +332,7 @@ DATA_BLOB spnego_gen_negTokenTarg(const char *principal, int time_offset) tkt = krb5_get_ticket(principal, time_offset); /* wrap that up in a nice GSS-API wrapping */ - tkt_wrapped = spnego_gen_krb5_wrap(tkt); + tkt_wrapped = spnego_gen_krb5_wrap(tkt, TOK_ID_KRB_AP_REQ); /* and wrap that in a shiny SPNEGO wrapper */ targ = gen_negTokenTarg(krb_mechs, tkt_wrapped); @@ -438,9 +440,10 @@ BOOL spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth) } /* - generate a minimal SPNEGO NTLMSSP response packet. Doesn't contain much. + generate a minimal SPNEGO response packet. Doesn't contain much. */ -DATA_BLOB spnego_gen_auth_response(DATA_BLOB *ntlmssp_reply, NTSTATUS nt_status) +DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status, + const char *mechOID) { ASN1_DATA data; DATA_BLOB ret; @@ -462,13 +465,13 @@ DATA_BLOB spnego_gen_auth_response(DATA_BLOB *ntlmssp_reply, NTSTATUS nt_status) asn1_write_enumerated(&data, negResult); asn1_pop_tag(&data); - if (negResult == SPNEGO_NEG_RESULT_INCOMPLETE) { + if (reply->data != NULL) { asn1_push_tag(&data,ASN1_CONTEXT(1)); - asn1_write_OID(&data, OID_NTLMSSP); + asn1_write_OID(&data, mechOID); asn1_pop_tag(&data); asn1_push_tag(&data,ASN1_CONTEXT(2)); - asn1_write_OctetString(&data, ntlmssp_reply->data, ntlmssp_reply->length); + asn1_write_OctetString(&data, reply->data, reply->length); asn1_pop_tag(&data); } diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c index eafe805aba..7e5ec56a27 100644 --- a/source3/smbd/sesssetup.c +++ b/source3/smbd/sesssetup.c @@ -4,6 +4,7 @@ Copyright (C) Andrew Tridgell 1998-2001 Copyright (C) Andrew Bartlett 2001 Copyright (C) Jim McDonough 2002 + Copyright (C) Luke Howard 2003 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 @@ -146,11 +147,14 @@ static int reply_spnego_kerberos(connection_struct *conn, int sess_vuid; NTSTATUS ret; DATA_BLOB auth_data; + DATA_BLOB ap_rep, ap_rep_wrapped, response; auth_serversupplied_info *server_info = NULL; ADS_STRUCT *ads; + uint8 session_key[16]; + uint8 tok_id[2]; BOOL foreign = False; - if (!spnego_parse_krb5_wrap(*secblob, &ticket)) { + if (!spnego_parse_krb5_wrap(*secblob, &ticket, tok_id)) { return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -162,7 +166,7 @@ static int reply_spnego_kerberos(connection_struct *conn, ads->auth.realm = strdup(lp_realm()); - ret = ads_verify_ticket(ads, &ticket, &client, &auth_data); + ret = ads_verify_ticket(ads, &ticket, &client, &auth_data, &ap_rep, session_key); if (!NT_STATUS_IS_OK(ret)) { DEBUG(1,("Failed to verify incoming ticket!\n")); ads_destroy(&ads); @@ -177,6 +181,7 @@ static int reply_spnego_kerberos(connection_struct *conn, if (!p) { DEBUG(3,("Doesn't look like a valid principal\n")); ads_destroy(&ads); + data_blob_free(&ap_rep); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } @@ -184,6 +189,7 @@ static int reply_spnego_kerberos(connection_struct *conn, if (strcasecmp(p+1, ads->auth.realm) != 0) { DEBUG(3,("Ticket for foreign realm %s@%s\n", client, p+1)); if (!lp_allow_trusted_domains()) { + data_blob_free(&ap_rep); return ERROR_NT(NT_STATUS_LOGON_FAILURE); } foreign = True; @@ -209,31 +215,51 @@ static int reply_spnego_kerberos(connection_struct *conn, if (!pw) { DEBUG(1,("Username %s is invalid on this system\n",user)); + data_blob_free(&ap_rep); return ERROR_NT(NT_STATUS_NO_SUCH_USER); } if (!NT_STATUS_IS_OK(ret = make_server_info_pw(&server_info,pw))) { DEBUG(1,("make_server_info_from_pw failed!\n")); + data_blob_free(&ap_rep); return ERROR_NT(ret); } - + + /* Copy out the session key from the AP_REQ. */ + memcpy(server_info->session_key, session_key, sizeof(session_key)); + /* register_vuid keeps the server info */ sess_vuid = register_vuid(server_info, user); free(user); if (sess_vuid == -1) { - return ERROR_NT(NT_STATUS_LOGON_FAILURE); + ret = NT_STATUS_LOGON_FAILURE; + } else { + set_message(outbuf,4,0,True); + SSVAL(outbuf, smb_vwv3, 0); + + if (server_info->guest) { + SSVAL(outbuf,smb_vwv2,1); + } + + SSVAL(outbuf, smb_uid, sess_vuid); } - set_message(outbuf,4,0,True); - SSVAL(outbuf, smb_vwv3, 0); - add_signature(outbuf); - - SSVAL(outbuf,smb_uid,sess_vuid); - SSVAL(inbuf,smb_uid,sess_vuid); - - return chain_reply(inbuf,outbuf,length,bufsize); + /* wrap that up in a nice GSS-API wrapping */ + if (NT_STATUS_IS_OK(ret)) { + ap_rep_wrapped = spnego_gen_krb5_wrap(ap_rep, TOK_ID_KRB_AP_REP); + } else { + ap_rep_wrapped = data_blob(NULL, 0); + } + response = spnego_gen_auth_response(&ap_rep_wrapped, ret, OID_KERBEROS5_OLD); + reply_sesssetup_blob(conn, outbuf, response, ret); + + data_blob_free(&ap_rep); + data_blob_free(&ap_rep_wrapped); + data_blob_free(&response); + + return -1; /* already replied */ } #endif @@ -280,7 +306,7 @@ static BOOL reply_spnego_ntlmssp(connection_struct *conn, char *outbuf, } } - response = spnego_gen_auth_response(ntlmssp_blob, nt_status); + response = spnego_gen_auth_response(ntlmssp_blob, nt_status, OID_NTLMSSP); ret = reply_sesssetup_blob(conn, outbuf, response, nt_status); data_blob_free(&response); -- cgit From 0e6dbeb2737700ece2a4502a6edf094f4f26894c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 11:16:27 +0000 Subject: typo (This used to be commit a47dee787413daaf0b550a47bbd78125490c356e) --- source3/smbwrapper/smbsh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/smbwrapper/smbsh.c b/source3/smbwrapper/smbsh.c index 845d1d5606..2cbdc76de1 100644 --- a/source3/smbwrapper/smbsh.c +++ b/source3/smbwrapper/smbsh.c @@ -101,7 +101,7 @@ int main(int argc, char *argv[]) smbw_setshared(line, wd); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd); - etenv("LD_PRELOAD", line); + setenv("LD_PRELOAD", line); slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); -- cgit From 426cd68f74bb0490df54da500d3d9c1ea475e16f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 11:23:15 +0000 Subject: Move off-by-one buggy malloc()/safe_strcpy() combination to strdup() instead. Andrew Bartlett (This used to be commit c26881633d8a7f6d9b9ed9c6a97ce2b45bf2b317) --- source3/lib/util_getent.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 7d45287bba..32641dbf83 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -224,18 +224,16 @@ static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_he for (i = 0; i < num_users; i++) { struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry)); - size_t len = strlen(grp->gr_mem[i])+1; if (entry == NULL) { free_userlist(list_head); return NULL; } - entry->unix_name = (char *)malloc(len); + entry->unix_name = (char *)strdup(grp->gr_mem[i]); if (entry->unix_name == NULL) { SAFE_FREE(entry); free_userlist(list_head); return NULL; } - safe_strcpy(entry->unix_name, grp->gr_mem[i],len); DLIST_ADD(list_head, entry); } return list_head; -- cgit From 05262ea49a3d428e015ef71c975231b108847b72 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 11:24:27 +0000 Subject: Finish removing setenv replacements from smbwrapper. (This used to be commit 059ac2d839bf258408490f5ceb786a47cb5acb58) --- source3/smbwrapper/shared.c | 20 +------------------- source3/smbwrapper/smbsh.c | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) (limited to 'source3') diff --git a/source3/smbwrapper/shared.c b/source3/smbwrapper/shared.c index 00dd30b70e..b4cfcf7148 100644 --- a/source3/smbwrapper/shared.c +++ b/source3/smbwrapper/shared.c @@ -52,7 +52,7 @@ void smbw_setup_shared(void) slprintf(s,sizeof(s)-1,"%d", shared_fd); - smbw_setenv("SMBW_HANDLE", s); + setenv("SMBW_HANDLE", s, 1); return; @@ -194,24 +194,6 @@ void smbw_setshared(const char *name, const char *val) } -/***************************************************************** -set an env variable - some systems don't have this -*****************************************************************/ -int smbw_setenv(const char *name, const char *value) -{ - pstring s; - char *p; - int ret = -1; - - slprintf(s,sizeof(s)-1,"%s=%s", name, value); - - p = strdup(s); - - if (p) ret = putenv(p); - - return ret; -} - /***************************************************************** return true if the passed fd is the SMBW_HANDLE *****************************************************************/ diff --git a/source3/smbwrapper/smbsh.c b/source3/smbwrapper/smbsh.c index 2cbdc76de1..221c6d87c2 100644 --- a/source3/smbwrapper/smbsh.c +++ b/source3/smbwrapper/smbsh.c @@ -101,7 +101,7 @@ int main(int argc, char *argv[]) smbw_setshared(line, wd); slprintf(line,sizeof(line)-1,"%s/smbwrapper.so", libd); - setenv("LD_PRELOAD", line); + setenv("LD_PRELOAD", line, 1); slprintf(line,sizeof(line)-1,"%s/smbwrapper.32.so", libd); -- cgit From 79aaa35ea5e8c74ff7755ec650aca88cc7e4cf7e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 21:07:03 +0000 Subject: Clean up non-krb5 breakages from my modifications to luke howard's patch. Andrew Bartlett (This used to be commit 32fd0c49009e38022523cc5c14567dd55de08206) --- source3/include/includes.h | 1 + source3/libsmb/clikrb5.c | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'source3') diff --git a/source3/include/includes.h b/source3/include/includes.h index 5b4c5a695f..fab02141cb 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1239,6 +1239,7 @@ krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt); krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters); krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes); void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes); +BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]); #endif /* HAVE_KRB5 */ #endif /* _INCLUDES_H */ diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index 47dec1f171..6b0c7ddaf2 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -365,7 +365,7 @@ failed: return data_blob(NULL, 0); } -BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) + BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) { krb5_keyblock *skey; BOOL ret = False; @@ -394,10 +394,4 @@ DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) return data_blob(NULL, 0); } -BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context ac, uint8 session_key[16]) - { - DEBUG(0,("NO KERBEROS SUPPORT\n")); - memset(session_key, 0, 16); - return False; - } #endif -- cgit From c5871a1893ccaf81116defcdc20d644502e2f98c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 22:25:19 +0000 Subject: Whenever we have a password, use the in-memory ccache. This fixes a bug where we were overwriting the user's ccache with the machine password (the -P option). Andrew Bartlett (This used to be commit 231d2f84ef36b30be98baf3b56ebf4a5cd8dad11) --- source3/utils/net_ads.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 75bb29f213..bb87879044 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -131,7 +131,6 @@ static ADS_STRUCT *ads_startup(void) if (opt_user_specified) { need_password = True; - use_in_memory_ccache(); } retry: @@ -142,8 +141,10 @@ retry: free(prompt); } - if (opt_password) + if (opt_password) { + use_in_memory_ccache(); ads->auth.password = strdup(opt_password); + } ads->auth.user_name = strdup(opt_user_name); -- cgit From f803c3237635880694d668d9ce3c29b46c311d43 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Feb 2003 02:20:46 +0000 Subject: Fix a really nasty bug where some users in AD domains (particularly child domains) would not have the tokenGroups or memberOf attributes filled in. This would cause a user to have no supplementary group membership. Detect this by the fact that the primaryGid must be present in the tokenGroups, and if it isn't (ie, if there is no tokenGroups at all), do a server-side search on all groups using the 'member' attribute and the user's DN. Andrew Bartlett (This used to be commit a074f74e627e1d947a76bcf3a39e3c5df4d4ffe5) --- source3/nsswitch/winbindd_ads.c | 104 ++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 14 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 9fd391870b..93c9babd5e 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -455,8 +455,10 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, ADS_STRUCT *ads = NULL; const char *attrs[] = {"distinguishedName", NULL}; const char *attrs2[] = {"tokenGroups", "primaryGroupID", NULL}; + const char *group_attrs[] = {"objectSid", "cn", NULL}; ADS_STATUS rc; int count; + void *res = NULL; void *msg = NULL; char *exp; char *user_dn; @@ -467,22 +469,30 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, char *sidstr; NTSTATUS status = NT_STATUS_UNSUCCESSFUL; - *num_groups = 0; - DEBUG(3,("ads: lookup_usergroups\n")); - - (*num_groups) = 0; + *num_groups = 0; sid_from_rid(domain, user_rid, &sid); ads = ads_cached_connection(domain); if (!ads) goto done; - sidstr = sid_binstring(&sid); - asprintf(&exp, "(objectSid=%s)", sidstr); + if (!(sidstr = sid_binstring(&sid))) { + DEBUG(1,("lookup_usergroups(rid=%d) sid_binstring returned NULL\n", user_rid)); + status = NT_STATUS_NO_MEMORY; + goto done; + } + if (asprintf(&exp, "(objectSid=%s)", sidstr) == -1) { + free(sidstr); + DEBUG(1,("lookup_usergroups(rid=%d) asprintf failed!\n", user_rid)); + status = NT_STATUS_NO_MEMORY; + goto done; + } + rc = ads_search_retry(ads, &msg, exp, attrs); free(exp); free(sidstr); + if (!ADS_ERR_OK(rc)) { DEBUG(1,("lookup_usergroups(rid=%d) ads_search: %s\n", user_rid, ads_errstr(rc))); goto done; @@ -507,20 +517,86 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, goto done; } - count = ads_pull_sids(ads, mem_ctx, msg, "tokenGroups", &sids) + 1; - (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * count); - (*user_gids)[(*num_groups)++] = primary_group; + count = ads_pull_sids(ads, mem_ctx, msg, "tokenGroups", &sids); - for (i=1;isid, &sids[i-1], &rid)) continue; - (*user_gids)[*num_groups] = rid; - (*num_groups)++; + if (msg) ads_msgfree(ads, msg); + + /* there must always be at least one group in the token, + unless we are talking to a buggy Win2k server */ + if (count == 0) { + /* buggy server, no tokenGroups. Instead lookup what groups this user + is a member of by DN search on member*/ + if (asprintf(&exp, "(&(member=%s)(objectClass=group))", user_dn) == -1) { + free(sidstr); + DEBUG(1,("lookup_usergroups(rid=%d) asprintf failed!\n", user_rid)); + status = NT_STATUS_NO_MEMORY; + goto done; + } + + rc = ads_search_retry(ads, &res, exp, group_attrs); + free(exp); + + if (!ADS_ERR_OK(rc)) { + DEBUG(1,("lookup_usergroups(rid=%d) ads_search member=%s: %s\n", user_rid, user_dn, ads_errstr(rc))); + goto done; + } + + count = ads_count_replies(ads, res); + if (count == 0) { + DEBUG(5,("lookup_usergroups: No supp groups found\n")); + goto done; + } + + (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids)[0] = primary_group; + + *num_groups = 1; + + for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { + uint32 rid; + DOM_SID group_sid; + fstring sid_string; + const char *cn; + + cn = ads_pull_string(ads, mem_ctx, msg, "cn"); + if (!cn) { + cn = ""; + } + + if (!ads_pull_sid(ads, msg, "objectSid", &group_sid)) { + DEBUG(1,("No sid for %s !?\n", cn)); + continue; + } + + if (!sid_peek_check_rid(&domain->sid, &group_sid, &rid)) { + DEBUG(5,("sid for %s is out of domain or invalid\n", sid_to_string(sid_string, &sid))); + continue; + } + if (rid == primary_group) continue; + + (*user_gids)[*num_groups] = rid; + (*num_groups)++; + + } + } else { + (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids)[0] = primary_group; + + *num_groups = 1; + + for (i=0;isid, &sids[i-1], &rid)) continue; + if (rid == primary_group) continue; + (*user_gids)[*num_groups] = rid; + (*num_groups)++; + } } status = NT_STATUS_OK; DEBUG(3,("ads lookup_usergroups for rid=%d\n", user_rid)); done: + if (res) ads_msgfree(ads, res); if (msg) ads_msgfree(ads, msg); return status; -- cgit From d116f2c884ce66f69df2973faf34f20a1a7ec988 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Feb 2003 02:23:19 +0000 Subject: tokenGroups are SIDs, so dump them as such. (This used to be commit 43f07e9de70ad9993265e28a54239caba0121ab6) --- source3/libads/ldap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3') diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 29f44672f4..67827d27f3 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1215,6 +1215,7 @@ static BOOL ads_dump_field(char *field, void **values, void *data_area) {"nTSecurityDescriptor", False, dump_sd}, {"dnsRecord", False, dump_binary}, {"objectSid", False, dump_sid}, + {"tokenGroups", False, dump_sid}, {NULL, True, NULL} }; int i; -- cgit From bf095b837272cf2a17c7ffeb94a96f304922a6bf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Feb 2003 03:30:39 +0000 Subject: For some reason some attributes in ADS do not appear (and are not available) in general searches, but only if searching for the DN only. In my case, it was the tokenGroups attribute that caused me trouble, hence this patch. Andrew Bartlett (This used to be commit 8a0cc4c2beb5d6ad7e44bf47bf0f9ec4a3ffdb96) --- source3/utils/net_ads.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index bb87879044..8cd3bac802 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -53,6 +53,8 @@ int net_ads_usage(int argc, const char **argv) "\n\t lookup, add, or remove directory entry for a printer\n"\ "\nnet ads search"\ "\n\tperform a raw LDAP search and dump the results\n" +"\nnet ads dn"\ +"\n\tperform a raw LDAP search and dump attributes of a particular DN\n" ); return -1; } @@ -1003,7 +1005,7 @@ static int net_ads_search(int argc, const char **argv) exp = argv[0]; attrs = (argv + 1); - rc = ads_do_search_all(ads, ads->config.bind_path, + rc = ads_do_search_all(ads, ads->config.bind_path, LDAP_SCOPE_SUBTREE, exp, attrs, &res); if (!ADS_ERR_OK(rc)) { @@ -1023,6 +1025,65 @@ static int net_ads_search(int argc, const char **argv) } +/* + help for net ads search +*/ +static int net_ads_dn_usage(int argc, const char **argv) +{ + d_printf( + "\nnet ads dn \n"\ + "\nperform a raw LDAP search on a ADS server and dump the results\n"\ + "The DN standard LDAP DN, and the attributes are a list of LDAP fields \n"\ + "to show in the results\n\n"\ + "Example: net ads dn 'CN=administrator,CN=Users,DC=my,DC=domain' sAMAccountName\n\n" + ); + net_common_flags_usage(argc, argv); + return -1; +} + + +/* + general ADS search function. Useful in diagnosing problems in ADS +*/ +static int net_ads_dn(int argc, const char **argv) +{ + ADS_STRUCT *ads; + ADS_STATUS rc; + const char *dn; + const char **attrs; + void *res = NULL; + + if (argc < 1) { + return net_ads_dn_usage(argc, argv); + } + + if (!(ads = ads_startup())) { + return -1; + } + + dn = argv[0]; + attrs = (argv + 1); + + rc = ads_do_search_all(ads, dn, + LDAP_SCOPE_BASE, + "(objectclass=*)", attrs, &res); + if (!ADS_ERR_OK(rc)) { + d_printf("search failed: %s\n", ads_errstr(rc)); + return -1; + } + + d_printf("Got %d replies\n\n", ads_count_replies(ads, res)); + + /* dump the results */ + ads_dump(ads, res); + + ads_msgfree(ads, res); + ads_destroy(&ads); + + return 0; +} + + int net_ads_help(int argc, const char **argv) { struct functable func[] = { @@ -1058,6 +1119,7 @@ int net_ads(int argc, const char **argv) {"CHOSTPASS", net_ads_change_localhost_pass}, {"PRINTER", net_ads_printer}, {"SEARCH", net_ads_search}, + {"DN", net_ads_dn}, {"WORKGROUP", net_ads_workgroup}, {"LOOKUP", net_ads_lookup}, {"HELP", net_ads_help}, -- cgit From 589371e1d5844be9ea0da4c674635ccc42ab9498 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 25 Feb 2003 05:49:24 +0000 Subject: After some comments from tridge, clean the new usergroups code into a helper function. Andrew Bartlett (This used to be commit 212a52b3d2ca39fcea2990f9293754b08e9b68e4) --- source3/nsswitch/winbindd_ads.c | 165 +++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 71 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 93c9babd5e..22e4648f15 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -4,6 +4,7 @@ Winbind ADS backend functions Copyright (C) Andrew Tridgell 2001 + Copyright (C) Andrew Bartlett 2003 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 @@ -445,6 +446,84 @@ done: return status; } +/* Lookup groups a user is a member of - alternate method, for when + tokenGroups are not available. */ +static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, + const char *user_dn, + uint32 primary_group, + uint32 *num_groups, uint32 **user_gids) +{ + ADS_STATUS rc; + NTSTATUS status = NT_STATUS_UNSUCCESSFUL; + int count; + void *res = NULL; + void *msg = NULL; + char *exp; + ADS_STRUCT *ads; + const char *group_attrs[] = {"objectSid", NULL}; + + ads = ads_cached_connection(domain); + if (!ads) goto done; + + /* buggy server, no tokenGroups. Instead lookup what groups this user + is a member of by DN search on member*/ + if (asprintf(&exp, "(&(member=%s)(objectClass=group))", user_dn) == -1) { + DEBUG(1,("lookup_usergroups(dn=%s) asprintf failed!\n", user_dn)); + return NT_STATUS_NO_MEMORY; + } + + rc = ads_search_retry(ads, &res, exp, group_attrs); + free(exp); + + if (!ADS_ERR_OK(rc)) { + DEBUG(1,("lookup_usergroups ads_search member=%s: %s\n", user_dn, ads_errstr(rc))); + return ads_ntstatus(rc); + } + + count = ads_count_replies(ads, res); + if (count == 0) { + DEBUG(5,("lookup_usergroups: No supp groups found\n")); + + status = ads_ntstatus(rc); + goto done; + } + + (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids)[0] = primary_group; + + *num_groups = 1; + + for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { + uint32 rid; + DOM_SID group_sid; + fstring sid_string; + + if (!ads_pull_sid(ads, msg, "objectSid", &group_sid)) { + DEBUG(1,("No sid for this group ?!?\n")); + continue; + } + + if (!sid_peek_check_rid(&domain->sid, &group_sid, &rid)) { + DEBUG(5,("sid for %s is out of domain or invalid\n", sid_to_string(sid_string, &group_sid))); + continue; + } + if (rid == primary_group) continue; + + (*user_gids)[*num_groups] = rid; + (*num_groups)++; + + } + + if (res) ads_msgfree(ads, res); + if (msg) ads_msgfree(ads, msg); + + status = NT_STATUS_OK; + + DEBUG(3,("ads lookup_usergroups (alt) for dn=%s\n", user_dn)); +done: + return status; +} /* Lookup groups a user is a member of. */ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, @@ -455,10 +534,8 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, ADS_STRUCT *ads = NULL; const char *attrs[] = {"distinguishedName", NULL}; const char *attrs2[] = {"tokenGroups", "primaryGroupID", NULL}; - const char *group_attrs[] = {"objectSid", "cn", NULL}; ADS_STATUS rc; int count; - void *res = NULL; void *msg = NULL; char *exp; char *user_dn; @@ -524,81 +601,27 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, /* there must always be at least one group in the token, unless we are talking to a buggy Win2k server */ if (count == 0) { - /* buggy server, no tokenGroups. Instead lookup what groups this user - is a member of by DN search on member*/ - if (asprintf(&exp, "(&(member=%s)(objectClass=group))", user_dn) == -1) { - free(sidstr); - DEBUG(1,("lookup_usergroups(rid=%d) asprintf failed!\n", user_rid)); - status = NT_STATUS_NO_MEMORY; - goto done; - } - - rc = ads_search_retry(ads, &res, exp, group_attrs); - free(exp); - - if (!ADS_ERR_OK(rc)) { - DEBUG(1,("lookup_usergroups(rid=%d) ads_search member=%s: %s\n", user_rid, user_dn, ads_errstr(rc))); - goto done; - } - - count = ads_count_replies(ads, res); - if (count == 0) { - DEBUG(5,("lookup_usergroups: No supp groups found\n")); - goto done; - } - - (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); - (*user_gids)[0] = primary_group; - - *num_groups = 1; - - for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { - uint32 rid; - DOM_SID group_sid; - fstring sid_string; - const char *cn; - - cn = ads_pull_string(ads, mem_ctx, msg, "cn"); - if (!cn) { - cn = ""; - } - - if (!ads_pull_sid(ads, msg, "objectSid", &group_sid)) { - DEBUG(1,("No sid for %s !?\n", cn)); - continue; - } - - if (!sid_peek_check_rid(&domain->sid, &group_sid, &rid)) { - DEBUG(5,("sid for %s is out of domain or invalid\n", sid_to_string(sid_string, &sid))); - continue; - } - if (rid == primary_group) continue; - - (*user_gids)[*num_groups] = rid; - (*num_groups)++; + return lookup_usergroups_alt(domain, mem_ctx, user_dn, + primary_group, + num_groups, user_gids); + } - } - } else { - (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); - (*user_gids)[0] = primary_group; - - *num_groups = 1; - - for (i=0;isid, &sids[i-1], &rid)) continue; - if (rid == primary_group) continue; - (*user_gids)[*num_groups] = rid; - (*num_groups)++; - } + (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids)[0] = primary_group; + + *num_groups = 1; + + for (i=0;isid, &sids[i-1], &rid)) continue; + if (rid == primary_group) continue; + (*user_gids)[*num_groups] = rid; + (*num_groups)++; } status = NT_STATUS_OK; DEBUG(3,("ads lookup_usergroups for rid=%d\n", user_rid)); done: - if (res) ads_msgfree(ads, res); - if (msg) ads_msgfree(ads, msg); - return status; } -- cgit From 3a2f56cb630a7566ef0a70052b3102651bf653cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 06:24:13 +0000 Subject: Fixed up some const related compiler warnings. (This used to be commit 923425e497112c5d1e2e569da6c13dcd02b6a8af) --- source3/client/client.c | 9 ++++++--- source3/rpcclient/cmd_lsarpc.c | 24 ++++++++++++------------ source3/rpcclient/cmd_samr.c | 38 +++++++++++++++++++------------------- source3/rpcclient/rpcclient.c | 6 +++--- source3/rpcclient/rpcclient.h | 4 ++-- 5 files changed, 42 insertions(+), 39 deletions(-) (limited to 'source3') diff --git a/source3/client/client.c b/source3/client/client.c index 5da12fd984..b95d4d877c 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -51,7 +51,8 @@ static int max_protocol = PROTOCOL_NT1; extern pstring user_socket_options; static int process_tok(fstring tok); -static int cmd_help(void); +static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv); /* 30 second timeout on most commands */ #define CLIENT_TIMEOUT (30*1000) @@ -979,7 +980,8 @@ static BOOL do_altname(char *name) /**************************************************************************** Exit client. ****************************************************************************/ -static int cmd_quit(void) +static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv) { cli_shutdown(cli); exit(0); @@ -2149,7 +2151,8 @@ static int process_tok(fstring tok) /**************************************************************************** help ****************************************************************************/ -static int cmd_help(void) +static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv) { int i=0,j; fstring buf; diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c index 03df170c09..fab6a89ed5 100644 --- a/source3/rpcclient/cmd_lsarpc.c +++ b/source3/rpcclient/cmd_lsarpc.c @@ -64,7 +64,7 @@ done: static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -134,7 +134,7 @@ static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli, static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -179,7 +179,7 @@ static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli, /* Resolve a list of SIDs to a list of names */ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -246,7 +246,7 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -301,7 +301,7 @@ static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli, static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -354,7 +354,7 @@ static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli, static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -392,7 +392,7 @@ static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli, static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -445,7 +445,7 @@ static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli, static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND dom_pol; POLICY_HND user_pol; @@ -500,7 +500,7 @@ static NTSTATUS cmd_lsa_enum_privsaccounts(struct cli_state *cli, static NTSTATUS cmd_lsa_enum_acct_rights(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND dom_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -666,8 +666,8 @@ static NTSTATUS cmd_lsa_remove_acct_rights(struct cli_state *cli, /* Get a privilege value given its name */ static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli, - TALLOC_CTX *mem_ctx, int argc, - char **argv) + TALLOC_CTX *mem_ctx, int argc, + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -702,7 +702,7 @@ static NTSTATUS cmd_lsa_lookupprivvalue(struct cli_state *cli, static NTSTATUS cmd_lsa_query_secobj(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c index 85aface7be..cec6b1680b 100644 --- a/source3/rpcclient/cmd_samr.c +++ b/source3/rpcclient/cmd_samr.c @@ -264,7 +264,7 @@ static NTSTATUS try_samr_connects(struct cli_state *cli, TALLOC_CTX *mem_ctx, */ static NTSTATUS cmd_samr_query_user(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, user_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -373,7 +373,7 @@ static void display_group_info_ctr(GROUP_INFO_CTR *ctr) */ static NTSTATUS cmd_samr_query_group(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, group_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -435,7 +435,7 @@ done: static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, @@ -499,8 +499,8 @@ static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli, /* Query aliases a user is a member of */ static NTSTATUS cmd_samr_query_useraliases(struct cli_state *cli, - TALLOC_CTX *mem_ctx, - int argc, char **argv) + TALLOC_CTX *mem_ctx, + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -568,7 +568,7 @@ static NTSTATUS cmd_samr_query_useraliases(struct cli_state *cli, static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, group_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -630,7 +630,7 @@ static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli, static NTSTATUS cmd_samr_enum_dom_users(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -704,7 +704,7 @@ static NTSTATUS cmd_samr_enum_dom_users(struct cli_state *cli, static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -777,7 +777,7 @@ static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli, static NTSTATUS cmd_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -859,7 +859,7 @@ static NTSTATUS cmd_samr_enum_als_groups(struct cli_state *cli, static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, alias_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -933,7 +933,7 @@ static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli, static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -1067,7 +1067,7 @@ static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli, static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -1137,11 +1137,11 @@ static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli, static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, user_pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - char *acct_name; + const char *acct_name; uint16 acb_info; uint32 unknown, user_rid; uint32 access_mask = MAXIMUM_ALLOWED_ACCESS; @@ -1193,7 +1193,7 @@ static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli, static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; POLICY_HND connect_pol, domain_pol; @@ -1263,7 +1263,7 @@ static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli, static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; POLICY_HND connect_pol, domain_pol; @@ -1320,7 +1320,7 @@ static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli, static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; POLICY_HND connect_pol, domain_pol, user_pol; @@ -1389,7 +1389,7 @@ static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli, */ static NTSTATUS cmd_samr_query_sec_obj(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND connect_pol, domain_pol, user_pol, *pol; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -1466,7 +1466,7 @@ done: static NTSTATUS cmd_samr_get_dom_pwinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uint16 unk_0, unk_1, unk_2; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 7a9c464cf6..5803055598 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -259,7 +259,7 @@ static void fetch_machine_sid(struct cli_state *cli) /* List the available commands on a given pipe */ static NTSTATUS cmd_listcommands(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { struct cmd_list *tmp; struct cmd_set *tmp_set; @@ -364,7 +364,7 @@ static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Change the debug level */ static NTSTATUS cmd_debuglevel(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { if (argc > 2) { printf("Usage: %s [debuglevel]\n", argv[0]); @@ -479,7 +479,7 @@ static NTSTATUS do_cmd(struct cli_state *cli, /* Run command */ - result = cmd_entry->fn(cli, mem_ctx, argc, (char **) argv); + result = cmd_entry->fn(cli, mem_ctx, argc, (const char **) argv); /* Cleanup */ diff --git a/source3/rpcclient/rpcclient.h b/source3/rpcclient/rpcclient.h index 3276a62437..1bd3c1a641 100644 --- a/source3/rpcclient/rpcclient.h +++ b/source3/rpcclient/rpcclient.h @@ -24,8 +24,8 @@ struct cmd_set { const char *name; - NTSTATUS (*fn)(struct cli_state*, TALLOC_CTX *mem_ctx, int argc, - char **argv); + NTSTATUS (*fn)(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, + const char **argv); int pipe_idx; const char *description; const char *usage; -- cgit From 7c7d796b6d292a7c98b099ad1e1adbc4f2363512 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 25 Feb 2003 20:51:23 +0000 Subject: Progress on CR 601 cache the printer_info_2 with the open printer handle. cache is invalidated on a mod_a_printer() call **on that smbd**. Yes, this means that the window for admins to step on each other from different clients just got larger, but since handles a generally short lived this is probably ok. (This used to be commit 33c7b7522504fb15989f32add8e9a087c8d9d0fa) --- source3/include/nt_printing.h | 45 +++++ source3/printing/nt_printing.c | 366 +++++++++++++++++++++--------------- source3/registry/reg_printing.c | 7 +- source3/rpc_parse/parse_spoolss.c | 2 +- source3/rpc_server/srv_spoolss_nt.c | 277 ++++++++++++--------------- source3/smbd/lanman.c | 6 +- 6 files changed, 388 insertions(+), 315 deletions(-) (limited to 'source3') diff --git a/source3/include/nt_printing.h b/source3/include/nt_printing.h index 6d952a89a5..ca65a40d48 100644 --- a/source3/include/nt_printing.h +++ b/source3/include/nt_printing.h @@ -434,4 +434,49 @@ typedef struct { SPOOLSS_NOTIFY_MSG_GROUP *msg_groups; } SPOOLSS_NOTIFY_MSG_CTR; +#define PRINTER_HANDLE_IS_PRINTER 0 +#define PRINTER_HANDLE_IS_PRINTSERVER 1 + +/* structure to store the printer handles */ +/* and a reference to what it's pointing to */ +/* and the notify info asked about */ +/* that's the central struct */ +typedef struct _Printer{ + struct _Printer *prev, *next; + BOOL document_started; + BOOL page_started; + uint32 jobid; /* jobid in printing backend */ + BOOL printer_type; + TALLOC_CTX *ctx; + union { + fstring handlename; + fstring printerservername; + } dev; + uint32 type; + uint32 access_granted; + struct { + uint32 flags; + uint32 options; + fstring localmachine; + uint32 printerlocal; + SPOOL_NOTIFY_OPTION *option; + POLICY_HND client_hnd; + BOOL client_connected; + uint32 change; + /* are we in a FindNextPrinterChangeNotify() call? */ + BOOL fnpcn; + } notify; + struct { + fstring machine; + fstring user; + } client; + + /* devmode sent in the OpenPrinter() call */ + NT_DEVICEMODE *nt_devmode; + + /* cache the printer info */ + NT_PRINTER_INFO_LEVEL *printer_info; + +} Printer_entry; + #endif /* NT_PRINTING_H_ */ diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 836324ecc9..0f5067c5a0 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -3,7 +3,7 @@ * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Jean François Micouleau 1998-2000. - * Copyright (C) Gerald Carter 2002. + * Copyright (C) Gerald Carter 2002-2003. * * 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 @@ -565,8 +565,9 @@ BOOL add_a_form(nt_forms_struct **list, const FORM *form, int *count) } /**************************************************************************** - delete a named form struct + Delete a named form struct. ****************************************************************************/ + BOOL delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, WERROR *ret) { pstring key; @@ -603,8 +604,9 @@ BOOL delete_a_form(nt_forms_struct **list, UNISTR2 *del_name, int *count, WERROR } /**************************************************************************** -update a form struct + Update a form struct. ****************************************************************************/ + void update_a_form(nt_forms_struct **list, const FORM *form, int count) { int n=0; @@ -612,8 +614,7 @@ void update_a_form(nt_forms_struct **list, const FORM *form, int count) unistr2_to_ascii(form_name, &(form->name), sizeof(form_name)-1); DEBUG(106, ("[%s]\n", form_name)); - for (n=0; ndevicename, @@ -1937,15 +1940,13 @@ static int pack_values(NT_PRINTER_DATA *data, char *buf, int buflen) /* loop over all keys */ - for ( i=0; inum_keys; i++ ) - { + for ( i=0; inum_keys; i++ ) { val_ctr = &data->keys[i].values; num_values = regval_ctr_numvals( val_ctr ); /* loop over all values */ - for ( j=0; j\ */ val = regval_ctr_specific_value( val_ctr, j ); @@ -1991,7 +1992,7 @@ uint32 del_a_printer(char *sharename) } /* FIXME!!! Reorder so this forward declaration is not necessary --jerry */ -static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **, fstring); +static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **, const char* sharename); static void free_nt_printer_info_level_2(NT_PRINTER_INFO_LEVEL_2 **); /**************************************************************************** ****************************************************************************/ @@ -2169,6 +2170,9 @@ NT_DEVICEMODE *dup_nt_devicemode(NT_DEVICEMODE *nt_devicemode) { NT_DEVICEMODE *new_nt_devicemode = NULL; + if ( !nt_devicemode ) + return NULL; + if ((new_nt_devicemode = (NT_DEVICEMODE *)memdup(nt_devicemode, sizeof(NT_DEVICEMODE))) == NULL) { DEBUG(0,("dup_nt_devicemode: malloc fail.\n")); return NULL; @@ -2222,8 +2226,7 @@ static void free_nt_printer_info_level_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr) /* clean up all registry keys */ data = &info->data; - for ( i=0; inum_keys; i++ ) - { + for ( i=0; inum_keys; i++ ) { SAFE_FREE( data->keys[i].name ); regval_ctr_destroy( &data->keys[i].values ); } @@ -2311,8 +2314,8 @@ int unpack_devicemode(NT_DEVICEMODE **nt_devmode, char *buf, int buflen) } /**************************************************************************** - allocate and initialize a new slot in - ***************************************************************************/ + Allocate and initialize a new slot. +***************************************************************************/ static int add_new_printer_key( NT_PRINTER_DATA *data, const char *name ) { @@ -2360,8 +2363,7 @@ int lookup_printerkey( NT_PRINTER_DATA *data, const char *name ) /* loop over all existing keys */ - for ( i=0; inum_keys; i++ ) - { + for ( i=0; inum_keys; i++ ) { if ( strequal(data->keys[i].name, name) ) { DEBUG(12,("lookup_printerkey: Found [%s]!\n", name)); key_index = i; @@ -2388,10 +2390,8 @@ uint32 get_printer_subkeys( NT_PRINTER_DATA *data, const char* key, fstring **su if ( !data ) return 0; - for ( i=0; inum_keys; i++ ) - { - if ( StrnCaseCmp(data->keys[i].name, key, strlen(key)) == 0 ) - { + for ( i=0; inum_keys; i++ ) { + if ( StrnCaseCmp(data->keys[i].name, key, strlen(key)) == 0 ) { /* match sure it is a subkey and not the key itself */ key_len = strlen( key ); @@ -2436,7 +2436,7 @@ uint32 get_printer_subkeys( NT_PRINTER_DATA *data, const char* key, fstring **su /* tag of the end */ if (num_subkeys) - fstrcpy( subkeys_ptr[num_subkeys], "" ); + fstrcpy(subkeys_ptr[num_subkeys], "" ); *subkeys = subkeys_ptr; @@ -2692,12 +2692,12 @@ WERROR unpublish_it(NT_PRINTER_INFO_LEVEL *printer) * @return WERROR indicating status of publishing ***************************************************************************/ -WERROR nt_printer_publish(int snum, int action) +WERROR nt_printer_publish(Printer_entry *print_hnd, int snum, int action) { NT_PRINTER_INFO_LEVEL *printer = NULL; WERROR win_rc; - win_rc = get_a_printer(&printer, 2, lp_servicename(snum)); + win_rc = get_a_printer(print_hnd, &printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(win_rc)) return win_rc; @@ -2718,7 +2718,7 @@ WERROR nt_printer_publish(int snum, int action) return win_rc; } -BOOL is_printer_published(int snum, GUID *guid) +BOOL is_printer_published(Printer_entry *print_hnd, int snum, GUID *guid) { NT_PRINTER_INFO_LEVEL *printer = NULL; REGVAL_CTR *ctr; @@ -2727,7 +2727,7 @@ BOOL is_printer_published(int snum, GUID *guid) int i; - win_rc = get_a_printer(&printer, 2, lp_servicename(snum)); + win_rc = get_a_printer(print_hnd, &printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(win_rc)) return False; @@ -2753,11 +2753,11 @@ BOOL is_printer_published(int snum, GUID *guid) } #else -WERROR nt_printer_publish(int snum, int action) +WERROR nt_printer_publish(Printer_entry *print_hnd, int snum, int action) { return WERR_OK; } -BOOL is_printer_published(int snum, GUID *guid) +BOOL is_printer_published(Printer_entry *print_hnd, int snum, GUID *guid) { return False; } @@ -2780,10 +2780,8 @@ WERROR delete_all_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key ) /* remove all keys */ - if ( !strlen(key) ) - { - for ( i=0; inum_keys; i++ ) - { + if ( !strlen(key) ) { + for ( i=0; inum_keys; i++ ) { DEBUG(8,("delete_all_printer_data: Removed all Printer Data from key [%s]\n", data->keys[i].name)); @@ -2802,10 +2800,8 @@ WERROR delete_all_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key ) /* remove a specific key (and all subkeys) */ - for ( i=0; inum_keys; i++ ) - { - if ( StrnCaseCmp( data->keys[i].name, key, strlen(key)) == 0 ) - { + for ( i=0; inum_keys; i++ ) { + if ( StrnCaseCmp( data->keys[i].name, key, strlen(key)) == 0 ) { DEBUG(8,("delete_all_printer_data: Removed all Printer Data from key [%s]\n", data->keys[i].name)); @@ -2849,8 +2845,7 @@ WERROR delete_all_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *key ) /* sanity check to see if anything is left */ - if ( !data->num_keys ) - { + if ( !data->num_keys ) { DEBUG(8,("delete_all_printer_data: No keys left for printer [%s]\n", p2->printername )); SAFE_FREE( data->keys ); @@ -2956,8 +2951,7 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen) /* loop and unpack the rest of the registry values */ - while ( True ) - { + while ( True ) { /* check to see if there are any more registry values */ @@ -3007,7 +3001,8 @@ static int unpack_values(NT_PRINTER_DATA *printer_data, char *buf, int buflen) regval_ctr_addvalue( &printer_data->keys[key_index].values, valuename, type, data_p, size ); - SAFE_FREE(data_p); /* 'B' option to tdb_unpack does a malloc() */ + SAFE_FREE(data_p); /* 'B' option to tdbpack does a malloc() */ + DEBUG(8,("specific: [%s:%s], len: %d\n", keyname, valuename, size)); } @@ -3099,9 +3094,9 @@ static void map_to_os2_driver(fstring drivername) } /**************************************************************************** -get a default printer info 2 struct + Get a default printer info 2 struct. ****************************************************************************/ -static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharename) +static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sharename) { int snum; NT_PRINTER_INFO_LEVEL_2 info; @@ -3180,7 +3175,7 @@ static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin /**************************************************************************** ****************************************************************************/ -static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharename) +static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sharename) { pstring key; NT_PRINTER_INFO_LEVEL_2 info; @@ -3270,7 +3265,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen } /**************************************************************************** -debugging function, dump at level 6 the struct in the logs + Debugging function, dump at level 6 the struct in the logs. ****************************************************************************/ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) { @@ -3279,8 +3274,7 @@ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) DEBUG(106,("Dumping printer at level [%d]\n", level)); - switch (level) - { + switch (level) { case 2: { if (printer.info_2 == NULL) @@ -3325,26 +3319,6 @@ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) return result; } -/**************************************************************************** - Get the parameters we can substitute in an NT print job. -****************************************************************************/ - -void get_printer_subst_params(int snum, fstring *printername, fstring *sharename, fstring *portname) -{ - NT_PRINTER_INFO_LEVEL *printer = NULL; - - **printername = **sharename = **portname = '\0'; - - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) - return; - - fstrcpy(*printername, printer->info_2->printername); - fstrcpy(*sharename, printer->info_2->sharename); - fstrcpy(*portname, printer->info_2->portname); - - free_a_printer(&printer, 2); -} - /**************************************************************************** Update the changeid time. This is SO NASTY as some drivers need this to change, others need it @@ -3388,8 +3362,15 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) dump_a_printer(printer, level); - switch (level) - { + /* + * invalidate cache for all open handles to this printer. + * cache for a given handle will be updated on the next + * get_a_printer() + */ + + invalidate_printer_hnd_cache( printer.info_2->sharename ); + + switch (level) { case 2: { /* @@ -3424,6 +3405,7 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) */ result=update_a_printer_2(printer.info_2); + break; } default: @@ -3528,8 +3510,7 @@ BOOL set_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level) { BOOL result = False; - switch (level) - { + switch (level) { case 2: result = set_driver_init_2(printer->info_2); break; @@ -3600,7 +3581,8 @@ static uint32 update_driver_init_2(NT_PRINTER_INFO_LEVEL_2 *info) ret = -1; goto done; } - else buf = tb; + else + buf = tb; buflen = len; goto again; } @@ -3636,13 +3618,10 @@ uint32 update_driver_init(NT_PRINTER_INFO_LEVEL printer, uint32 level) dump_a_printer(printer, level); - switch (level) - { + switch (level) { case 2: - { result = update_driver_init_2(printer.info_2); break; - } default: result = 1; break; @@ -3711,8 +3690,7 @@ static WERROR save_driver_init_2(NT_PRINTER_INFO_LEVEL *printer, uint8 *data, ui */ DEBUG(8,("save_driver_init_2: Enter...\n")); - if ( !printer->info_2->devmode && data_len ) - { + if ( !printer->info_2->devmode && data_len ) { /* * Set devmode on printer info, so entire printer initialization can be * saved to tdb. @@ -3781,13 +3759,10 @@ WERROR save_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level, uint8 *dat { WERROR status = WERR_OK; - switch (level) - { + switch (level) { case 2: - { status = save_driver_init_2( printer, data, data_len ); break; - } default: status = WERR_UNKNOWN_LEVEL; break; @@ -3796,11 +3771,80 @@ WERROR save_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level, uint8 *dat return status; } +/**************************************************************************** + Deep copy a NT_PRINTER_DATA +****************************************************************************/ + +static NTSTATUS copy_printer_data( NT_PRINTER_DATA *dst, NT_PRINTER_DATA *src ) +{ + int i, j, num_vals, new_key_index; + REGVAL_CTR *src_key, *dst_key; + + if ( !dst || !src ) + return NT_STATUS_NO_MEMORY; + + for ( i=0; inum_keys; i++ ) { + + /* create a new instance of the printerkey in the destination + printer_data object */ + + new_key_index = add_new_printer_key( dst, src->keys[i].name ); + dst_key = &dst->keys[new_key_index].values; + + src_key = &src->keys[i].values; + num_vals = regval_ctr_numvals( src_key ); + + /* dup the printer entire printer key */ + + for ( j=0; jdevmode = dup_nt_devicemode( printer->devmode ); + + ZERO_STRUCT( copy->data ); + copy_printer_data( ©->data, &printer->data ); + + /* this is talloc()'d; very ugly that we have a structure that + is half malloc()'d and half talloc()'d but that is the way + that the PRINTER_INFO stuff is written right now. --jerry */ + + copy->secdesc_buf = dup_sec_desc_buf( ctx, printer->secdesc_buf ); + + return copy; +} + /**************************************************************************** Get a NT_PRINTER_INFO_LEVEL struct. It returns malloced memory. ****************************************************************************/ -WERROR get_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, fstring sharename) +#define ENABLE_PRINT_HND_CACHE 1 + +WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, + const char *sharename) { WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; @@ -3809,24 +3853,70 @@ WERROR get_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, fstring s DEBUG(10,("get_a_printer: [%s] level %u\n", sharename, (unsigned int)level)); - switch (level) - { + switch (level) { case 2: - { if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) { DEBUG(0,("get_a_printer: malloc fail.\n")); return WERR_NOMEM; } ZERO_STRUCTP(printer); + + /* + * check for cache first. A Printer handle cannot changed + * to another printer object so we only check that the printer + * is actually for a printer and that the printer_info pointer + * is valid + */ +#ifdef ENABLE_PRINT_HND_CACHE /* JERRY */ + if ( print_hnd + && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER) + && print_hnd->printer_info ) + { + if ( !(printer->info_2 = dup_printer_2(print_hnd->ctx, print_hnd->printer_info->info_2)) ) { + DEBUG(0,("get_a_printer: unable to copy cached printer info!\n")); + + SAFE_FREE(printer); + return WERR_NOMEM; + } + + DEBUG(10,("get_a_printer: using cached copy of printer_info_2\n")); + + *pp_printer = printer; + result = WERR_OK; + + break; + } +#endif + + /* no cache; look it up on disk */ + result=get_a_printer_2(&printer->info_2, sharename); if (W_ERROR_IS_OK(result)) { dump_a_printer(*printer, level); + +#if ENABLE_PRINT_HND_CACHE /* JERRY */ + /* save a copy in cache */ + if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) { + if ( !print_hnd->printer_info ) + print_hnd->printer_info = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL)); + + if ( print_hnd->printer_info ) { + print_hnd->printer_info->info_2 = dup_printer_2(print_hnd->ctx, printer->info_2); + + /* don't fail the lookup just because the cache update failed */ + if ( !print_hnd->printer_info->info_2 ) + DEBUG(0,("get_a_printer: unable to copy new printer info!\n")); + } + + } +#endif *pp_printer = printer; - } else { - SAFE_FREE(printer); } + else + SAFE_FREE(printer); + + break; - } default: result=WERR_UNKNOWN_LEVEL; break; @@ -3851,21 +3941,15 @@ uint32 free_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level) if (printer == NULL) return 0; - switch (level) - { + switch (level) { case 2: - { - if (printer->info_2 != NULL) - { + if (printer->info_2 != NULL) { free_nt_printer_info_level_2(&printer->info_2); result=0; - } - else - { + } else result=4; - } break; - } + default: result=1; break; @@ -3883,19 +3967,15 @@ uint32 add_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level) DEBUG(104,("adding a printer at level [%d]\n", level)); dump_a_printer_driver(driver, level); - switch (level) - { + switch (level) { case 3: - { result=add_a_printer_driver_3(driver.info_3); break; - } case 6: - { result=add_a_printer_driver_6(driver.info_6); break; - } + default: result=1; break; @@ -3905,13 +3985,13 @@ uint32 add_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level) } /**************************************************************************** ****************************************************************************/ + WERROR get_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level, fstring drivername, const char *architecture, uint32 version) { WERROR result; - switch (level) - { + switch (level) { case 3: /* Sometime we just want any version of the driver */ @@ -3924,8 +4004,7 @@ WERROR get_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL *driver, uint32 level, result = get_a_printer_driver_3( &driver->info_3, drivername, architecture, 2 ); } - } - else { + } else { result = get_a_printer_driver_3(&driver->info_3, drivername, architecture, version); } @@ -3948,8 +4027,7 @@ uint32 free_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level) { uint32 result; - switch (level) - { + switch (level) { case 3: { NT_PRINTER_DRIVER_INFO_LEVEL_3 *info3; @@ -3960,9 +4038,7 @@ uint32 free_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level) ZERO_STRUCTP(info3); SAFE_FREE(info3); result=0; - } - else - { + } else { result=4; } break; @@ -3970,17 +4046,14 @@ uint32 free_a_printer_driver(NT_PRINTER_DRIVER_INFO_LEVEL driver, uint32 level) case 6: { NT_PRINTER_DRIVER_INFO_LEVEL_6 *info6; - if (driver.info_6 != NULL) - { + if (driver.info_6 != NULL) { info6=driver.info_6; SAFE_FREE(info6->dependentfiles); SAFE_FREE(info6->previousnames); ZERO_STRUCTP(info6); SAFE_FREE(info6); result=0; - } - else - { + } else { result=4; } break; @@ -4011,12 +4084,11 @@ BOOL printer_driver_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3 ) /* loop through the printers.tdb and check for the drivername */ - for (snum=0; snumname, printer->info_2->drivername) ) { @@ -4063,11 +4135,9 @@ static BOOL drv_file_in_use( char* file, NT_PRINTER_DRIVER_INFO_LEVEL_3 *info ) if ( !info->dependentfiles ) return False; - while ( *info->dependentfiles[i] ) - { + while ( *info->dependentfiles[i] ) { if ( strequal(file, info->dependentfiles[i]) ) return True; - i++; } @@ -4085,8 +4155,7 @@ static void trim_dependent_file( fstring files[], int idx ) /* bump everything down a slot */ - while( *files[idx+1] ) - { + while( *files[idx+1] ) { fstrcpy( files[idx], files[idx+1] ); idx++; } @@ -4140,14 +4209,12 @@ static BOOL trim_overlap_drv_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *src, if ( !src->dependentfiles ) return in_use; - while ( *src->dependentfiles[i] ) - { + while ( *src->dependentfiles[i] ) { if ( drv_file_in_use(src->dependentfiles[i], drv) ) { in_use = True; DEBUG(10,("Removing [%s] from dependent file list\n", src->dependentfiles[i])); trim_dependent_file( src->dependentfiles, i ); - } - else + } else i++; } @@ -4192,15 +4259,12 @@ BOOL printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info ) /* check each driver for overlap in files */ - for (i=0; ienvironment, version)) ) - { + if ( !W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, list[i], info->environment, version)) ) { SAFE_FREE(list); return True; } @@ -4208,8 +4272,7 @@ BOOL printer_driver_files_in_use ( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info ) /* check if d2 uses any files from d1 */ /* only if this is a different driver than the one being deleted */ - if ( !strequal(info->name, driver.info_3->name) ) - { + if ( !strequal(info->name, driver.info_3->name) ) { if ( trim_overlap_drv_files(info, driver.info_3) ) { free_a_printer_driver(driver, 3); SAFE_FREE( list ); @@ -4307,15 +4370,13 @@ static BOOL delete_driver_files( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct /* check if we are done removing files */ - if ( info_3->dependentfiles ) - { + if ( info_3->dependentfiles ) { while ( *info_3->dependentfiles[i] ) { char *file; /* bypass the "\print$" portion of the path */ - if ( (file = strchr( info_3->dependentfiles[i]+1, '\\' )) != NULL ) - { + if ( (file = strchr( info_3->dependentfiles[i]+1, '\\' )) != NULL ) { DEBUG(10,("deleting dependent file [%s]\n", file)); unlink_internals(conn, 0, file ); } @@ -4560,8 +4621,9 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *printername, SEC_DESC_BUF * fstring key; char *temp; - if (strlen(printername) > 2 && (temp = strchr(printername + 2, '\\'))) + if (strlen(printername) > 2 && (temp = strchr(printername + 2, '\\'))) { printername = temp + 1; + } /* Fetch security descriptor from tdb */ @@ -4803,7 +4865,7 @@ BOOL print_time_access_check(int snum) struct tm *t; uint32 mins; - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_servicename(snum)))) return False; if (printer->info_2->starttime == 0 && printer->info_2->untiltime == 0) diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 4b8eaa658e..619ffc7ee7 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -497,7 +497,7 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) keystr = key2; reg_split_path( keystr, &base, &new_path ); - if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, base) ) ) + if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, base) ) ) goto done; num_subkeys = get_printer_subkeys( &printer->info_2->data, new_path?new_path:"", &subkey_names ); @@ -557,7 +557,7 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) { /* we are dealing with the printer itself */ - if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, printername) ) ) + if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) ) goto done; info2 = printer->info_2; @@ -628,7 +628,6 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) } } - prs_mem_free( &prs ); num_values = regval_ctr_numvals( val ); @@ -639,7 +638,7 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) /* now enumerate the key */ - if ( !W_ERROR_IS_OK( get_a_printer(&printer, 2, printername) ) ) + if ( !W_ERROR_IS_OK( get_a_printer(NULL, &printer, 2, printername) ) ) goto done; /* iterate over all printer data and fill the regval container */ diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c index fb2aaf71ec..a34740f9ff 100644 --- a/source3/rpc_parse/parse_spoolss.c +++ b/source3/rpc_parse/parse_spoolss.c @@ -1372,7 +1372,7 @@ BOOL spoolss_io_r_getprinterdata(const char *desc, SPOOL_R_GETPRINTERDATA *r_u, return False; } - if (!prs_uint8s( r_u->type&(REG_SZ|REG_MULTI_SZ), "data", ps, depth, r_u->data, r_u->size )) + if (!prs_uint8s( False, "data", ps, depth, r_u->data, r_u->size )) return False; if (!prs_align(ps)) diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 93566c2bb7..fa9b8eaeff 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -5,7 +5,7 @@ * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean François Micouleau 1998-2000, * Copyright (C) Jeremy Allison 2001-2002, - * Copyright (C) Gerald Carter 2000-2002, + * Copyright (C) Gerald Carter 2000-2003, * Copyright (C) Tim Potter 2001-2002. * * This program is free software; you can redistribute it and/or modify @@ -37,8 +37,7 @@ #define MAGIC_DISPLAY_FREQUENCY 0xfade2bad #define PHANTOM_DEVMODE_KEY "_p_f_a_n_t_0_m_" -#define PRINTER_HANDLE_IS_PRINTER 0 -#define PRINTER_HANDLE_IS_PRINTSERVER 1 + /* Table to map the driver version */ /* to OS */ @@ -55,46 +54,6 @@ struct table_node { int version; }; - -/* structure to store the printer handles */ -/* and a reference to what it's pointing to */ -/* and the notify info asked about */ -/* that's the central struct */ -typedef struct _Printer{ - struct _Printer *prev, *next; - BOOL document_started; - BOOL page_started; - uint32 jobid; /* jobid in printing backend */ - BOOL printer_type; - union { - fstring handlename; - fstring printerservername; - } dev; - uint32 type; - uint32 access_granted; - struct { - uint32 flags; - uint32 options; - fstring localmachine; - uint32 printerlocal; - SPOOL_NOTIFY_OPTION *option; - POLICY_HND client_hnd; - BOOL client_connected; - uint32 change; - /* are we in a FindNextPrinterChangeNotify() call? */ - BOOL fnpcn; - } notify; - struct { - fstring machine; - fstring user; - } client; - - /* devmode sent in the OpenPrinter() call */ - NT_DEVICEMODE *nt_devmode; - - -} Printer_entry; - static Printer_entry *printers_list; typedef struct _counter_printer_0 { @@ -251,6 +210,9 @@ static void free_printer_entry(void *ptr) Printer->notify.client_connected=False; free_nt_devicemode( &Printer->nt_devmode ); + free_a_printer( &Printer->printer_info, 2 ); + + talloc_destroy( Printer->ctx ); /* Remove from the internal list. */ DLIST_REMOVE(printers_list, Printer); @@ -303,6 +265,29 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd return find_printer; } +/**************************************************************************** + find printer index by handle +****************************************************************************/ + +void invalidate_printer_hnd_cache( char *printername ) +{ + Printer_entry *p; + + DEBUG(10,("invalidate_printer_hnd_cache: printer [%s]\n", printername)); + + for ( p=printers_list; p; p=p->next ) + { + if ( p->printer_type==PRINTER_HANDLE_IS_PRINTER + && StrCaseCmp(p->dev.handlename, printername)==0) + { + DEBUG(10,("invalidating printer_info cache for handl:\n")); + free_a_printer( &p->printer_info, 2 ); + p->printer_info = NULL; + } + } + + return; +} /**************************************************************************** Close printer index by handle. ****************************************************************************/ @@ -534,6 +519,11 @@ static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name, uint3 ZERO_STRUCTP(new_printer); + if ( !(new_printer->ctx = talloc_init("Printer Entry [0x%x]", (uint32)hnd)) ) { + DEBUG(0,("open_printer_hnd: talloc_init() failed!\n")); + return False; + } + new_printer->notify.option=NULL; /* Add to the internal list. */ @@ -861,8 +851,7 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS /* add a new group? */ - if ( i == ctr->num_groups ) - { + if ( i == ctr->num_groups ) { ctr->num_groups++; if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) { @@ -929,8 +918,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* loop over all printers */ - for (p = printers_list; p; p = p->next) - { + for (p = printers_list; p; p = p->next) { SPOOL_NOTIFY_INFO_DATA *data; uint32 data_len = 0; uint32 id; @@ -961,8 +949,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* build the array of change notifications */ - for ( i=0; inum_msgs; i++ ) - { + for ( i=0; inum_msgs; i++ ) { SPOOLSS_NOTIFY_MSG *msg = &messages[i]; /* Are we monitoring this event? */ @@ -995,8 +982,7 @@ static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32 idx ) /* Convert unix jobid to smb jobid */ - if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) - { + if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) { id = sysjob_to_jobid(msg->id); if (id == -1) { @@ -1204,7 +1190,7 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) continue; @@ -1300,7 +1286,7 @@ void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) WERROR result; NT_PRINTER_INFO_LEVEL *printer = NULL; - result = get_a_printer( &printer, 2, lp_servicename(snum) ); + result = get_a_printer( NULL, &printer, 2, lp_const_servicename(snum) ); if ( !W_ERROR_IS_OK(result) ) continue; @@ -2157,9 +2143,7 @@ static WERROR get_printer_dataex( TALLOC_CTX *ctx, NT_PRINTER_INFO_LEVEL *printe static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value ) { - delete_printer_data( printer->info_2, key, value ); - - return mod_a_printer(*printer, 2); + return delete_printer_data( printer->info_2, key, value ); } /**************************************************************************** @@ -2171,9 +2155,7 @@ static WERROR set_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *ke { delete_printer_data( printer->info_2, key, value ); - add_printer_data( printer->info_2, key, value, type, data, real_len ); - - return mod_a_printer(*printer, 2); + return add_printer_data( printer->info_2, key, value, type, data, real_len ); } /******************************************************************** @@ -2349,7 +2331,7 @@ WERROR _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO goto done; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(status) ) goto done; @@ -3443,7 +3425,7 @@ void construct_info_data(SPOOL_NOTIFY_INFO_DATA *info_data, uint16 type, uint16 * ********************************************************************/ -static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int +static BOOL construct_notify_printer_info(Printer_entry *print_hnd, SPOOL_NOTIFY_INFO *info, int snum, SPOOL_NOTIFY_OPTION_TYPE *option_type, uint32 id, TALLOC_CTX *mem_ctx) @@ -3462,11 +3444,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int (option_type->type==PRINTER_NOTIFY_TYPE?"PRINTER_NOTIFY_TYPE":"JOB_NOTIFY_TYPE"), option_type->count, lp_servicename(snum))); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum)))) return False; - for(field_num=0; field_numcount; field_num++) - { + for(field_num=0; field_numcount; field_num++) { field = option_type->fields[field_num]; DEBUG(4,("construct_notify_printer_info: notify [%d]: type [%x], field [%x]\n", field_num, type, field)); @@ -3474,12 +3455,10 @@ static BOOL construct_notify_printer_info(SPOOL_NOTIFY_INFO *info, int if (!search_notify(type, field, &j) ) continue; - if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) - { + if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) { DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n")); return False; - } - else + } else info->data = tid; current_data = &info->data[info->count]; @@ -3611,7 +3590,7 @@ static WERROR printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, for (snum=0; snumtype ) { case PRINTER_NOTIFY_TYPE: - if(construct_notify_printer_info(info, snum, + if(construct_notify_printer_info(Printer, info, snum, option_type, id, mem_ctx)) id--; @@ -3682,8 +3661,7 @@ static WERROR printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY count = print_queue_status(snum, &queue, &status); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, - lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) goto done; for (j=0; jflags=flags; @@ -3997,7 +3975,7 @@ DEVICEMODE *construct_dev_mode(int snum) DEBUGADD(8,("getting printer characteristics\n")); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return NULL; if ( !printer->info_2->devmode ) { @@ -4030,14 +4008,14 @@ done: * fill a printer_info_2 struct ********************************************************************/ -static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) +static BOOL construct_printer_info_2(Printer_entry *print_hnd, PRINTER_INFO_2 *printer, int snum) { int count; NT_PRINTER_INFO_LEVEL *ntprinter = NULL; print_status_struct status; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; count = print_queue_length(snum, &status); @@ -4093,12 +4071,12 @@ static BOOL construct_printer_info_2(PRINTER_INFO_2 *printer, int snum) * fill a printer_info_3 struct ********************************************************************/ -static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) +static BOOL construct_printer_info_3(Printer_entry *print_hnd, PRINTER_INFO_3 **pp_printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; PRINTER_INFO_3 *printer = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; *pp_printer = NULL; @@ -4148,11 +4126,11 @@ static BOOL construct_printer_info_3(PRINTER_INFO_3 **pp_printer, int snum) * fill a printer_info_4 struct ********************************************************************/ -static BOOL construct_printer_info_4(PRINTER_INFO_4 *printer, int snum) +static BOOL construct_printer_info_4(Printer_entry *print_hnd, PRINTER_INFO_4 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); /* printername*/ @@ -4168,11 +4146,11 @@ static BOOL construct_printer_info_4(PRINTER_INFO_4 *printer, int snum) * fill a printer_info_5 struct ********************************************************************/ -static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) +static BOOL construct_printer_info_5(Printer_entry *print_hnd, PRINTER_INFO_5 *printer, int snum) { NT_PRINTER_INFO_LEVEL *ntprinter = NULL; - if (!W_ERROR_IS_OK(get_a_printer(&ntprinter, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum)))) return False; init_unistr(&printer->printername, ntprinter->info_2->printername); @@ -4194,12 +4172,12 @@ static BOOL construct_printer_info_5(PRINTER_INFO_5 *printer, int snum) * fill a printer_info_7 struct ********************************************************************/ -static BOOL construct_printer_info_7(PRINTER_INFO_7 *printer, int snum) +static BOOL construct_printer_info_7(Printer_entry *print_hnd, PRINTER_INFO_7 *printer, int snum) { char *guid_str = NULL; GUID guid; - if (is_printer_published(snum, &guid)) { + if (is_printer_published(print_hnd, snum, &guid)) { asprintf(&guid_str, "{%s}", uuid_string_static(guid)); strupper(guid_str); init_unistr(&printer->guid, guid_str); @@ -4230,7 +4208,7 @@ static WERROR enum_all_printers_info_1(uint32 flags, NEW_BUFFER *buffer, uint32 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_1(flags, ¤t_prt, snum)) { + if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) { DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); @@ -4399,7 +4377,7 @@ static WERROR enum_all_printers_info_2(NEW_BUFFER *buffer, uint32 offered, uint3 if (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) { DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum)); - if (construct_printer_info_2(¤t_prt, snum)) { + if (construct_printer_info_2(NULL, ¤t_prt, snum)) { if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) { DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n")); SAFE_FREE(printers); @@ -4570,14 +4548,14 @@ WERROR _spoolss_enumprinters( pipes_struct *p, SPOOL_Q_ENUMPRINTERS *q_u, SPOOL_ /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_0(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_0 *printer=NULL; if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL) return WERR_NOMEM; - construct_printer_info_0(printer, snum); + construct_printer_info_0(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_0(printer); @@ -4603,14 +4581,14 @@ static WERROR getprinter_level_0(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_1(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_1 *printer=NULL; if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL) return WERR_NOMEM; - construct_printer_info_1(PRINTER_ENUM_ICON8, printer, snum); + construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_1(printer); @@ -4636,14 +4614,14 @@ static WERROR getprinter_level_1(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_2(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_2 *printer=NULL; if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL) return WERR_NOMEM; - construct_printer_info_2(printer, snum); + construct_printer_info_2(print_hnd, printer, snum); /* check the required size. */ *needed += spoolss_size_printer_info_2(printer); @@ -4672,11 +4650,11 @@ static WERROR getprinter_level_2(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_3(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_3 *printer=NULL; - if (!construct_printer_info_3(&printer, snum)) + if (!construct_printer_info_3(print_hnd, &printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4703,14 +4681,14 @@ static WERROR getprinter_level_3(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_4(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_4 *printer=NULL; if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_4(printer, snum)) + if (!construct_printer_info_4(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4737,14 +4715,14 @@ static WERROR getprinter_level_4(int snum, NEW_BUFFER *buffer, uint32 offered, u /**************************************************************************** ****************************************************************************/ -static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_5(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_5 *printer=NULL; if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_5(printer, snum)) + if (!construct_printer_info_5(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4768,14 +4746,14 @@ static WERROR getprinter_level_5(int snum, NEW_BUFFER *buffer, uint32 offered, u return WERR_OK; } -static WERROR getprinter_level_7(int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinter_level_7(Printer_entry *print_hnd, int snum, NEW_BUFFER *buffer, uint32 offered, uint32 *needed) { PRINTER_INFO_7 *printer=NULL; if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL) return WERR_NOMEM; - if (!construct_printer_info_7(printer, snum)) + if (!construct_printer_info_7(print_hnd, printer, snum)) return WERR_NOMEM; /* check the required size. */ @@ -4809,6 +4787,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET NEW_BUFFER *buffer = NULL; uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; + Printer_entry *Printer=find_printer_index_by_hnd(p, handle); int snum; @@ -4823,19 +4802,19 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET switch (level) { case 0: - return getprinter_level_0(snum, buffer, offered, needed); + return getprinter_level_0(Printer, snum, buffer, offered, needed); case 1: - return getprinter_level_1(snum, buffer, offered, needed); + return getprinter_level_1(Printer, snum, buffer, offered, needed); case 2: - return getprinter_level_2(snum, buffer, offered, needed); + return getprinter_level_2(Printer, snum, buffer, offered, needed); case 3: - return getprinter_level_3(snum, buffer, offered, needed); + return getprinter_level_3(Printer, snum, buffer, offered, needed); case 4: - return getprinter_level_4(snum, buffer, offered, needed); + return getprinter_level_4(Printer, snum, buffer, offered, needed); case 5: - return getprinter_level_5(snum, buffer, offered, needed); + return getprinter_level_5(Printer, snum, buffer, offered, needed); case 7: - return getprinter_level_7(snum, buffer, offered, needed); + return getprinter_level_7(Printer, snum, buffer, offered, needed); } return WERR_UNKNOWN_LEVEL; } @@ -4860,7 +4839,7 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst ZERO_STRUCT(driver); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) @@ -4920,7 +4899,7 @@ static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fst ZERO_STRUCT(printer); ZERO_STRUCT(driver); - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum)))) + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, lp_const_servicename(snum)))) return WERR_INVALID_PRINTER_NAME; if (!W_ERROR_IS_OK(get_a_printer_driver(&driver, 3, printer->info_2->drivername, architecture, version))) @@ -5059,7 +5038,7 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst WERROR status; ZERO_STRUCT(driver); - status=get_a_printer(&printer, 2, lp_servicename(snum) ); + status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_3: status: %s\n", dos_errstr(status))); if (!W_ERROR_IS_OK(status)) return WERR_INVALID_PRINTER_NAME; @@ -5184,7 +5163,7 @@ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, ZERO_STRUCT(driver); - status=get_a_printer(&printer, 2, lp_servicename(snum) ); + status=get_a_printer(NULL, &printer, 2, lp_const_servicename(snum) ); DEBUG(8,("construct_printer_driver_info_6: status: %s\n", dos_errstr(status))); @@ -5853,13 +5832,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_OK; - if (level!=2) { - DEBUG(0,("update_printer: Send a mail to samba@samba.org\n")); - DEBUGADD(0,("with the following message: update_printer: level!=2\n")); - result = WERR_UNKNOWN_LEVEL; - goto done; - } - if (!Printer) { result = WERR_BADFID; goto done; @@ -5870,8 +5842,8 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, goto done; } - if (!W_ERROR_IS_OK(get_a_printer(&printer, 2, lp_servicename(snum))) || - (!W_ERROR_IS_OK(get_a_printer(&old_printer, 2, lp_servicename(snum))))) { + if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) || + (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) { result = WERR_BADFID; goto done; } @@ -5899,13 +5871,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, result = WERR_NOMEM; goto done; } - - /* - * make sure we actually reload the services after - * this as smb.conf could have a new section in it - * .... shouldn't .... but could - */ - reload_services(False); } /* Do sanity check on the requested changes for Samba */ @@ -5964,9 +5929,6 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, notify_printer_driver(snum, printer->info_2->drivername); } - /* Update printer info */ - result = mod_a_printer(*printer, 2); - /* * flag which changes actually occured. This is a small subset of * all the possible changes. We also have to update things in the @@ -6022,6 +5984,9 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, set_printer_dataex( printer, SPOOL_DSSPOOLER_KEY, "uNCName", REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); + /* Update printer info */ + result = mod_a_printer(*printer, 2); + done: free_a_printer(&printer, 2); free_a_printer(&old_printer, 2); @@ -6051,7 +6016,7 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p, POLICY_HND *handle, if (!get_printer_snum(p, handle, &snum)) return WERR_BADFID; - nt_printer_publish(snum, info7->action); + nt_printer_publish(Printer, snum, info7->action); return WERR_OK; #else @@ -6287,7 +6252,7 @@ static WERROR enumjobs_level2(print_queue_struct *queue, int snum, goto done; } - result = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(result)) { *returned = 0; goto done; @@ -7591,7 +7556,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; @@ -7655,9 +7620,9 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S /* out_value should default to "" or else NT4 has problems unmarshalling the response */ - *out_max_value_len = (in_value_len/sizeof(uint16)); + *out_max_value_len=(in_value_len/sizeof(uint16)); - if ( (*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) + if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL) { result = WERR_NOMEM; goto done; @@ -7692,7 +7657,7 @@ WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S */ /* name */ - *out_max_value_len = ( in_value_len / sizeof(uint16) ); + *out_max_value_len=(in_value_len/sizeof(uint16)); if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL ) { result = WERR_NOMEM; @@ -7765,7 +7730,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP goto done; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -7857,7 +7822,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -7901,7 +7866,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -7972,7 +7937,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -8040,7 +8005,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * if (!get_printer_snum(p,handle, &snum)) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) goto done; } @@ -8390,7 +8355,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin goto done; } - ret = get_a_printer(&ntprinter, 2, lp_servicename(snum)); + ret = get_a_printer(NULL, &ntprinter, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(ret)) goto done; @@ -8543,7 +8508,7 @@ WERROR _spoolss_getprinterdataex(pipes_struct *p, SPOOL_Q_GETPRINTERDATAEX *q_u, if ( !get_printer_snum(p,handle, &snum) ) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if ( !W_ERROR_IS_OK(status) ) goto done; @@ -8638,7 +8603,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8657,11 +8622,10 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, status = set_printer_dataex( printer, keyname, valuename, type, data, real_len ); - /* save the OID if one was specified and the previous set call succeeded */ - - if ( W_ERROR_IS_OK(status) && oid_string ) + if ( W_ERROR_IS_OK(status) ) { - + /* save the OID if one was specified */ + if ( oid_string ) { fstrcat( keyname, "\\" ); fstrcat( keyname, SPOOL_OID_KEY ); @@ -8676,6 +8640,9 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); } + status = mod_a_printer(*printer, 2); + } + free_a_printer(&printer, 2); return status; @@ -8713,7 +8680,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8757,7 +8724,7 @@ WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPO if ( !get_printer_snum(p,handle, &snum) ) return WERR_BADFID; - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8832,7 +8799,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, return WERR_ACCESS_DENIED; } - status = get_a_printer(&printer, 2, lp_servicename(snum)); + status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(status)) return status; @@ -8901,7 +8868,7 @@ WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_ return WERR_BADFID; ZERO_STRUCT(printer); - result = get_a_printer(&printer, 2, lp_servicename(snum)); + result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)); if (!W_ERROR_IS_OK(result)) return result; diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c index 25f390be55..98857c6d32 100644 --- a/source3/smbd/lanman.c +++ b/source3/smbd/lanman.c @@ -500,7 +500,7 @@ static BOOL get_driver_name(int snum, pstring drivername) NT_PRINTER_INFO_LEVEL *info = NULL; BOOL in_tdb = False; - get_a_printer (&info, 2, lp_servicename(snum)); + get_a_printer (NULL, &info, 2, lp_servicename(snum)); if (info != NULL) { pstrcpy( drivername, info->info_2->drivername); in_tdb = True; @@ -522,7 +522,7 @@ static void fill_printq_info_52(connection_struct *conn, int snum, NT_PRINTER_DRIVER_INFO_LEVEL driver; NT_PRINTER_INFO_LEVEL *printer = NULL; - if ( !W_ERROR_IS_OK(get_a_printer( &printer, 2, lp_servicename(snum))) ) { + if ( !W_ERROR_IS_OK(get_a_printer( NULL, &printer, 2, lp_servicename(snum))) ) { DEBUG(3,("fill_printq_info_52: Failed to lookup printer [%s]\n", lp_servicename(snum))); goto err; @@ -679,7 +679,7 @@ static int get_printerdrivernumber(int snum) NT_PRINTER_DRIVER_INFO_LEVEL driver; NT_PRINTER_INFO_LEVEL *printer = NULL; - if ( !W_ERROR_IS_OK(get_a_printer( &printer, 2, lp_servicename(snum))) ) { + if ( !W_ERROR_IS_OK(get_a_printer( NULL, &printer, 2, lp_servicename(snum))) ) { DEBUG(3,("get_printerdrivernumber: Failed to lookup printer [%s]\n", lp_servicename(snum))); goto done; -- cgit From 64e53c9b22f23506acfd2fb4552b7c43129631a6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 23:28:28 +0000 Subject: Fix breakage done by myself yesterday. (This used to be commit f4492de2d668082df6ae06933d12a3cfe120d403) --- source3/client/client.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3') diff --git a/source3/client/client.c b/source3/client/client.c index b95d4d877c..5da12fd984 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -51,8 +51,7 @@ static int max_protocol = PROTOCOL_NT1; extern pstring user_socket_options; static int process_tok(fstring tok); -static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv); +static int cmd_help(void); /* 30 second timeout on most commands */ #define CLIENT_TIMEOUT (30*1000) @@ -980,8 +979,7 @@ static BOOL do_altname(char *name) /**************************************************************************** Exit client. ****************************************************************************/ -static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv) +static int cmd_quit(void) { cli_shutdown(cli); exit(0); @@ -2151,8 +2149,7 @@ static int process_tok(fstring tok) /**************************************************************************** help ****************************************************************************/ -static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - const char **argv) +static int cmd_help(void) { int i=0,j; fstring buf; -- cgit From 7d581bebd437cd66000a1cac4b74b1ec4408f672 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 23:30:46 +0000 Subject: Fix unused variable warning when ENCTYPE_ARCFOUR_HMAC is not defined. (This used to be commit 92abafa62894a125c5a09fc92f5056e4d8b51089) --- source3/libsmb/clikrb5.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3') diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c index 6b0c7ddaf2..5edc56daa9 100644 --- a/source3/libsmb/clikrb5.c +++ b/source3/libsmb/clikrb5.c @@ -367,7 +367,9 @@ failed: BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) { +#ifdef ENCTYPE_ARCFOUR_HMAC krb5_keyblock *skey; +#endif BOOL ret = False; memset(session_key, 0, 16); -- cgit From 991f6cc3c13cdeb8d7cf0dea25af29bbc7987c64 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 23:34:57 +0000 Subject: More const fixes and flow on fixes from yesterday's const-fest. (This used to be commit 018733eedd7897e6811e8461c07e3acf418c0e09) --- source3/rpc_client/cli_dfs.c | 12 ++++--- source3/rpc_client/cli_lsarpc.c | 5 +-- source3/rpc_client/cli_netlogon.c | 2 +- source3/rpc_client/cli_spoolss.c | 17 +++++----- source3/rpc_client/cli_srvsvc.c | 7 +++-- source3/rpc_parse/parse_dfs.c | 13 ++++---- source3/rpc_parse/parse_spoolss.c | 14 +++++---- source3/rpcclient/cmd_dfs.c | 16 +++++----- source3/rpcclient/cmd_ds.c | 2 +- source3/rpcclient/cmd_netlogon.c | 12 +++---- source3/rpcclient/cmd_reg.c | 4 +-- source3/rpcclient/cmd_spoolss.c | 66 +++++++++++++++++++-------------------- source3/rpcclient/cmd_srvsvc.c | 8 ++--- source3/rpcclient/rpcclient.c | 4 +-- source3/torture/samtest.c | 2 +- source3/torture/vfstest.c | 2 +- 16 files changed, 97 insertions(+), 89 deletions(-) (limited to 'source3') diff --git a/source3/rpc_client/cli_dfs.c b/source3/rpc_client/cli_dfs.c index 7fc27b9c3b..2136b69df0 100644 --- a/source3/rpc_client/cli_dfs.c +++ b/source3/rpc_client/cli_dfs.c @@ -67,8 +67,8 @@ NTSTATUS cli_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx, } NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *entrypath, char *servername, char *sharename, - char *comment, uint32 flags) + const char *entrypath, const char *servername, + const char *sharename, const char *comment, uint32 flags) { prs_struct qbuf, rbuf; DFS_Q_DFS_ADD q; @@ -111,7 +111,8 @@ NTSTATUS cli_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx, } NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *entrypath, char *servername, char *sharename) + const char *entrypath, const char *servername, + const char *sharename) { prs_struct qbuf, rbuf; DFS_Q_DFS_REMOVE q; @@ -153,8 +154,9 @@ NTSTATUS cli_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx, } NTSTATUS cli_dfs_get_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *entrypath, char *servername, char *sharename, - uint32 info_level, DFS_INFO_CTR *ctr) + const char *entrypath, const char *servername, + const char *sharename, uint32 info_level, + DFS_INFO_CTR *ctr) { prs_struct qbuf, rbuf; diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c index e878d02211..9002ad3d1b 100644 --- a/source3/rpc_client/cli_lsarpc.c +++ b/source3/rpc_client/cli_lsarpc.c @@ -805,7 +805,8 @@ NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx, /** Get privilege name */ NTSTATUS cli_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol, char *name, uint16 lang_id, uint16 lang_id_sys, + POLICY_HND *pol, const char *name, + uint16 lang_id, uint16 lang_id_sys, fstring description, uint16 *lang_id_desc) { prs_struct qbuf, rbuf; @@ -1050,7 +1051,7 @@ NTSTATUS cli_lsa_enum_privsaccount(struct cli_state *cli, TALLOC_CTX *mem_ctx, /** Get a privilege value given its name */ NTSTATUS cli_lsa_lookupprivvalue(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol, char *name, LUID *luid) + POLICY_HND *pol, const char *name, LUID *luid) { prs_struct qbuf, rbuf; LSA_Q_LOOKUPPRIVVALUE q; diff --git a/source3/rpc_client/cli_netlogon.c b/source3/rpc_client/cli_netlogon.c index b5ad798755..cbb09803af 100644 --- a/source3/rpc_client/cli_netlogon.c +++ b/source3/rpc_client/cli_netlogon.c @@ -489,7 +489,7 @@ NTSTATUS cli_netlogon_sam_deltas(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Logon domain user */ NTSTATUS cli_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *username, char *password, + const char *username, const char *password, int logon_type) { prs_struct qbuf, rbuf; diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index a1aa6664c1..bb6ce1b998 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -1243,8 +1243,8 @@ WERROR cli_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, */ WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *handle, uint32 level, char *form_name, - FORM *form) + POLICY_HND *handle, uint32 level, + const char *form_name, FORM *form) { prs_struct qbuf, rbuf; SPOOL_Q_SETFORM q; @@ -1305,8 +1305,8 @@ WERROR cli_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 offered, uint32 *needed, - POLICY_HND *handle, char *formname, uint32 level, - FORM_1 *form) + POLICY_HND *handle, const char *formname, + uint32 level, FORM_1 *form) { prs_struct qbuf, rbuf; SPOOL_Q_GETFORM q; @@ -1377,7 +1377,7 @@ WERROR cli_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, */ WERROR cli_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *handle, char *form_name) + POLICY_HND *handle, const char *form_name) { prs_struct qbuf, rbuf; SPOOL_Q_DELETEFORM q; @@ -1899,7 +1899,7 @@ WERROR cli_spoolss_enddocprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 offered, uint32 *needed, - POLICY_HND *hnd, char *valuename, + POLICY_HND *hnd, const char *valuename, REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; @@ -1953,8 +1953,9 @@ WERROR cli_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, WERROR cli_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 offered, uint32 *needed, - POLICY_HND *hnd, char *keyname, - char *valuename, REGISTRY_VALUE *value) + POLICY_HND *hnd, const char *keyname, + const char *valuename, + REGISTRY_VALUE *value) { prs_struct qbuf, rbuf; SPOOL_Q_GETPRINTERDATAEX q; diff --git a/source3/rpc_client/cli_srvsvc.c b/source3/rpc_client/cli_srvsvc.c index b6c6b377ff..6cd18f2e43 100644 --- a/source3/rpc_client/cli_srvsvc.c +++ b/source3/rpc_client/cli_srvsvc.c @@ -230,9 +230,10 @@ WERROR cli_srvsvc_net_share_del(struct cli_state *cli, TALLOC_CTX *mem_ctx, } WERROR cli_srvsvc_net_share_add(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *netname, uint32 type, char *remark, - uint32 perms, uint32 max_uses, uint32 num_uses, - char *path, char *passwd) + const char *netname, uint32 type, + const char *remark, uint32 perms, + uint32 max_uses, uint32 num_uses, + const char *path, const char *passwd) { prs_struct qbuf, rbuf; SRV_Q_NET_SHARE_ADD q; diff --git a/source3/rpc_parse/parse_dfs.c b/source3/rpc_parse/parse_dfs.c index ccd6d429fa..6f13500359 100644 --- a/source3/rpc_parse/parse_dfs.c +++ b/source3/rpc_parse/parse_dfs.c @@ -76,8 +76,8 @@ BOOL dfs_io_r_dfs_exist(const char *desc, DFS_R_DFS_EXIST *q_d, prs_struct *ps, Make a DFS_Q_DFS_REMOVE structure *******************************************************************/ -BOOL init_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, char *entrypath, - char *servername, char *sharename) +BOOL init_dfs_q_dfs_remove(DFS_Q_DFS_REMOVE *q_d, const char *entrypath, + const char *servername, const char *sharename) { DEBUG(5,("init_dfs_q_dfs_remove\n")); init_unistr2(&q_d->DfsEntryPath, entrypath, strlen(entrypath)+1); @@ -149,8 +149,9 @@ BOOL dfs_io_r_dfs_remove(const char *desc, DFS_R_DFS_REMOVE *r_d, prs_struct *ps Make a DFS_Q_DFS_ADD structure *******************************************************************/ -BOOL init_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, char *entrypath, char *servername, - char *sharename, char *comment, uint32 flags) +BOOL init_dfs_q_dfs_add(DFS_Q_DFS_ADD *q_d, const char *entrypath, + const char *servername, const char *sharename, + const char *comment, uint32 flags) { DEBUG(5,("init_dfs_q_dfs_add\n")); q_d->ptr_DfsEntryPath = q_d->ptr_ServerName = q_d->ptr_ShareName = 1; @@ -231,8 +232,8 @@ BOOL dfs_io_r_dfs_add(const char *desc, DFS_R_DFS_ADD *r_d, prs_struct *ps, int return True; } -BOOL init_dfs_q_dfs_get_info(DFS_Q_DFS_GET_INFO *q_d, char *entrypath, - char *servername, char *sharename, +BOOL init_dfs_q_dfs_get_info(DFS_Q_DFS_GET_INFO *q_d, const char *entrypath, + const char *servername, const char *sharename, uint32 info_level) { DEBUG(5,("init_dfs_q2_get_info\n")); diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c index a34740f9ff..47737908f0 100644 --- a/source3/rpc_parse/parse_spoolss.c +++ b/source3/rpc_parse/parse_spoolss.c @@ -1202,7 +1202,7 @@ BOOL make_spoolss_q_deleteprinterdriver( BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u, const POLICY_HND *handle, - char *valuename, uint32 size) + const char *valuename, uint32 size) { if (q_u == NULL) return False; @@ -1221,7 +1221,8 @@ BOOL make_spoolss_q_getprinterdata(SPOOL_Q_GETPRINTERDATA *q_u, BOOL make_spoolss_q_getprinterdataex(SPOOL_Q_GETPRINTERDATAEX *q_u, const POLICY_HND *handle, - char *keyname, char *valuename, uint32 size) + const char *keyname, + const char *valuename, uint32 size) { if (q_u == NULL) return False; @@ -7503,7 +7504,7 @@ BOOL make_spoolss_q_addform(SPOOL_Q_ADDFORM *q_u, POLICY_HND *handle, ********************************************************************/ BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle, - int level, char *form_name, FORM *form) + int level, const char *form_name, FORM *form) { memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); q_u->level = level; @@ -7518,7 +7519,8 @@ BOOL make_spoolss_q_setform(SPOOL_Q_SETFORM *q_u, POLICY_HND *handle, * init a structure. ********************************************************************/ -BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, char *form) +BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, + const char *form) { memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); init_unistr2(&q_u->name, form, strlen(form) + 1); @@ -7530,8 +7532,8 @@ BOOL make_spoolss_q_deleteform(SPOOL_Q_DELETEFORM *q_u, POLICY_HND *handle, char ********************************************************************/ BOOL make_spoolss_q_getform(SPOOL_Q_GETFORM *q_u, POLICY_HND *handle, - char *formname, uint32 level, NEW_BUFFER *buffer, - uint32 offered) + const char *formname, uint32 level, + NEW_BUFFER *buffer, uint32 offered) { memcpy(&q_u->handle, handle, sizeof(POLICY_HND)); q_u->level = level; diff --git a/source3/rpcclient/cmd_dfs.c b/source3/rpcclient/cmd_dfs.c index e3c4b77645..715174c824 100644 --- a/source3/rpcclient/cmd_dfs.c +++ b/source3/rpcclient/cmd_dfs.c @@ -25,7 +25,7 @@ /* Check DFS is supported by the remote server */ static NTSTATUS cmd_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { BOOL dfs_exists; NTSTATUS result; @@ -44,10 +44,10 @@ static NTSTATUS cmd_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx, } static NTSTATUS cmd_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result; - char *entrypath, *servername, *sharename, *comment; + const char *entrypath, *servername, *sharename, *comment; uint32 flags = 0; if (argc != 5) { @@ -68,10 +68,10 @@ static NTSTATUS cmd_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx, } static NTSTATUS cmd_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result; - char *entrypath, *servername, *sharename; + const char *entrypath, *servername, *sharename; if (argc != 4) { printf("Usage: %s entrypath servername sharename\n", argv[0]); @@ -169,7 +169,7 @@ static void display_dfs_info_ctr(DFS_INFO_CTR *ctr) /* Enumerate dfs shares */ static NTSTATUS cmd_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { DFS_INFO_CTR ctr; NTSTATUS result; @@ -192,10 +192,10 @@ static NTSTATUS cmd_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, } static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result; - char *entrypath, *servername, *sharename; + const char *entrypath, *servername, *sharename; uint32 info_level = 1; DFS_INFO_CTR ctr; diff --git a/source3/rpcclient/cmd_ds.c b/source3/rpcclient/cmd_ds.c index 946015c1e3..9de6d6a9ec 100644 --- a/source3/rpcclient/cmd_ds.c +++ b/source3/rpcclient/cmd_ds.c @@ -26,7 +26,7 @@ static NTSTATUS cmd_ds_dsrole_getprimarydominfo(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { NTSTATUS result; DS_DOMINFO_CTR ctr; diff --git a/source3/rpcclient/cmd_netlogon.c b/source3/rpcclient/cmd_netlogon.c index 53a926d52b..407bff3735 100644 --- a/source3/rpcclient/cmd_netlogon.c +++ b/source3/rpcclient/cmd_netlogon.c @@ -24,7 +24,7 @@ static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { uint32 query_level = 1; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -47,7 +47,7 @@ static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli, static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { #if 0 uint32 query_level = 1; @@ -143,7 +143,7 @@ static void display_sam_sync(uint32 num_deltas, SAM_DELTA_HDR *hdr_deltas, static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; unsigned char trust_passwd[16]; @@ -204,7 +204,7 @@ static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli, static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; unsigned char trust_passwd[16]; @@ -266,12 +266,12 @@ static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli, static NTSTATUS cmd_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { unsigned char trust_passwd[16]; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; int logon_type = NET_LOGON_TYPE; - char *username, *password; + const char *username, *password; uint32 neg_flags = 0x000001ff; int auth_level = 2; diff --git a/source3/rpcclient/cmd_reg.c b/source3/rpcclient/cmd_reg.c index 5d29b4c51a..19c0e7f71f 100644 --- a/source3/rpcclient/cmd_reg.c +++ b/source3/rpcclient/cmd_reg.c @@ -895,7 +895,7 @@ static void cmd_reg_get_key_sec(struct client_info *info) nt registry shutdown ****************************************************************************/ static NTSTATUS cmd_reg_shutdown(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; fstring msg; @@ -950,7 +950,7 @@ abort a shutdown ****************************************************************************/ static NTSTATUS cmd_reg_abort_shutdown(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { NTSTATUS result = NT_STATUS_UNSUCCESSFUL; diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index 66f2e8dc99..9f6f539e19 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -86,7 +86,7 @@ BOOL get_short_archi(char *short_archi, const char *long_archi) */ static NTSTATUS cmd_spoolss_not_implemented(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { printf ("(*) This command is not currently implemented.\n"); return NT_STATUS_OK; @@ -98,7 +98,7 @@ static NTSTATUS cmd_spoolss_not_implemented(struct cli_state *cli, */ static NTSTATUS cmd_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR werror; fstring printername; @@ -300,7 +300,7 @@ static void display_print_info_3(PRINTER_INFO_3 *i3) static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; uint32 info_level = 1; @@ -405,7 +405,7 @@ static void display_port_info_2(PORT_INFO_2 *i2) static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { WERROR result; uint32 needed, info_level = 1; @@ -457,7 +457,7 @@ static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli, */ static NTSTATUS cmd_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR result; @@ -527,7 +527,7 @@ static NTSTATUS cmd_spoolss_setprinter(struct cli_state *cli, */ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR result; @@ -646,7 +646,7 @@ static void display_reg_value(REGISTRY_VALUE value) */ static NTSTATUS cmd_spoolss_getprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR result; @@ -655,7 +655,7 @@ static NTSTATUS cmd_spoolss_getprinterdata(struct cli_state *cli, servername, user; uint32 needed; - char *valuename; + const char *valuename; REGISTRY_VALUE value; if (argc != 3) { @@ -690,7 +690,7 @@ static NTSTATUS cmd_spoolss_getprinterdata(struct cli_state *cli, /* Get printer info */ result = cli_spoolss_getprinterdata(cli, mem_ctx, 0, &needed, - &pol, valuename, &value); + &pol, valuename, &value); if (W_ERROR_V(result) == ERRmoredata) result = cli_spoolss_getprinterdata( @@ -717,7 +717,7 @@ static NTSTATUS cmd_spoolss_getprinterdata(struct cli_state *cli, */ static NTSTATUS cmd_spoolss_getprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR result; @@ -726,7 +726,7 @@ static NTSTATUS cmd_spoolss_getprinterdataex(struct cli_state *cli, servername, user; uint32 needed; - char *valuename, *keyname; + const char *valuename, *keyname; REGISTRY_VALUE value; if (argc != 4) { @@ -902,7 +902,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) */ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR werror; @@ -992,7 +992,7 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, */ static NTSTATUS cmd_spoolss_enum_drivers(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR werror; uint32 info_level = 1; @@ -1080,7 +1080,7 @@ static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1) */ static NTSTATUS cmd_spoolss_getdriverdir(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; fstring env; @@ -1145,7 +1145,7 @@ void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch) wrapper for strtok to get the next parameter from a delimited list. Needed to handle the empty parameter string denoted by "NULL" *************************************************************************/ -static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest) +static char* get_driver_3_param (const char* str, const char* delim, UNISTR* dest) { char *ptr; @@ -1175,7 +1175,7 @@ static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest) static BOOL init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info, - char *args + const char *args ) { char *str, *str2; @@ -1224,7 +1224,7 @@ static BOOL init_drv_info_3_members ( static NTSTATUS cmd_spoolss_addprinterdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; uint32 level = 3; @@ -1277,7 +1277,7 @@ static NTSTATUS cmd_spoolss_addprinterdriver(struct cli_state *cli, static NTSTATUS cmd_spoolss_addprinterex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; uint32 level = 2; @@ -1334,7 +1334,7 @@ static NTSTATUS cmd_spoolss_addprinterex(struct cli_state *cli, static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND pol; WERROR result; @@ -1412,7 +1412,7 @@ done: static NTSTATUS cmd_spoolss_deletedriver(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; fstring servername; @@ -1454,7 +1454,7 @@ static NTSTATUS cmd_spoolss_deletedriver(struct cli_state *cli, static NTSTATUS cmd_spoolss_getprintprocdir(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; char *servername = NULL, *environment = NULL; @@ -1497,7 +1497,7 @@ static NTSTATUS cmd_spoolss_getprintprocdir(struct cli_state *cli, /* Add a form */ static NTSTATUS cmd_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND handle; WERROR werror; @@ -1556,7 +1556,7 @@ static NTSTATUS cmd_spoolss_addform(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Set a form */ static NTSTATUS cmd_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND handle; WERROR werror; @@ -1614,7 +1614,7 @@ static NTSTATUS cmd_spoolss_setform(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Get a form */ static NTSTATUS cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { POLICY_HND handle; WERROR werror; @@ -1678,7 +1678,7 @@ static NTSTATUS cmd_spoolss_getform(struct cli_state *cli, TALLOC_CTX *mem_ctx, static NTSTATUS cmd_spoolss_deleteform(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND handle; WERROR werror; @@ -1725,7 +1725,7 @@ static NTSTATUS cmd_spoolss_deleteform(struct cli_state *cli, static NTSTATUS cmd_spoolss_enum_forms(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { POLICY_HND handle; WERROR werror; @@ -1793,7 +1793,7 @@ static NTSTATUS cmd_spoolss_enum_forms(struct cli_state *cli, static NTSTATUS cmd_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { WERROR result; uint32 needed; @@ -1912,7 +1912,7 @@ static void display_job_info_2(JOB_INFO_2 *job) static NTSTATUS cmd_spoolss_enum_jobs(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { WERROR result; uint32 needed, level = 1, num_jobs, i; @@ -1987,7 +1987,7 @@ done: static NTSTATUS cmd_spoolss_enum_data( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { WERROR result; uint32 i=0, val_needed, data_needed; @@ -2046,14 +2046,14 @@ done: static NTSTATUS cmd_spoolss_enum_data_ex( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { WERROR result; uint32 needed, i; BOOL got_hnd = False; pstring printername; fstring servername, user; - char *keyname = NULL; + const char *keyname = NULL; POLICY_HND hnd; REGVAL_CTR ctr; @@ -2111,7 +2111,7 @@ done: static NTSTATUS cmd_spoolss_enum_printerkey( struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { WERROR result; uint32 needed, returned; @@ -2183,7 +2183,7 @@ done: static NTSTATUS cmd_spoolss_rffpcnex(struct cli_state *cli, TALLOC_CTX *mem_ctx, int argc, - char **argv) + const char **argv) { fstring servername, printername; POLICY_HND hnd; diff --git a/source3/rpcclient/cmd_srvsvc.c b/source3/rpcclient/cmd_srvsvc.c index 10fdfd7437..8597c7bc2e 100644 --- a/source3/rpcclient/cmd_srvsvc.c +++ b/source3/rpcclient/cmd_srvsvc.c @@ -181,7 +181,7 @@ static void display_srv_info_102(SRV_INFO_102 *sv102) /* Server query info */ static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { uint32 info_level = 101; SRV_INFO_CTR ctr; @@ -248,7 +248,7 @@ static void display_share_info_2(SRV_SHARE_INFO_2 *info2) static NTSTATUS cmd_srvsvc_net_share_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { uint32 info_level = 2; SRV_SHARE_INFO_CTR ctr; @@ -294,7 +294,7 @@ static NTSTATUS cmd_srvsvc_net_share_enum(struct cli_state *cli, static NTSTATUS cmd_srvsvc_net_remote_tod(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { TIME_OF_DAY_INFO tod; WERROR result; @@ -316,7 +316,7 @@ static NTSTATUS cmd_srvsvc_net_remote_tod(struct cli_state *cli, static NTSTATUS cmd_srvsvc_net_file_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { uint32 info_level = 3; SRV_FILE_INFO_CTR ctr; diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 5803055598..127506fb39 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -304,7 +304,7 @@ static NTSTATUS cmd_listcommands(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Display help on commands */ static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { struct cmd_list *tmp; struct cmd_set *tmp_set; @@ -381,7 +381,7 @@ static NTSTATUS cmd_debuglevel(struct cli_state *cli, TALLOC_CTX *mem_ctx, } static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { exit(0); return NT_STATUS_OK; /* NOTREACHED */ diff --git a/source3/torture/samtest.c b/source3/torture/samtest.c index a1ccec098b..0de2e5d288 100644 --- a/source3/torture/samtest.c +++ b/source3/torture/samtest.c @@ -73,7 +73,7 @@ static NTSTATUS cmd_conf(struct samtest_state *sam, TALLOC_CTX *mem_ctx, /* Display help on commands */ static NTSTATUS cmd_help(struct samtest_state *st, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { struct cmd_list *tmp; struct cmd_set *tmp_set; diff --git a/source3/torture/vfstest.c b/source3/torture/vfstest.c index fd1f83109e..04f31656d3 100644 --- a/source3/torture/vfstest.c +++ b/source3/torture/vfstest.c @@ -124,7 +124,7 @@ static NTSTATUS cmd_conf(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, /* Display help on commands */ static NTSTATUS cmd_help(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, - int argc, char **argv) + int argc, const char **argv) { struct cmd_list *tmp; struct cmd_set *tmp_set; -- cgit From f9d577ac099974f58522c1c5c42e5804a62c8e0b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 25 Feb 2003 23:35:25 +0000 Subject: Fix compiler warning. (This used to be commit 0308f24ad209a28799b36d041be2dc2be2b2dac8) --- source3/utils/profiles.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c index b4087cf6cf..4f40b93810 100644 --- a/source3/utils/profiles.c +++ b/source3/utils/profiles.c @@ -391,7 +391,7 @@ typedef struct acl_struct { #define OFF(f) (0x1000 + (f) + 4) -void print_sid(DOM_SID *sid); +static void print_sid(DOM_SID *sid); int verbose = 1; DOM_SID old_sid, new_sid; -- cgit From b906a9df75b6bdc6fe166e9aa5a8aa398176a518 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 26 Feb 2003 00:52:41 +0000 Subject: Merge from appliance: >Another hopeful fix for CR#1168. Change the RPC used in querying >domain users from QueryDispInfo to EnumDomainUsers. Hopefully this >will fix the random dropouts that keep occuring when listing large >domains. > >My thought is that since QueryDispInfo is only used in the NT user >manager it may have a bug with large domains. A more commonly used >RPC may not have such problems. (This used to be commit 0501b7d0b12fa8063ffe6a9d4ecc3391d0c2f45d) --- source3/nsswitch/winbindd_rpc.c | 57 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c index 48f528f520..90d8e4f616 100644 --- a/source3/nsswitch/winbindd_rpc.c +++ b/source3/nsswitch/winbindd_rpc.c @@ -3,7 +3,7 @@ Winbind rpc backend functions - Copyright (C) Tim Potter 2000-2001 + Copyright (C) Tim Potter 2000-2001,2003 Copyright (C) Andrew Tridgell 2001 This program is free software; you can redistribute it and/or modify @@ -39,18 +39,17 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, POLICY_HND dom_pol; BOOL got_dom_pol = False; uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED; - int i, loop_count = 0; - int retry; + int i, start_idx, retry; DEBUG(3,("rpc: query_user_list\n")); *num_entries = 0; *info = NULL; - /* Get sam handle */ - retry = 0; do { + /* Get sam handle */ + if (!(hnd = cm_get_sam_handle(domain->name))) goto done; @@ -66,50 +65,39 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, got_dom_pol = True; - i = 0; + i = start_idx = 0; do { - SAM_DISPINFO_CTR ctr; - SAM_DISPINFO_1 info1; - uint32 count = 0, start=i, max_entries, max_size; - int j; TALLOC_CTX *ctx2; + char **dom_users; + uint32 num_dom_users, *dom_rids, j, size = 0xffff; + uint16 acb_mask = ACB_NORMAL; - ctr.sam.info1 = &info1; - - ctx2 = talloc_init("winbindd dispinfo"); - if (!ctx2) { + if (!(ctx2 = talloc_init("winbindd enum_users"))) { result = NT_STATUS_NO_MEMORY; goto done; - } - - get_query_dispinfo_params( - loop_count, &max_entries, &max_size); - - /* Query display info level 1 */ - result = cli_samr_query_dispinfo( - hnd->cli, ctx2, &dom_pol, &start, 1, &count, - max_entries, max_size, &ctr); + } - loop_count++; + result = cli_samr_enum_dom_users( + hnd->cli, ctx2, &dom_pol, &start_idx, acb_mask, + size, &dom_users, &dom_rids, &num_dom_users); - if (!NT_STATUS_IS_OK(result) && - !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) break; + *num_entries += num_dom_users; - (*num_entries) += count; + *info = talloc_realloc( + mem_ctx, *info, + (*num_entries) * sizeof(WINBIND_USERINFO)); - /* now map the result into the WINBIND_USERINFO structure */ - (*info) = talloc_realloc(mem_ctx, *info, - (*num_entries)*sizeof(WINBIND_USERINFO)); if (!(*info)) { result = NT_STATUS_NO_MEMORY; talloc_destroy(ctx2); goto done; } - for (j=0;j Date: Wed, 26 Feb 2003 06:19:16 +0000 Subject: init_valid_table: Fix a memory leak that would lose the dynamically-created valid table every time the configuration was reloaded. (This used to be commit e42b237d980461caf2dd2a8f82c17bf674facb7d) --- source3/lib/util_unistr.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source3') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 522ab7eb40..c666155f9f 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -105,27 +105,34 @@ static int check_dos_char(smb_ucs2_t c) **/ void init_valid_table(void) { - static int initialised; static int mapped_file; int i; const char *allowed = ".!#$%&'()_-@^`~"; + uint8 *valid_file; - if (initialised && mapped_file) return; - initialised = 1; + if (mapped_file) { + /* Can't unmap files, so stick with what we have */ + return; + } - valid_table = map_file(lib_path("valid.dat"), 0x10000); - if (valid_table) { + valid_file = map_file(lib_path("valid.dat"), 0x10000); + if (valid_file) { + valid_table = valid_file; mapped_file = 1; return; } - /* Otherwise, using a dynamically loaded one. */ + /* Otherwise, we're using a dynamically created valid_table. + * It might need to be regenerated if the code page changed. + * We know that we're not using a mapped file, so we can + * free() the old one. */ if (valid_table) free(valid_table); DEBUG(2,("creating default valid table\n")); valid_table = malloc(0x10000); - for (i=0;i<128;i++) valid_table[i] = isalnum(i) || - strchr(allowed,i); + for (i=0;i<128;i++) + valid_table[i] = isalnum(i) || strchr(allowed,i); + for (;i<0x10000;i++) { smb_ucs2_t c; SSVAL(&c, 0, i); -- cgit From cee64b535355ed14aa8c9a30f51432563391ea34 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Feb 2003 12:21:01 +0000 Subject: Kill RID-only and domain+RID madness from winbind. Now we deal with SIDs in almost all of winbind (a couple of limited exceptions remain, but I'm looking into them - they use non-winbind structs ATM). This has particular benifits in returning out-of-domain SIDs for group membership (Need to look into this a bit more) as well as general code quality. This also removes much of the complexity from the idmap interface, which now only deals with mapping IDs, not with SID->domain translations. Breifly tested, but needs more. Fixes some valgrind-found bugs from my previous commit. Winbind cache chagned to using SID strings in some places, as I could not follow exactly how to save and restore multiple packed sids properly. Andrew Bartlett (This used to be commit 9247cf08c40f016a924d600ac906cfc6a7016777) --- source3/nsswitch/winbindd.h | 28 +++--- source3/nsswitch/winbindd_ads.c | 178 ++++++++++++++++++---------------- source3/nsswitch/winbindd_cache.c | 159 +++++++++++++++++------------- source3/nsswitch/winbindd_group.c | 114 +++++++++++----------- source3/nsswitch/winbindd_idmap.c | 82 ---------------- source3/nsswitch/winbindd_idmap_tdb.c | 78 --------------- source3/nsswitch/winbindd_rpc.c | 93 ++++++++++++------ source3/nsswitch/winbindd_user.c | 56 +++++------ source3/nsswitch/winbindd_util.c | 29 +++++- 9 files changed, 377 insertions(+), 440 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd.h b/source3/nsswitch/winbindd.h index a498b76626..8bd8a83748 100644 --- a/source3/nsswitch/winbindd.h +++ b/source3/nsswitch/winbindd.h @@ -63,7 +63,8 @@ struct getent_state { struct getpwent_user { fstring name; /* Account name */ fstring gecos; /* User information */ - uint32 user_rid, group_rid; /* NT user and group rids */ + DOM_SID user_sid; /* NT user and primary group SIDs */ + DOM_SID group_sid; }; /* Server state structure */ @@ -81,8 +82,8 @@ extern struct winbindd_state server_state; /* Server information */ typedef struct { char *acct_name; char *full_name; - uint32 user_rid; - uint32 group_rid; /* primary group */ + DOM_SID *user_sid; /* NT user and primary group SIDs */ + DOM_SID *group_sid; } WINBIND_USERINFO; /* Structures to hold per domain information */ @@ -138,6 +139,7 @@ struct winbindd_methods { /* convert one user or group name to a sid */ NTSTATUS (*name_to_sid)(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, const char *name, DOM_SID *sid, enum SID_NAME_USE *type); @@ -149,10 +151,10 @@ struct winbindd_methods { char **name, enum SID_NAME_USE *type); - /* lookup user info for a given rid */ + /* lookup user info for a given SID */ NTSTATUS (*query_user)(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, + DOM_SID *user_sid, WINBIND_USERINFO *user_info); /* lookup all groups that a user is a member of. The backend @@ -160,14 +162,15 @@ struct winbindd_methods { function */ NTSTATUS (*lookup_usergroups)(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, - uint32 *num_groups, uint32 **user_gids); + DOM_SID *user_sid, + uint32 *num_groups, DOM_SID ***user_gids); /* find all members of the group with the specified group_rid */ NTSTATUS (*lookup_groupmem)(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 group_rid, uint32 *num_names, - uint32 **rid_mem, char ***names, + DOM_SID *group_sid, + uint32 *num_names, + DOM_SID ***sid_mem, char ***names, uint32 **name_types); /* return the current global sequence number */ @@ -207,13 +210,6 @@ struct idmap_methods { BOOL (*get_uid_from_sid)(DOM_SID *sid, uid_t *uid); BOOL (*get_gid_from_sid)(DOM_SID *sid, gid_t *gid); - BOOL (*get_rid_from_uid)(uid_t uid, uint32 *user_rid, - struct winbindd_domain **domain); - BOOL (*get_rid_from_gid)(gid_t gid, uint32 *group_rid, - struct winbindd_domain **domain); - BOOL (*get_uid_from_rid)(const char *dom_name, uint32 rid, uid_t *uid); - BOOL (*get_gid_from_rid)(const char *dom_name, uint32 rid, gid_t *gid); - /* Called when backend is unloaded */ BOOL (*close)(void); /* Called to dump backend status */ diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 22e4648f15..6c79e59bae 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -89,13 +89,6 @@ static ADS_STRUCT *ads_cached_connection(struct winbindd_domain *domain) return ads; } -/* useful utility */ -static void sid_from_rid(struct winbindd_domain *domain, uint32 rid, DOM_SID *sid) -{ - sid_copy(sid, &domain->sid); - sid_append_rid(sid, rid); -} - /* Query display info for a realm. This is the basic user list fn */ static NTSTATUS query_user_list(struct winbindd_domain *domain, @@ -144,7 +137,9 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { char *name, *gecos; DOM_SID sid; - uint32 rid, group; + DOM_SID *sid2; + DOM_SID *group_sid; + uint32 group; uint32 atype; if (!ads_pull_uint32(ads, msg, "sAMAccountType", &atype) || @@ -164,15 +159,20 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, continue; } - if (!sid_peek_check_rid(&domain->sid, &sid, &rid)) { - DEBUG(1,("No rid for %s !?\n", name)); - continue; + sid2 = talloc(mem_ctx, sizeof(*sid2)); + if (!sid2) { + status = NT_STATUS_NO_MEMORY; + goto done; } + sid_copy(sid2, &sid); + + group_sid = rid_to_talloced_sid(domain, mem_ctx, group); + (*info)[i].acct_name = name; (*info)[i].full_name = gecos; - (*info)[i].user_rid = rid; - (*info)[i].group_rid = group; + (*info)[i].user_sid = sid2; + (*info)[i].group_sid = group_sid; i++; } @@ -297,6 +297,7 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain, /* convert a single name to a sid in a domain */ static NTSTATUS name_to_sid(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, const char *name, DOM_SID *sid, enum SID_NAME_USE *type) @@ -329,13 +330,13 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain, } -/* convert a DN to a name, rid and name type +/* convert a DN to a name, SID and name type this might become a major speed bottleneck if groups have lots of users, in which case we could cache the results */ static BOOL dn_lookup(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, const char *dn, - char **name, uint32 *name_type, uint32 *rid) + char **name, uint32 *name_type, DOM_SID *sid) { char *exp; void *res = NULL; @@ -343,7 +344,6 @@ static BOOL dn_lookup(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, "objectSid", "sAMAccountType", NULL}; ADS_STATUS rc; uint32 atype; - DOM_SID sid; char *escaped_dn = escape_ldap_string_alloc(dn); if (!escaped_dn) { @@ -366,8 +366,7 @@ static BOOL dn_lookup(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, } (*name_type) = ads_atype_map(atype); - if (!ads_pull_sid(ads, res, "objectSid", &sid) || - !sid_peek_rid(&sid, rid)) { + if (!ads_pull_sid(ads, res, "objectSid", sid)) { goto failed; } @@ -382,60 +381,63 @@ failed: /* Lookup user information from a rid */ static NTSTATUS query_user(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, + DOM_SID *sid, WINBIND_USERINFO *info) { ADS_STRUCT *ads = NULL; const char *attrs[] = {"userPrincipalName", "sAMAccountName", - "name", "objectSid", + "name", "primaryGroupID", NULL}; ADS_STATUS rc; int count; void *msg = NULL; char *exp; - DOM_SID sid; char *sidstr; + uint32 group_rid; NTSTATUS status = NT_STATUS_UNSUCCESSFUL; + DOM_SID *sid2; + fstring sid_string; DEBUG(3,("ads: query_user\n")); - sid_from_rid(domain, user_rid, &sid); - ads = ads_cached_connection(domain); if (!ads) goto done; - sidstr = sid_binstring(&sid); + sidstr = sid_binstring(sid); asprintf(&exp, "(objectSid=%s)", sidstr); rc = ads_search_retry(ads, &msg, exp, attrs); free(exp); free(sidstr); if (!ADS_ERR_OK(rc)) { - DEBUG(1,("query_user(rid=%d) ads_search: %s\n", user_rid, ads_errstr(rc))); + DEBUG(1,("query_user(sid=%s) ads_search: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc))); goto done; } count = ads_count_replies(ads, msg); if (count != 1) { - DEBUG(1,("query_user(rid=%d): Not found\n", user_rid)); + DEBUG(1,("query_user(sid=%s): Not found\n", sid_to_string(sid_string, sid))); goto done; } info->acct_name = ads_pull_username(ads, mem_ctx, msg); info->full_name = ads_pull_string(ads, mem_ctx, msg, "name"); - if (!ads_pull_sid(ads, msg, "objectSid", &sid)) { - DEBUG(1,("No sid for %d !?\n", user_rid)); - goto done; - } - if (!ads_pull_uint32(ads, msg, "primaryGroupID", &info->group_rid)) { - DEBUG(1,("No primary group for %d !?\n", user_rid)); + + if (!ads_pull_uint32(ads, msg, "primaryGroupID", &group_rid)) { + DEBUG(1,("No primary group for %s !?\n", sid_to_string(sid_string, sid))); goto done; } - if (!sid_peek_check_rid(&domain->sid,&sid, &info->user_rid)) { - DEBUG(1,("No rid for %d !?\n", user_rid)); + sid2 = talloc(mem_ctx, sizeof(*sid2)); + if (!sid2) { + status = NT_STATUS_NO_MEMORY; goto done; } + sid_copy(sid2, sid); + + info->user_sid = sid2; + + info->group_sid = rid_to_talloced_sid(domain, mem_ctx, group_rid); status = NT_STATUS_OK; @@ -451,8 +453,8 @@ done: static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, const char *user_dn, - uint32 primary_group, - uint32 *num_groups, uint32 **user_gids) + DOM_SID *primary_group, + uint32 *num_groups, DOM_SID ***user_gids) { ADS_STATUS rc; NTSTATUS status = NT_STATUS_UNSUCCESSFUL; @@ -489,47 +491,48 @@ static NTSTATUS lookup_usergroups_alt(struct winbindd_domain *domain, goto done; } - (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1)); (*user_gids)[0] = primary_group; *num_groups = 1; for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { - uint32 rid; DOM_SID group_sid; - fstring sid_string; if (!ads_pull_sid(ads, msg, "objectSid", &group_sid)) { DEBUG(1,("No sid for this group ?!?\n")); continue; } - if (!sid_peek_check_rid(&domain->sid, &group_sid, &rid)) { - DEBUG(5,("sid for %s is out of domain or invalid\n", sid_to_string(sid_string, &group_sid))); - continue; - } - if (rid == primary_group) continue; + if (sid_equal(&group_sid, primary_group)) continue; - (*user_gids)[*num_groups] = rid; + (*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids)); + if (!(*user_gids)[*num_groups]) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + sid_copy((*user_gids)[*num_groups], &group_sid); + (*num_groups)++; } - if (res) ads_msgfree(ads, res); - if (msg) ads_msgfree(ads, msg); - status = NT_STATUS_OK; DEBUG(3,("ads lookup_usergroups (alt) for dn=%s\n", user_dn)); done: + if (res) ads_msgfree(ads, res); + if (msg) ads_msgfree(ads, msg); + return status; } /* Lookup groups a user is a member of. */ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, - uint32 *num_groups, uint32 **user_gids) + DOM_SID *sid, + uint32 *num_groups, DOM_SID ***user_gids) { ADS_STRUCT *ads = NULL; const char *attrs[] = {"distinguishedName", NULL}; @@ -541,27 +544,26 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, char *user_dn; DOM_SID *sids; int i; - uint32 primary_group; - DOM_SID sid; + DOM_SID *primary_group; + uint32 primary_group_rid; char *sidstr; + fstring sid_string; NTSTATUS status = NT_STATUS_UNSUCCESSFUL; DEBUG(3,("ads: lookup_usergroups\n")); *num_groups = 0; - sid_from_rid(domain, user_rid, &sid); - ads = ads_cached_connection(domain); if (!ads) goto done; - if (!(sidstr = sid_binstring(&sid))) { - DEBUG(1,("lookup_usergroups(rid=%d) sid_binstring returned NULL\n", user_rid)); + if (!(sidstr = sid_binstring(sid))) { + DEBUG(1,("lookup_usergroups(sid=%s) sid_binstring returned NULL\n", sid_to_string(sid_string, sid))); status = NT_STATUS_NO_MEMORY; goto done; } if (asprintf(&exp, "(objectSid=%s)", sidstr) == -1) { free(sidstr); - DEBUG(1,("lookup_usergroups(rid=%d) asprintf failed!\n", user_rid)); + DEBUG(1,("lookup_usergroups(sid=%s) asprintf failed!\n", sid_to_string(sid_string, sid))); status = NT_STATUS_NO_MEMORY; goto done; } @@ -571,13 +573,13 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, free(sidstr); if (!ADS_ERR_OK(rc)) { - DEBUG(1,("lookup_usergroups(rid=%d) ads_search: %s\n", user_rid, ads_errstr(rc))); + DEBUG(1,("lookup_usergroups(sid=%s) ads_search: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc))); goto done; } user_dn = ads_pull_string(ads, mem_ctx, msg, "distinguishedName"); if (!user_dn) { - DEBUG(1,("lookup_usergroups(rid=%d) ads_search did not return a a distinguishedName!\n", user_rid)); + DEBUG(1,("lookup_usergroups(sid=%s) ads_search did not return a a distinguishedName!\n", sid_to_string(sid_string, sid))); goto done; } @@ -585,15 +587,17 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, rc = ads_search_retry_dn(ads, &msg, user_dn, attrs2); if (!ADS_ERR_OK(rc)) { - DEBUG(1,("lookup_usergroups(rid=%d) ads_search tokenGroups: %s\n", user_rid, ads_errstr(rc))); + DEBUG(1,("lookup_usergroups(sid=%s) ads_search tokenGroups: %s\n", sid_to_string(sid_string, sid), ads_errstr(rc))); goto done; } - if (!ads_pull_uint32(ads, msg, "primaryGroupID", &primary_group)) { - DEBUG(1,("%s: No primary group for rid=%d !?\n", domain->name, user_rid)); + if (!ads_pull_uint32(ads, msg, "primaryGroupID", &primary_group_rid)) { + DEBUG(1,("%s: No primary group for sid=%s !?\n", domain->name, sid_to_string(sid_string, sid))); goto done; } + primary_group = rid_to_talloced_sid(domain, mem_ctx, primary_group_rid); + count = ads_pull_sids(ads, mem_ctx, msg, "tokenGroups", &sids); if (msg) ads_msgfree(ads, msg); @@ -602,25 +606,30 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, unless we are talking to a buggy Win2k server */ if (count == 0) { return lookup_usergroups_alt(domain, mem_ctx, user_dn, - primary_group, - num_groups, user_gids); + primary_group, + num_groups, user_gids); } - (*user_gids) = (uint32 *)talloc_zero(mem_ctx, sizeof(uint32) * (count + 1)); + (*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1)); (*user_gids)[0] = primary_group; *num_groups = 1; for (i=0;isid, &sids[i-1], &rid)) continue; - if (rid == primary_group) continue; - (*user_gids)[*num_groups] = rid; + if (sid_equal(&sids[i], primary_group)) continue; + + (*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids)); + if (!(*user_gids)[*num_groups]) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + + sid_copy((*user_gids)[*num_groups], &sids[i]); (*num_groups)++; } status = NT_STATUS_OK; - DEBUG(3,("ads lookup_usergroups for rid=%d\n", user_rid)); + DEBUG(3,("ads lookup_usergroups for sid=%s\n", sid_to_string(sid_string, sid))); done: return status; } @@ -630,11 +639,10 @@ done: */ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 group_rid, uint32 *num_names, - uint32 **rid_mem, char ***names, + DOM_SID *group_sid, uint32 *num_names, + DOM_SID ***sid_mem, char ***names, uint32 **name_types) { - DOM_SID group_sid; ADS_STATUS rc; int count; void *res=NULL; @@ -645,14 +653,14 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, const char *attrs[] = {"member", NULL}; char **members; int i, num_members; + fstring sid_string; *num_names = 0; ads = ads_cached_connection(domain); if (!ads) goto done; - sid_from_rid(domain, group_rid, &group_sid); - sidstr = sid_binstring(&group_sid); + sidstr = sid_binstring(group_sid); /* search for all members of the group */ asprintf(&exp, "(objectSid=%s)",sidstr); @@ -684,24 +692,30 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, for (i=0;members[i];i++) /* noop */ ; num_members = i; - (*rid_mem) = talloc_zero(mem_ctx, sizeof(uint32) * num_members); - (*name_types) = talloc_zero(mem_ctx, sizeof(uint32) * num_members); - (*names) = talloc_zero(mem_ctx, sizeof(char *) * num_members); + (*sid_mem) = talloc_zero(mem_ctx, sizeof(**sid_mem) * num_members); + (*name_types) = talloc_zero(mem_ctx, sizeof(**name_types) * num_members); + (*names) = talloc_zero(mem_ctx, sizeof(**names) * num_members); for (i=0;iofs += len; } +static void centry_put_sid(struct cache_entry *centry, const DOM_SID *sid) +{ + int len; + fstring sid_string; + centry_put_string(centry, sid_to_string(sid_string, sid)); +} + /* start a centry for output. When finished, call centry_end() */ @@ -393,6 +420,7 @@ struct cache_entry *centry_start(struct winbindd_domain *domain, NTSTATUS status /* finish a centry and write it to the tdb */ +static void centry_end(struct cache_entry *centry, const char *format, ...) PRINTF_ATTRIBUTE(2,3); static void centry_end(struct cache_entry *centry, const char *format, ...) { va_list ap; @@ -412,39 +440,30 @@ static void centry_end(struct cache_entry *centry, const char *format, ...) free(kstr); } -/* form a sid from the domain plus rid */ -static DOM_SID *form_sid(struct winbindd_domain *domain, uint32 rid) -{ - static DOM_SID sid; - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); - return &sid; -} - -static void wcache_save_name_to_sid(struct winbindd_domain *domain, NTSTATUS status, - const char *name, DOM_SID *sid, enum SID_NAME_USE type) +static void wcache_save_name_to_sid(struct winbindd_domain *domain, + NTSTATUS status, + const char *name, DOM_SID *sid, + enum SID_NAME_USE type) { struct cache_entry *centry; uint32 len; fstring uname; + fstring sid_string; centry = centry_start(domain, status); if (!centry) return; - len = sid_size(sid); - centry_expand(centry, len); - centry_put_uint32(centry, type); - sid_linearize(centry->data + centry->ofs, len, sid); - centry->ofs += len; + centry_put_sid(centry, sid); fstrcpy(uname, name); strupper(uname); - centry_end(centry, "NS/%s/%s", domain->name, uname); + centry_end(centry, "NS/%s", sid_to_string(sid_string, sid)); centry_free(centry); } static void wcache_save_sid_to_name(struct winbindd_domain *domain, NTSTATUS status, - DOM_SID *sid, const char *name, enum SID_NAME_USE type, uint32 rid) + DOM_SID *sid, const char *name, enum SID_NAME_USE type) { struct cache_entry *centry; + fstring sid_string; centry = centry_start(domain, status); if (!centry) return; @@ -452,7 +471,7 @@ static void wcache_save_sid_to_name(struct winbindd_domain *domain, NTSTATUS sta centry_put_uint32(centry, type); centry_put_string(centry, name); } - centry_end(centry, "SN/%s/%d", domain->name, rid); + centry_end(centry, "SN/%s", sid_to_string(sid_string, sid)); centry_free(centry); } @@ -460,14 +479,15 @@ static void wcache_save_sid_to_name(struct winbindd_domain *domain, NTSTATUS sta static void wcache_save_user(struct winbindd_domain *domain, NTSTATUS status, WINBIND_USERINFO *info) { struct cache_entry *centry; + fstring sid_string; centry = centry_start(domain, status); if (!centry) return; centry_put_string(centry, info->acct_name); centry_put_string(centry, info->full_name); - centry_put_uint32(centry, info->user_rid); - centry_put_uint32(centry, info->group_rid); - centry_end(centry, "U/%s/%d", domain->name, info->user_rid); + centry_put_sid(centry, info->user_sid); + centry_put_sid(centry, info->group_sid); + centry_end(centry, "U/%s", sid_to_string(sid_string, info->user_sid)); centry_free(centry); } @@ -481,7 +501,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - int i; + unsigned int i; if (!cache->tdb) goto do_query; @@ -497,8 +517,8 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, for (i=0; i<(*num_entries); i++) { (*info)[i].acct_name = centry_string(centry, mem_ctx); (*info)[i].full_name = centry_string(centry, mem_ctx); - (*info)[i].user_rid = centry_uint32(centry); - (*info)[i].group_rid = centry_uint32(centry); + (*info)[i].user_sid = centry_sid(centry, mem_ctx); + (*info)[i].group_sid = centry_sid(centry, mem_ctx); } do_cached: @@ -524,18 +544,18 @@ do_query: for (i=0; i<(*num_entries); i++) { centry_put_string(centry, (*info)[i].acct_name); centry_put_string(centry, (*info)[i].full_name); - centry_put_uint32(centry, (*info)[i].user_rid); - centry_put_uint32(centry, (*info)[i].group_rid); + centry_put_sid(centry, (*info)[i].user_sid); + centry_put_sid(centry, (*info)[i].group_sid); if (cache->backend->consistent) { /* when the backend is consistent we can pre-prime some mappings */ wcache_save_name_to_sid(domain, NT_STATUS_OK, (*info)[i].acct_name, - form_sid(domain, (*info)[i].user_rid), + (*info)[i].user_sid, SID_NAME_USER); wcache_save_sid_to_name(domain, NT_STATUS_OK, - form_sid(domain, (*info)[i].user_rid), + (*info)[i].user_sid, (*info)[i].acct_name, - SID_NAME_USER, (*info)[i].user_rid); + SID_NAME_USER); wcache_save_user(domain, NT_STATUS_OK, &(*info)[i]); } } @@ -555,7 +575,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain, struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - int i; + unsigned int i; if (!cache->tdb) goto do_query; @@ -615,7 +635,7 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain, struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - int i; + unsigned int i; if (!cache->tdb) goto do_query; @@ -669,7 +689,7 @@ do_query: centry_put_string(centry, (*info)[i].acct_name); centry_put_string(centry, (*info)[i].acct_desc); centry_put_uint32(centry, (*info)[i].rid); - } + } centry_end(centry, "GL/%s/local", domain->name); centry_free(centry); @@ -679,6 +699,7 @@ skip_save: /* convert a single name to a sid in a domain */ static NTSTATUS name_to_sid(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, const char *name, DOM_SID *sid, enum SID_NAME_USE *type) @@ -687,6 +708,7 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain, struct cache_entry *centry = NULL; NTSTATUS status; fstring uname; + DOM_SID *sid2; if (!cache->tdb) goto do_query; @@ -695,7 +717,12 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain, centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname); if (!centry) goto do_query; *type = centry_uint32(centry); - sid_parse(centry->data + centry->ofs, centry->len - centry->ofs, sid); + sid2 = centry_sid(centry, mem_ctx); + if (!sid2) { + ZERO_STRUCTP(sid); + } else { + sid_copy(sid, sid2); + } status = centry->status; centry_free(centry); @@ -707,7 +734,7 @@ do_query: if (wcache_server_down(domain)) { return NT_STATUS_SERVER_DISABLED; } - status = cache->backend->name_to_sid(domain, name, sid, type); + status = cache->backend->name_to_sid(domain, mem_ctx, name, sid, type); /* and save it */ wcache_save_name_to_sid(domain, status, name, sid, *type); @@ -729,14 +756,11 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain, struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - uint32 rid = 0; - - if (!sid_peek_check_rid(&domain->sid, sid, &rid)) - return NT_STATUS_INVALID_PARAMETER; + fstring sid_string; if (!cache->tdb) goto do_query; - centry = wcache_fetch(cache, domain, "SN/%s/%d", domain->name, rid); + centry = wcache_fetch(cache, domain, "SN/%s", sid_to_string(sid_string, sid)); if (!centry) goto do_query; if (NT_STATUS_IS_OK(centry->status)) { *type = centry_uint32(centry); @@ -756,7 +780,7 @@ do_query: /* and save it */ refresh_sequence_number(domain, True); - wcache_save_sid_to_name(domain, status, sid, *name, *type, rid); + wcache_save_sid_to_name(domain, status, sid, *name, *type); wcache_save_name_to_sid(domain, status, *name, sid, *type); return status; @@ -766,22 +790,23 @@ do_query: /* Lookup user information from a rid */ static NTSTATUS query_user(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, + DOM_SID *user_sid, WINBIND_USERINFO *info) { struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; + fstring sid_string; if (!cache->tdb) goto do_query; - centry = wcache_fetch(cache, domain, "U/%s/%d", domain->name, user_rid); + centry = wcache_fetch(cache, domain, "U/%s", sid_to_string(sid_string, user_sid)); if (!centry) goto do_query; info->acct_name = centry_string(centry, mem_ctx); info->full_name = centry_string(centry, mem_ctx); - info->user_rid = centry_uint32(centry); - info->group_rid = centry_uint32(centry); + info->user_sid = centry_sid(centry, mem_ctx); + info->group_sid = centry_sid(centry, mem_ctx); status = centry->status; centry_free(centry); return status; @@ -793,7 +818,7 @@ do_query: return NT_STATUS_SERVER_DISABLED; } - status = cache->backend->query_user(domain, mem_ctx, user_rid, info); + status = cache->backend->query_user(domain, mem_ctx, user_sid, info); /* and save it */ refresh_sequence_number(domain, True); @@ -806,17 +831,18 @@ do_query: /* Lookup groups a user is a member of. */ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, - uint32 *num_groups, uint32 **user_gids) + DOM_SID *user_sid, + uint32 *num_groups, DOM_SID ***user_gids) { struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - int i; + unsigned int i; + fstring sid_string; if (!cache->tdb) goto do_query; - centry = wcache_fetch(cache, domain, "UG/%s/%d", domain->name, user_rid); + centry = wcache_fetch(cache, domain, "UG/%s", sid_to_string(sid_string, user_sid)); if (!centry) goto do_query; *num_groups = centry_uint32(centry); @@ -826,7 +852,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, (*user_gids) = talloc(mem_ctx, sizeof(**user_gids) * (*num_groups)); if (! (*user_gids)) smb_panic("lookup_usergroups out of memory"); for (i=0; i<(*num_groups); i++) { - (*user_gids)[i] = centry_uint32(centry); + (*user_gids)[i] = centry_sid(centry, mem_ctx); } do_cached: @@ -841,7 +867,7 @@ do_query: if (wcache_server_down(domain)) { return NT_STATUS_SERVER_DISABLED; } - status = cache->backend->lookup_usergroups(domain, mem_ctx, user_rid, num_groups, user_gids); + status = cache->backend->lookup_usergroups(domain, mem_ctx, user_sid, num_groups, user_gids); /* and save it */ refresh_sequence_number(domain, True); @@ -849,9 +875,9 @@ do_query: if (!centry) goto skip_save; centry_put_uint32(centry, *num_groups); for (i=0; i<(*num_groups); i++) { - centry_put_uint32(centry, (*user_gids)[i]); + centry_put_sid(centry, (*user_gids)[i]); } - centry_end(centry, "UG/%s/%d", domain->name, user_rid); + centry_end(centry, "UG/%s", sid_to_string(sid_string, user_sid)); centry_free(centry); skip_save: @@ -861,34 +887,35 @@ skip_save: static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 group_rid, uint32 *num_names, - uint32 **rid_mem, char ***names, + DOM_SID *group_sid, uint32 *num_names, + DOM_SID ***sid_mem, char ***names, uint32 **name_types) { struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS status; - int i; + unsigned int i; + fstring sid_string; if (!cache->tdb) goto do_query; - centry = wcache_fetch(cache, domain, "GM/%s/%d", domain->name, group_rid); + centry = wcache_fetch(cache, domain, "GM/%s", sid_to_string(sid_string, group_sid)); if (!centry) goto do_query; *num_names = centry_uint32(centry); if (*num_names == 0) goto do_cached; - (*rid_mem) = talloc(mem_ctx, sizeof(**rid_mem) * (*num_names)); + (*sid_mem) = talloc(mem_ctx, sizeof(**sid_mem) * (*num_names)); (*names) = talloc(mem_ctx, sizeof(**names) * (*num_names)); (*name_types) = talloc(mem_ctx, sizeof(**name_types) * (*num_names)); - if (! (*rid_mem) || ! (*names) || ! (*name_types)) { + if (! (*sid_mem) || ! (*names) || ! (*name_types)) { smb_panic("lookup_groupmem out of memory"); } for (i=0; i<(*num_names); i++) { - (*rid_mem)[i] = centry_uint32(centry); + (*sid_mem)[i] = centry_sid(centry, mem_ctx); (*names)[i] = centry_string(centry, mem_ctx); (*name_types)[i] = centry_uint32(centry); } @@ -900,7 +927,7 @@ do_cached: do_query: (*num_names) = 0; - (*rid_mem) = NULL; + (*sid_mem) = NULL; (*names) = NULL; (*name_types) = NULL; @@ -908,8 +935,8 @@ do_query: if (wcache_server_down(domain)) { return NT_STATUS_SERVER_DISABLED; } - status = cache->backend->lookup_groupmem(domain, mem_ctx, group_rid, num_names, - rid_mem, names, name_types); + status = cache->backend->lookup_groupmem(domain, mem_ctx, group_sid, num_names, + sid_mem, names, name_types); /* and save it */ refresh_sequence_number(domain, True); @@ -917,11 +944,11 @@ do_query: if (!centry) goto skip_save; centry_put_uint32(centry, *num_names); for (i=0; i<(*num_names); i++) { - centry_put_uint32(centry, (*rid_mem)[i]); + centry_put_sid(centry, (*sid_mem)[i]); centry_put_string(centry, (*names)[i]); centry_put_uint32(centry, (*name_types)[i]); } - centry_end(centry, "GM/%s/%d", domain->name, group_rid); + centry_end(centry, "GM/%s", sid_to_string(sid_string, group_sid)); centry_free(centry); skip_save: diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c index 94a826fbbc..d06db5943c 100644 --- a/source3/nsswitch/winbindd_group.c +++ b/source3/nsswitch/winbindd_group.c @@ -49,43 +49,44 @@ static BOOL fill_grent(struct winbindd_gr *gr, const char *dom_name, return True; } -/* Fill in the group membership field of a NT group given by group_rid */ +/* Fill in the group membership field of a NT group given by group_sid */ static BOOL fill_grent_mem(struct winbindd_domain *domain, - uint32 group_rid, + DOM_SID *group_sid, enum SID_NAME_USE group_name_type, int *num_gr_mem, char **gr_mem, int *gr_mem_len) { - uint32 *rid_mem = NULL, num_names = 0; + DOM_SID **sid_mem = NULL; + uint32 num_names = 0; uint32 *name_types = NULL; - int buf_len, buf_ndx, i; + unsigned int buf_len, buf_ndx, i; char **names = NULL, *buf; BOOL result = False; TALLOC_CTX *mem_ctx; NTSTATUS status; + fstring sid_string; if (!(mem_ctx = talloc_init("fill_grent_mem(%s)", domain->name))) return False; /* Initialise group membership information */ - DEBUG(10, ("group %s rid 0x%x\n", domain ? domain->name : "NULL", - group_rid)); + DEBUG(10, ("group SID %s\n", sid_to_string(sid_string, group_sid))); *num_gr_mem = 0; if (group_name_type != SID_NAME_DOM_GRP) { - DEBUG(1, ("rid %d in domain %s isn't a domain group\n", - group_rid, domain->name)); + DEBUG(1, ("SID %s in domain %s isn't a domain group\n", + sid_to_string(sid_string, group_sid), domain->name)); goto done; } /* Lookup group members */ - status = domain->methods->lookup_groupmem(domain, mem_ctx, group_rid, &num_names, - &rid_mem, &names, &name_types); + status = domain->methods->lookup_groupmem(domain, mem_ctx, group_sid, &num_names, + &sid_mem, &names, &name_types); if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("could not lookup membership for group rid %d in domain %s (error: %s)\n", - group_rid, domain->name, nt_errstr(status))); + DEBUG(1, ("could not lookup membership for group rid %s in domain %s (error: %s)\n", + sid_to_string(sid_string, group_sid), domain->name, nt_errstr(status))); goto done; } @@ -94,7 +95,7 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, if (DEBUGLEVEL >= 10) { for (i = 0; i < num_names; i++) - DEBUG(10, ("\t%20s %x %d\n", names[i], rid_mem[i], + DEBUG(10, ("\t%20s %s %d\n", names[i], sid_to_string(sid_string, sid_mem[i]), name_types[i])); } @@ -190,7 +191,6 @@ enum winbindd_result winbindd_getgrnam(struct winbindd_cli_state *state) DOM_SID group_sid; struct winbindd_domain *domain; enum SID_NAME_USE name_type; - uint32 group_rid; fstring name_domain, name_group; char *tmp, *gr_mem; gid_t gid; @@ -233,10 +233,6 @@ enum winbindd_result winbindd_getgrnam(struct winbindd_cli_state *state) return WINBINDD_ERROR; } - /* Fill in group structure */ - if (!sid_peek_check_rid(&domain->sid, &group_sid, &group_rid)) - return WINBINDD_ERROR; - if (!winbindd_idmap_get_gid_from_sid(&group_sid, &gid)) { DEBUG(1, ("error converting unix gid to sid\n")); return WINBINDD_ERROR; @@ -244,7 +240,7 @@ enum winbindd_result winbindd_getgrnam(struct winbindd_cli_state *state) if (!fill_grent(&state->response.data.gr, name_domain, name_group, gid) || - !fill_grent_mem(domain, group_rid, name_type, + !fill_grent_mem(domain, &group_sid, name_type, &state->response.data.gr.num_gr_mem, &gr_mem, &gr_mem_len)) { return WINBINDD_ERROR; @@ -269,7 +265,6 @@ enum winbindd_result winbindd_getgrgid(struct winbindd_cli_state *state) enum SID_NAME_USE name_type; fstring dom_name; fstring group_name; - uint32 group_rid; int gr_mem_len; char *gr_mem; @@ -284,17 +279,13 @@ enum winbindd_result winbindd_getgrgid(struct winbindd_cli_state *state) /* Get rid from gid */ - if (!winbindd_idmap_get_rid_from_gid(state->request.data.gid, - &group_rid, &domain)) { + if (!winbindd_idmap_get_sid_from_gid(state->request.data.gid, &group_sid)) { DEBUG(1, ("could not convert gid %d to rid\n", state->request.data.gid)); return WINBINDD_ERROR; } - /* Get sid from gid */ - - sid_copy(&group_sid, &domain->sid); - sid_append_rid(&group_sid, group_rid); + /* Get name from sid */ if (!winbindd_lookup_name_by_sid(&group_sid, dom_name, group_name, &name_type)) { DEBUG(1, ("could not lookup sid\n")); @@ -310,9 +301,16 @@ enum winbindd_result winbindd_getgrgid(struct winbindd_cli_state *state) /* Fill in group structure */ + domain = find_domain_from_sid(&group_sid); + + if (!domain) { + DEBUG(1,("Can't find domain from sid\n")); + return WINBINDD_ERROR; + } + if (!fill_grent(&state->response.data.gr, dom_name, group_name, state->request.data.gid) || - !fill_grent_mem(domain, group_rid, name_type, + !fill_grent_mem(domain, &group_sid, name_type, &state->response.data.gr.num_gr_mem, &gr_mem, &gr_mem_len)) return WINBINDD_ERROR; @@ -544,7 +542,9 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) gid_t group_gid; int gr_mem_len; char *gr_mem, *new_gr_mem_list; - + DOM_SID group_sid; + struct winbindd_domain *domain; + /* Do we need to fetch another chunk of groups? */ tryagain: @@ -578,16 +578,25 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) name_list = ent->sam_entries; + if (!(domain = + find_domain_from_name(ent->domain_name))) { + DEBUG(3, ("No such domain %s in winbindd_getgrent\n", ent->domain_name)); + result = False; + goto done; + } + /* Lookup group info */ - if (!winbindd_idmap_get_gid_from_rid( - ent->domain_name, - name_list[ent->sam_entry_index].rid, - &group_gid)) { + sid_copy(&group_sid, &domain->sid); + sid_append_rid(&group_sid, name_list[ent->sam_entry_index].rid); + + if (!winbindd_idmap_get_gid_from_sid( + &group_sid, + &group_gid)) { DEBUG(1, ("could not look up gid for group %s\n", name_list[ent->sam_entry_index].acct_name)); - + ent->sam_entry_index++; goto tryagain; } @@ -608,15 +617,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) /* Fill in group membership entry */ if (result) { - struct winbindd_domain *domain; - - if (!(domain = - find_domain_from_name(ent->domain_name))) { - DEBUG(3, ("No such domain %s in winbindd_getgrent\n", ent->domain_name)); - result = False; - goto done; - } - + DOM_SID member_sid; group_list[group_list_ndx].num_gr_mem = 0; gr_mem = NULL; gr_mem_len = 0; @@ -625,9 +626,11 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) if (state->request.cmd == WINBINDD_GETGRLST) { result = True; } else { + sid_copy(&member_sid, &domain->sid); + sid_append_rid(&member_sid, name_list[ent->sam_entry_index].rid); result = fill_grent_mem( domain, - name_list[ent->sam_entry_index].rid, + &member_sid, SID_NAME_DOM_GRP, &group_list[group_list_ndx].num_gr_mem, &gr_mem, &gr_mem_len); @@ -730,7 +733,7 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state) struct winbindd_domain *domain; char *extra_data = NULL; char *ted = NULL; - int extra_data_len = 0, i; + unsigned int extra_data_len = 0, i; DEBUG(3, ("[%5d]: list groups\n", state->pid)); @@ -805,13 +808,13 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) fstring name_domain, name_user; DOM_SID user_sid; enum SID_NAME_USE name_type; - uint32 user_rid, num_groups, num_gids; + uint32 num_groups, num_gids; NTSTATUS status; - uint32 *user_gids; + DOM_SID **user_gids; struct winbindd_domain *domain; enum winbindd_result result = WINBINDD_ERROR; gid_t *gid_list; - int i; + unsigned int i; TALLOC_CTX *mem_ctx; /* Ensure null termination */ @@ -852,9 +855,9 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) goto done; } - sid_split_rid(&user_sid, &user_rid); - - status = domain->methods->lookup_usergroups(domain, mem_ctx, user_rid, &num_groups, &user_gids); + status = domain->methods->lookup_usergroups(domain, mem_ctx, + &user_sid, &num_groups, + &user_gids); if (!NT_STATUS_IS_OK(status)) goto done; /* Copy data back to client */ @@ -866,12 +869,13 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) goto done; for (i = 0; i < num_groups; i++) { - if (!winbindd_idmap_get_gid_from_rid(domain->name, - user_gids[i], - &gid_list[num_gids])) { + if (!winbindd_idmap_get_gid_from_sid( + user_gids[i], + &gid_list[num_gids])) { + fstring sid_string; - DEBUG(1, ("unable to convert group rid %d to gid\n", - user_gids[i])); + DEBUG(1, ("unable to convert group sid %s to gid\n", + sid_to_string(sid_string, user_gids[i]))); continue; } diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c index 0a17fcd87f..de547cde41 100644 --- a/source3/nsswitch/winbindd_idmap.c +++ b/source3/nsswitch/winbindd_idmap.c @@ -121,48 +121,6 @@ BOOL winbindd_idmap_get_gid_from_sid(DOM_SID *sid, gid_t *gid) return ret; } -/* Get UID from RID */ -BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid, - uid_t *uid) -{ - BOOL ret = False; - - if (!impl) { - impl = get_impl(lp_idmap_backend()); - if (!impl) { - DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_idmap_backend())); - } - } - - if (impl) { - ret = impl->get_uid_from_rid(dom_name, rid, uid); - } - - return ret; -} - -/* Get GID From RID */ -BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid, - gid_t *gid) -{ - BOOL ret = False; - - if (!impl) { - impl = get_impl(lp_idmap_backend()); - if (!impl) { - DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_idmap_backend())); - } - } - - if (impl) { - ret = impl->get_gid_from_rid(dom_name, rid, gid); - } - - return ret; -} - /* Get SID from UID */ BOOL winbindd_idmap_get_sid_from_uid(uid_t uid, DOM_SID *sid) { @@ -202,46 +160,6 @@ BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid) return ret; } -/* Get RID From UID */ -BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid, - struct winbindd_domain **domain) -{ - BOOL ret = False; - - if (!impl) { - impl = get_impl(lp_idmap_backend()); - } - - if (impl) { - ret = impl->get_rid_from_uid(uid, user_rid, domain); - } else { - DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_idmap_backend())); - } - - return ret; -} - -/* Get RID from GID */ -BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid, - struct winbindd_domain **domain) -{ - BOOL ret = False; - - if (!impl) { - impl = get_impl(lp_idmap_backend()); - } - - if (impl) { - ret = impl->get_rid_from_gid(gid, group_rid, domain); - } else { - DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n", - lp_idmap_backend())); - } - - return ret; -} - /* Close backend */ BOOL winbindd_idmap_close(void) { diff --git a/source3/nsswitch/winbindd_idmap_tdb.c b/source3/nsswitch/winbindd_idmap_tdb.c index f27c3c1b5f..911b3b41d2 100644 --- a/source3/nsswitch/winbindd_idmap_tdb.c +++ b/source3/nsswitch/winbindd_idmap_tdb.c @@ -342,78 +342,6 @@ static BOOL tdb_get_gid_from_sid(DOM_SID * sid, gid_t * gid) return tdb_get_id_from_sid(sid, gid, True); } -/* Get a uid from a user rid */ -static BOOL tdb_get_uid_from_rid(const char *dom_name, uint32 rid, - uid_t * uid) -{ - struct winbindd_domain *domain; - DOM_SID sid; - - if (!(domain = find_domain_from_name(dom_name))) { - return False; - } - - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); - - return tdb_get_id_from_sid(&sid, uid, False); -} - -/* Get a gid from a group rid */ -static BOOL tdb_get_gid_from_rid(const char *dom_name, uint32 rid, - gid_t * gid) -{ - struct winbindd_domain *domain; - DOM_SID sid; - - if (!(domain = find_domain_from_name(dom_name))) { - return False; - } - - sid_copy(&sid, &domain->sid); - sid_append_rid(&sid, rid); - - return tdb_get_id_from_sid(&sid, gid, True); -} - -/* Get a user rid from a uid */ -static BOOL tdb_get_rid_from_uid(uid_t uid, uint32 * user_rid, - struct winbindd_domain **domain) -{ - DOM_SID sid; - - if (!tdb_get_sid_from_id((int) uid, &sid, False)) { - return False; - } - - *domain = find_domain_from_sid(&sid); - if (!*domain) - return False; - - sid_split_rid(&sid, user_rid); - - return True; -} - -/* Get a group rid from a gid */ -static BOOL tdb_get_rid_from_gid(gid_t gid, uint32 * group_rid, - struct winbindd_domain **domain) -{ - DOM_SID sid; - - if (!tdb_get_sid_from_id((int) gid, &sid, True)) { - return False; - } - - *domain = find_domain_from_sid(&sid); - if (!*domain) - return False; - - sid_split_rid(&sid, group_rid); - - return True; -} - /* Close the tdb */ static BOOL tdb_idmap_close(void) { @@ -500,12 +428,6 @@ struct idmap_methods tdb_idmap_methods = { tdb_get_uid_from_sid, tdb_get_gid_from_sid, - tdb_get_rid_from_uid, - tdb_get_rid_from_gid, - - tdb_get_uid_from_rid, - tdb_get_gid_from_rid, - tdb_idmap_close, tdb_idmap_status diff --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c index 90d8e4f616..03b0a1e706 100644 --- a/source3/nsswitch/winbindd_rpc.c +++ b/source3/nsswitch/winbindd_rpc.c @@ -26,6 +26,7 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND + /* Query display info for a domain. This returns enough information plus a bit extra to give an overview of domain users for the User Manager application. */ @@ -39,7 +40,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, POLICY_HND dom_pol; BOOL got_dom_pol = False; uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED; - int i, start_idx, retry; + unsigned int i, start_idx, retry; DEBUG(3,("rpc: query_user_list\n")); @@ -97,7 +98,7 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, (*info)[i].acct_name = talloc_strdup(mem_ctx, dom_users[j]); (*info)[i].full_name = talloc_strdup(mem_ctx, ""); - (*info)[i].user_rid = dom_rids[j]; + (*info)[i].user_sid = rid_to_talloced_sid(domain, mem_ctx, dom_rids[j]); /* For the moment we set the primary group for every user to be the Domain Users group. There are serious problems with determining @@ -105,7 +106,10 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain, This should really be made into a 'winbind force group' smb.conf parameter or something like that. */ - (*info)[i].group_rid = DOMAIN_GROUP_RID_USERS; + (*info)[i].user_sid + = rid_to_talloced_sid(domain, + mem_ctx, + DOMAIN_GROUP_RID_USERS); } talloc_destroy(ctx2); @@ -252,11 +256,11 @@ static NTSTATUS enum_local_groups(struct winbindd_domain *domain, /* convert a single name to a sid in a domain */ static NTSTATUS name_to_sid(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, const char *name, DOM_SID *sid, enum SID_NAME_USE *type) { - TALLOC_CTX *mem_ctx; CLI_POLICY_HND *hnd; NTSTATUS status; DOM_SID *sids = NULL; @@ -266,23 +270,16 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain, DEBUG(3,("rpc: name_to_sid name=%s\n", name)); - if (!(mem_ctx = talloc_init("name_to_sid[rpc] for [%s]\\[%s]", domain->name, name))) { - DEBUG(0, ("talloc_init failed!\n")); - return NT_STATUS_NO_MEMORY; - } - full_name = talloc_asprintf(mem_ctx, "%s\\%s", domain->name, name); if (!full_name) { DEBUG(0, ("talloc_asprintf failed!\n")); - talloc_destroy(mem_ctx); return NT_STATUS_NO_MEMORY; } retry = 0; do { if (!(hnd = cm_get_lsa_handle(domain->name))) { - talloc_destroy(mem_ctx); return NT_STATUS_UNSUCCESSFUL; } @@ -297,7 +294,6 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain, *type = types[0]; } - talloc_destroy(mem_ctx); return status; } @@ -345,17 +341,22 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain, /* Lookup user information from a rid or username. */ static NTSTATUS query_user(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, + DOM_SID *user_sid, WINBIND_USERINFO *user_info) { CLI_POLICY_HND *hnd; - NTSTATUS result; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; POLICY_HND dom_pol, user_pol; BOOL got_dom_pol = False, got_user_pol = False; SAM_USERINFO_CTR *ctr; int retry; + fstring sid_string; + uint32 user_rid; - DEBUG(3,("rpc: query_user rid=%u\n", user_rid)); + DEBUG(3,("rpc: query_user rid=%s\n", sid_to_string(sid_string, user_sid))); + if (!sid_peek_check_rid(&domain->sid, user_sid, &user_rid)) { + goto done; + } retry = 0; do { @@ -394,8 +395,8 @@ static NTSTATUS query_user(struct winbindd_domain *domain, cli_samr_close(hnd->cli, mem_ctx, &user_pol); got_user_pol = False; - user_info->user_rid = user_rid; - user_info->group_rid = ctr->info.id21->group_rid; + user_info->user_sid = rid_to_talloced_sid(domain, mem_ctx, user_rid); + user_info->group_sid = rid_to_talloced_sid(domain, mem_ctx, ctr->info.id21->group_rid); user_info->acct_name = unistr2_tdup(mem_ctx, &ctr->info.id21->uni_user_name); user_info->full_name = unistr2_tdup(mem_ctx, @@ -415,8 +416,8 @@ static NTSTATUS query_user(struct winbindd_domain *domain, /* Lookup groups a user is a member of. I wish Unix had a call like this! */ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 user_rid, - uint32 *num_groups, uint32 **user_gids) + DOM_SID *user_sid, + uint32 *num_groups, DOM_SID ***user_gids) { CLI_POLICY_HND *hnd; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -424,15 +425,17 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED; BOOL got_dom_pol = False, got_user_pol = False; DOM_GID *user_groups; - int i; - int retry; + unsigned int i; + unsigned int retry; + fstring sid_string; + uint32 user_rid; - DEBUG(3,("rpc: lookup_usergroups rid=%u\n", user_rid)); + DEBUG(3,("rpc: lookup_usergroups sid=%s\n", sid_to_string(sid_string, user_sid))); *num_groups = 0; /* First try cached universal groups from logon */ - *user_gids = uni_group_cache_fetch(&domain->sid, user_rid, mem_ctx, num_groups); + *user_gids = uni_group_cache_fetch(&domain->sid, user_sid, mem_ctx, num_groups); if((*num_groups > 0) && *user_gids) { return NT_STATUS_OK; } else { @@ -448,7 +451,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, /* Get domain handle */ result = cli_samr_open_domain(hnd->cli, mem_ctx, &hnd->pol, - des_access, &domain->sid, &dom_pol); + des_access, &domain->sid, &dom_pol); } while (!NT_STATUS_IS_OK(result) && (retry++ < 1) && hnd && hnd->cli && hnd->cli->fd == -1); if (!NT_STATUS_IS_OK(result)) @@ -456,6 +459,11 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, got_dom_pol = True; + + if (!sid_peek_check_rid(&domain->sid, user_sid, &user_rid)) { + goto done; + } + /* Get user handle */ result = cli_samr_open_user(hnd->cli, mem_ctx, &dom_pol, des_access, user_rid, &user_pol); @@ -473,8 +481,13 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, goto done; (*user_gids) = talloc(mem_ctx, sizeof(uint32) * (*num_groups)); + if (!(*user_gids)) { + result = NT_STATUS_NO_MEMORY; + goto done; + } + for (i=0;i<(*num_groups);i++) { - (*user_gids)[i] = user_groups[i].g_rid; + (*user_gids)[i] = rid_to_talloced_sid(domain, mem_ctx, user_groups[i].g_rid); } done: @@ -492,8 +505,8 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, /* Lookup group membership given a rid. */ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, - uint32 group_rid, uint32 *num_names, - uint32 **rid_mem, char ***names, + DOM_SID *group_sid, uint32 *num_names, + DOM_SID ***sid_mem, char ***names, uint32 **name_types) { CLI_POLICY_HND *hnd; @@ -502,9 +515,17 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, POLICY_HND dom_pol, group_pol; uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED; BOOL got_dom_pol = False, got_group_pol = False; + uint32 *rid_mem = NULL; + uint32 group_rid; int retry; + unsigned int j; + fstring sid_string; + + DEBUG(10,("rpc: lookup_groupmem %s sid=%s\n", domain->name, sid_to_string(sid_string, group_sid))); - DEBUG(10,("rpc: lookup_groupmem %s rid=%u\n", domain->name, group_rid)); + if (!sid_peek_check_rid(&domain->sid, group_sid, &group_rid)) { + goto done; + } *num_names = 0; @@ -539,7 +560,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, group. */ result = cli_samr_query_groupmem(hnd->cli, mem_ctx, - &group_pol, num_names, rid_mem, + &group_pol, num_names, &rid_mem, name_types); if (!NT_STATUS_IS_OK(result)) @@ -554,6 +575,16 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, *names = talloc_zero(mem_ctx, *num_names * sizeof(char *)); *name_types = talloc_zero(mem_ctx, *num_names * sizeof(uint32)); + *sid_mem = talloc_zero(mem_ctx, *num_names * sizeof(DOM_SID *)); + + for (j=0;j<(*num_names);j++) { + (*sid_mem)[j] = rid_to_talloced_sid(domain, mem_ctx, (rid_mem)[j]); + } + + if (!*names || !*name_types) { + result = NT_STATUS_NO_MEMORY; + goto done; + } for (i = 0; i < *num_names; i += MAX_LOOKUP_RIDS) { int num_lookup_rids = MIN(*num_names - i, MAX_LOOKUP_RIDS); @@ -566,7 +597,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, result = cli_samr_lookup_rids(hnd->cli, mem_ctx, &dom_pol, 1000, /* flags */ num_lookup_rids, - &(*rid_mem)[i], + &rid_mem[i], &tmp_num_names, &tmp_names, &tmp_types); @@ -581,7 +612,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain, memcpy(&(*name_types)[i], tmp_types, sizeof(uint32) * tmp_num_names); - + total_names += tmp_num_names; } diff --git a/source3/nsswitch/winbindd_user.c b/source3/nsswitch/winbindd_user.c index 06c95224ab..ee05543d30 100644 --- a/source3/nsswitch/winbindd_user.c +++ b/source3/nsswitch/winbindd_user.c @@ -29,29 +29,30 @@ /* Fill a pwent structure with information we have obtained */ static BOOL winbindd_fill_pwent(char *dom_name, char *user_name, - uint32 user_rid, uint32 group_rid, + DOM_SID *user_sid, DOM_SID *group_sid, char *full_name, struct winbindd_pw *pw) { extern userdom_struct current_user_info; fstring output_username; pstring homedir; + fstring sid_string; if (!pw || !dom_name || !user_name) return False; /* Resolve the uid number */ - if (!winbindd_idmap_get_uid_from_rid(dom_name, user_rid, + if (!winbindd_idmap_get_uid_from_sid(user_sid, &pw->pw_uid)) { - DEBUG(1, ("error getting user id for rid %d\n", user_rid)); + DEBUG(1, ("error getting user id for sid %s\n", sid_to_string(sid_string, user_sid))); return False; } /* Resolve the gid number */ - if (!winbindd_idmap_get_gid_from_rid(dom_name, group_rid, + if (!winbindd_idmap_get_gid_from_sid(group_sid, &pw->pw_gid)) { - DEBUG(1, ("error getting group id for rid %d\n", group_rid)); + DEBUG(1, ("error getting group id for sid %s\n", sid_to_string(sid_string, group_sid))); return False; } @@ -95,7 +96,6 @@ static BOOL winbindd_fill_pwent(char *dom_name, char *user_name, enum winbindd_result winbindd_getpwnam(struct winbindd_cli_state *state) { - uint32 user_rid; WINBIND_USERINFO user_info; DOM_SID user_sid; NTSTATUS status; @@ -144,9 +144,7 @@ enum winbindd_result winbindd_getpwnam(struct winbindd_cli_state *state) return WINBINDD_ERROR; } - sid_split_rid(&user_sid, &user_rid); - - status = domain->methods->query_user(domain, mem_ctx, user_rid, + status = domain->methods->query_user(domain, mem_ctx, &user_sid, &user_info); if (!NT_STATUS_IS_OK(status)) { @@ -158,7 +156,7 @@ enum winbindd_result winbindd_getpwnam(struct winbindd_cli_state *state) /* Now take all this information and fill in a passwd structure */ if (!winbindd_fill_pwent(name_domain, name_user, - user_rid, user_info.group_rid, + user_info.user_sid, user_info.group_sid, user_info.full_name, &state->response.data.pw)) { talloc_destroy(mem_ctx); @@ -176,7 +174,6 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) { DOM_SID user_sid; struct winbindd_domain *domain; - uint32 user_rid; fstring dom_name; fstring user_name; enum SID_NAME_USE name_type; @@ -196,18 +193,15 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) /* Get rid from uid */ - if (!winbindd_idmap_get_rid_from_uid(state->request.data.uid, - &user_rid, &domain)) { - DEBUG(1, ("could not convert uid %d to rid\n", + if (!winbindd_idmap_get_sid_from_uid(state->request.data.uid, + &user_sid)) { + DEBUG(1, ("could not convert uid %d to SID\n", state->request.data.uid)); return WINBINDD_ERROR; } /* Get name and name type from rid */ - sid_copy(&user_sid, &domain->sid); - sid_append_rid(&user_sid, user_rid); - if (!winbindd_lookup_name_by_sid(&user_sid, dom_name, user_name, &name_type)) { fstring temp; @@ -216,6 +210,13 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) return WINBINDD_ERROR; } + domain = find_domain_from_sid(&user_sid); + + if (!domain) { + DEBUG(1,("Can't find domain from sid\n")); + return WINBINDD_ERROR; + } + /* Get some user info */ if (!(mem_ctx = talloc_init("winbind_getpwuid(%d)", @@ -225,7 +226,7 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) return WINBINDD_ERROR; } - status = domain->methods->query_user(domain, mem_ctx, user_rid, + status = domain->methods->query_user(domain, mem_ctx, &user_sid, &user_info); if (!NT_STATUS_IS_OK(status)) { @@ -237,7 +238,7 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) /* Resolve gid number */ - if (!winbindd_idmap_get_gid_from_rid(domain->name, user_info.group_rid, &gid)) { + if (!winbindd_idmap_get_gid_from_sid(user_info.group_sid, &gid)) { DEBUG(1, ("error getting group id for user %s\n", user_name)); talloc_destroy(mem_ctx); return WINBINDD_ERROR; @@ -245,7 +246,8 @@ enum winbindd_result winbindd_getpwuid(struct winbindd_cli_state *state) /* Fill in password structure */ - if (!winbindd_fill_pwent(domain->name, user_name, user_rid, user_info.group_rid, + if (!winbindd_fill_pwent(domain->name, user_name, user_info.user_sid, + user_info.group_sid, user_info.full_name, &state->response.data.pw)) { talloc_destroy(mem_ctx); return WINBINDD_ERROR; @@ -332,13 +334,13 @@ static BOOL get_sam_user_entries(struct getent_state *ent) TALLOC_CTX *mem_ctx; struct winbindd_domain *domain; struct winbindd_methods *methods; - int i; + unsigned int i; if (ent->num_sam_entries) return False; if (!(mem_ctx = talloc_init("get_sam_user_entries(%s)", - ent->domain_name))) + ent->domain_name))) return False; if (!(domain = find_domain_from_name(ent->domain_name))) { @@ -393,8 +395,8 @@ static BOOL get_sam_user_entries(struct getent_state *ent) } /* User and group ids */ - name_list[ent->num_sam_entries+i].user_rid = info[i].user_rid; - name_list[ent->num_sam_entries+i].group_rid = info[i].group_rid; + sid_copy(&name_list[ent->num_sam_entries+i].user_sid, info[i].user_sid); + sid_copy(&name_list[ent->num_sam_entries+i].group_sid, info[i].group_sid); } ent->num_sam_entries += num_entries; @@ -492,8 +494,8 @@ enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state) result = winbindd_fill_pwent( ent->domain_name, name_list[ent->sam_entry_index].name, - name_list[ent->sam_entry_index].user_rid, - name_list[ent->sam_entry_index].group_rid, + &name_list[ent->sam_entry_index].user_sid, + &name_list[ent->sam_entry_index].group_sid, name_list[ent->sam_entry_index].gecos, &user_list[user_list_ndx]); @@ -540,7 +542,7 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state) for (domain = domain_list(); domain; domain = domain->next) { NTSTATUS status; struct winbindd_methods *methods; - int i; + unsigned int i; methods = domain->methods; diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c index 3fa08029b6..fdbfd92b5a 100644 --- a/source3/nsswitch/winbindd_util.c +++ b/source3/nsswitch/winbindd_util.c @@ -271,14 +271,20 @@ BOOL winbindd_lookup_sid_by_name(struct winbindd_domain *domain, enum SID_NAME_USE *type) { NTSTATUS result; - + TALLOC_CTX *mem_ctx; /* Don't bother with machine accounts */ - + if (name[strlen(name) - 1] == '$') return False; + mem_ctx = talloc_init("lookup_sid_by_name for %s\n", name); + if (!mem_ctx) + return False; + /* Lookup name */ - result = domain->methods->name_to_sid(domain, name, sid, type); + result = domain->methods->name_to_sid(domain, mem_ctx, name, sid, type); + + talloc_destroy(mem_ctx); /* Return rid and type if lookup successful */ if (!NT_STATUS_IS_OK(result)) { @@ -528,3 +534,20 @@ int winbindd_num_clients(void) { return _num_clients; } + +/* Help with RID -> SID conversion */ + +DOM_SID *rid_to_talloced_sid(struct winbindd_domain *domain, + TALLOC_CTX *mem_ctx, + uint32 rid) +{ + DOM_SID *sid; + sid = talloc(mem_ctx, sizeof(*sid)); + if (!sid) { + smb_panic("rid_to_to_talloced_sid: talloc for DOM_SID failed!\n"); + } + sid_copy(sid, &domain->sid); + sid_append_rid(sid, rid); + return sid; +} + -- cgit From ca80787248bfe7fe8dff12486ba32520f6910341 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Feb 2003 12:23:03 +0000 Subject: Netlogon-unigroup changes needed for the winbind RID-to-SID conversion. This changes the cache format, which will simply invalidate existing entries, leaving them dead in the cache. Andrew Bartlett (This used to be commit 3fc179362ea849db23490b971a9f64f943e7f7f8) --- source3/libsmb/netlogon_unigrp.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'source3') diff --git a/source3/libsmb/netlogon_unigrp.c b/source3/libsmb/netlogon_unigrp.c index fa2fe32f35..466410d800 100644 --- a/source3/libsmb/netlogon_unigrp.c +++ b/source3/libsmb/netlogon_unigrp.c @@ -22,6 +22,7 @@ */ #include "includes.h" +#define UNIGROUP_PREFIX "UNIGROUP" /* Handle for netlogon_unigrp.tdb database. It is used internally @@ -50,17 +51,22 @@ BOOL uni_group_cache_init(void) BOOL uni_group_cache_store_netlogon(TALLOC_CTX *mem_ctx, NET_USER_INFO_3 *user) { TDB_DATA key,data; - fstring keystr; - int i; + fstring keystr, sid_string; + DOM_SID user_sid; + unsigned int i; if (!uni_group_cache_init()) { DEBUG(0,("uni_group_cache_store_netlogon: cannot open netlogon_unigrp.tdb for write!\n")); return False; } - /* Prepare key as DOMAIN-SID/USER-RID string */ - slprintf(keystr, sizeof(keystr), "%s/%d", - sid_string_static(&user->dom_sid.sid), user->user_rid); + sid_copy(&user_sid, &user->dom_sid.sid); + sid_append_rid(&user_sid, user->user_rid); + + /* Prepare key as USER-SID string */ + slprintf(keystr, sizeof(keystr), "%s/%s", + UNIGROUP_PREFIX, + sid_to_string(sid_string, &user_sid)); key.dptr = keystr; key.dsize = strlen(keystr) + 1; @@ -90,14 +96,15 @@ BOOL uni_group_cache_store_netlogon(TALLOC_CTX *mem_ctx, NET_USER_INFO_3 *user) and elements are array[0] ... array[num_elements-1] */ -uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, +DOM_SID **uni_group_cache_fetch(DOM_SID *domain, DOM_SID *user_sid, TALLOC_CTX *mem_ctx, uint32 *num_groups) { TDB_DATA key,data; fstring keystr; - uint32 *groups; + DOM_SID **groups; uint32 i; uint32 group_count; + fstring sid_string; if (!domain) { DEBUG(1,("uni_group_cache_fetch: expected non-null domain sid\n")); @@ -123,8 +130,9 @@ uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, *num_groups = 0; /* Fetch universal groups */ - slprintf(keystr, sizeof(keystr), "%s/%d", - sid_string_static(domain), user_rid); + slprintf(keystr, sizeof(keystr), "%s/%s", + UNIGROUP_PREFIX, + sid_to_string(sid_string, user_sid)); key.dptr = keystr; key.dsize = strlen(keystr) + 1; data = tdb_fetch(netlogon_unigrp_tdb, key); @@ -136,12 +144,17 @@ uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, /* Transfer data to receiver's memory context */ group_count = IVAL(&((uint32*)data.dptr)[0],0); - groups = talloc(mem_ctx, (group_count)*sizeof(uint32)); + groups = talloc(mem_ctx, (group_count)*sizeof(*groups)); if (groups) { for(i=0; i Date: Wed, 26 Feb 2003 12:31:17 +0000 Subject: Add -Wwrite-strings to our --enable-developer settings. We have compiled relitivly 'clean' with this setting since I did a massive cleanup last month. This should help us stay that way. Andrew Bartlett (This used to be commit 284479bf388f5e39d9be78eeb1ac6cdd001fb8df) --- source3/configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/configure.in b/source3/configure.in index e3b5f2fe15..269d70c2fc 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -205,12 +205,12 @@ AC_ARG_ENABLE(debug, AC_ARG_ENABLE(developer, [ --enable-developer Turn on developer warnings and debugging (default=no)], [if eval "test x$enable_developer = xyes"; then - CFLAGS="${CFLAGS} -g -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -DDEBUG_PASSWORD -DDEVELOPER" + CFLAGS="${CFLAGS} -g -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER" fi]) AC_ARG_ENABLE(krb5developer, [ --enable-krb5developer Turn on developer warnings and debugging, except -Wstrict-prototypes (default=no)], [if eval "test x$enable_krb5developer = xyes"; then - CFLAGS="${CFLAGS} -g -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -DDEBUG_PASSWORD -DDEVELOPER" + CFLAGS="${CFLAGS} -g -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER" fi]) AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc Enable heap debugging [default=no]]) -- cgit From f6f76ad5ed7b3eee7cbd3bca6f3ccd1194a0e98a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Feb 2003 00:43:23 +0000 Subject: Fix to allow blocking lock notification to be done rapidly (no wait for smb -> smb lock release). Adds new PENDING_LOCK type to lockdb (does not interfere with existing locks). Jeremy. (This used to be commit 22fc0d48ff2052b4274c65f85050c58b235bf4e4) --- source3/include/messages.h | 1 + source3/include/smb.h | 2 +- source3/locking/brlock.c | 82 ++++++++++++++++++++++++++++++++++++++++++---- source3/locking/locking.c | 4 +-- source3/smbd/blocking.c | 78 +++++++++++++++++++++++++++++++++++++++---- source3/smbd/process.c | 7 ++++ source3/smbd/reply.c | 7 ++-- 7 files changed, 162 insertions(+), 19 deletions(-) (limited to 'source3') diff --git a/source3/include/messages.h b/source3/include/messages.h index 2b8ca8bbe9..ce167a772d 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -62,6 +62,7 @@ #define MSG_SMB_FORCE_TDIS 3002 #define MSG_SMB_SAM_SYNC 3003 #define MSG_SMB_SAM_REPL 3004 +#define MSG_SMB_UNLOCK 3005 /* Flags to classify messages - used in message_send_all() */ /* Sender will filter by flag. */ diff --git a/source3/include/smb.h b/source3/include/smb.h index 71051e341e..a2b341d0fc 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -772,7 +772,7 @@ typedef enum } parm_class; /* passed to br lock code */ -enum brl_type {READ_LOCK, WRITE_LOCK}; +enum brl_type {READ_LOCK, WRITE_LOCK, PENDING_LOCK}; struct enum_list { int value; diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index 9902c7bbd7..4cd885f1a6 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -98,6 +98,9 @@ static BOOL brl_same_context(struct lock_context *ctx1, static BOOL brl_conflict(struct lock_struct *lck1, struct lock_struct *lck2) { + if (lck1->lock_type == PENDING_LOCK || lck2->lock_type == PENDING_LOCK ) + return False; + if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) { return False; } @@ -119,6 +122,9 @@ static BOOL brl_conflict(struct lock_struct *lck1, static BOOL brl_conflict1(struct lock_struct *lck1, struct lock_struct *lck2) { + if (lck1->lock_type == PENDING_LOCK || lck2->lock_type == PENDING_LOCK ) + return False; + if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) { return False; } @@ -148,6 +154,9 @@ static BOOL brl_conflict1(struct lock_struct *lck1, static BOOL brl_conflict_other(struct lock_struct *lck1, struct lock_struct *lck2) { + if (lck1->lock_type == PENDING_LOCK || lck2->lock_type == PENDING_LOCK ) + return False; + if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) return False; @@ -385,16 +394,30 @@ NTSTATUS brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, return status; } +/**************************************************************************** + Check if an unlock overlaps a pending lock. +****************************************************************************/ + +static BOOL brl_pending_overlap(struct lock_struct *lock, struct lock_struct *pend_lock) +{ + if ((lock->start <= pend_lock->start) && (lock->start + lock->size > pend_lock->start)) + return True; + if ((lock->start >= pend_lock->start) && (lock->start <= pend_lock->start + pend_lock->size)) + return True; + return False; +} + /**************************************************************************** Unlock a range of bytes. ****************************************************************************/ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, uint16 smbpid, pid_t pid, uint16 tid, - br_off start, br_off size) + br_off start, br_off size, + BOOL remove_pending_locks_only) { TDB_DATA kbuf, dbuf; - int count, i; + int count, i, j; struct lock_struct *locks; struct lock_context context; @@ -452,9 +475,34 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, struct lock_struct *lock = &locks[i]; if (brl_same_context(&lock->context, &context) && - lock->fnum == fnum && - lock->start == start && - lock->size == size) { + lock->fnum == fnum && + lock->start == start && + lock->size == size) { + + if (remove_pending_locks_only && lock->lock_type != PENDING_LOCK) + continue; + + if (lock->lock_type != PENDING_LOCK) { + /* Send unlock messages to any pending waiters that overlap. */ + for (j=0; jlock_type != PENDING_LOCK) + continue; + + /* We could send specific lock info here... */ + if (brl_pending_overlap(lock, pend_lock)) { + DEBUG(10,("brl_unlock: sending unlock message to pid %u\n", + (unsigned int)pend_lock->context.pid )); + + message_send_pid(pend_lock->context.pid, + MSG_SMB_UNLOCK, + NULL, 0, True); + } + } + } + /* found it - delete it */ if (count == 1) { tdb_delete(tdb, kbuf); @@ -546,7 +594,7 @@ BOOL brl_locktest(SMB_DEV_T dev, SMB_INO_T ino, int fnum, void brl_close(SMB_DEV_T dev, SMB_INO_T ino, pid_t pid, int tid, int fnum) { TDB_DATA kbuf, dbuf; - int count, i, dcount=0; + int count, i, j, dcount=0; struct lock_struct *locks; kbuf = locking_key(dev,ino); @@ -561,12 +609,34 @@ void brl_close(SMB_DEV_T dev, SMB_INO_T ino, pid_t pid, int tid, int fnum) /* there are existing locks - remove any for this fnum */ locks = (struct lock_struct *)dbuf.dptr; count = dbuf.dsize / sizeof(*locks); + for (i=0; icontext.tid == tid && lock->context.pid == pid && lock->fnum == fnum) { + + /* Send unlock messages to any pending waiters that overlap. */ + for (j=0; jlock_type != PENDING_LOCK) + continue; + + if (pend_lock->context.tid == tid && + pend_lock->context.pid == pid && + pend_lock->fnum == fnum) + continue; + + /* We could send specific lock info here... */ + if (brl_pending_overlap(lock, pend_lock)) + message_send_pid(pend_lock->context.pid, + MSG_SMB_UNLOCK, + NULL, 0, True); + } + /* found it - delete it */ if (count > 1 && i < count-1) { memmove(&locks[i], &locks[i+1], diff --git a/source3/locking/locking.c b/source3/locking/locking.c index fdfd4d661c..651f905e15 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -132,7 +132,7 @@ static NTSTATUS do_lock(files_struct *fsp,connection_struct *conn, uint16 lock_p */ (void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum, lock_pid, sys_getpid(), conn->cnum, - offset, count); + offset, count, False); } } } @@ -201,7 +201,7 @@ NTSTATUS do_unlock(files_struct *fsp,connection_struct *conn, uint16 lock_pid, */ ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum, - lock_pid, sys_getpid(), conn->cnum, offset, count); + lock_pid, sys_getpid(), conn->cnum, offset, count, False); if (!ok) { DEBUG(10,("do_unlock: returning ERRlock.\n" )); diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c index 14239272c2..581ce43f91 100644 --- a/source3/smbd/blocking.c +++ b/source3/smbd/blocking.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. Blocking Locking functions - Copyright (C) Jeremy Allison 1998 + Copyright (C) Jeremy Allison 1998-2003 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 @@ -33,6 +33,9 @@ typedef struct { files_struct *fsp; time_t expire_time; int lock_num; + SMB_BIG_UINT offset; + SMB_BIG_UINT count; + uint16 lock_pid; char *inbuf; int length; } blocking_lock_record; @@ -77,13 +80,18 @@ static BOOL in_chained_smb(void) return (chain_size != 0); } +static void received_unlock_msg(int msg_type, pid_t src, void *buf, size_t len); + /**************************************************************************** Function to push a blocking lock request onto the lock queue. ****************************************************************************/ -BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int lock_num) +BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, + int lock_num, uint16 lock_pid, SMB_BIG_UINT offset, SMB_BIG_UINT count) { + static BOOL set_lock_msg; blocking_lock_record *blr; + NTSTATUS status; if(in_chained_smb() ) { DEBUG(0,("push_blocking_lock_request: cannot queue a chained request (currently).\n")); @@ -110,11 +118,31 @@ BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int blr->fsp = get_fsp_from_pkt(inbuf); blr->expire_time = (lock_timeout == -1) ? (time_t)-1 : time(NULL) + (time_t)lock_timeout; blr->lock_num = lock_num; + blr->lock_pid = lock_pid; + blr->offset = offset; + blr->count = count; memcpy(blr->inbuf, inbuf, length); blr->length = length; + /* Add a pending lock record for this. */ + status = brl_lock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum, + lock_pid, sys_getpid(), blr->fsp->conn->cnum, + offset, count, + PENDING_LOCK); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0,("push_blocking_lock_request: failed to add PENDING_LOCK record.\n")); + free_blocking_lock_record(blr); + return False; + } + ubi_slAddTail(&blocking_lock_queue, blr); + /* Ensure we'll receive messages when this is unlocked. */ + if (!set_lock_msg) { + message_register(MSG_SMB_UNLOCK, received_unlock_msg); + set_lock_msg = True; + } DEBUG(3,("push_blocking_lock_request: lock request length=%d blocked with expiry time %d (+%d) \ for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout, @@ -493,6 +521,10 @@ void remove_pending_lock_requests_by_fid(files_struct *fsp) DEBUG(10,("remove_pending_lock_requests_by_fid - removing request type %d for \ file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum )); + brl_unlock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum, + blr->lock_pid, sys_getpid(), blr->fsp->conn->cnum, + blr->offset, blr->count, True); + free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); continue; @@ -520,6 +552,9 @@ void remove_pending_lock_requests_by_mid(int mid) file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum )); blocking_lock_reply_error(blr,NT_STATUS_CANCELLED); + brl_unlock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum, + blr->lock_pid, sys_getpid(), blr->fsp->conn->cnum, + blr->offset, blr->count, True); free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); continue; @@ -530,9 +565,20 @@ file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum )); } } +/**************************************************************************** + Set a flag as an unlock request affects one of our pending locks. +*****************************************************************************/ + +static void received_unlock_msg(int msg_type, pid_t src, void *buf, size_t len) +{ + DEBUG(10,("received_unlock_msg\n")); + process_blocking_lock_queue(time(NULL)); +} + /**************************************************************************** Return the number of seconds to the next blocking locks timeout, or default_timeout *****************************************************************************/ + unsigned blocking_locks_timeout(unsigned default_timeout) { unsigned timeout = default_timeout; @@ -540,22 +586,21 @@ unsigned blocking_locks_timeout(unsigned default_timeout) blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst(&blocking_lock_queue); /* note that we avoid the time() syscall if there are no blocking locks */ - if (!blr) { + if (!blr) return timeout; - } t = time(NULL); while (blr) { - if (timeout > (blr->expire_time - t)) { + if ((blr->expire_time != (time_t)-1) && + (timeout > (blr->expire_time - t))) { timeout = blr->expire_time - t; } blr = (blocking_lock_record *)ubi_slNext(blr); } - if (timeout < 1) { + if (timeout < 1) timeout = 1; - } return timeout; } @@ -604,6 +649,10 @@ void process_blocking_lock_queue(time_t t) DEBUG(5,("process_blocking_lock_queue: pending lock fnum = %d for file %s timed out.\n", fsp->fnum, fsp->fsp_name )); + brl_unlock(fsp->dev, fsp->inode, fsp->fnum, + blr->lock_pid, sys_getpid(), conn->cnum, + blr->offset, blr->count, True); + blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT); free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); @@ -617,6 +666,11 @@ void process_blocking_lock_queue(time_t t) * Remove the entry and return an error to the client. */ blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED); + + brl_unlock(fsp->dev, fsp->inode, fsp->fnum, + blr->lock_pid, sys_getpid(), conn->cnum, + blr->offset, blr->count, True); + free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); continue; @@ -628,6 +682,11 @@ void process_blocking_lock_queue(time_t t) * Remove the entry and return an error to the client. */ blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED); + + brl_unlock(fsp->dev, fsp->inode, fsp->fnum, + blr->lock_pid, sys_getpid(), conn->cnum, + blr->offset, blr->count, True); + free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); change_to_root_user(); @@ -641,6 +700,11 @@ void process_blocking_lock_queue(time_t t) */ if(blocking_lock_record_process(blr)) { + + brl_unlock(fsp->dev, fsp->inode, fsp->fnum, + blr->lock_pid, sys_getpid(), conn->cnum, + blr->offset, blr->count, True); + free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev)); blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue)); change_to_root_user(); diff --git a/source3/smbd/process.c b/source3/smbd/process.c index c002abad16..57bc236eef 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1271,6 +1271,13 @@ void smbd_process(void) lp_talloc_free(); main_loop_talloc_free(); + /* Did someone ask for immediate checks on things like blocking locks ? */ + if (select_timeout == 0) { + if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) + return; + num_smbs = 0; /* Reset smb counter. */ + } + while (!receive_message_or_smb(InBuffer,BUFFER_SIZE+LARGE_WRITEX_HDR_SIZE,select_timeout)) { if(!timeout_processing( deadtime, &select_timeout, &last_timeout_processing_time)) return; diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 580878fe32..71e880476c 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1609,7 +1609,8 @@ int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int length * this smb into a queued request and push it * onto the blocking lock queue. */ - if(push_blocking_lock_request(inbuf, length, -1, 0)) { + if(push_blocking_lock_request(inbuf, length, -1, 0, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)startpos, + (SMB_BIG_UINT)numtoread)) { END_PROFILE(SMBlockread); return -1; } @@ -2514,7 +2515,7 @@ int reply_lock(connection_struct *conn, * this smb into a queued request and push it * onto the blocking lock queue. */ - if(push_blocking_lock_request(inbuf, length, -1, 0)) { + if(push_blocking_lock_request(inbuf, length, -1, 0, SVAL(inbuf,smb_pid), offset, count)) { END_PROFILE(SMBlock); return -1; } @@ -3955,7 +3956,7 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name)); * this smb into a queued request and push it * onto the blocking lock queue. */ - if(push_blocking_lock_request(inbuf, length, lock_timeout, i)) { + if(push_blocking_lock_request(inbuf, length, lock_timeout, i, lock_pid, offset, count)) { END_PROFILE(SMBlockingX); return -1; } -- cgit From d62f60f53ac18b3de9c7922105c6796361b91a11 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 27 Feb 2003 01:05:12 +0000 Subject: Fix possible memory leak on failure. (This used to be commit 052ebc44cde8d31571ed1edb602794349825be11) --- source3/nsswitch/winbindd_ads.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_ads.c b/source3/nsswitch/winbindd_ads.c index 6c79e59bae..de3757aa44 100644 --- a/source3/nsswitch/winbindd_ads.c +++ b/source3/nsswitch/winbindd_ads.c @@ -580,6 +580,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain, user_dn = ads_pull_string(ads, mem_ctx, msg, "distinguishedName"); if (!user_dn) { DEBUG(1,("lookup_usergroups(sid=%s) ads_search did not return a a distinguishedName!\n", sid_to_string(sid_string, sid))); + if (msg) ads_msgfree(ads, msg); goto done; } -- cgit From d21b15ff57aa39337e76a06da74a55e48f4b0696 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Feb 2003 01:54:41 +0000 Subject: - Rename 'modules = ' to 'preload modules = ' - Add smb_probe_module() - Add init_modules() - Call these functions (This used to be commit f8f21653225792c0001d183c6efe8b7d89a0785d) --- source3/lib/module.c | 35 +++++++++++++++++++++++++--- source3/param/loadparm.c | 6 ++--- source3/passdb/pdb_interface.c | 53 +++++++++++++++++++++++++++--------------- source3/smbd/server.c | 3 +-- source3/utils/pdbedit.c | 3 +-- source3/utils/testparm.c | 6 +++++ 6 files changed, 77 insertions(+), 29 deletions(-) (limited to 'source3') diff --git a/source3/lib/module.c b/source3/lib/module.c index dd94f79950..4e2fe48af7 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -75,18 +75,47 @@ int smb_load_modules(const char **modules) return success; } +int smb_probe_module(const char *subsystem, const char *module) +{ + pstring full_path; + + /* Check for absolute path */ + if(module[0] == '/')return smb_load_module(module); + + pstrcpy(full_path, lib_path(subsystem)); + pstrcat(full_path, "/"); + pstrcat(full_path, module); + pstrcat(full_path, "."); + pstrcat(full_path, shlib_ext()); + + return smb_load_module(full_path); +} + #else /* HAVE_DLOPEN */ int smb_load_module(const char *module_name) { - DEBUG(0,("This samba executable has not been build with plugin support")); + DEBUG(0,("This samba executable has not been built with plugin support")); return False; } int smb_load_modules(const char **modules) { - DEBUG(0,("This samba executable has not been build with plugin support")); - return -1; + DEBUG(0,("This samba executable has not been built with plugin support")); + return False; +} + +int smb_probe_module(const char *subsystem, const char *module) +{ + DEBUG(0,("This samba executable has not been built with plugin support, not probing")); + return False; } #endif /* HAVE_DLOPEN */ + +void init_modules(void) +{ + if(lp_preload_modules()) + smb_load_modules(lp_preload_modules()); + /* FIXME: load static modules */ +} diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index b57b169adc..0eeb9be9de 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -120,7 +120,7 @@ typedef struct char *szPrivateDir; char **szPassdbBackend; char **szSamBackend; - char **szModules; + char **szPreloadModules; char *szPasswordServer; char *szSocketOptions; char *szRealm; @@ -823,7 +823,7 @@ static struct parm_struct parm_table[] = { {"allow hosts", P_LIST, P_LOCAL, &sDefault.szHostsallow, NULL, NULL, FLAG_HIDE}, {"hosts deny", P_LIST, P_LOCAL, &sDefault.szHostsdeny, NULL, NULL, FLAG_GLOBAL | FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT | FLAG_DEVELOPER}, {"deny hosts", P_LIST, P_LOCAL, &sDefault.szHostsdeny, NULL, NULL, FLAG_HIDE}, - {"modules", P_LIST, P_GLOBAL, &Globals.szModules, NULL, NULL, FLAG_BASIC | FLAG_GLOBAL}, + {"preload modules", P_LIST, P_GLOBAL, &Globals.szPreloadModules, NULL, NULL, FLAG_BASIC | FLAG_GLOBAL}, {"Logging Options", P_SEP, P_SEPARATOR}, @@ -1609,7 +1609,7 @@ static FN_GLOBAL_STRING(lp_announce_version, &Globals.szAnnounceVersion) FN_GLOBAL_LIST(lp_netbios_aliases, &Globals.szNetbiosAliases) FN_GLOBAL_LIST(lp_passdb_backend, &Globals.szPassdbBackend) FN_GLOBAL_LIST(lp_sam_backend, &Globals.szSamBackend) -FN_GLOBAL_LIST(lp_modules, &Globals.szModules) +FN_GLOBAL_LIST(lp_preload_modules, &Globals.szPreloadModules) FN_GLOBAL_STRING(lp_panic_action, &Globals.szPanicAction) FN_GLOBAL_STRING(lp_adduser_script, &Globals.szAddUserScript) FN_GLOBAL_STRING(lp_deluser_script, &Globals.szDelUserScript) diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index d465439dda..48a039b3de 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -86,6 +86,18 @@ BOOL smb_register_passdb(const char *name, pdb_init_function init, int version) return True; } +struct pdb_init_function_entry *pdb_find_backend_entry(const char *name) +{ + struct pdb_init_function_entry *entry = backends; + + while(entry) { + if (strequal(entry->name, name)) return entry; + entry = entry->next; + } + + return NULL; +} + static NTSTATUS context_setsampwent(struct pdb_context *context, BOOL update) { NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; @@ -423,8 +435,6 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c lazy_initialize_passdb(); - entry = backends; - p = strchr(module_name, ':'); if (p) { @@ -435,27 +445,32 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c trim_string(module_name, " ", " "); + DEBUG(5,("Attempting to find an passdb backend to match %s (%s)\n", selected, module_name)); - while(entry) { - if (strequal(entry->name, module_name)) - { - DEBUG(5,("Found pdb backend %s\n", module_name)); - nt_status = entry->init(context, methods, module_location); - if (NT_STATUS_IS_OK(nt_status)) { - DEBUG(5,("pdb backend %s has a valid init\n", selected)); - } else { - DEBUG(0,("pdb backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status))); - } - SAFE_FREE(module_name); - return nt_status; - break; /* unreached */ - } - entry = entry->next; - } + entry = pdb_find_backend_entry(module_name); + + /* Try to find a module that contains this module */ + if(!entry) { + smb_probe_module("passdb", module_name); + entry = pdb_find_backend_entry(module_name); + } + /* No such backend found */ + if(!entry) { + SAFE_FREE(module_name); + return NT_STATUS_INVALID_PARAMETER; + } + + DEBUG(5,("Found pdb backend %s\n", module_name)); + nt_status = entry->init(context, methods, module_location); + if (NT_STATUS_IS_OK(nt_status)) { + DEBUG(5,("pdb backend %s has a valid init\n", selected)); + } else { + DEBUG(0,("pdb backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status))); + } SAFE_FREE(module_name); - return NT_STATUS_INVALID_PARAMETER; + return nt_status; } /****************************************************************** diff --git a/source3/smbd/server.c b/source3/smbd/server.c index ba03a9b9de..b7fb3b5701 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -412,8 +412,7 @@ static BOOL open_sockets_smbd(BOOL is_daemon, BOOL interactive, const char *smb_ } /* Load DSO's */ - if(lp_modules()) - smb_load_modules(lp_modules()); + init_modules(); return True; } diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c index ee269114c9..cec3e70687 100644 --- a/source3/utils/pdbedit.c +++ b/source3/utils/pdbedit.c @@ -536,8 +536,7 @@ int main (int argc, char **argv) exit(1); } - if(lp_modules()) - smb_load_modules(lp_modules()); + init_modules(); if (!init_names()) exit(1); diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index 0fafd1b83d..b68deaaa5d 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -177,6 +177,12 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_ 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; } -- cgit From 742dcedfa2d5ae6361e62cb057e87eb54eb46d26 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Feb 2003 02:17:54 +0000 Subject: We now use instead of just (strict XML syntax) (This used to be commit 7c00fff475e15a9e9d5c3d2c8394a2cdc1b90cac) --- source3/script/find_missing_doc.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/script/find_missing_doc.pl b/source3/script/find_missing_doc.pl index b582446569..b27a405e4d 100755 --- a/source3/script/find_missing_doc.pl +++ b/source3/script/find_missing_doc.pl @@ -30,7 +30,7 @@ close(IN); open(IN,$topdir.$doc_file) || die("Can't open $topdir$doc_file"); while() { - if( /([^<]*?)([ ]*)\(.\)([ ]*)<\/term>/g ) { + if( /([^<]*?)([ ]*)\(.\)([ ]*)<\/term>/g ) { $key = $1; $value = $2; $doc{$value} = $key; -- cgit From 5c82d3f00a2973b7f0881606d94ed36f0d0aa6be Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 27 Feb 2003 05:53:25 +0000 Subject: Doxygen janitor (This used to be commit 67bf36c69d19463c28066b276d74ac4784b26bed) --- source3/lib/iconv.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 5292e9cf0a..f622704853 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -90,11 +90,12 @@ static size_t sys_iconv(void *cd, #endif } -/* - this is a simple portable iconv() implementaion. It only knows about - a very small number of character sets - just enough that Samba works - on systems that don't have iconv - */ +/** + * This is a simple portable iconv() implementaion. + * + * It only knows about a very small number of character sets - just + * enough that Samba works on systems that don't have iconv. + **/ size_t smb_iconv(smb_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) -- cgit From 97e7d2ffae74c9c07b38143c8fb028ee91b153bd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 21:21:02 +0000 Subject: additional fix for CR 601 * distinguish WinXP from Win2k * add a 1/3 of a second delay in OpenPrinter in order to trigger a LAN/WAN optimization in 2k clients. (This used to be commit 96570699d1b715f47c35aa211da6ec18f6fc4109) --- source3/include/smb.h | 2 +- source3/lib/util.c | 3 +++ source3/rpc_server/srv_spoolss_nt.c | 6 ++++++ source3/smbd/sesssetup.c | 17 ++++++++++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/include/smb.h b/source3/include/smb.h index a2b341d0fc..bd4f113039 100644 --- a/source3/include/smb.h +++ b/source3/include/smb.h @@ -1408,7 +1408,7 @@ enum ldap_ssl_types {LDAP_SSL_ON, LDAP_SSL_OFF, LDAP_SSL_START_TLS}; enum ldap_passwd_sync_types {LDAP_PASSWD_SYNC_ON, LDAP_PASSWD_SYNC_OFF, LDAP_PASSWD_SYNC_ONLY}; /* Remote architectures we know about. */ -enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_SAMBA}; +enum remote_arch_types {RA_UNKNOWN, RA_WFWG, RA_OS2, RA_WIN95, RA_WINNT, RA_WIN2K, RA_WINXP, RA_SAMBA}; /* case handling */ enum case_handling {CASE_LOWER,CASE_UPPER}; diff --git a/source3/lib/util.c b/source3/lib/util.c index 3958600cbd..15b75356a8 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1764,6 +1764,9 @@ void set_remote_arch(enum remote_arch_types type) case RA_WIN2K: fstrcpy(remote_arch, "Win2K"); return; + case RA_WINXP: + fstrcpy(remote_arch, "WinXP"); + return; case RA_SAMBA: fstrcpy(remote_arch,"Samba"); return; diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index fa9b8eaeff..4006d0c08e 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1675,6 +1675,12 @@ Can't find printer handle we created for printer %s\n", name )); &Printer->nt_devmode ); } + /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN + optimization in Windows 2000 clients --jerry */ + + if ( RA_WIN2K == get_remote_arch() ) + usleep( 384000 ); + return WERR_OK; } diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c index 7e5ec56a27..dfe246e398 100644 --- a/source3/smbd/sesssetup.c +++ b/source3/smbd/sesssetup.c @@ -557,7 +557,7 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf, set_remote_arch( RA_WIN95); } } - + if (!doencrypt) { /* both Win95 and WinNT stuff up the password lengths for non-encrypting systems. Uggh. @@ -607,6 +607,21 @@ int reply_sesssetup_and_X(connection_struct *conn, char *inbuf,char *outbuf, p += srvstr_pull_buf(inbuf, native_lanman, p, sizeof(native_lanman), STR_TERMINATE); DEBUG(3,("Domain=[%s] NativeOS=[%s] NativeLanMan=[%s]\n", domain,native_os,native_lanman)); + + /* + * we distinguish between 2K and XP by the "Native Lan Manager" string + * WinXP => "Windows 2002 5.1" + * Win2k => "Windows 2000 5.0" + * NT4 => "Windows NT 4.0" + * Win9x => "Windows 4.0" + */ + + if ( ra_type == RA_WIN2K ) { + if ( 0 == strcmp( native_lanman, "Windows 2002 5.1" ) ) + set_remote_arch( RA_WINXP ); + } + + } DEBUG(3,("sesssetupX:name=[%s]\\[%s]@[%s]\n", domain, user, get_remote_machine_name())); -- cgit From dc1cd583cb4224f0fdb8c4529b59a66eeddba2f9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 21:37:54 +0000 Subject: don't pass NULL pointers to strcmp() (This used to be commit 6631984b12a3f74b93f7031c433dd81d6586a5df) --- source3/smbd/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index e022d26ea3..2a5f7ffd71 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1063,8 +1063,8 @@ char *DirCacheCheck( const char *path, const char *name, int snum ) NULL != entry; entry = (dir_cache_entry *)ubi_dlNext( entry ) ) { if( entry->snum == snum - && 0 == strcmp( name, entry->name ) - && 0 == strcmp( path, entry->path ) ) { + && entry->name && 0 == strcmp( name, entry->name ) + && entry->path && 0 == strcmp( path, entry->path ) ) { DEBUG(4, ("Got dir cache hit on %s %s -> %s\n",path,name,entry->dname)); return( entry->dname ); } -- cgit From 3a7d807ec9974f0b4d7938a4b734c2c7f350cd08 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 23:24:26 +0000 Subject: and the winner of "i should have just written it in assembly is..." don't use pstrcpy() when you are not dealing with pstrings. (This used to be commit 7d547f50f914747291acc71fd3544ad92ce91f0e) --- source3/smbd/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 2a5f7ffd71..10241e88d9 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1028,9 +1028,9 @@ void DirCacheAdd( const char *path, char *name, char *dname, int snum ) return; /* so just return as if nothing happened. */ /* Set pointers correctly and load values. */ - entry->path = pstrcpy( (char *)&entry[1], path); - entry->name = pstrcpy( &(entry->path[pathlen]), name); - entry->dname = pstrcpy( &(entry->name[namelen]), dname); + entry->path = memcpy( (char *)&entry[1], path, strlen(path) ); + entry->name = memcpy( &(entry->path[pathlen]), name, strlen(name) ); + entry->dname = memcpy( &(entry->name[namelen]), dname, strlen(dname) ); entry->snum = snum; /* Add the new entry to the linked list. */ -- cgit From 17c417e6e66e05d6bcee98cb1c7ebfa7d98a5347 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 23:52:37 +0000 Subject: don't forget the NULL (This used to be commit f80610120483c929afbec83d2b8649cb3e5111b0) --- source3/smbd/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index 10241e88d9..95acf4a262 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1028,9 +1028,9 @@ void DirCacheAdd( const char *path, char *name, char *dname, int snum ) return; /* so just return as if nothing happened. */ /* Set pointers correctly and load values. */ - entry->path = memcpy( (char *)&entry[1], path, strlen(path) ); - entry->name = memcpy( &(entry->path[pathlen]), name, strlen(name) ); - entry->dname = memcpy( &(entry->name[namelen]), dname, strlen(dname) ); + entry->path = memcpy( (char *)&entry[1], path, strlen(path)+1 ); + entry->name = memcpy( &(entry->path[pathlen]), name, strlen(name)+1 ); + entry->dname = memcpy( &(entry->name[namelen]), dname, strlen(dname)+1 ); entry->snum = snum; /* Add the new entry to the linked list. */ -- cgit From 9f0ae6fad2d0099a58fec389ddd430c0448ec02e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Feb 2003 00:26:20 +0000 Subject: *Excellent* patch from Michael Steffens to limit the unix domain sockets used by winbindd (also solves FD_SETSIZE problem in winbindd to boot !). Adds a "last_access" field to winbindd connections, and will close the oldest idle connection once the number of open connections goes over WINBINDD_MAX_SIMULTANEOUS_CLIENTS (defined in local.h as 200 currently). Jeremy. (This used to be commit a82caefda49396641e8650db8a7ef51752ba6c41) --- source3/include/local.h | 2 ++ source3/nsswitch/winbindd.c | 53 ++++++++++++++++++++++++++++++++++++++++----- source3/nsswitch/winbindd.h | 21 +++++++++--------- 3 files changed, 61 insertions(+), 15 deletions(-) (limited to 'source3') diff --git a/source3/include/local.h b/source3/include/local.h index e16cdbbc5d..29b0641119 100644 --- a/source3/include/local.h +++ b/source3/include/local.h @@ -221,4 +221,6 @@ /* Number in seconds for winbindd to wait for the mutex. Make this 2 * smbd wait time. */ #define WINBIND_SERVER_MUTEX_WAIT_TIME (( ((NUM_CLI_AUTH_CONNECT_RETRIES) * ((CLI_AUTH_TIMEOUT)/1000)) + 5)*2) +/* Max number of simultaneous winbindd socket connections. */ +#define WINBINDD_MAX_SIMULTANEOUS_CLIENTS 200 #endif diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index 09b89462ec..ad37768c09 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -339,7 +339,9 @@ static void new_connection(int listen_sock) ZERO_STRUCTP(state); state->sock = sock; - + + state->last_access = time(NULL); + /* Add to connection list */ winbindd_add_client(state); @@ -375,6 +377,35 @@ static void remove_client(struct winbindd_cli_state *state) } +/* Shutdown client connection which has been idle for the longest time */ + +static BOOL remove_idle_client(void) +{ + struct winbindd_cli_state *state, *remove_state = NULL; + time_t last_access = 0; + int nidle = 0; + + for (state = winbindd_client_list(); state; state = state->next) { + if (state->read_buf_len == 0 && state->write_buf_len == 0 && + !state->getpwent_state && !state->getgrent_state) { + nidle++; + if (!last_access || state->last_access < last_access) { + last_access = state->last_access; + remove_state = state; + } + } + } + + if (remove_state) { + DEBUG(5,("Found %d idle client connections, shutting down sock %d, pid %u\n", + nidle, remove_state->sock, (unsigned int)remove_state->pid)); + remove_client(remove_state); + return True; + } + + return False; +} + /* Process a complete received packet from a client */ void winbind_process_packet(struct winbindd_cli_state *state) @@ -427,6 +458,7 @@ void winbind_client_read(struct winbindd_cli_state *state) /* Update client state */ state->read_buf_len += n; + state->last_access = time(NULL); } /* Write some data to a client connection */ @@ -477,7 +509,8 @@ static void client_write(struct winbindd_cli_state *state) /* Update client state */ state->write_buf_len -= num_written; - + state->last_access = time(NULL); + /* Have we written all data? */ if (state->write_buf_len == 0) { @@ -508,7 +541,7 @@ static void client_write(struct winbindd_cli_state *state) } } -/* Process incoming clients on accept_sock. We use a tricky non-blocking, +/* Process incoming clients on listen_sock. We use a tricky non-blocking, non-forking, non-threaded model which allows us to handle many simultaneous connections while remaining impervious to many denial of service attacks. */ @@ -608,7 +641,7 @@ static void process_loop(void) exit(1); } - /* Create a new connection if accept_sock readable */ + /* Create a new connection if listen_sock readable */ if (selret > 0) { @@ -616,8 +649,18 @@ static void process_loop(void) dual_select(&w_fds); } - if (FD_ISSET(listen_sock, &r_fds)) + if (FD_ISSET(listen_sock, &r_fds)) { + while (winbindd_num_clients() > WINBINDD_MAX_SIMULTANEOUS_CLIENTS - 1) { + DEBUG(5,("winbindd: Exceeding %d client connections, removing idle connection.\n", + WINBINDD_MAX_SIMULTANEOUS_CLIENTS)); + if (!remove_idle_client()) { + DEBUG(0,("winbindd: Exceeding %d client connections, no idle connection found\n", + WINBINDD_MAX_SIMULTANEOUS_CLIENTS)); + break; + } + } new_connection(listen_sock); + } /* Process activity on client connections */ diff --git a/source3/nsswitch/winbindd.h b/source3/nsswitch/winbindd.h index 8bd8a83748..42ef209faf 100644 --- a/source3/nsswitch/winbindd.h +++ b/source3/nsswitch/winbindd.h @@ -36,16 +36,17 @@ /* Client state structure */ struct winbindd_cli_state { - struct winbindd_cli_state *prev, *next; /* Linked list pointers */ - int sock; /* Open socket from client */ - pid_t pid; /* pid of client */ - int read_buf_len, write_buf_len; /* Indexes in request/response */ - BOOL finished; /* Can delete from list */ - BOOL write_extra_data; /* Write extra_data field */ - struct winbindd_request request; /* Request from client */ - struct winbindd_response response; /* Respose to client */ - struct getent_state *getpwent_state; /* State for getpwent() */ - struct getent_state *getgrent_state; /* State for getgrent() */ + struct winbindd_cli_state *prev, *next; /* Linked list pointers */ + int sock; /* Open socket from client */ + pid_t pid; /* pid of client */ + int read_buf_len, write_buf_len; /* Indexes in request/response */ + BOOL finished; /* Can delete from list */ + BOOL write_extra_data; /* Write extra_data field */ + time_t last_access; /* Time of last access (read or write) */ + struct winbindd_request request; /* Request from client */ + struct winbindd_response response; /* Respose to client */ + struct getent_state *getpwent_state; /* State for getpwent() */ + struct getent_state *getgrent_state; /* State for getgrent() */ }; /* State between get{pw,gr}ent() calls */ -- cgit From a001b706bd85f40b2b9096af1ab92b135440f184 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 28 Feb 2003 03:21:22 +0000 Subject: Improve net ads lookup: - More info is printed - (grand)child domains handled properly Thanks to Anthony Liguori (aliguori@us.ibm.com) (This used to be commit 3dbcb4d93f7c192eb2ccea5941a3843b5de1190e) --- source3/utils/net_ads_cldap.c | 203 +++++++++++++++++++++++++++++------------- 1 file changed, 142 insertions(+), 61 deletions(-) (limited to 'source3') diff --git a/source3/utils/net_ads_cldap.c b/source3/utils/net_ads_cldap.c index f81c763093..d369fbdf50 100644 --- a/source3/utils/net_ads_cldap.c +++ b/source3/utils/net_ads_cldap.c @@ -2,6 +2,7 @@ Samba Unix/Linux SMB client library net ads cldap functions Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) + Copyright (C) 2003 Jim McDonough (jmcd@us.ibm.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 @@ -23,60 +24,69 @@ #ifdef HAVE_ADS +struct netlogon_string { + uint32 comp_len; + char **component; + uint8 extra_flag; +}; + struct cldap_netlogon_reply { - uint32 version; + uint32 type; uint32 flags; GUID guid; - char *domain; - char *server_name; - char *domain_flatname; - char *server_flatname; - char *dns_name; - uint32 unknown2[2]; -}; + struct netlogon_string forest; + struct netlogon_string domain; + struct netlogon_string hostname; -/* - pull a length prefixed string from a packet - return number of bytes consumed -*/ -static unsigned pull_len_string(char **ret, const char *p) -{ - unsigned len = *p; - (*ret) = NULL; - if (len == 0) return 1; - (*ret) = smb_xstrndup(p+1, len); - return len+1; -} + struct netlogon_string netbios_domain; + struct netlogon_string netbios_hostname; + + struct netlogon_string user_name; + struct netlogon_string site_name; + + struct netlogon_string unk0; + + uint32 version; + uint16 lmnt_token; + uint16 lm20_token; +}; /* - pull a dotted string from a packet - return number of bytes consumed + These strings are rather interesting... They are composed of a series of + length encoded strings, terminated by either 1) a zero length string or 2) + a 0xc0 byte with what appears to be a one byte flags immediately following. */ -static unsigned pull_dotted_string(char **ret, const char *p) +static unsigned pull_netlogon_string(struct netlogon_string *ret,const char *d) { - char *s; - unsigned len, total_len=0; + char *s, *p = (char *)d; + + ZERO_STRUCTP(ret); - (*ret) = NULL; + do { + unsigned len = (unsigned char)*p; + p++; - while ((len = pull_len_string(&s, p)) > 1) { - if (total_len) { - char *s2; - asprintf(&s2, "%s.%s", *ret, s); - SAFE_FREE(*ret); - (*ret) = s2; + if (len > 0 && len != 0xc0) { + ret->component = realloc(ret->component, + ++ret->comp_len * + sizeof(char *)); + + ret->component[ret->comp_len - 1] = + smb_xstrndup(p, len); + p += len; } else { - (*ret) = s; + if (len == 0xc0) { + ret->extra_flag = *p; + p++; + }; + break; } - total_len += len; - p += len; - } + } while (1); - return total_len + 1; + return (p - d); } - /* do a cldap netlogon query */ @@ -190,19 +200,25 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply) p = os3.data; - reply->version = IVAL(p, 0); p += 4; + reply->type = IVAL(p, 0); p += 4; reply->flags = IVAL(p, 0); p += 4; + memcpy(&reply->guid.info, p, GUID_SIZE); p += GUID_SIZE; - p += pull_dotted_string(&reply->domain, p); - p += 2; /* 0xc018 - whats this? */ - p += pull_len_string(&reply->server_name, p); - p += 2; /* 0xc018 - whats this? */ - p += pull_len_string(&reply->domain_flatname, p); - p += 1; - p += pull_len_string(&reply->server_flatname, p); - p += 2; - p += pull_len_string(&reply->dns_name, p); + + p += pull_netlogon_string(&reply->forest, p); + p += pull_netlogon_string(&reply->domain, p); + p += pull_netlogon_string(&reply->hostname, p); + p += pull_netlogon_string(&reply->netbios_domain, p); + p += pull_netlogon_string(&reply->netbios_hostname, p); + p += pull_netlogon_string(&reply->user_name, p); + p += pull_netlogon_string(&reply->site_name, p); + + p += pull_netlogon_string(&reply->unk0, p); + + reply->version = IVAL(p, 0); + reply->lmnt_token = SVAL(p, 4); + reply->lm20_token = SVAL(p, 6); data_blob_free(&os1); data_blob_free(&os2); @@ -212,17 +228,50 @@ static int recv_cldap_netlogon(int sock, struct cldap_netlogon_reply *reply) return 0; } +/* + free a netlogon string +*/ +static void netlogon_string_free(struct netlogon_string *str) +{ + int i; + + for (i = 0; i < str->comp_len; ++i) { + SAFE_FREE(str->component[i]); + } + SAFE_FREE(str->component); +} /* free a cldap reply packet */ static void cldap_reply_free(struct cldap_netlogon_reply *reply) { - SAFE_FREE(reply->domain); - SAFE_FREE(reply->server_name); - SAFE_FREE(reply->domain_flatname); - SAFE_FREE(reply->server_flatname); - SAFE_FREE(reply->dns_name); + netlogon_string_free(&reply->forest); + netlogon_string_free(&reply->domain); + netlogon_string_free(&reply->hostname); + netlogon_string_free(&reply->netbios_domain); + netlogon_string_free(&reply->netbios_hostname); + netlogon_string_free(&reply->user_name); + netlogon_string_free(&reply->site_name); + netlogon_string_free(&reply->unk0); +} + +static void d_print_netlogon_string(const char *label, + struct netlogon_string *str) +{ + int i; + + if (str->comp_len) { + d_printf("%s", label); + if (str->extra_flag) { + d_printf("[%d]", str->extra_flag); + } + d_printf(": "); + for (i = 0; i < str->comp_len; ++i) { + d_printf("%s%s", (i ? "." : ""), str->component[i]); + } + d_printf("\n"); + } } /* @@ -246,7 +295,6 @@ int ads_cldap_netlogon(ADS_STRUCT *ads) if (ret != 0) { return ret; } - ret = recv_cldap_netlogon(sock, &reply); close(sock); @@ -254,15 +302,48 @@ int ads_cldap_netlogon(ADS_STRUCT *ads) return -1; } - d_printf("Version: 0x%x\n", reply.version); + d_printf("Information for Domain Controller: %s\n\n", + ads->config.ldap_server_name); + + d_printf("Response Type: 0x%x\n", reply.type); d_printf("GUID: "); print_guid(&reply.guid); - d_printf("Flags: 0x%x\n", reply.flags); - d_printf("Domain: %s\n", reply.domain); - d_printf("Server Name: %s\n", reply.server_name); - d_printf("Flatname: %s\n", reply.domain_flatname); - d_printf("Server Name2: %s\n", reply.server_flatname); - d_printf("DNS Name: %s\n", reply.dns_name); + d_printf("Flags:\n" + "\tIs a PDC: %s\n" + "\tIs a GC of the forest: %s\n" + "\tIs an LDAP server: %s\n" + "\tSupports DS: %s\n" + "\tIs running a KDC: %s\n" + "\tIs running time services: %s\n" + "\tIs the closest DC: %s\n" + "\tIs writable: %s\n" + "\tHas a hardware clock: %s\n" + "\tIs a non-domain NC serviced by LDAP server: %s\n", + (reply.flags & ADS_PDC) ? "yes" : "no", + (reply.flags & ADS_GC) ? "yes" : "no", + (reply.flags & ADS_LDAP) ? "yes" : "no", + (reply.flags & ADS_DS) ? "yes" : "no", + (reply.flags & ADS_KDC) ? "yes" : "no", + (reply.flags & ADS_TIMESERV) ? "yes" : "no", + (reply.flags & ADS_CLOSEST) ? "yes" : "no", + (reply.flags & ADS_WRITABLE) ? "yes" : "no", + (reply.flags & ADS_GOOD_TIMESERV) ? "yes" : "no", + (reply.flags & ADS_NDNC) ? "yes" : "no"); + + d_print_netlogon_string("Forest", &reply.forest); + d_print_netlogon_string("Domain", &reply.domain); + d_print_netlogon_string("Hostname", &reply.hostname); + + d_print_netlogon_string("Pre-Win2k Domain", &reply.netbios_domain); + d_print_netlogon_string("Pre-Win2k Hostname", &reply.netbios_hostname); + + d_print_netlogon_string("User name", &reply.user_name); + d_print_netlogon_string("Site Name", &reply.site_name); + d_print_netlogon_string("Unknown Field", &reply.unk0); + + d_printf("NT Version: %d\n", reply.version); + d_printf("LMNT Token: %0.2x\n", reply.lmnt_token); + d_printf("LM20 Token: %0.2x\n", reply.lm20_token); cldap_reply_free(&reply); -- cgit From db47e9450aff5ff5b6853f163d4aab117d1c77aa Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 28 Feb 2003 03:29:03 +0000 Subject: cleanup some compiler warnings (This used to be commit 87cebe797f06fab4a5d0077fd78b2183ff7333a5) --- source3/utils/net_ads_cldap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3') diff --git a/source3/utils/net_ads_cldap.c b/source3/utils/net_ads_cldap.c index d369fbdf50..ad66af0439 100644 --- a/source3/utils/net_ads_cldap.c +++ b/source3/utils/net_ads_cldap.c @@ -59,7 +59,7 @@ struct cldap_netlogon_reply { */ static unsigned pull_netlogon_string(struct netlogon_string *ret,const char *d) { - char *s, *p = (char *)d; + char *p = (char *)d; ZERO_STRUCTP(ret); @@ -342,8 +342,8 @@ int ads_cldap_netlogon(ADS_STRUCT *ads) d_print_netlogon_string("Unknown Field", &reply.unk0); d_printf("NT Version: %d\n", reply.version); - d_printf("LMNT Token: %0.2x\n", reply.lmnt_token); - d_printf("LM20 Token: %0.2x\n", reply.lm20_token); + d_printf("LMNT Token: %.2x\n", reply.lmnt_token); + d_printf("LM20 Token: %.2x\n", reply.lm20_token); cldap_reply_free(&reply); -- cgit From 37e39f5be4ae0156565b009ae210f2c95e906142 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 03:34:18 +0000 Subject: Add simple test harness that exposes StrCaseCmp for testing. (This used to be commit ab77beca041595bc3bd70de3a6e1b49159a4964b) --- source3/torture/t_strcmp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 source3/torture/t_strcmp.c (limited to 'source3') diff --git a/source3/torture/t_strcmp.c b/source3/torture/t_strcmp.c new file mode 100644 index 0000000000..622769001b --- /dev/null +++ b/source3/torture/t_strcmp.c @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2003 by Martin Pool + * + * Test harness for StrCaseCmp + */ + +#include "includes.h" + +int main(int argc, char *argv[]) +{ + if (argc != 3) { + fprintf(stderr, "usage: %s STRING1 STRING2\nCompares two strings\n", + argv[0]); + return 2; + } + + printf("%d\n", StrCaseCmp(argv[1], argv[2])); + + return 0; +} -- cgit From 921e569ed50408d42ddab5d524cf39a86429d488 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 03:51:25 +0000 Subject: Add a comment about the meaning of samba's internal character set and how this interacts with it. (This used to be commit eb876ee9cf24eda04e0856899b232d060c669c0c) --- source3/lib/iconv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index f622704853..6786003de5 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -21,6 +21,30 @@ #include "includes.h" + +/** + * @file + * + * @brief Samba wrapper/stub for iconv character set conversion. + * + * iconv is the XPG2 interface for converting between character + * encodings. This file provides a Samba wrapper around it, and also + * a simple reimplementation that is used if the system does not + * implement iconv. + * + * Samba only works with encodings that are supersets of ASCII: ascii + * characters like whitespace can be tested for directly, multibyte + * sequences start with a byte with the high bit set, and strings are + * terminated by \0. + * + * Note that the only function provided by iconv is conversion between + * characters. It doesn't directly support operations like + * uppercasing or comparison. We have to convert to UCS-2 and compare + * there. + * + * @sa Samba Developers Guide + **/ + static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); static size_t ascii_push(void *,char **, size_t *, char **, size_t *); static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); -- cgit From 290098e39e04d66897e09c792a85b9a79cd86d49 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 03:59:47 +0000 Subject: Remove reference to "mainpage.dox" and CodingStandards, which have been removed. Put subdirectory names in file list, so we get lib/util_chr.c, not just util_chr.c. (This used to be commit aa2efaab1ffc77bec051cd206000951c72adeccc) --- source3/Doxyfile | 7 +++---- source3/mainpage.dox | 7 ------- 2 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 source3/mainpage.dox (limited to 'source3') diff --git a/source3/Doxyfile b/source3/Doxyfile index 914ba25672..c1040781d8 100644 --- a/source3/Doxyfile +++ b/source3/Doxyfile @@ -23,8 +23,8 @@ HIDE_UNDOC_CLASSES = NO BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ALWAYS_DETAILED_SEC = NO -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = *source +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = $(PWD)/ INTERNAL_DOCS = YES CLASS_DIAGRAMS = YES SOURCE_BROWSER = YES @@ -61,8 +61,7 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = . \ - mainpage.dox +INPUT = . FILE_PATTERNS = *.c \ *.h \ *.idl diff --git a/source3/mainpage.dox b/source3/mainpage.dox deleted file mode 100644 index 8b72f80462..0000000000 --- a/source3/mainpage.dox +++ /dev/null @@ -1,7 +0,0 @@ -/** - -@mainpage - -@li \ref CodingSuggestions - -**/ -- cgit From 7ca743713b71fe31e3e81f56c91b70206df7a143 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:06:56 +0000 Subject: Fix comment typo (This used to be commit d2fd52c1b50f2d1abad84668911b04c72fdc4b8d) --- source3/web/swat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/web/swat.c b/source3/web/swat.c index 21ae104cef..4211b2f15a 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -21,7 +21,7 @@ */ /** - * @group swat SWAT + * @defgroup swat SWAT * @{ * @file swat.c * -- cgit From 22d482dade44b51bc150aa9f34fc89e995ccc934 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:09:58 +0000 Subject: Doxygen janitor: check_domain_match parameter is spelled "auth_context". (This used to be commit 571c3ce19344276aac1af56d2f69fcc5523f36eb) --- source3/auth/auth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/auth/auth.c b/source3/auth/auth.c index 2abdec3a39..8b33010e91 100644 --- a/source3/auth/auth.c +++ b/source3/auth/auth.c @@ -162,8 +162,8 @@ static BOOL check_domain_match(const char *user, const char *domain) * @param user_info Contains the user supplied components, including the passwords. * Must be created with make_user_info() or one of its wrappers. * - * @param auth_info Supplies the challenges and some other data. - * Must be created with make_auth_info(), and the challenges should be + * @param auth_context Supplies the challenges and some other data. + * Must be created with make_auth_context(), and the challenges should be * filled in, either at creation or by calling the challenge geneation * function auth_get_challenge(). * -- cgit From 4125dfca83930b42d28ef08f920e41c6b2f62134 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:11:28 +0000 Subject: Doxygen janitor: rpc_resolve_dc parameter is spelled "trust_passwd" (This used to be commit 9dbc3dcfe0bccf1f76930ae86970b48ba5ed1e91) --- source3/auth/auth_domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3') diff --git a/source3/auth/auth_domain.c b/source3/auth/auth_domain.c index b3f50072bc..0d90a184a4 100644 --- a/source3/auth/auth_domain.c +++ b/source3/auth/auth_domain.c @@ -115,7 +115,7 @@ static NTSTATUS rpc_resolve_dc(const char *server, * @param cli the cli to return containing the active connection * @param server either a machine name or text IP address to * connect to. - * @param trust_password the trust password to establish the + * @param trust_passwd the trust password to establish the * credentials with. * **/ -- cgit From f5f59e866e5b761a6b0c95d29bb2d1ec0136652f Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:17:30 +0000 Subject: Doxygen janitor: fix parameter names, grammar, tag names. (This used to be commit 42d9ec28cd55dbcfda546c84fb842938aeda544d) --- source3/lib/gencache.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3') diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 7260e477b8..5c8ad1339b 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -94,12 +94,12 @@ BOOL gencache_shutdown(void) * Set an entry in the cache file. If there's no such * one, then add it. * - * @param key string that represents a key of this entry + * @param keystr string that represents a key of this entry * @param value text representation value being cached * @param timeout time when the value is expired * - * @return true when entry is successfuly stored or - * false on the attempt's failure + * @retval true when entry is successfuly stored + * @retval false on failure **/ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) @@ -134,12 +134,12 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) /** * Set existing entry to the cache file. * - * @param key string that represents a key of this entry - * @param value text representation value being cached + * @param keystr string that represents a key of this entry + * @param valstr text representation value being cached * @param timeout time when the value is expired * - * @return true when entry is successfuly set or - * false on the attempt's failure + * @retval true when entry is successfuly set + * @retval false on failure **/ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) @@ -189,10 +189,10 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) /** * Delete one entry from the cache file. * - * @param key string that represents a key of this entry + * @param keystr string that represents a key of this entry * - * @return true upon successful deletion or - * false in case of failure + * @retval true upon successful deletion + * @retval false in case of failure **/ BOOL gencache_del(const char *keystr) @@ -218,14 +218,14 @@ BOOL gencache_del(const char *keystr) /** * Get existing entry from the cache file. * - * @param key string that represents a key of this entry - * @param value buffer that is allocated and filled with the entry value + * @param keystr string that represents a key of this entry + * @param valstr buffer that is allocated and filled with the entry value * buffer's disposing must be done outside * @param timeout pointer to a time_t that is filled with entry's * timeout * - * @return true when entry is successfuly fetched or - * false on the failure + * @retval true when entry is successfuly fetched + * @retval False for failure **/ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) -- cgit From 481b4e6d6ceeab644b5c4d1ee11bc221d8035202 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:21:55 +0000 Subject: Doxygen janitor (This used to be commit 9af07173152c5e861d13b33a8d4aee8167a50b66) --- source3/lib/iconv.c | 2 +- source3/lib/messages.c | 14 +++++++------- source3/web/swat.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6786003de5..8b360a14c6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -35,7 +35,7 @@ * Samba only works with encodings that are supersets of ASCII: ascii * characters like whitespace can be tested for directly, multibyte * sequences start with a byte with the high bit set, and strings are - * terminated by \0. + * terminated by a nul byte. * * Note that the only function provided by iconv is conversion between * characters. It doesn't directly support operations like diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 3603758e9f..5ff0e45c61 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -21,11 +21,11 @@ */ /** - @defgroups messages Internal messaging framework - @{ - @file messages.c - - This module is used for internal messaging between Samba daemons. + @defgroup messages Internal messaging framework + @{ + @file messages.c + + @brief Module for internal messaging between Samba daemons. The idea is that if a part of Samba wants to do communication with another Samba process then it will do a message_register() of a @@ -36,7 +36,7 @@ use that to reply by message_send_pid(). See ping_message() for a simple example. - *NOTE*: Dispatch functions must be able to cope with incoming + @caution Dispatch functions must be able to cope with incoming messages on an *odd* byte boundary. This system doesn't have any inherent size limitations but is not @@ -524,7 +524,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void * @param n_sent Set to the number of messages sent. This should be * equal to the number of processes, but be careful for races. * - * @return True for success. + * @retval True for success. **/ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, const void *buf, size_t len, diff --git a/source3/web/swat.c b/source3/web/swat.c index 4211b2f15a..d6693b4e75 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -21,7 +21,7 @@ */ /** - * @defgroup swat SWAT + * @defgroup swat SWAT - Samba Web Administration Tool * @{ * @file swat.c * -- cgit From e7ff3803a385925b52f09526d2bbc8ca479d2ae4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Feb 2003 04:36:08 +0000 Subject: - added help on -P option - added general options to 'net -h' help (This used to be commit ee8a7fdab7f5aa6f4a64f2eea90f0d44ae0f388a) --- source3/utils/net_help.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3') diff --git a/source3/utils/net_help.c b/source3/utils/net_help.c index 782a530035..4000a248ff 100644 --- a/source3/utils/net_help.c +++ b/source3/utils/net_help.c @@ -47,6 +47,7 @@ int net_common_flags_usage(int argc, const char **argv) d_printf("\t-U or --user=\t\tuser name\n"); d_printf("\t-s or --conf=\t\tpathname of smb.conf file\n"); d_printf("\t-l or --long\t\t\tDisplay full information\n"); + d_printf("\t-P or --machine-pass\t\tAuthenticate as machine account\n"); return -1; } @@ -160,6 +161,7 @@ static int net_usage(int argc, const char **argv) " net rpc \tto run RPC commands\n"\ "\n"\ "Type \"net help