static struct cli_state * /* O - SMB connection */ smb_connect(const char *workgroup, /* I - Workgroup */ const char *server, /* I - Server */ const int port, /* I - Port */ const char *share, /* I - Printer */ const char *username, /* I - Username */ const char *password, /* I - Password */ const char *jobusername) /* I - User who issued the print job */ { struct cli_state *cli; /* New connection */ pstring myname; /* Client name */ struct passwd *pwd; /* * Get the names and addresses of the client and server... */ get_myname(myname); /* See if we have a username first. This is for backwards compatible behavior with 3.0.14a */ if ( username && *username ) { cli = smb_complete_connection(myname, server, port, username, password, workgroup, share, 0 ); if (cli) return cli; } /* * Try to use the user kerberos credentials (if any) to authenticate */ cli = smb_complete_connection(myname, server, port, jobusername, "", workgroup, share, CLI_FULL_CONNECTION_USE_KERBEROS ); if (cli ) { return cli; } /* give a chance for a passwordless NTLMSSP session setup */ pwd = getpwuid(geteuid()); if (pwd == NULL) { return NULL; } cli = smb_complete_connection(myname, server, port, pwd->pw_name, "", workgroup, share, 0); if (cli) { return cli; } /* * last try. Use anonymous authentication */ cli = smb_complete_connection(myname, server, port, "", "", workgroup, share, 0); /* * Return the new connection... */ return (cli); }
static struct cli_state * /* O - SMB connection */ smb_connect(const char *workgroup, /* I - Workgroup */ const char *server, /* I - Server */ const int port, /* I - Port */ const char *share, /* I - Printer */ const char *username, /* I - Username */ const char *password, /* I - Password */ const char *jobusername, /* I - User who issued the print job */ bool *need_auth) { /* O - Need authentication? */ struct cli_state *cli; /* New connection */ char *myname = NULL; /* Client name */ struct passwd *pwd; /* * Get the names and addresses of the client and server... */ myname = get_myname(talloc_tos()); if (!myname) { return NULL; } /* * See if we have a username first. This is for backwards compatible * behavior with 3.0.14a */ if (username && *username && !getenv("KRB5CCNAME")) { cli = smb_complete_connection(myname, server, port, username, password, workgroup, share, 0, need_auth); if (cli) { fputs("DEBUG: Connected with username/password...\n", stderr); return (cli); } } /* * Try to use the user kerberos credentials (if any) to authenticate */ cli = smb_complete_connection(myname, server, port, jobusername, "", workgroup, share, CLI_FULL_CONNECTION_USE_KERBEROS, need_auth); if (cli) { fputs("DEBUG: Connected using Kerberos...\n", stderr); return (cli); } /* give a chance for a passwordless NTLMSSP session setup */ pwd = getpwuid(geteuid()); if (pwd == NULL) { return NULL; } cli = smb_complete_connection(myname, server, port, pwd->pw_name, "", workgroup, share, 0, need_auth); if (cli) { fputs("DEBUG: Connected with NTLMSSP...\n", stderr); return (cli); } /* * last try. Use anonymous authentication */ cli = smb_complete_connection(myname, server, port, "", "", workgroup, share, 0, need_auth); /* * Return the new connection... */ return (cli); }