//########################################### int main() { char *mysentence; //mysentence = give_hello(); //printf("Give hello: %s\n", mysentence); //mysentence = give_goodbye( mysentence ); //printf("give goodbye: |%s|\n", mysentence); *mysentence = 0; int number = 0; a_num( &number); printf("Number is %d\n", number); //char *string2; //here or in string_concat? or both? //add_goodbye( string2 ); //printf("add goodbye: %s\n", string2); //add_hello( string2); //printf("add hello: %s\n", string2); struct hash myhash; int results = assign_hash( &myhash ); printf("hash: %s %s \n",myhash.key, myhash.value); return 0; }
static gid_t a_gid(const char *s, const char *id_type) { struct group *gr; if ((gr = getgrnam(s)) != NULL) return gr->gr_gid; return a_num(s, id_type); }
static uid_t a_uid(const char *s, const char *id_type) { struct passwd *pw; if ((pw = getpwnam(s)) != NULL) return pw->pw_uid; return a_num(s, id_type); }
static int mount_udf(char *mntdir, char *fs_name, char *opts, int on_autofs) { udf_args_t udf_args; mntent_t mnt; int flags; char *str; #if defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) uid_t uid_nobody; gid_t gid_nobody; #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) */ /* * Figure out the name of the file system type. */ MTYPE_TYPE type = MOUNT_TYPE_UDF; #if defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) uid_nobody = a_uid("nobody", "user"); if (uid_nobody == 0) { plog(XLOG_ERROR, "mount_udf: invalid uid for nobody"); return EPERM; } #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_UID) || defined(HAVE_UDF_ARGS_T_ANON_UID) */ #if defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_ANON_GID) gid_nobody = a_gid("nobody", "group"); if (gid_nobody == 0) { plog(XLOG_ERROR, "mount_udf: invalid gid for nobody"); return EPERM; } #endif /* defined(HAVE_UDF_ARGS_T_NOBODY_GID) || defined(HAVE_UDF_ARGS_T_ANON_GID) */ str = NULL; memset((voidp) &udf_args, 0, sizeof(udf_args)); /* Paranoid */ /* * Fill in the mount structure */ memset((voidp)&mnt, 0, sizeof(mnt)); mnt.mnt_dir = mntdir; mnt.mnt_fsname = fs_name; mnt.mnt_type = MNTTAB_TYPE_UDF; mnt.mnt_opts = opts; flags = compute_mount_flags(&mnt); #ifdef HAVE_UDF_ARGS_T_UDFMFLAGS # if defined(MNT2_UDF_OPT_CLOSESESSION) && defined(MNTTAB_OPT_CLOSESESSION) if (amu_hasmntopt(&mnt, MNTTAB_OPT_CLOSESESSION)) udf_args.udfmflags |= MNT2_UDF_OPT_CLOSESESSION; # endif /* defined(MNT2_UDF_OPT_CLOSESESSION) && defined(MNTTAB_OPT_CLOSESESSION) */ #endif /* HAVE_UDF_ARGS_T_UDFMFLAGS */ #ifdef HAVE_UDF_ARGS_T_NOBODY_UID udf_args.nobody_uid = uid_nobody; #endif /* HAVE_UDF_ARGS_T_NOBODY_UID */ #ifdef HAVE_UDF_ARGS_T_NOBODY_GID udf_args.nobody_gid = gid_nobody; #endif /* HAVE_UDF_ARGS_T_NOBODY_GID */ #ifdef HAVE_UDF_ARGS_T_ANON_UID udf_args.anon_uid = uid_nobody; /* default to nobody */ if ((str = hasmntstr(&mnt, MNTTAB_OPT_USER)) != NULL) { udf_args.anon_uid = a_uid(str, MNTTAB_OPT_USER); XFREE(str); } #endif /* HAVE_UDF_ARGS_T_ANON_UID */ #ifdef HAVE_UDF_ARGS_T_ANON_GID udf_args.anon_gid = gid_nobody; /* default to nobody */ if ((str = hasmntstr(&mnt, MNTTAB_OPT_GROUP)) != NULL) { udf_args.anon_gid = a_gid(str, MNTTAB_OPT_GROUP); XFREE(str); } #endif /* HAVE_UDF_ARGS_T_ANON_GID */ #ifdef HAVE_UDF_ARGS_T_GMTOFF udf_args.gmtoff = 0; if ((str = hasmntstr(&mnt, MNTTAB_OPT_GMTOFF)) != NULL) { udf_args.gmtoff = a_num(str, MNTTAB_OPT_GMTOFF); XFREE(str); } #endif /* HAVE_UDF_ARGS_T_GMTOFF */ #ifdef HAVE_UDF_ARGS_T_SESSIONNR udf_args.sessionnr = 0; if ((str = hasmntstr(&mnt, MNTTAB_OPT_SESSIONNR)) != NULL) { udf_args.sessionnr = a_num(str, MNTTAB_OPT_SESSIONNR); XFREE(str); } #endif /* HAVE_UDF_ARGS_T_SESSIONNR */ #ifdef HAVE_UDF_ARGS_T_VERSION # ifdef UDFMNT_VERSION udf_args.version = UDFMNT_VERSION; # endif /* UDFMNT_VERSION */ #endif /* HAVE_UDF_ARGS_T_VERSION */ #ifdef HAVE_UFS_ARGS_T_FSPEC udf_args.fspec = fs_name; #endif /* HAVE_UFS_ARGS_T_FSPEC */ /* * Call generic mount routine */ return mount_fs(&mnt, flags, (caddr_t)&udf_args, 0, type, 0, NULL, mnttab_file_name, on_autofs); }
/* main routine */ int mount_udf_parseargs(int argc, char **argv, struct udf_args *args, int *mntflags, char *canon_dev, char *canon_dir) { uid_t anon_uid, nobody_uid; gid_t anon_gid, nobody_gid; int ch, set_gmtoff; uint32_t sector_size; mntoptparse_t mp; /* initialise */ (void)memset(args, 0, sizeof(*args)); set_gmtoff = *mntflags = 0; sector_size = 0; /* get nobody */ nobody_uid = anon_uid = a_uid("nobody"); nobody_gid = anon_gid = a_gid("nobody"); while ((ch = getopt(argc, argv, "cg:o:s:t:u:")) != -1) { switch (ch) { #ifdef notyet case 'c' : args->udfmflags |= UDFMNT_CLOSESESSION; break; #endif case 'g' : /* convert groupname or numeric equiv. */ anon_gid = a_gid(optarg); break; case 'u' : /* convert username or numeric equiv. */ anon_uid = a_uid(optarg); break; case 'o' : /* process generic mount options */ mp = getmntopts(optarg, mopts, mntflags, 0); if (mp == NULL) { warn("getmntopts"); return 1; } freemntopts(mp); break; case 's' : args->sessionnr = a_num(optarg, "session number"); break; case 't' : args->gmtoff = a_num(optarg, "gmtoff"); set_gmtoff = 1; break; default : return 1; /* NOTREACHED */ } } if (optind + 2 != argc) return 1; if (!set_gmtoff) { #ifdef HAVE_STRUCT_TM_TM_GMTOFF time_t now; struct tm *tm; /* use user's time zone as default */ (void)time(&now); tm = localtime(&now); args->gmtoff = tm->tm_gmtoff; #else args->gmtoff = 0; #endif } /* get device and directory specifier */ pathadj(argv[optind], canon_dev); pathadj(argv[optind+1], canon_dir); args->version = UDFMNT_VERSION; args->fspec = canon_dev; args->anon_uid = anon_uid; args->anon_gid = anon_gid; args->nobody_uid = nobody_uid; args->nobody_gid = nobody_gid; args->sector_size = sector_size; /* invalid */ return 0; }