BMailAccountSettings*
AutoConfigWindow::GenerateBasicAccount()
{
	if (!fAccount) {
		fParentWindow->Lock();
		fAccount = fParentWindow->AddAccount();
		fParentWindow->Unlock();
	}

	fAccount->SetName(fAccountInfo.accountName.String());
	fAccount->SetRealName(fAccountInfo.name.String());
	fAccount->SetReturnAddress(fAccountInfo.email.String());

	BMessage& inboundArchive = fAccount->InboundSettings();
	inboundArchive.MakeEmpty();
	BString inServerName;
	int32 authType = 0;
	int32 ssl = 0;
	if (fAccountInfo.inboundType == IMAP) {
		inServerName = fAccountInfo.providerInfo.imap_server;
		ssl = fAccountInfo.providerInfo.ssl_imap;
		fAccount->SetInboundAddOn("IMAP");
	} else {
		inServerName = fAccountInfo.providerInfo.pop_server;
		authType = fAccountInfo.providerInfo.authentification_pop;
		ssl = fAccountInfo.providerInfo.ssl_pop;
		fAccount->SetInboundAddOn("POP3");
	}
	inboundArchive.AddString("server", inServerName);
	inboundArchive.AddInt32("auth_method", authType);
	inboundArchive.AddInt32("flavor", ssl);
	inboundArchive.AddString("username", fAccountInfo.loginName);
	set_passwd(&inboundArchive, "cpasswd", fAccountInfo.password);
	inboundArchive.AddBool("leave_mail_on_server", true);
	inboundArchive.AddBool("delete_remote_when_local", true);

	BMessage& outboundArchive = fAccount->OutboundSettings();
	outboundArchive.MakeEmpty();
	fAccount->SetOutboundAddOn("SMTP");
	outboundArchive.AddString("server",
		fAccountInfo.providerInfo.smtp_server);
	outboundArchive.AddString("username", fAccountInfo.loginName);
	set_passwd(&outboundArchive, "cpasswd", fAccountInfo.password);
	outboundArchive.AddInt32("auth_method",
		fAccountInfo.providerInfo.authentification_smtp);
	outboundArchive.AddInt32("flavor",
		fAccountInfo.providerInfo.ssl_smtp);

	fParentWindow->Lock();
	fParentWindow->AccountUpdated(fAccount);
	fParentWindow->Unlock();

	return fAccount;
}
Example #2
0
const char* users_mod(const char *name, const char *passwd, char **msg)
{
	assert(name);
	assert(passwd);

	/* set password */
	if (strlen(passwd) != 0) {
		return (set_passwd(name, passwd, msg));
	}

	return (NULL);
}
Example #3
0
int main()
{
	alarm(15);
        setbuf(stdin,0);
        setbuf(stdout,0);
	char passwd[PASS_LEN + 1];
	set_passwd(passwd, PASS_LEN);

	play((unsigned char*)passwd, PASS_LEN);


	return 0;
}
Example #4
0
static int do_passwd(int argc, char *argv[])
{
	unsigned char passwd2[PASSWD_MAX_LENGTH];
	unsigned char passwd1[PASSWD_MAX_LENGTH];
	int passwd1_len;
	int passwd2_len;
	int ret = 1;

	puts("Enter new password: "******"Retype new password: "******"Sorry, passwords write failed\n");
		ret = 1;
		goto disable;
	}

	return 0;
err:
	puts("Sorry, passwords do not match\n");
	puts("passwd: password unchanged\n");
	return 1;

