void MainPage::init(){ this->man = NULL; ToolUtil::initStyle(this); IconHelper::Instance()->SetIcon(ui->btnMenu_Close, QChar(0xf00d), 10); IconHelper::Instance()->SetIcon(ui->btnMenu_Min, QChar(0xf068), 10); IconHelper::Instance()->SetIcon(ui->btnMenu, QChar(0xf0c9), 10); // IconHelper::Instance()->Set(ui->lab_Ico, QChar(0xf19c), 12); IconHelper::Instance()->SetBackground(ui->lab_Ico, "logo.png"); main_menu = new MainMenu(); icon_menu = new IconMenu(); //信号量注册 connect(ui->bt_quit,SIGNAL(clicked()),this,SLOT(userLogout())); /***********menu slot****************/ connect(main_menu,SIGNAL(setting()),this,SLOT(menuSetting())); connect(main_menu,SIGNAL(aboutus()),this,SLOT(menuAboutus())); connect(icon_menu,SIGNAL(login()),this,SLOT(menuLogin())); connect(icon_menu,SIGNAL(logout()),this,SLOT(userLogout())); connect(icon_menu,SIGNAL(min()),this,SLOT(on_btnMenu_Min_clicked())); connect(icon_menu,SIGNAL(useradd()),this,SLOT(userAdd())); connect(icon_menu,SIGNAL(clo()),this,SLOT(close())); connect(icon_menu,SIGNAL(pwdchange()),this,SLOT(menuPwdChange())); /*********login************/ this->showLoginDlg(); }
int do_adduser(){ s8 ret; u32 i=0; u8 id; u8 password[PASSWORD_LENGTH] , ch; u8 username[MAX_NAME]; if (!check_for_args(ADDUSER,0)) return 1; vd_puts("ENTER USER NAME ::" ); gets(username); username[--i] = 0; i=0; vd_puts("\nENTER PASSWORD ::" ); while (i <= PASSWORD_LENGTH && (ch = password[i++] = getch()) != (u8)('\n') && ch != (u8)('\r'))vd_putchar('#'); password[--i] = 0; vd_puts("\n"); ret=useradd(username,password); if (ret == -1) { vd_puts("COULD NOT ADD USER\n"); errormessage(geterror()); fl_clean(); return 1; } fl_clean(); return 0; }
int GroupMgr() { /* User mgr Key */ if(gethostname(computer, 255) !=0 || uname(&uts) < 0) { MsgBoxError("Unable to get hostname information"); } int GroupMgrItem = 0; keypad(stdscr, TRUE); noecho(); while(1) { DrawGroupMgrScreen(GroupMgrItem); do { GRkey = getch(); switch(GRkey) { case KEY_F(2): listgrctr = 100; newgrlist = 0; break; case KEY_F(3): useradd(); break; case KEY_F(10): return 0; break;; case KEY_DOWN: wscrl(GroupPad, 3); //mvprintw(1, x/2, "Username: %s", usernames[UserNo++]); break;; case KEY_UP: wscrl(GroupPad, -3); break;; }; DrawGroupMgrScreen(GroupMgrItem); } while(GRkey != '\n'); /* Responses */ }; /*End of While */ return 0; }
int init() { struct user root_user; memset(users, 0, sizeof(users)); user_created = 0; memset(fds, 0, sizeof(fds)); fd_opened = 0; // 创建根用户 if (user_get_by_id(useradd("root"), &root_user) != E_OK) PANIC("系统初始化失败"); // 创建根目录 root = entry_create_dir("/", &root_user, PERM_WR | PERM_RD, PERM_WR | PERM_RD); return E_OK; }
void Shell::select(const std::string& exec, size_t argc, const std::string* argv) { if(exec == "open") open(argc, argv); else if(exec == "seek") seek(argc, argv); else if(exec == "tell") tell(argc, argv); else if(exec == "write") write(argc, argv); else if(exec == "read") read(argc, argv); else if(exec == "close") close(argc, argv); else if(exec == "useradd") useradd(argc, argv); else if(exec == "chpsd") chpsd(argc, argv); else if(exec == "cd") cd(argc, argv); else if(exec == "mkdir") mkdir(argc, argv); else if(exec == "mkfile") mkfile(argc, argv); else if(exec == "rm") rm(argc, argv); else if(exec == "cat") cat(argc, argv); else if(exec == "ls") ls(argc, argv); else if(exec == "chmod") chmod(argc, argv); else if(exec == "see") see(argc, argv); else if(exec == "ocp") ocp(argc, argv); else runshell(exec, argc, argv); }
int main(int argc, const char **argv) { uid_t pc_uid = 0; const char *pc_gecos = NULL; const char *pc_home = NULL; char *pc_shell = NULL; int pc_debug = SSSDBG_DEFAULT; int pc_create_home = 0; const char *pc_username = NULL; const char *pc_skeldir = NULL; const char *pc_selinux_user = NULL; struct poptOption long_options[] = { POPT_AUTOHELP { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, { "uid", 'u', POPT_ARG_INT, &pc_uid, 0, _("The UID of the user"), NULL }, { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, _("The comment string"), NULL }, { "home", 'h', POPT_ARG_STRING, &pc_home, 0, _("Home directory"), NULL }, { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login shell"), NULL }, { "groups", 'G', POPT_ARG_STRING, NULL, 'G', _("Groups"), NULL }, { "create-home", 'm', POPT_ARG_NONE, NULL, 'm', _("Create user's directory if it does not exist"), NULL }, { "no-create-home", 'M', POPT_ARG_NONE, NULL, 'M', _("Never create user's directory, overrides config"), NULL }, { "skel", 'k', POPT_ARG_STRING, &pc_skeldir, 0, _("Specify an alternative skeleton directory"), NULL }, { "selinux-user", 'Z', POPT_ARG_STRING, &pc_selinux_user, 0, _("The SELinux user for user's login"), NULL }, POPT_TABLEEND }; poptContext pc = NULL; struct tools_ctx *tctx = NULL; char *groups = NULL; char *badgroup = NULL; int ret; errno_t sret; bool in_transaction = false; debug_prg_name = argv[0]; ret = set_locale(); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "set_locale failed (%d): %s\n", ret, strerror(ret)); ERROR("Error setting the locale\n"); ret = EXIT_FAILURE; goto fini; } /* parse parameters */ pc = poptGetContext(NULL, argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "USERNAME"); while ((ret = poptGetNextOpt(pc)) > 0) { switch (ret) { case 'G': groups = poptGetOptArg(pc); if (!groups) { BAD_POPT_PARAMS(pc, _("Specify group to add to\n"), ret, fini); } break; case 'm': pc_create_home = DO_CREATE_HOME; break; case 'M': pc_create_home = DO_NOT_CREATE_HOME; break; } } DEBUG_CLI_INIT(pc_debug); if (ret != -1) { BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini); } /* username is an argument without --option */ pc_username = poptGetArg(pc); if (pc_username == NULL) { BAD_POPT_PARAMS(pc, _("Specify user to add\n"), ret, fini); } CHECK_ROOT(ret, debug_prg_name); ret = init_sss_tools(&tctx); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "init_sss_tools failed (%d): %s\n", ret, strerror(ret)); if (ret == ENOENT) { ERROR("Error initializing the tools - no local domain\n"); } else { ERROR("Error initializing the tools\n"); } ret = EXIT_FAILURE; goto fini; } /* if the domain was not given as part of FQDN, default to local domain */ ret = parse_name_domain(tctx, pc_username); if (ret != EOK) { ERROR("Invalid domain specified in FQDN\n"); ret = EXIT_FAILURE; goto fini; } if (groups) { ret = parse_groups(tctx, groups, &tctx->octx->addgroups); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Cannot parse groups to add the user to\n"); ERROR("Internal error while parsing parameters\n"); ret = EXIT_FAILURE; goto fini; } ret = parse_group_name_domain(tctx, tctx->octx->addgroups); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Cannot parse FQDN groups to add the user to\n"); ERROR("Groups must be in the same domain as user\n"); ret = EXIT_FAILURE; goto fini; } /* Check group names in the LOCAL domain */ ret = check_group_names(tctx, tctx->octx->addgroups, &badgroup); if (ret != EOK) { ERROR("Cannot find group %1$s in local domain\n", badgroup); ret = EXIT_FAILURE; goto fini; } } tctx->octx->uid = pc_uid; /* * Fills in defaults for ops_ctx user did not specify. */ ret = useradd_defaults(tctx, tctx->confdb, tctx->octx, pc_gecos, pc_home, pc_shell, pc_create_home, pc_skeldir); if (ret != EOK) { ERROR("Cannot set default values\n"); ret = EXIT_FAILURE; goto fini; } /* arguments processed, go on to actual work */ if (id_in_range(tctx->octx->uid, tctx->octx->domain) != EOK) { ERROR("The selected UID is outside the allowed range\n"); ret = EXIT_FAILURE; goto fini; } tctx->error = sysdb_transaction_start(tctx->sysdb); if (tctx->error != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n"); goto done; } in_transaction = true; /* useradd */ tctx->error = useradd(tctx, tctx->octx); if (tctx->error) { goto done; } tctx->error = sysdb_transaction_commit(tctx->sysdb); if (tctx->error) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n"); goto done; } in_transaction = false; /* Set SELinux login context - must be done after transaction is done * b/c libselinux calls getpwnam */ ret = set_seuser(tctx->octx->name, pc_selinux_user, NULL); if (ret != EOK) { ERROR("Cannot set SELinux login context\n"); ret = EXIT_FAILURE; goto fini; } /* Create user's home directory and/or mail spool */ if (tctx->octx->create_homedir) { /* We need to know the UID of the user, if * sysdb did assign it automatically, do a lookup */ if (tctx->octx->uid == 0) { ret = sysdb_getpwnam_sync(tctx, tctx->octx->name, tctx->octx); if (ret != EOK) { ERROR("Cannot get info about the user\n"); ret = EXIT_FAILURE; goto fini; } } ret = create_homedir(tctx->octx->skeldir, tctx->octx->home, tctx->octx->uid, tctx->octx->gid, tctx->octx->umask); if (ret == EEXIST) { ERROR("User's home directory already exists, not copying " "data from skeldir\n"); } else if (ret != EOK) { ERROR("Cannot create user's home directory: %1$s\n", strerror(ret)); ret = EXIT_FAILURE; goto fini; } ret = create_mail_spool(tctx, tctx->octx->name, tctx->octx->maildir, tctx->octx->uid, tctx->octx->gid); if (ret != EOK) { ERROR("Cannot create user's mail spool: %1$s\n", strerror(ret)); DEBUG(SSSDBG_CRIT_FAILURE, "Cannot create user's mail spool: [%d][%s].\n", ret, strerror(ret)); ret = EXIT_FAILURE; goto fini; } } done: if (in_transaction) { sret = sysdb_transaction_cancel(tctx->sysdb); if (sret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Failed to cancel transaction\n"); } } if (tctx->error) { switch (tctx->error) { case ERANGE: ERROR("Could not allocate ID for the user - domain full?\n"); break; case EEXIST: ERROR("A user or group with the same name or ID already exists\n"); break; default: DEBUG(SSSDBG_CRIT_FAILURE, "sysdb operation failed (%d)[%s]\n", tctx->error, strerror(tctx->error)); ERROR("Transaction error. Could not add user.\n"); break; } ret = EXIT_FAILURE; goto fini; } ret = EXIT_SUCCESS; fini: poptFreeContext(pc); talloc_free(tctx); free(groups); exit(ret); }
mainWidget::mainWidget(const char *name) : KTMainWindow(name) { md = new mainDlg(this); md->init(); QPopupMenu *file = new QPopupMenu; CHECK_PTR( file ); file->insertItem(i18n("&Save"), md, SLOT(save()) ); file->insertSeparator(); file->insertItem(i18n("&Preferences..."), md, SLOT(properties()) ); file->insertSeparator(); file->insertItem(i18n("&Quit"), md, SLOT(quit()) ); QPopupMenu *user = new QPopupMenu; CHECK_PTR(user); user->insertItem(i18n("&Edit..."), md, SLOT(useredit()) ); user->insertItem(i18n("&Delete..."), md, SLOT(userdel()) ); user->insertItem(i18n("&Add..."), md, SLOT(useradd()) ); user->insertItem(i18n("&Set password..."), md, SLOT(setpwd()) ); QPopupMenu *group = new QPopupMenu; CHECK_PTR(group); group->insertItem(i18n("&Edit..."), md, SLOT(grpedit()) ); group->insertItem(i18n("&Delete..."), md, SLOT(grpdel()) ); group->insertItem(i18n("&Add..."), md, SLOT(grpadd()) ); QString tmp; tmp.sprintf(i18n("KUser version %s\n" "KDE project\n" "This program was created by\n" "Denis Pershin\n" "[email protected]\n" "Copyright 1997(c)"), _KU_VERSION); QPopupMenu *help = kapp->getHelpMenu(true, tmp); menubar = new KMenuBar( this ); CHECK_PTR( menubar ); menubar->insertItem(i18n("&File"), file ); menubar->insertItem(i18n("&User"), user ); menubar->insertItem(i18n("&Group"), group ); menubar->insertSeparator(); menubar->insertItem(i18n("&Help"), help ); setMenu(menubar); toolbar = new KToolBar(this, "toolbar"); QPixmap pix; pix = kapp->getIconLoader()->loadIcon("useradd.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(useradd()), TRUE, i18n("Add user")); pix = kapp->getIconLoader()->loadIcon("userdel.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(userdel()), TRUE, i18n("Delete user")); pix = kapp->getIconLoader()->loadIcon("useredit.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(useredit()), TRUE, i18n("Edit user")); toolbar->insertSeparator(); pix = kapp->getIconLoader()->loadIcon("grpadd.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpadd()), TRUE, i18n("Add group")); pix = kapp->getIconLoader()->loadIcon("grpdel.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpdel()), TRUE, i18n("Delete group")); pix = kapp->getIconLoader()->loadIcon("grpedit.xpm"); toolbar->insertButton(pix, 0, SIGNAL(clicked()), md, SLOT(grpedit()), TRUE, i18n("Edit group")); toolbar->setBarPos(KToolBar::Top); addToolBar(toolbar); sbar = new KStatusBar(this); sbar->insertItem("Reading config", 0); setStatusBar(sbar); setView(md); resize(500, 400); // restore geometry settings KConfig *config = KApplication::getKApplication()->getConfig(); config->setGroup( "Appearance" ); QString geom = config->readEntry( "Geometry" ); if (!geom.isEmpty()) { int width, height; sscanf( geom, "%dx%d", &width, &height ); resize( width, height ); } sbar->changeItem(i18n("Ready"), 0); }