static const char *automount_server(const char *user_name) { static pstring server_name; const char *local_machine_name = get_local_machine_name(); /* use the local machine name as the default */ /* this will be the default if WITH_AUTOMOUNT is not used or fails */ if (local_machine_name && *local_machine_name) pstrcpy(server_name, local_machine_name); else pstrcpy(server_name, global_myname()); #if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT)) if (lp_nis_home_map()) { int home_server_len; char *automount_value = automount_lookup(user_name); home_server_len = strcspn(automount_value,":"); DEBUG(5, ("NIS lookup succeeded. Home server length: %d\n",home_server_len)); if (home_server_len > sizeof(pstring)) home_server_len = sizeof(pstring); strncpy(server_name, automount_value, home_server_len); server_name[home_server_len] = '\0'; } #endif DEBUG(4,("Home server: %s\n", server_name)); return server_name; }
static void sync_child(char *name, int nm_type, char *workgroup, struct in_addr ip, bool local, bool servers, char *fname) { fstring unix_workgroup; struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct sockaddr_storage ss; NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. * Patch from Andy Levine [email protected]. */ in_addr_to_sockaddr_storage(&ss, ip); status = cli_connect_nb(name, &ss, NBT_SMB_PORT, nm_type, get_local_machine_name(), SMB_SIGNING_DEFAULT, 0, &cli); if (!NT_STATUS_IS_OK(status)) { return; } status = cli_negprot(cli, PROTOCOL_NT1); if (!NT_STATUS_IS_OK(status)) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 1, "", 0, workgroup))) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_tree_connect(cli, "IPC$", "IPC", "", 1))) { cli_shutdown(cli); return; } /* All the cli_XX functions take UNIX character set. */ fstrcpy(unix_workgroup, cli->server_domain ? cli->server_domain : workgroup); /* Fetch a workgroup list. */ cli_NetServerEnum(cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback, NULL); /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); cli_NetServerEnum(cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); } cli_shutdown(cli); }
static void sync_child(char *name, int nm_type, char *workgroup, struct in_addr ip, bool local, bool servers, char *fname) { fstring unix_workgroup; struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; struct sockaddr_storage ss; NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. * Patch from Andy Levine [email protected]. */ cli = cli_initialise(); if (!cli) { return; } if (!cli_set_port(cli, 139)) { cli_shutdown(cli); return; } in_addr_to_sockaddr_storage(&ss, ip); status = cli_connect(cli, name, &ss); if (!NT_STATUS_IS_OK(status)) { cli_shutdown(cli); return; } make_nmb_name(&calling, get_local_machine_name(), 0x0); make_nmb_name(&called , name, nm_type); if (!cli_session_request(cli, &calling, &called)) { cli_shutdown(cli); return; } if (!cli_negprot(cli)) { cli_shutdown(cli); return; } if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 1, "", 0, workgroup))) { cli_shutdown(cli); return; } if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { cli_shutdown(cli); return; } /* All the cli_XX functions take UNIX character set. */ fstrcpy(unix_workgroup, cli->server_domain ? cli->server_domain : workgroup); /* Fetch a workgroup list. */ cli_NetServerEnum(cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback, NULL); /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); cli_NetServerEnum(cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); } cli_shutdown(cli); }
char *alloc_sub_basic(const char *smb_name, const char *str) { char *b, *p, *s, *t, *r, *a_string; fstring pidstr; struct passwd *pass; const char *local_machine_name = get_local_machine_name(); /* workaround to prevent a crash while lookinf at bug #687 */ if ( !str ) { DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n")); return NULL; } a_string = strdup(str); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; } for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { r = NULL; b = t = a_string; switch (*(p+1)) { case 'U' : r = strdup_lower(smb_name); if (r == NULL) goto error; t = realloc_string_sub(t, "%U", r); break; case 'G' : r = strdup(smb_name); if (r == NULL) goto error; if ((pass = Get_Pwnam(r))!=NULL) { t = realloc_string_sub(t, "%G", gidtoname(pass->pw_gid)); } break; case 'D' : r = strdup_upper(current_user_info.domain); if (r == NULL) goto error; t = realloc_string_sub(t, "%D", r); break; case 'I' : t = realloc_string_sub(t, "%I", client_addr()); break; case 'L' : if (local_machine_name && *local_machine_name) t = realloc_string_sub(t, "%L", local_machine_name); else t = realloc_string_sub(t, "%L", global_myname()); break; case 'N': t = realloc_string_sub(t, "%N", automount_server(smb_name)); break; case 'M' : t = realloc_string_sub(t, "%M", client_name()); break; case 'R' : t = realloc_string_sub(t, "%R", remote_proto); break; case 'T' : t = realloc_string_sub(t, "%T", timestring(False)); break; case 'a' : t = realloc_string_sub(t, "%a", remote_arch); break; case 'd' : slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid()); t = realloc_string_sub(t, "%d", pidstr); break; case 'h' : t = realloc_string_sub(t, "%h", myhostname()); break; case 'm' : t = realloc_string_sub(t, "%m", remote_machine); break; case 'v' : t = realloc_string_sub(t, "%v", SAMBA_VERSION_STRING); break; case '$' : t = realloc_expand_env_var(t, p); /* Expand environment variables */ break; default: break; } p++; SAFE_FREE(r); if (t == NULL) goto error; a_string = t; } return a_string; error: SAFE_FREE(a_string); return NULL; }
void standard_sub_basic(const char *smb_name, char *str,size_t len) { char *p, *s; fstring pidstr; struct passwd *pass; const char *local_machine_name = get_local_machine_name(); for (s=str; (p=strchr_m(s, '%'));s=p) { fstring tmp_str; int l = (int)len - (int)(p-str); if (l < 0) l = 0; switch (*(p+1)) { case 'U' : fstrcpy(tmp_str, smb_name); strlower_m(tmp_str); string_sub(p,"%U",tmp_str,l); break; case 'G' : fstrcpy(tmp_str, smb_name); if ((pass = Get_Pwnam(tmp_str))!=NULL) { string_sub(p,"%G",gidtoname(pass->pw_gid),l); } else { p += 2; } break; case 'D' : fstrcpy(tmp_str, current_user_info.domain); strupper_m(tmp_str); string_sub(p,"%D", tmp_str,l); break; case 'I' : string_sub(p,"%I", client_addr(),l); break; case 'i' : string_sub(p,"%i", client_socket_addr(),l); break; case 'L' : if (local_machine_name && *local_machine_name) string_sub(p,"%L", local_machine_name,l); else { pstring temp_name; pstrcpy(temp_name, global_myname()); strlower_m(temp_name); string_sub(p,"%L", temp_name,l); } break; case 'M' : string_sub(p,"%M", client_name(),l); break; case 'R' : string_sub(p,"%R", remote_proto,l); break; case 'T' : string_sub(p,"%T", timestring(False),l); break; case 'a' : string_sub(p,"%a", remote_arch,l); break; case 'd' : slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid()); string_sub(p,"%d", pidstr,l); break; case 'h' : string_sub(p,"%h", myhostname(),l); break; case 'm' : string_sub(p,"%m", get_remote_machine_name(),l); break; case 'v' : string_sub(p,"%v", SAMBA_VERSION_STRING,l); break; case '$' : p += expand_env_var(p,l); break; /* Expand environment variables */ case '\0': p++; break; /* don't run off the end of the string */ default: p+=2; break; } } }