disable:
	passwd_disable();
	puts("passwd: password disabled\n");
	return ret;
}
Example #5
0
const char* users_add(const char *name, const char *passwd, char **msg)
{
	int ret;
	const char *retstr;
	char *aux = NULL;
	char *cmdline = NULL;
	const char *errmsg[] = {
		/* 0 success */ "",
		/* 1 */ "can't update password file",
		/* 2 */ "invalid command syntax",
		/* 3 */ "invalid argument to option",
		/* 4 */ "UID already in use (and no -o)",
		/* 5 */ "",
		/* 6 */ "specified group doesn't exist",
		/* 7,8 */ "", "",
		/* 9 */ "username already in use",
		/* 10 */ "can't update group file",
		/* 11 */ "",
		/* 12 */ "can't create home directory",
		/* 13 */ "",
		/* 14 */ "can't update SELinux user mapping"
	};

	assert(name);
	assert(passwd);

	/* create user */
	asprintf(&cmdline, "%s -m %s", USERADD_PATH, name);
	ret = WEXITSTATUS(system(cmdline));
	free(cmdline);

	if (ret != 0) {
		*msg = strdup(errmsg[ret]);
		return (NULL);
	}

	/* set password */
	if (strlen(passwd) != 0) {
		retstr = set_passwd(name, passwd, msg);
		if (retstr == NULL) {
			/* revert changes */
			users_rm(name, &aux);
			free(aux);
		}
		return (retstr);
	}

	return (passwd);
}
Example #6
0
int
main(void)
{
    krb5_context ctx;
    const char *message;
    char *expected;
    char long_principal[VERY_LONG_PRINCIPAL];
    const char *acls[5];
    const struct rule rule = {
        (char *) "TEST", 0, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0, 0,
        NULL, NULL, (char **) acls
    };

    plan(16);

    /* Use a krb5.conf with a default realm of EXAMPLE.ORG. */
    kerberos_generate_conf("EXAMPLE.ORG");

    /* Check behavior with empty groups. */
    fake_queue_group(&empty, 0);
    set_passwd("someone", 0);
    acls[0] = "localgroup:empty";
    acls[1] = NULL;
    ok(!acl_permit(&rule, "*****@*****.**"), "Empty");

    /* Check behavior when user is expected to be in supplied group. */
    fake_queue_group(&goodguys, 0);
    set_passwd("remi", 0);
    acls[0] = "localgroup:goodguys";
    acls[1] = NULL;
    ok(acl_permit(&rule, "*****@*****.**"), "User in group");

    /* And when the user is not in the supplied group. */
    fake_queue_group(&goodguys, 0);
    set_passwd("someoneelse", 0);
    ok(!acl_permit(&rule, "*****@*****.**"), "User not in group");

    /* Check that the user's primary group also counts. */
    fake_queue_group(&goodguys, 0);
    set_passwd("otheruser", 42);
    ok(acl_permit(&rule, "*****@*****.**"),
       "User has group as primary group");

    /* And when the user does not convert to a local user or is complex. */
    fake_queue_group(&goodguys, 0);
    set_passwd("remi", 0);
    errors_capture();
    ok(!acl_permit(&rule, "remi/[email protected]"),
       "User with instance with base user in group");
    is_string(NULL, errors, "...with no error");

    /* Principal name is too long. */
    fake_queue_group(&goodguys, 0);
    memset(long_principal, 'A', sizeof(long_principal));
    long_principal[sizeof(long_principal) - 1] = '\0';
    errors_capture();
    ok(!acl_permit(&rule, long_principal), "Long principal");

    /* Determine the expected error message and check it. */
    if (krb5_init_context(&ctx) != 0)
        bail("cannot create Kerberos context");
    message = krb5_get_error_message(ctx, KRB5_CONFIG_NOTENUFSPACE);
    basprintf(&expected, "conversion of %s to local name failed: %s\n",
              long_principal, message);
    krb5_free_context(ctx);
    is_string(expected, errors, "...with correct error message");
    krb5_free_error_message(ctx, message);
    free(expected);

    /* Unsupported realm. */
    fake_queue_group(&goodguys, 0);
    set_passwd("eagle", 0);
    ok(!acl_permit(&rule, "*****@*****.**"), "Non-local realm");

    /* Check behavior when syscall fails */
    fake_queue_group(&goodguys, EPERM);
    set_passwd("remi", 0);
    errors_capture();
    ok(!acl_permit(&rule, "*****@*****.**"), "Failing getgrnam_r");
    is_string("TEST:0: retrieving membership of localgroup goodguys failed\n",
              errors, "...with correct error message");

    /* Check that deny group works as expected */
    fake_queue_group(&badguys, 0);
    set_passwd("boba-fett", 0);
    acls[0] = "deny:localgroup:badguys";
    acls[1] = NULL;
    ok(!acl_permit(&rule, "*****@*****.**"), "Denied user");
    fake_queue_group(&badguys, 0);
    set_passwd("remi", 0);
    ok(!acl_permit(&rule, "*****@*****.**"),
       "User not in denied group but also not allowed");

    /* Check that both deny and "allow" pragma work together */
    fake_queue_group(&goodguys, 0);
    fake_queue_group(&badguys, 0);
    set_passwd("eagle", 0);
    acls[0] = "localgroup:goodguys";
    acls[1] = "deny:localgroup:badguys";
    acls[2] = NULL;
    ok(acl_permit(&rule, "*****@*****.**"),
       "User in allowed group plus a denied group");
    fake_queue_group(&goodguys, 0);
    fake_queue_group(&badguys, 0);
    set_passwd("darth-maul", 0);
    ok(!acl_permit(&rule, "*****@*****.**"),
       "User in a denied group plus an allowed group");
    fake_queue_group(&goodguys, 0);
    fake_queue_group(&badguys, 0);
    set_passwd("anyoneelse", 0);
    ok(!acl_permit(&rule, "*****@*****.**"),
       "User in neither denied nor allowed group");

    /* Clean up. */
    free(errors);
    return 0;
}
Example #7
0
int
pw_group(int mode, char *name, long id, struct cargs * args)
{
	int		rc;
	struct carg    *arg;
	struct group   *grp = NULL;
	int	        grmembers = 0;
	char           **members = NULL;
	struct userconf	*cnf = conf.userconf;

	static struct group fakegroup =
	{
		"nogroup",
		"*",
		-1,
		NULL
	};

	if (mode == M_LOCK || mode == M_UNLOCK)
		errx(EX_USAGE, "'lock' command is not available for groups");

	/*
	 * With M_NEXT, we only need to return the
	 * next gid to stdout
	 */
	if (mode == M_NEXT) {
		gid_t next = gr_gidpolicy(cnf, id);
		if (getarg(args, 'q'))
			return next;
		printf("%u\n", next);
		return EXIT_SUCCESS;
	}

	if (mode == M_PRINT && getarg(args, 'a')) {
		SETGRENT();
		while ((grp = GETGRENT()) != NULL)
			print_group(grp);
		ENDGRENT();
		return EXIT_SUCCESS;
	}
	if (id < 0 && name == NULL)
		errx(EX_DATAERR, "group name or id required");

	grp = (name != NULL) ? GETGRNAM(name) : GETGRGID(id);

	if (mode == M_UPDATE || mode == M_DELETE || mode == M_PRINT) {
		if (name == NULL && grp == NULL)	/* Try harder */
			grp = GETGRGID(id);

		if (grp == NULL) {
			if (mode == M_PRINT && getarg(args, 'F')) {
				char	*fmems[1];
				fmems[0] = NULL;
				fakegroup.gr_name = name ? name : "nogroup";
				fakegroup.gr_gid = (gid_t) id;
				fakegroup.gr_mem = fmems;
				return print_group(&fakegroup);
			}
			if (name == NULL)
				errx(EX_DATAERR, "unknown group `%s'", name);
			else
				errx(EX_DATAERR, "unknown group `%ld'", id);
		}
		if (name == NULL)	/* Needed later */
			name = grp->gr_name;

		/*
		 * Handle deletions now
		 */
		if (mode == M_DELETE) {
			rc = delgrent(grp);
			if (rc == -1)
				err(EX_IOERR, "group '%s' not available (NIS?)",
				    name);
			else if (rc != 0) {
				err(EX_IOERR, "group update");
			}
			pw_log(cnf, mode, W_GROUP, "%s(%ld) removed", name, id);
			return EXIT_SUCCESS;
		} else if (mode == M_PRINT)
			return print_group(grp);

		if (id > 0)
			grp->gr_gid = (gid_t) id;

		if (conf.newname != NULL)
			grp->gr_name = pw_checkname(conf.newname, 0);
	} else {
		if (name == NULL)	/* Required */
			errx(EX_DATAERR, "group name required");
		else if (grp != NULL)	/* Exists */
			errx(EX_DATAERR, "group name `%s' already exists", name);

		extendarray(&members, &grmembers, 200);
		members[0] = NULL;
		grp = &fakegroup;
		grp->gr_name = pw_checkname(name, 0);
		grp->gr_passwd = "*";
		grp->gr_gid = gr_gidpolicy(cnf, id);
		grp->gr_mem = members;
	}

	/*
	 * This allows us to set a group password Group passwords is an
	 * antique idea, rarely used and insecure (no secure database) Should
	 * be discouraged, but it is apparently still supported by some
	 * software.
	 */

	if (conf.fd != -1)
		set_passwd(grp, mode == M_UPDATE);

	if (((arg = getarg(args, 'M')) != NULL ||
	    (arg = getarg(args, 'd')) != NULL ||
	    (arg = getarg(args, 'm')) != NULL) && arg->val) {
		int	i = 0;
		char   *p;
		struct passwd	*pwd;

		/* Make sure this is not stay NULL with -M "" */
		extendarray(&members, &grmembers, 200);
		if (arg->ch == 'd')
			delete_members(&members, &grmembers, &i, arg, grp);
		else if (arg->ch == 'm') {
			int	k = 0;

			if (grp->gr_mem != NULL) {
				while (grp->gr_mem[k] != NULL) {
					if (extendarray(&members, &grmembers, i + 2) != -1)
						members[i++] = grp->gr_mem[k];
					k++;
				}
			}
		}

		if (arg->ch != 'd')
			for (p = strtok(arg->val, ", \t"); p != NULL; p = strtok(NULL, ", \t")) {
				int	j;

				/*
				 * Check for duplicates
				 */
				pwd = lookup_pwent(p);
				for (j = 0; j < i && strcmp(members[j], pwd->pw_name) != 0; j++)
					;
				if (j == i && extendarray(&members, &grmembers, i + 2) != -1)
					members[i++] = newstr(pwd->pw_name);
			}
		while (i < grmembers)
			members[i++] = NULL;
		grp->gr_mem = members;
	}

	if (conf.dryrun)
		return print_group(grp);

	if (mode == M_ADD && (rc = addgrent(grp)) != 0) {
		if (rc == -1)
			errx(EX_IOERR, "group '%s' already exists",
			    grp->gr_name);
		else
			err(EX_IOERR, "group update");
	} else if (mode == M_UPDATE && (rc = chggrent(name, grp)) != 0) {
		if (rc == -1)
			errx(EX_IOERR, "group '%s' not available (NIS?)",
			    grp->gr_name);
		else
			err(EX_IOERR, "group update");
	}

	if (conf.newname != NULL)
		name = conf.newname;
	/* grp may have been invalidated */
	if ((grp = GETGRNAM(name)) == NULL)
		errx(EX_SOFTWARE, "group disappeared during update");

	pw_log(cnf, mode, W_GROUP, "%s(%u)", grp->gr_name, grp->gr_gid);

	free(members);

	return EXIT_SUCCESS;
}
Example #8
0
status_t
BMailProtocolConfigView::Archive(BMessage *into, bool deep) const
{
	const char *host = TextControl((BView *)this,"host");
	int32 port = -1;
	BString host_name = host;
	if (host_name.FindFirst(':') > -1) {
		port = atol(host_name.String() + host_name.FindFirst(':') + 1);
		host_name.Truncate(host_name.FindFirst(':'));
	}

	if (into->ReplaceString("server",host_name.String()) != B_OK)
		into->AddString("server",host_name.String());

	// since there is no need for the port option, remove it here
	into->RemoveName("port");
	if (port != -1)
		into->AddInt32("port",port);

	if (into->ReplaceString("username",TextControl((BView *)this,"user")) != B_OK)
		into->AddString("username",TextControl((BView *)this,"user"));

	// remove old unencrypted passwords
	into->RemoveName("password");

	set_passwd(into,"cpasswd",TextControl((BView *)this,"pass"));

	BMenuField *field;
	int32 index = -1;

	if ((field = (BMenuField *)(FindView("flavor"))) != NULL) {
		BMenuItem *item = field->Menu()->FindMarked();
		if (item != NULL)
			index = field->Menu()->IndexOf(item);
	}

	if (into->ReplaceInt32("flavor",index) != B_OK)
		into->AddInt32("flavor",index);

	index = -1;

	if ((field = (BMenuField *)(FindView("auth_method"))) != NULL) {
		BMenuItem *item = field->Menu()->FindMarked();
		if (item != NULL)
			index = field->Menu()->IndexOf(item);
	}

	if (into->ReplaceInt32("auth_method",index) != B_OK)
		into->AddInt32("auth_method",index);

	if (FindView("leave_mail_on_server") != NULL) {
		BControl* control = (BControl*)FindView("leave_mail_on_server");
		bool on = (control->Value() == B_CONTROL_ON);
		if (into->ReplaceBool("leave_mail_on_server", on) != B_OK)
			into->AddBool("leave_mail_on_server", on);

		control = (BControl*)FindView("delete_remote_when_local");
		on = (control->Value() == B_CONTROL_ON);
		if (into->ReplaceBool("delete_remote_when_local", on)) {
			into->AddBool("delete_remote_when_local", on);
		}
	} else {
		if (into->ReplaceBool("leave_mail_on_server", false) != B_OK)
			into->AddBool("leave_mail_on_server", false);

		if (into->ReplaceBool("delete_remote_when_local", false) != B_OK)
			into->AddBool("delete_remote_when_local", false);
	}

	if (fBodyDownloadConfig)
		fBodyDownloadConfig->Archive(into, deep);
	return B_OK;
}