static void get_credentials_file(const char *file, struct user_auth_info *info) { XFILE *auth; fstring buf; uint16 len = 0; char *ptr, *val, *param; if ((auth=x_fopen(file, O_RDONLY, 0)) == NULL) { /* fail if we can't open the credentials file */ d_printf("ERROR: Unable to open credentials file!\n"); exit(-1); } while (!x_feof(auth)) { /* get a line from the file */ if (!x_fgets(buf, sizeof(buf), auth)) continue; len = strlen(buf); if ((len) && (buf[len-1]=='\n')) { buf[len-1] = '\0'; len--; } if (len == 0) continue; /* break up the line into parameter & value. * will need to eat a little whitespace possibly */ param = buf; if (!(ptr = strchr_m (buf, '='))) continue; val = ptr+1; *ptr = '\0'; /* eat leading white space */ while ((*val!='\0') && ((*val==' ') || (*val=='\t'))) val++; if (strwicmp("password", param) == 0) { pstrcpy(info->password, val); info->got_pass = True; } else if (strwicmp("username", param) == 0) pstrcpy(info->username, val); else if (strwicmp("domain", param) == 0) set_global_myworkgroup(val); memset(buf, 0, sizeof(buf)); } x_fclose(auth); }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { if (reason == POPT_CALLBACK_REASON_PRE) { set_logfile(con, dyn_LOGFILEBASE); return; } switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } break; case 'V': printf( "Version %s\n", SAMBA_VERSION_STRING); exit(0); break; case 'O': if (arg) { pstrcpy(user_socket_options,arg); } break; case 's': if (arg) { pstrcpy(dyn_CONFIGFILE, arg); } break; case 'n': if (arg) { set_global_myname(arg); } break; case 'l': if (arg) { set_logfile(con, arg); override_logfile = True; pstr_sprintf(dyn_LOGFILEBASE, "%s", arg); } break; case 'i': if (arg) { set_global_scope(arg); } break; case 'W': if (arg) { set_global_myworkgroup(arg); } break; } }
int main(int argc,char *argv[]) { extern BOOL AllowDebugChange; int opt; BOOL message = False; poptContext pc; char *p; fstring new_workgroup; struct poptOption long_options[] = { POPT_AUTOHELP { "message", 'M', POPT_ARG_STRING, NULL, 'M', "Send message", "HOST" }, POPT_COMMON_SAMBA POPT_COMMON_CONNECTION POPT_COMMON_CREDENTIALS POPT_TABLEEND }; /* initialize the workgroup name so we can determine whether or not it was set by a command line option */ set_global_myworkgroup( "" ); /* set default debug level to 0 regardless of what smb.conf sets */ setup_logging( "smbmessage", True ); DEBUGLEVEL_CLASS[DBGC_ALL] = 1; dbf = x_stderr; x_setbuf( x_stderr, NULL ); pc = poptGetContext("smbmessage", argc, (const char **) argv, long_options, POPT_CONTEXT_KEEP_FIRST); in_client = True; /* Make sure that we tell lp_load we are */ while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'M': /* Messages are sent to NetBIOS name type 0x3 * (Messenger Service). Make sure we default * to port 139 instead of port 445. srl,crh */ name_type = 0x03; pstrcpy(desthost,poptGetOptArg(pc)); if( 0 == port ) port = 139; message = True; break; } } poptGetArg(pc); /* * Don't load debug level from smb.conf. It should be * set by cmdline arg or remain default (0) */ AllowDebugChange = False; /* save the workgroup... FIXME!! do we need to do tyhis for other options as well (or maybe a generic way to keep lp_load() from overwriting everything)? */ fstrcpy( new_workgroup, lp_workgroup() ); if (!lp_load(dyn_CONFIGFILE,True,False,False)) { fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", argv[0], dyn_CONFIGFILE); } load_interfaces(); if ( strlen(new_workgroup) != 0 ) set_global_myworkgroup( new_workgroup ); if (poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); exit(1); } init_names(); if (!message) { poptPrintUsage(pc, stderr, 0); exit(1); } poptFreeContext(pc); pstrcpy(username, cmdline_auth_info.username); pstrcpy(password, cmdline_auth_info.password); DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING)); return do_message_op(); }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { pstring logfile; const char *pname; /* Find out basename of current program */ pname = strrchr_m(poptGetInvocationName(con),'/'); if (!pname) pname = poptGetInvocationName(con); else pname++; if (reason == POPT_CALLBACK_REASON_PRE) { pstr_sprintf(logfile, "%s/log.%s", dyn_LOGFILEBASE, pname); lp_set_logfile(logfile); return; } switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } break; case 'V': printf( "Version %s\n", SAMBA_VERSION_STRING); exit(0); break; case 'O': if (arg) { pstrcpy(user_socket_options,arg); } break; case 's': if (arg) { pstrcpy(dyn_CONFIGFILE, arg); } break; case 'n': if (arg) { set_global_myname(arg); } break; case 'l': if (arg) { pstr_sprintf(logfile, "%s/log.%s", arg, pname); lp_set_logfile(logfile); } break; case 'i': if (arg) { set_global_scope(arg); } break; case 'W': if (arg) { set_global_myworkgroup(arg); } break; } }
static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { if (reason == POPT_CALLBACK_REASON_PRE) { set_logfile(con, get_dyn_LOGFILEBASE()); return; } if (reason == POPT_CALLBACK_REASON_POST) { if (PrintSambaVersionString) { printf( "Version %s\n", samba_version_string()); exit(0); } if (is_default_dyn_CONFIGFILE()) { if(getenv("SMB_CONF_PATH")) { set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); } } /* Further 'every Samba program must do this' hooks here. */ return; } switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } break; case 'V': PrintSambaVersionString = True; break; case 'O': if (arg) { lp_do_parameter(-1, "socket options", arg); } break; case 's': if (arg) { set_dyn_CONFIGFILE(arg); } break; case 'n': if (arg) { set_global_myname(arg); } break; case 'l': if (arg) { set_logfile(con, arg); override_logfile = True; set_dyn_LOGFILEBASE(arg); } break; case 'i': if (arg) { set_global_scope(arg); } break; case 'W': if (arg) { set_global_myworkgroup(arg); } break; } }