All 'usage' messages are still printed to stdout.
Fix some compiler warnings for system() calls where we didn't used the
return code. Add appropriate error messages and return with the error
code we got from system() or NT_STATUS_UNSUCCESSFUL.
if (StrCaseCmp(argv[0], table[i].funcname) == 0)
return table[i].fn(argc-1, argv+1);
}
- d_printf("No command: %s\n", argv[0]);
+ d_fprintf(stderr, "No command: %s\n", argv[0]);
return usage_fn(argc, argv);
}
if (NT_STATUS_IS_OK(nt_status)) {
return nt_status;
} else {
- d_printf("Could not connect to server %s\n", server_name);
+ d_fprintf(stderr, "Could not connect to server %s\n", server_name);
/* Display a nicer message depending on the result */
if (NT_STATUS_V(nt_status) ==
NT_STATUS_V(NT_STATUS_LOGON_FAILURE))
- d_printf("The username or password was not correct.\n");
+ d_fprintf(stderr, "The username or password was not correct.\n");
if (NT_STATUS_V(nt_status) ==
NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT))
- d_printf("The account was locked out.\n");
+ d_fprintf(stderr, "The account was locked out.\n");
if (NT_STATUS_V(nt_status) ==
NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED))
- d_printf("The account was disabled.\n");
+ d_fprintf(stderr, "The account was disabled.\n");
return nt_status;
}
char *user_name = NULL;
if (!secrets_init()) {
- d_printf("ERROR: Unable to open secrets database\n");
+ d_fprintf(stderr, "ERROR: Unable to open secrets database\n");
exit(1);
}
NTSTATUS nt_status;
if (!net_find_server(flags, &server_ip, &server_name)) {
- d_printf("\nUnable to find a suitable server\n");
+ d_fprintf(stderr, "\nUnable to find a suitable server\n");
return NULL;
}
if (net_ads_join(argc, argv) == 0)
return 0;
else
- d_printf("ADS join did not work, falling back to RPC...\n");
+ d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n");
}
return net_rpc_join(argc, argv);
}
trust_pw = getpass("Enter machine password: ");
if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) {
- d_printf("Unable to write the machine account password in the secrets database");
+ d_fprintf(stderr, "Unable to write the machine account password in the secrets database");
return 1;
}
else {
panic when we can't. */
if (!secrets_init()) {
- d_printf("Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name);
+ d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name);
return 1;
}
get_global_sam_sid();
if (!secrets_fetch_domain_sid(global_myname(), &domain_sid)) {
- d_printf("Could not fetch local SID\n");
+ d_fprintf(stderr, "Could not fetch local SID\n");
return 1;
}
sid_to_string(sid_str, &domain_sid);
d_printf("SID for domain %s is: %s\n", global_myname(), sid_str);
if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) {
- d_printf("Could not fetch domain SID\n");
+ d_fprintf(stderr, "Could not fetch domain SID\n");
return 1;
}
}
if (!secrets_init()) {
- d_printf("Could not open secrets.tdb\n");
+ d_fprintf(stderr, "Could not open secrets.tdb\n");
return -1;
}
if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
- d_printf("Could not open %s\n", argv[0]);
+ d_fprintf(stderr, "Could not open %s\n", argv[0]);
return -1;
}
if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
- d_printf("Could not read keyfile\n");
+ d_fprintf(stderr, "Could not read keyfile\n");
return -1;
}
if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
- d_printf("Could not write keyfile to secrets.tdb\n");
+ d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n");
return -1;
}
uint32 i, num_entries;
if (search == NULL) {
- d_printf("get_maxrid: Could not search %s\n", type);
+ d_fprintf(stderr, "get_maxrid: Could not search %s\n", type);
return False;
}
case 'I':
opt_dest_ip = *interpret_addr2(poptGetOptArg(pc));
if (is_zero_ip(opt_dest_ip))
- d_printf("\nInvalid ip address specified\n");
+ d_fprintf(stderr, "\nInvalid ip address specified\n");
else
opt_have_ip = True;
break;
}
break;
default:
- d_printf("\nInvalid option %s: %s\n",
+ d_fprintf(stderr, "\nInvalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
net_help(argc, argv);
exit(1);
ads_connect(ads);
if (!ads) {
- d_printf("Didn't find the cldap server!\n");
+ d_fprintf(stderr, "Didn't find the cldap server!\n");
return -1;
} if (!ads->config.realm) {
ads->config.realm = CONST_DISCARD(char *, opt_target_workgroup);
ads_connect(ads);
if (!ads || !ads->config.realm) {
- d_printf("Didn't find the ldap server!\n");
+ d_fprintf(stderr, "Didn't find the ldap server!\n");
return -1;
}
}
if (!ADS_ERR_OK(ads_workgroup_name(ads, ctx, &workgroup))) {
- d_printf("Failed to find workgroup for realm '%s'\n",
+ d_fprintf(stderr, "Failed to find workgroup for realm '%s'\n",
ads->config.realm);
talloc_destroy(ctx);
ads_destroy(&ads);
status = ads_find_user_acct(ads, &res, argv[0]);
if (!ADS_ERR_OK(status)) {
- d_printf("ads_user_add: %s\n", ads_errstr(status));
+ d_fprintf(stderr, "ads_user_add: %s\n", ads_errstr(status));
goto done;
}
if (ads_count_replies(ads, res)) {
- d_printf("ads_user_add: User %s already exists\n", argv[0]);
+ d_fprintf(stderr, "ads_user_add: User %s already exists\n", argv[0]);
goto done;
}
status = ads_add_user_acct(ads, argv[0], opt_container, opt_comment);
if (!ADS_ERR_OK(status)) {
- d_printf("Could not add user %s: %s\n", argv[0],
+ d_fprintf(stderr, "Could not add user %s: %s\n", argv[0],
ads_errstr(status));
goto done;
}
}
/* password didn't set, delete account */
- d_printf("Could not add user %s. Error setting password %s\n",
+ d_fprintf(stderr, "Could not add user %s. Error setting password %s\n",
argv[0], ads_errstr(status));
ads_msgfree(ads, res);
status=ads_find_user_acct(ads, &res, argv[0]);
}
if (!escaped_user) {
- d_printf("ads_user_info: failed to escape user %s\n", argv[0]);
+ d_fprintf(stderr, "ads_user_info: failed to escape user %s\n", argv[0]);
ads_destroy(&ads);
return -1;
}
safe_free(searchstring);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_search: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_search: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
ads_destroy(&ads);
return 0;
}
- d_printf("Error deleting user %s: %s\n", argv[0],
+ d_fprintf(stderr, "Error deleting user %s: %s\n", argv[0],
ads_errstr(rc));
ads_destroy(&ads);
return -1;
status = ads_find_user_acct(ads, &res, argv[0]);
if (!ADS_ERR_OK(status)) {
- d_printf("ads_group_add: %s\n", ads_errstr(status));
+ d_fprintf(stderr, "ads_group_add: %s\n", ads_errstr(status));
goto done;
}
if (ads_count_replies(ads, res)) {
- d_printf("ads_group_add: Group %s already exists\n", argv[0]);
+ d_fprintf(stderr, "ads_group_add: Group %s already exists\n", argv[0]);
ads_msgfree(ads, res);
goto done;
}
d_printf("Group %s added\n", argv[0]);
rc = 0;
} else {
- d_printf("Could not add group %s: %s\n", argv[0],
+ d_fprintf(stderr, "Could not add group %s: %s\n", argv[0],
ads_errstr(status));
}
ads_destroy(&ads);
return 0;
}
- d_printf("Error deleting group %s: %s\n", argv[0],
+ d_fprintf(stderr, "Error deleting group %s: %s\n", argv[0],
ads_errstr(rc));
ads_destroy(&ads);
return -1;
rc = ads_find_machine_acct(ads, &res, global_myname());
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_find_machine_acct: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_find_machine_acct: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
if (ads_count_replies(ads, res) == 0) {
- d_printf("No machine account for '%s' found\n", global_myname());
+ d_fprintf(stderr, "No machine account for '%s' found\n", global_myname());
ads_destroy(&ads);
return -1;
}
rc = ads_leave_realm(ads, global_myname());
if (!ADS_ERR_OK(rc)) {
- d_printf("Failed to delete host '%s' from the '%s' realm.\n",
+ d_fprintf(stderr, "Failed to delete host '%s' from the '%s' realm.\n",
global_myname(), ads->config.realm);
ads_destroy(&ads);
return -1;
}
if (!*lp_realm()) {
- d_printf("realm must be set in in smb.conf for ADS join to succeed.\n");
+ d_fprintf(stderr, "realm must be set in in smb.conf for ADS join to succeed.\n");
ads_destroy(&ads);
return -1;
}
if (strcmp(ads->config.realm, lp_realm()) != 0) {
- d_printf("realm of remote server (%s) and realm in smb.conf (%s) DO NOT match. Aborting join\n", ads->config.realm, lp_realm());
+ d_fprintf(stderr, "realm of remote server (%s) and realm in smb.conf (%s) DO NOT match. Aborting join\n", ads->config.realm, lp_realm());
ads_destroy(&ads);
return -1;
}
ads_msgfree(ads, res);
if (rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_NO_SUCH_OBJECT) {
- d_printf("ads_join_realm: organizational unit %s does not exist (dn:%s)\n",
+ d_fprintf(stderr, "ads_join_realm: organizational unit %s does not exist (dn:%s)\n",
org_unit, dn);
ads_destroy(&ads);
return -1;
free(dn);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_join_realm: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_join_realm: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
rc = ads_join_realm(ads, global_myname(), account_type, org_unit);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_join_realm: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_join_realm: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
rc = ads_domain_sid(ads, &dom_sid);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_domain_sid: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_domain_sid: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
if (asprintf(&machine_account, "%s$", global_myname()) == -1) {
- d_printf("asprintf failed\n");
+ d_fprintf(stderr, "asprintf failed\n");
ads_destroy(&ads);
return -1;
}
rc = ads_set_machine_password(ads, machine_account, password);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_set_machine_password: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_set_machine_password: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
/* make sure we get the right workgroup */
if ( !(ctx = talloc_init("net ads join")) ) {
- d_printf("talloc_init() failed!\n");
+ d_fprintf(stderr, "talloc_init() failed!\n");
ads_destroy(&ads);
return -1;
}
rc = ads_find_printers(ads, &res);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_find_printer: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_find_printer: %s\n", ads_errstr(rc));
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
}
if (ads_count_replies(ads, res) == 0) {
- d_printf("No results found\n");
+ d_fprintf(stderr, "No results found\n");
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
rc = ads_find_printer_on_server(ads, &res, printername, servername);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_find_printer_on_server: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_find_printer_on_server: %s\n", ads_errstr(rc));
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
}
if (ads_count_replies(ads, res) == 0) {
- d_printf("Printer '%s' not found\n", printername);
+ d_fprintf(stderr, "Printer '%s' not found\n", printername);
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
Undefined, NULL);
if (NT_STATUS_IS_ERR(nt_status)) {
- d_printf("Unable to open a connnection to %s to obtain data "
+ d_fprintf(stderr, "Unable to open a connnection to %s to obtain data "
"for %s\n", servername, printername);
ads_destroy(&ads);
return -1;
ads_find_machine_acct(ads, &res, servername);
if (ads_count_replies(ads, res) == 0) {
- d_printf("Could not find machine account for server %s\n",
+ d_fprintf(stderr, "Could not find machine account for server %s\n",
servername);
ads_destroy(&ads);
return -1;
rc = ads_add_printer_entry(ads, prt_dn, mem_ctx, &mods);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_publish_printer: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_publish_printer: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
rc = ads_find_printer_on_server(ads, &res, argv[0], servername);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_find_printer_on_server: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_find_printer_on_server: %s\n", ads_errstr(rc));
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
}
if (ads_count_replies(ads, res) == 0) {
- d_printf("Printer '%s' not found\n", argv[1]);
+ d_fprintf(stderr, "Printer '%s' not found\n", argv[1]);
ads_msgfree(ads, res);
ads_destroy(&ads);
return -1;
ads_memfree(ads, prt_dn);
if (!ADS_ERR_OK(rc)) {
- d_printf("ads_del_dn: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
ADS_STATUS ret;
if (opt_user_name == NULL || opt_password == NULL) {
- d_printf("You must supply an administrator username/password\n");
+ d_fprintf(stderr, "You must supply an administrator username/password\n");
return -1;
}
if (argc < 1) {
- d_printf("ERROR: You must say which username to change password for\n");
+ d_fprintf(stderr, "ERROR: You must say which username to change password for\n");
return -1;
}
ads_connect(ads);
if (!ads || !ads->config.realm) {
- d_printf("Didn't find the kerberos server!\n");
+ d_fprintf(stderr, "Didn't find the kerberos server!\n");
return -1;
}
ret = kerberos_set_password(ads->auth.kdc_server, auth_principal,
auth_password, user, new_password, ads->auth.time_offset);
if (!ADS_ERR_OK(ret)) {
- d_printf("Password change failed :-( ...\n");
+ d_fprintf(stderr, "Password change failed :-( ...\n");
ads_destroy(&ads);
return -1;
}
ret = ads_change_trust_account_password(ads, host_principal);
if (!ADS_ERR_OK(ret)) {
- d_printf("Password change failed :-( ...\n");
+ d_fprintf(stderr, "Password change failed :-( ...\n");
ads_destroy(&ads);
SAFE_FREE(host_principal);
return -1;
LDAP_SCOPE_SUBTREE,
ldap_exp, attrs, &res);
if (!ADS_ERR_OK(rc)) {
- d_printf("search failed: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "search failed: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
LDAP_SCOPE_BASE,
"(objectclass=*)", attrs, &res);
if (!ADS_ERR_OK(rc)) {
- d_printf("search failed: %s\n", ads_errstr(rc));
+ d_fprintf(stderr, "search failed: %s\n", ads_errstr(rc));
ads_destroy(&ads);
return -1;
}
static int net_ads_noads(void)
{
- d_printf("ADS support not compiled in\n");
+ d_fprintf(stderr, "ADS support not compiled in\n");
return -1;
}
uint8 len = (uint8)*(ptr++);
if ((pret - ret + len + 1) >= MAX_DNS_LABEL) {
- d_printf("DC returning too long DNS name\n");
+ d_fprintf(stderr, "DC returning too long DNS name\n");
return 0;
}
asn1_pop_tag(&data);
if (data.has_error) {
- d_printf("Failed to build cldap netlogon at offset %d\n", (int)data.ofs);
+ d_fprintf(stderr, "Failed to build cldap netlogon at offset %d\n", (int)data.ofs);
asn1_free(&data);
return -1;
}
if (write(sock, data.data, data.length) != (ssize_t)data.length) {
- d_printf("failed to send cldap query (%s)\n", strerror(errno));
+ d_fprintf(stderr, "failed to send cldap query (%s)\n", strerror(errno));
}
asn1_free(&data);
ret = read(sock, blob.data, blob.length);
if (ret <= 0) {
- d_printf("no reply received to cldap netlogon\n");
+ d_fprintf(stderr, "no reply received to cldap netlogon\n");
return -1;
}
blob.length = ret;
asn1_end_tag(&data);
if (data.has_error) {
- d_printf("Failed to parse cldap reply\n");
+ d_fprintf(stderr, "Failed to parse cldap reply\n");
return -1;
}
sock = open_udp_socket(target, ads->ldap_port);
if (sock == -1) {
- d_printf("Failed to open udp socket to %s:%u\n",
+ d_fprintf(stderr, "Failed to open udp socket to %s:%u\n",
inet_ntoa(ads->ldap_ip),
ads->ldap_port);
return -1;
const time_t timeout, void* dptr)
{
if (!gencache_del(keystr))
- d_printf("Couldn't delete entry! key = %s\n", keystr);
+ d_fprintf(stderr, "Couldn't delete entry! key = %s\n", keystr);
}
/* parse timeout given in command line */
timeout = parse_timeout(timeout_str);
if (!timeout) {
- d_printf("Invalid timeout argument.\n");
+ d_fprintf(stderr, "Invalid timeout argument.\n");
return -1;
}
return 0;
}
- d_printf("Entry couldn't be added. Perhaps there's already such a key.\n");
+ d_fprintf(stderr, "Entry couldn't be added. Perhaps there's already such a key.\n");
gencache_shutdown();
return -1;
}
/* parse timeout given in command line */
timeout = parse_timeout(timeout_str);
if (!timeout) {
- d_printf("Invalid timeout argument.\n");
+ d_fprintf(stderr, "Invalid timeout argument.\n");
return -1;
}
return 0;
}
- d_printf("Entry couldn't be set. Perhaps there's no such a key.\n");
+ d_fprintf(stderr, "Entry couldn't be set. Perhaps there's no such a key.\n");
gencache_shutdown();
return -1;
}
return 0;
}
- d_printf("Couldn't delete specified entry\n");
+ d_fprintf(stderr, "Couldn't delete specified entry\n");
return -1;
}
return 0;
}
- d_printf("Failed to find entry\n");
+ d_fprintf(stderr, "Failed to find entry\n");
return -1;
}
else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
fstrcpy( ntgroup, get_string_param( argv[i] ) );
if ( !ntgroup[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
fstrcpy( sid_string, get_string_param( argv[i] ) );
if ( !sid_string[0] ) {
- d_printf("must supply a SID\n");
+ d_fprintf(stderr, "must supply a SID\n");
return -1;
}
}
else {
- d_printf("Bad option: %s\n", argv[i]);
+ d_fprintf(stderr, "Bad option: %s\n", argv[i]);
return -1;
}
}
/* Get the current mapping from the database */
if(!pdb_getgrsid(&map, sid)) {
- d_printf("Failure to local group SID in the database\n");
+ d_fprintf(stderr, "Failure to local group SID in the database\n");
return -1;
}
if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) {
rid = get_int_param(argv[i]);
if ( rid < DOMAIN_GROUP_RID_ADMINS ) {
- d_printf("RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1);
+ d_fprintf(stderr, "RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1);
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
fstrcpy( unixgrp, get_string_param( argv[i] ) );
if ( !unixgrp[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
fstrcpy( ntgroup, get_string_param( argv[i] ) );
if ( !ntgroup[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
fstrcpy( string_sid, get_string_param( argv[i] ) );
if ( !string_sid[0] ) {
- d_printf("must supply a SID\n");
+ d_fprintf(stderr, "must supply a SID\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
fstrcpy( ntcomment, get_string_param( argv[i] ) );
if ( !ntcomment[0] ) {
- d_printf("must supply a comment string\n");
+ d_fprintf(stderr, "must supply a comment string\n");
return -1;
}
}
}
}
else {
- d_printf("Bad option: %s\n", argv[i]);
+ d_fprintf(stderr, "Bad option: %s\n", argv[i]);
return -1;
}
}
}
if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) {
- d_printf("Can't lookup UNIX group %s\n", unixgrp);
+ d_fprintf(stderr, "Can't lookup UNIX group %s\n", unixgrp);
return -1;
}
if (!add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment)) {
- d_printf("adding entry for group %s failed!\n", ntgroup);
+ d_fprintf(stderr, "adding entry for group %s failed!\n", ntgroup);
return -1;
}
if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
fstrcpy( ntgroup, get_string_param( argv[i] ) );
if ( !ntgroup[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
fstrcpy( sid_string, get_string_param( argv[i] ) );
if ( !sid_string[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
fstrcpy( ntcomment, get_string_param( argv[i] ) );
if ( !ntcomment[0] ) {
- d_printf("must supply a comment string\n");
+ d_fprintf(stderr, "must supply a comment string\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
fstrcpy( unixgrp, get_string_param( argv[i] ) );
if ( !unixgrp[0] ) {
- d_printf("must supply a group name\n");
+ d_fprintf(stderr, "must supply a group name\n");
return -1;
}
}
}
}
else {
- d_printf("Bad option: %s\n", argv[i]);
+ d_fprintf(stderr, "Bad option: %s\n", argv[i]);
return -1;
}
}
/* Get the current mapping from the database */
if(!pdb_getgrsid(&map, sid)) {
- d_printf("Failure to local group SID in the database\n");
+ d_fprintf(stderr, "Failure to local group SID in the database\n");
return -1;
}
*/
if (sid_type != SID_NAME_UNKNOWN) {
if (map.sid_name_use == SID_NAME_WKN_GRP) {
- d_printf("You can only change between domain and local groups.\n");
+ d_fprintf(stderr, "You can only change between domain and local groups.\n");
return -1;
}
if ( unixgrp[0] ) {
gid = nametogid( unixgrp );
if ( gid == -1 ) {
- d_printf("Unable to lookup UNIX group %s. Make sure the group exists.\n",
+ d_fprintf(stderr, "Unable to lookup UNIX group %s. Make sure the group exists.\n",
unixgrp);
return -1;
}
}
if ( !pdb_update_group_mapping_entry(&map) ) {
- d_printf("Could not update group database\n");
+ d_fprintf(stderr, "Could not update group database\n");
return -1;
}
if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
fstrcpy( ntgroup, get_string_param( argv[i] ) );
if ( !ntgroup[0] ) {
- d_printf("must supply a name\n");
+ d_fprintf(stderr, "must supply a name\n");
return -1;
}
}
else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
fstrcpy( sid_string, get_string_param( argv[i] ) );
if ( !sid_string[0] ) {
- d_printf("must supply a SID\n");
+ d_fprintf(stderr, "must supply a SID\n");
return -1;
}
}
else {
- d_printf("Bad option: %s\n", argv[i]);
+ d_fprintf(stderr, "Bad option: %s\n", argv[i]);
return -1;
}
}
fstrcpy( ntgroup, sid_string );
if ( !get_sid_from_input(&sid, ntgroup) ) {
- d_printf("Unable to resolve group %s to a SID\n", ntgroup);
+ d_fprintf(stderr, "Unable to resolve group %s to a SID\n", ntgroup);
return -1;
}
if ( !pdb_delete_group_mapping_entry(sid) ) {
- printf("Failed to removing group %s from the mapping db!\n", ntgroup);
+ d_fprintf(stderr, "Failed to removing group %s from the mapping db!\n", ntgroup);
return -1;
}
grp = getgrnam(argv[1]);
if (grp == NULL) {
- d_printf("Could not find unix group %s\n", argv[1]);
+ d_fprintf(stderr, "Could not find unix group %s\n", argv[1]);
return -1;
}
}
/* Ok, add it */
if (grp == NULL) {
- d_printf("Could not find group mapping for %s\n",
+ d_fprintf(stderr, "Could not find group mapping for %s\n",
ntgroup);
return -1;
}
fstrcpy(map.comment, "");
if (!pdb_add_group_mapping_entry(&map)) {
- d_printf("Could not add mapping entry for %s\n",
+ d_fprintf(stderr, "Could not add mapping entry for %s\n",
ntgroup);
return -1;
}
if ( opt_localgroup || opt_domaingroup ) {
if (map.sid_name_use == SID_NAME_WKN_GRP) {
- d_printf("Can't change type of the BUILTIN group %s\n",
+ d_fprintf(stderr, "Can't change type of the BUILTIN group %s\n",
map.nt_name);
return -1;
}
map.gid = grp->gr_gid;
if (!pdb_update_group_mapping_entry(&map)) {
- d_printf("Could not update group mapping for %s\n", ntgroup);
+ d_fprintf(stderr, "Could not update group mapping for %s\n", ntgroup);
return -1;
}
if (!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &entries,
ENUM_ALL_MAPPED)) {
- d_printf("Could not list group mappings\n");
+ d_fprintf(stderr, "Could not list group mappings\n");
return -1;
}
}
if (!pdb_add_aliasmem(&alias, &member)) {
- d_printf("Could not add sid %s to alias %s\n",
+ d_fprintf(stderr, "Could not add sid %s to alias %s\n",
argv[1], argv[0]);
return -1;
}
}
if (!pdb_del_aliasmem(&alias, &member)) {
- d_printf("Could not delete sid %s from alias %s\n",
+ d_fprintf(stderr, "Could not delete sid %s from alias %s\n",
argv[1], argv[0]);
return -1;
}
num = 0;
if (!pdb_enum_aliasmem(&alias, &members, &num)) {
- d_printf("Could not list members for sid %s\n", argv[0]);
+ d_fprintf(stderr, "Could not list members for sid %s\n", argv[0]);
return -1;
}
if (!pdb_enum_alias_memberships(mem_ctx, domain_sid, member, 1,
&alias_rids, &num_alias_rids)) {
- d_printf("Could not list memberships for sid %s\n",
+ d_fprintf(stderr, "Could not list memberships for sid %s\n",
sid_string_static(member));
return False;
}
mem_ctx = talloc_init("net_groupmap_memberships");
if (mem_ctx == NULL) {
- d_printf("talloc_init failed\n");
+ d_fprintf(stderr, "talloc_init failed\n");
return -1;
}
domain_sid = get_global_sam_sid();
builtin_sid = string_sid_talloc(mem_ctx, "S-1-5-32");
if ((domain_sid == NULL) || (builtin_sid == NULL)) {
- d_printf("Could not get domain sid\n");
+ d_fprintf(stderr, "Could not get domain sid\n");
return -1;
}
/* we shouldn't have silly checks like this */
if (getuid() != 0) {
- d_printf("You must be root to edit group mappings.\nExiting...\n");
+ d_fprintf(stderr, "You must be root to edit group mappings.\nExiting...\n");
return -1;
}
idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0);
if (idmap_tdb == NULL) {
- d_printf("Could not open idmap: %s\n", argv[0]);
+ d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]);
return -1;
}
}
if (idptr == NULL) {
- d_printf("Illegal idmap entry: [%s]->[%s]\n",
+ d_fprintf(stderr, "Illegal idmap entry: [%s]->[%s]\n",
key.dptr, data.dptr);
hwms->ok = False;
return -1;
if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) ||
!lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) {
- d_printf("idmap range missing\n");
+ d_fprintf(stderr, "idmap range missing\n");
return NT_STATUS_UNSUCCESSFUL;
}
idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0);
if (idmap_tdb == NULL) {
- d_printf("Could not open idmap: %s\n", tdbfile);
+ d_fprintf(stderr, "Could not open idmap: %s\n", tdbfile);
return NT_STATUS_NO_SUCH_FILE;
}
hwms.user_hwm, hwms.group_hwm);
if (hwms.user_hwm >= highest.user_hwm) {
- d_printf("Highest UID out of uid range\n");
+ d_fprintf(stderr, "Highest UID out of uid range\n");
goto done;
}
if (hwms.group_hwm >= highest.group_hwm) {
- d_printf("Highest GID out of gid range\n");
+ d_fprintf(stderr, "Highest GID out of gid range\n");
goto done;
}
if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) ||
(tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) {
- d_printf("Could not store HWMs\n");
+ d_fprintf(stderr, "Could not store HWMs\n");
goto done;
}
static int net_idmap_restore(int argc, const char **argv)
{
if (!idmap_init(lp_idmap_backend())) {
- d_printf("Could not init idmap\n");
+ d_fprintf(stderr, "Could not init idmap\n");
return -1;
}
}
if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) {
- d_printf("Could not set mapping of %s %lu to sid %s\n",
+ d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n",
(type == ID_GROUPID) ? "GID" : "UID",
(type == ID_GROUPID) ? (unsigned long)id.gid:
(unsigned long)id.uid,
idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0);
if (idmap_tdb == NULL) {
- d_printf("Could not open idmap: %s\n", argv[0]);
+ d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]);
return -1;
}
fstrcpy(sid, argv[1]);
if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) {
- d_printf("Can only delete SIDs, %s is does not start with "
+ d_fprintf(stderr, "Can only delete SIDs, %s is does not start with "
"S-1-5-\n", sid);
return -1;
}
data = tdb_fetch(idmap_tdb, key);
if (data.dptr == NULL) {
- d_printf("Could not find sid %s\n", argv[1]);
+ d_fprintf(stderr, "Could not find sid %s\n", argv[1]);
return -1;
}
if (tdb_delete(idmap_tdb, key) != 0) {
- d_printf("Could not delete key %s\n", argv[1]);
+ d_fprintf(stderr, "Could not delete key %s\n", argv[1]);
return -1;
}
if (tdb_delete(idmap_tdb, data) != 0) {
- d_printf("Could not delete key %s\n", data.dptr);
+ d_fprintf(stderr, "Could not delete key %s\n", data.dptr);
return -1;
}
if (argc == 0)
return net_rap_file_usage(argc, argv);
- d_printf("net rap file user not implemented yet\n");
+ d_fprintf(stderr, "net rap file user not implemented yet\n");
return -1;
}
int rc = net_rpc_perform_oldjoin(argc, argv);
if (rc) {
- d_printf("Failed to join domain\n");
+ d_fprintf(stderr, "Failed to join domain\n");
}
return rc;
done:
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Failed to add user %s - %s\n", acct_name,
+ d_fprintf(stderr, "Failed to add user %s - %s\n", acct_name,
nt_errstr(result));
} else {
d_printf("Added user %s\n", acct_name);
/* Display results */
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Failed to delete user account - %s\n", nt_errstr(result));
+ d_fprintf(stderr, "Failed to delete user account - %s\n", nt_errstr(result));
} else {
d_printf("Deleted user account\n");
}
done:
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Failed to rename user from %s to %s - %s\n", old_name, new_name,
+ d_fprintf(stderr, "Failed to rename user from %s to %s - %s\n", old_name, new_name,
nt_errstr(result));
} else {
d_printf("Renamed user from %s to %s\n", old_name, new_name);
&connect_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Request samr_connect failed\n");
+ d_fprintf(stderr, "Request samr_connect failed\n");
goto done;
}
domain_sid, &domain_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Request open_domain failed\n");
+ d_fprintf(stderr, "Request open_domain failed\n");
goto done;
}
&name_types);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Lookup of '%s' failed\n",argv[0]);
+ d_fprintf(stderr, "Lookup of '%s' failed\n",argv[0]);
goto done;
}
MAXIMUM_ALLOWED_ACCESS,
group_rids[0], &group_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Request open_group failed");
+ d_fprintf(stderr, "Request open_group failed");
goto done;
}
&group_attrs);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Unable to query group members of %s",argv[0]);
+ d_fprintf(stderr, "Unable to query group members of %s",argv[0]);
goto done;
}
group_rids[i], &user_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Unable to open group member %d\n",group_rids[i]);
+ d_fprintf(stderr, "Unable to open group member %d\n",group_rids[i]);
goto done;
}
21, &user_ctr);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Unable to lookup userinfo for group member %d\n",group_rids[i]);
+ d_fprintf(stderr, "Unable to lookup userinfo for group member %d\n",group_rids[i]);
goto done;
}
}
if (group_is_primary) {
- d_printf("Unable to delete group because some of it's "
- "members have it as primary group\n");
+ d_fprintf(stderr, "Unable to delete group because some "
+ "of it's members have it as primary group\n");
result = NT_STATUS_MEMBERS_PRIMARY_GROUP;
goto done;
}
group_rids[0], &group_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Request open_alias failed\n");
+ d_fprintf(stderr, "Request open_alias failed\n");
goto done;
}
result = rpccli_samr_delete_dom_alias(pipe_hnd, mem_ctx, &group_pol);
break;
default:
- d_printf("%s is of type %s. This command is only for deleting local or global groups\n",
+ d_fprintf(stderr, "%s is of type %s. This command is only for deleting local or global groups\n",
argv[0],sid_type_lookup(name_types[0]));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
if (opt_verbose)
d_printf("Deleted %s '%s'\n",sid_type_lookup(name_types[0]),argv[0]);
} else {
- d_printf("Deleting of %s failed: %s\n",argv[0],
+ d_fprintf(stderr, "Deleting of %s failed: %s\n",argv[0],
get_friendly_nt_error_msg(result));
}
if (NT_STATUS_IS_OK(result))
DEBUG(5, ("add group succeeded\n"));
else
- d_printf("add group failed: %s\n", nt_errstr(result));
+ d_fprintf(stderr, "add group failed: %s\n", nt_errstr(result));
return result;
}
if (NT_STATUS_IS_OK(result))
DEBUG(5, ("add alias succeeded\n"));
else
- d_printf("add alias failed: %s\n", nt_errstr(result));
+ d_fprintf(stderr, "add alias failed: %s\n", nt_errstr(result));
return result;
}
&num_rids, &rids, &rid_types);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not lookup up group member %s\n", member);
+ d_fprintf(stderr, "Could not lookup up group member %s\n", member);
goto done;
}
&member_sid, &member_type);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not lookup up group member %s\n", member);
+ d_fprintf(stderr, "Could not lookup up group member %s\n", member);
return result;
}
if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
&group_sid, &group_type))) {
- d_printf("Could not lookup group name %s\n", argv[0]);
+ d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]);
return NT_STATUS_UNSUCCESSFUL;
}
&group_sid, argv[1]);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not add %s to %s: %s\n",
+ d_fprintf(stderr, "Could not add %s to %s: %s\n",
argv[1], argv[0], nt_errstr(result));
}
return result;
&group_sid, argv[1]);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not add %s to %s: %s\n",
+ d_fprintf(stderr, "Could not add %s to %s: %s\n",
argv[1], argv[0], nt_errstr(result));
}
return result;
}
- d_printf("Can only add members to global or local groups which "
- "%s is not\n", argv[0]);
+ d_fprintf(stderr, "Can only add members to global or local groups "
+ "which %s is not\n", argv[0]);
return NT_STATUS_UNSUCCESSFUL;
}
&num_rids, &rids, &rid_types);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not lookup up group member %s\n", member);
+ d_fprintf(stderr, "Could not lookup up group member %s\n", member);
goto done;
}
&member_sid, &member_type);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not lookup up group member %s\n", member);
+ d_fprintf(stderr, "Could not lookup up group member %s\n", member);
return result;
}
if (!NT_STATUS_IS_OK(get_sid_from_name(cli, mem_ctx, argv[0],
&group_sid, &group_type))) {
- d_printf("Could not lookup group name %s\n", argv[0]);
+ d_fprintf(stderr, "Could not lookup group name %s\n", argv[0]);
return NT_STATUS_UNSUCCESSFUL;
}
&group_sid, argv[1]);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not del %s from %s: %s\n",
+ d_fprintf(stderr, "Could not del %s from %s: %s\n",
argv[1], argv[0], nt_errstr(result));
}
return result;
&group_sid, argv[1]);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Could not del %s from %s: %s\n",
+ d_fprintf(stderr, "Could not del %s from %s: %s\n",
argv[1], argv[0], nt_errstr(result));
}
return result;
}
- d_printf("Can only delete members from global or local groups which "
- "%s is not\n", argv[0]);
+ d_fprintf(stderr, "Can only delete members from global or local groups "
+ "which %s is not\n", argv[0]);
return NT_STATUS_UNSUCCESSFUL;
}
&num_members, &alias_sids);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Couldn't list alias members\n");
+ d_fprintf(stderr, "Couldn't list alias members\n");
return result;
}
lsa_pipe = cli_rpc_pipe_open_noauth(pipe_hnd->cli, PI_LSARPC, &result);
if (!lsa_pipe) {
- d_printf("Couldn't open LSA pipe. Error was %s\n",
+ d_fprintf(stderr, "Couldn't open LSA pipe. Error was %s\n",
nt_errstr(result) );
return result;
}
SEC_RIGHTS_MAXIMUM_ALLOWED, &lsa_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Couldn't open LSA policy handle\n");
+ d_fprintf(stderr, "Couldn't open LSA policy handle\n");
cli_rpc_pipe_close(lsa_pipe);
return result;
}
if (!NT_STATUS_IS_OK(result) &&
!NT_STATUS_EQUAL(result, STATUS_SOME_UNMAPPED)) {
- d_printf("Couldn't lookup SIDs\n");
+ d_fprintf(stderr, "Couldn't lookup SIDs\n");
cli_rpc_pipe_close(lsa_pipe);
return result;
}
&sid_Builtin, &domain_pol);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Couldn't find group %s\n", argv[0]);
+ d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
return result;
}
&rids, &rid_types);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Couldn't find group %s\n", argv[0]);
+ d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
return result;
}
}
if (num_rids != 1) {
- d_printf("Couldn't find group %s\n", argv[0]);
+ d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
return result;
}
1, argv, &num_rids, &rids, &rid_types);
if (num_rids != 1) {
- d_printf("Couldn't find group %s\n", argv[0]);
+ d_fprintf(stderr, "Couldn't find group %s\n", argv[0]);
return result;
}
if (rid_types[0] != SID_NAME_DOM_GRP) {
- d_printf("Can only rename domain groups\n");
+ d_fprintf(stderr, "Can only rename domain groups\n");
return NT_STATUS_UNSUCCESSFUL;
}
False);
break;
default:
- d_printf("Unsupported mode %d\n", net_mode_share);
+ d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
return;
}
True);
break;
default:
- d_printf("Unsupported file mode %d\n", net_mode_share);
+ d_fprintf(stderr, "Unsupported file mode %d\n", net_mode_share);
return;
}
DEBUG(3,("calling cli_list with mask: %s\n", mask));
if (cli_list(cp_clistate->cli_share_src, mask, cp_clistate->attribute, copy_fn, cp_clistate) == -1) {
- d_printf("listing %s failed with error: %s\n",
+ d_fprintf(stderr, "listing %s failed with error: %s\n",
mask, cli_errstr(cp_clistate->cli_share_src));
return False;
}
False);
break;
default:
- d_printf("Unsupported mode %d\n", net_mode_share);
+ d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
break;
}
printf("syncing");
break;
default:
- d_printf("Unsupported mode %d\n", net_mode_share);
+ d_fprintf(stderr, "Unsupported mode %d\n", net_mode_share);
break;
}
printf(" [%s] files and directories %s ACLs, %s DOS Attributes %s\n",
}
if (!copy_top_level_perms(&cp_clistate, netname)) {
- d_printf("Could not handle the top level directory permissions for the share: %s\n", netname);
+ d_fprintf(stderr, "Could not handle the top level directory permissions for the share: %s\n", netname);
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
if (!sync_files(&cp_clistate, mask)) {
- d_printf("could not handle files for share: %s\n", netname);
+ d_fprintf(stderr, "could not handle files for share: %s\n", netname);
nt_status = NT_STATUS_UNSUCCESSFUL;
goto done;
}
if (lp_winbind_use_default_domain() &&
(opt_target_workgroup == NULL)) {
- d_printf("winbind use default domain = yes set, please "
- "specify a workgroup\n");
+ d_fprintf(stderr, "winbind use default domain = yes set, "
+ "please specify a workgroup\n");
return False;
}
if (W_ERROR_IS_OK(result)) {
d_printf("\nShutdown of remote machine succeeded\n");
} else {
- d_printf("\nShutdown of remote machine failed\n");
+ d_fprintf(stderr, "\nShutdown of remote machine failed\n");
if (W_ERROR_EQUAL(result,WERR_MACHINE_LOCKED))
- d_printf("\nMachine locked, use -f switch to force\n");
+ d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
else
- d_printf("\nresult was: %s\n", dos_errstr(result));
+ d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(result));
}
return werror_to_ntstatus(result);
if (remote_cli) {
/* query for domain's sid */
if (run_rpc_command(remote_cli, PI_LSARPC, 0, rpc_query_domain_sid, argc, argv))
- d_printf("couldn't get domain's sid\n");
+ d_fprintf(stderr, "couldn't get domain's sid\n");
cli_shutdown(remote_cli);
} else {
- d_printf("domain controller is not responding\n");
+ d_fprintf(stderr, "domain controller is not responding\n");
};
};
if (!NT_STATUS_IS_OK(result) &&
!NT_STATUS_EQUAL(result, NT_STATUS_USER_EXISTS)) {
- d_printf("Creation of workstation account failed\n");
+ d_fprintf(stderr, "Creation of workstation account failed\n");
/* If NT_STATUS_ACCESS_DENIED then we have a valid
username/password combo but the user does not have
administrator access. */
if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_ACCESS_DENIED))
- d_printf("User specified does not have administrator privileges\n");
+ d_fprintf(stderr, "User specified does not have administrator privileges\n");
goto done;
}
if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) &&
(sec_channel_type == SEC_CHAN_BDC) ) {
- d_printf("Please make sure that no computer account\n"
+ d_fprintf(stderr, "Please make sure that no computer account\n"
"named like this machine (%s) exists in the domain\n",
global_myname());
}
if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) &&
(sec_channel_type == SEC_CHAN_BDC) ) {
- d_printf("Please make sure that no computer account\n"
+ d_fprintf(stderr, "Please make sure that no computer account\n"
"named like this machine (%s) exists in the domain\n",
global_myname());
}
/* closing files */
if (!cli_close(cli_share_src, fnum_src)) {
- d_printf("could not close %s on originating server: %s\n",
+ d_fprintf(stderr, "could not close %s on originating server: %s\n",
is_file?"file":"dir", cli_errstr(cli_share_src));
nt_status = cli_nt_error(cli_share_src);
goto out;
}
if (!cli_close(cli_share_dst, fnum_dst)) {
- d_printf("could not close %s on destination server: %s\n",
+ d_fprintf(stderr, "could not close %s on destination server: %s\n",
is_file?"file":"dir", cli_errstr(cli_share_dst));
nt_status = cli_nt_error(cli_share_dst);
goto out;
/* allocate memory */
if (!(data = (char *)SMB_MALLOC(read_size))) {
- d_printf("malloc fail for size %d\n", read_size);
+ d_fprintf(stderr, "malloc fail for size %d\n", read_size);
nt_status = NT_STATUS_NO_MEMORY;
goto out;
}
nread + start, n);
if (n != ret) {
- d_printf("Error writing file: %s\n",
+ d_fprintf(stderr, "Error writing file: %s\n",
cli_errstr(cli_share_dst));
nt_status = cli_nt_error(cli_share_dst);
goto out;
}
if (!cli_chkpath(cli_share_dst, dst_name)) {
- d_printf("cannot check for directory %s: %s\n",
+ d_fprintf(stderr, "cannot check for directory %s: %s\n",
dst_name, cli_errstr(cli_share_dst));
goto out;
}
/* closing files */
if (!cli_close(cli_share_src, fnum_src)) {
- d_printf("could not close file on originating server: %s\n",
+ d_fprintf(stderr, "could not close file on originating server: %s\n",
cli_errstr(cli_share_src));
nt_status = cli_nt_error(cli_share_src);
goto out;
}
if (is_file && !cli_close(cli_share_dst, fnum_dst)) {
- d_printf("could not close file on destination server: %s\n",
+ d_fprintf(stderr, "could not close file on destination server: %s\n",
cli_errstr(cli_share_dst));
nt_status = cli_nt_error(cli_share_dst);
goto out;
}
if (!cli_chkpath(cli_share, dir)) {
- d_printf("cannot check %s: %s\n",
+ d_fprintf(stderr, "cannot check %s: %s\n",
dir, cli_errstr(cli_share));
goto out;
}
/* be more verbose */
if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
- d_printf("no access to printer [%s] on [%s] for user [%s] granted\n",
+ d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n",
printername2, servername, username);
return False;
}
if (!W_ERROR_IS_OK(result)) {
- d_printf("cannot open printer %s on server %s: %s\n",
+ d_fprintf(stderr, "cannot open printer %s on server %s: %s\n",
printername2, servername, dos_errstr(result));
return False;
}
if (W_ERROR_IS_OK(result))
d_printf ("printer [%s] successfully added.\n", printername);
else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
- d_printf ("printer [%s] already exists.\n", printername);
+ d_fprintf (stderr, "printer [%s] already exists.\n", printername);
else {
- printf ("could not create printer\n");
+ d_fprintf (stderr, "could not create printer [%s]\n", printername);
goto done;
}
}
if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
- d_printf("invalid registry path\n");
+ d_fprintf(stderr, "invalid registry path\n");
return NT_STATUS_OK;
}
result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Unable to connect to remote registry\n");
+ d_fprintf(stderr, "Unable to connect to remote registry\n");
return werror_to_ntstatus(result);
}
if ( strlen( subpath ) != 0 ) {
result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Unable to open [%s]\n", argv[0]);
+ d_fprintf(stderr, "Unable to open [%s]\n", argv[0]);
return werror_to_ntstatus(result);
}
}
}
if ( !reg_split_hive( argv[0], &hive, subpath ) ) {
- d_printf("invalid registry path\n");
+ d_fprintf(stderr, "invalid registry path\n");
return NT_STATUS_OK;
}
result = rpccli_reg_connect(pipe_hnd, mem_ctx, hive, MAXIMUM_ALLOWED_ACCESS, &pol_hive );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Unable to connect to remote registry\n");
+ d_fprintf(stderr, "Unable to connect to remote registry\n");
return werror_to_ntstatus(result);
}
result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Unable to open [%s]\n", argv[0]);
+ d_fprintf(stderr, "Unable to open [%s]\n", argv[0]);
return werror_to_ntstatus(result);
}
result = rpccli_reg_save_key(pipe_hnd, mem_ctx, &pol_key, argv[1] );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]);
+ d_fprintf(stderr, "Unable to save [%s] to %s:%s\n", argv[0], cli->desthost, argv[1]);
}
d_printf("\n");
dump_registry_tree( file, key, regpath );
}
-
+
return True;
}
d_printf("Opening %s....", argv[0]);
if ( !(registry = regfio_open( argv[0], O_RDONLY, 0)) ) {
- d_printf("Failed to open %s for reading\n", argv[0]);
+ d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]);
return 1;
}
d_printf("ok\n");
{
REGF_FILE *infile, *outfile;
REGF_NK_REC *nk;
+ int result = 1;
if (argc != 2 ) {
d_printf("Usage: net rpc copy <srcfile> <newfile>\n");
d_printf("Opening %s....", argv[0]);
if ( !(infile = regfio_open( argv[0], O_RDONLY, 0 )) ) {
- d_printf("Failed to open %s for reading\n", argv[0]);
+ d_fprintf(stderr, "Failed to open %s for reading\n", argv[0]);
return 1;
}
d_printf("ok\n");
d_printf("Opening %s....", argv[1]);
if ( !(outfile = regfio_open( argv[1], (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) {
- d_printf("Failed to open %s for writing\n", argv[1]);
- return 1;
+ d_fprintf(stderr, "Failed to open %s for writing\n", argv[1]);
+ goto out_close_infile;
}
d_printf("ok\n");
write_registry_tree( infile, nk, NULL, outfile, "" );
+ result = 0;
+
d_printf("Closing %s...", argv[1]);
regfio_close( outfile );
d_printf("ok\n");
+out_close_infile:
d_printf("Closing %s...", argv[0]);
regfio_close( infile );
d_printf("ok\n");
- return 0;
+ return( result);
}
/********************************************************************
if ( !NT_STATUS_IS_OK(result) ) {
if ( NT_STATUS_EQUAL( result, NT_STATUS_NO_SUCH_PRIVILEGE ) )
- d_printf("No such privilege exists: %s.\n", privname);
+ d_fprintf(stderr, "No such privilege exists: %s.\n", privname);
else
- d_printf("Error resolving privilege display name [%s].\n", nt_errstr(result));
+ d_fprintf(stderr, "Error resolving privilege display name [%s].\n", nt_errstr(result));
continue;
}
result = enum_accounts_for_privilege(pipe_hnd, mem_ctx, &pol, privname);
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Error enumerating accounts for privilege %s [%s].\n",
+ d_fprintf(stderr, "Error enumerating accounts for privilege %s [%s].\n",
privname, nt_errstr(result));
continue;
}
done:
if ( !NT_STATUS_IS_OK(result) ) {
- d_printf("Failed to grant privileges for %s (%s)\n",
+ d_fprintf(stderr, "Failed to grant privileges for %s (%s)\n",
argv[0], nt_errstr(result));
}
done:
if ( !NT_STATUS_IS_OK(result) ) {
- d_printf("Failed to revoke privileges for %s (%s)",
+ d_fprintf(stderr, "Failed to revoke privileges for %s (%s)",
argv[0], nt_errstr(result));
}
/* try and find the possible unix account again */
if ( !(passwd = Get_Pwnam(account)) ) {
- d_printf("Could not create posix account info for '%s'\n", account);
+ d_fprintf(stderr, "Could not create posix account info for '%s'\n", account);
nt_ret = NT_STATUS_NO_SUCH_USER;
goto done;
}
const char *add_ldif = "/tmp/add.ldif", *mod_ldif = "/tmp/mod.ldif";
FILE *add_fd, *mod_fd, *ldif_fd;
char sys_cmd[1024];
- int num_alloced = 0, g_index = 0, a_index = 0;
+ int num_alloced = 0, g_index = 0, a_index = 0, sys_cmd_result;
/* Set up array for mapping accounts to groups */
/* Array element is the group rid */
fflush(ldif_fd);
}
pstr_sprintf(sys_cmd, "cat %s >> %s", add_ldif, ldif_file);
- system(sys_cmd);
+ sys_cmd_result = system(sys_cmd);
+ if (sys_cmd_result) {
+ d_fprintf(stderr, "%s failed. Error was (%s)\n",
+ sys_cmd, strerror(errno));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
if (db_type == SAM_DATABASE_DOMAIN) {
fprintf(ldif_fd,
"# SAM_DATABASE_DOMAIN: MODIFY ENTITIES\n");
fflush(ldif_fd);
}
pstr_sprintf(sys_cmd, "cat %s >> %s", mod_ldif, ldif_file);
- system(sys_cmd);
+ sys_cmd_result = system(sys_cmd);
+ if (sys_cmd_result) {
+ d_fprintf(stderr, "%s failed. Error was (%s)\n",
+ sys_cmd, strerror(errno));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
/* Delete the temporary ldif files */
pstr_sprintf(sys_cmd, "rm -f %s %s", add_ldif, mod_ldif);
- system(sys_cmd);
+ sys_cmd_result = system(sys_cmd);
+ if (sys_cmd_result) {
+ d_fprintf(stderr, "%s failed. Error was (%s)\n",
+ sys_cmd, strerror(errno));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
/* Close the ldif file */
fclose(ldif_fd);
}
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Failed to fetch domain database: %s\n",
+ d_fprintf(stderr, "Failed to fetch domain database: %s\n",
nt_errstr(result));
if (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED))
- d_printf("Perhaps %s is a Windows 2000 native mode "
- "domain?\n", domain_name);
+ d_fprintf(stderr, "Perhaps %s is a Windows 2000 native "
+ "mode domain?\n", domain_name);
goto fail;
}
}
if (!NT_STATUS_IS_OK(result)) {
- d_printf("Failed to fetch builtin database: %s\n",
+ d_fprintf(stderr, "Failed to fetch builtin database: %s\n",
nt_errstr(result));
goto fail;
}
service, SC_RIGHT_SVC_QUERY_STATUS );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open service. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result));
return result;
}
service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open service. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result));
goto done;
}
control, &service_status );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Control service request failed. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Control service request failed. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
SVCCTL_STATE_ALL, &num_services, &services );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to enumerate services. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to enumerate services. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
(SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open service. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Query status request failed. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_query_config(pipe_hnd, mem_ctx, &hService, &config );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Query config request failed. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Query config request failed. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
return werror_to_ntstatus(result);
}
servicename, SC_RIGHT_SVC_START );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Failed to open service. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result));
goto done;
}
result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 );
if ( !W_ERROR_IS_OK(result) ) {
- d_printf("Query status request failed. [%s]\n", dos_errstr(result));
+ d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result));
goto done;
}
if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) )
d_printf("Successfully started service: %s\n", servicename );
else
- d_printf("Failed to start service: %s [%s]\n", servicename, dos_errstr(result) );
+ d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) );
done:
rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService );
TDB_DEFAULT, O_RDONLY, 0);
if (tdb == NULL) {
- d_printf("%s not initialised\n", lock_path("sessionid.tdb"));
+ d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb"));
return -1;
}
TDB_DEFAULT, O_RDONLY, 0);
if (tdb == NULL) {
- d_printf("%s not initialised\n", lock_path("sessionid.tdb"));
+ d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb"));
return -1;
}
TDB_DEFAULT, O_RDONLY, 0);
if (tdb == NULL) {
- d_printf("%s not initialised\n", lock_path("connections.tdb"));
- d_printf("This is normal if no SMB client has ever connected "
- "to your server.\n");
+ d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb"));
+ d_fprintf(stderr, "This is normal if no SMB client has ever "
+ "connected to your server.\n");
return -1;
}
TDB_DEFAULT, O_RDONLY, 0);
if (tdb == NULL) {
- d_printf("%s not initialised\n",
+ d_fprintf(stderr, "%s not initialised\n",
lock_path("connections.tdb"));
- d_printf("This is normal if no SMB client has ever "
- "connected to your server.\n");
+ d_fprintf(stderr, "This is normal if no SMB client has "
+ "ever connected to your server.\n");
return -1;
}
{
time_t t = nettime(NULL);
char *cmd;
+ int result;
if (t == 0) return -1;
roll your own. I'm putting this in as it works on a large number
of systems and the user has a choice in whether its used or not */
asprintf(&cmd, "/bin/date %s", systime(t));
- system(cmd);
+ result = system(cmd);
+ if (result)
+ d_fprintf(stderr, "%s failed. Error was (%s)\n",
+ cmd, strerror(errno));
free(cmd);
- return 0;
+ return result;
}
/* display the time on a remote box in a format ready for /bin/date */
if (!opt_host && !opt_have_ip &&
!find_master_ip(opt_target_workgroup, &opt_dest_ip)) {
- d_printf("Could not locate a time server. Try "\
+ d_fprintf(stderr, "Could not locate a time server. Try "\
"specifying a target host.\n");
net_time_usage(argc,argv);
return -1;