Back to index

courier  0.68.2
Defines | Functions
numlib.h File Reference
#include <sys/types.h>
#include <time.h>

Go to the source code of this file.

Defines

#define NUMBUFSIZE   60
#define LIBMAIL_STRIMPL(type, f1, f2)

Functions

char * libmail_str_time_t (time_t, char *)
char * libmail_str_off_t (off_t, char *)
char * libmail_str_int64_t (int64_t, char *)
char * libmail_str_pid_t (pid_t, char *)
char * libmail_str_dev_t (dev_t, char *)
char * libmail_str_ino_t (ino_t, char *)
char * libmail_str_uid_t (uid_t, char *)
char * libmail_str_gid_t (gid_t, char *)
char * libmail_str_size_t (size_t, char *)
char * libmail_str_sizekb (unsigned long, char *)
char * libmail_strh_time_t (time_t, char *)
char * libmail_strh_pid_t (pid_t, char *)
char * libmail_strh_ino_t (ino_t, char *)
char * libmail_strh_dev_t (dev_t, char *)
time_t libmail_strtotime_t (const char **)
time_t libmail_atotime_t (const char *)
uid_t libmail_strtouid_t (const char **)
uid_t libmail_atouid_t (const char *)
gid_t libmail_strtogid_t (const char **)
gid_t libmail_atogid_t (const char *)
void libmail_changegroup (gid_t)
void libmail_changeuidgid (uid_t, gid_t)
void libmail_changeusername (const char *, const gid_t *)

Define Documentation

#define LIBMAIL_STRIMPL (   type,
  f1,
  f2 
)
Value:
\
type f1(const char **p)\
{\
       type n=0;\
       while ( **p >= '0' && **p <= '9') n=n*10 + (char)(*(*p)++ - '0');\
       return n;\
}\
\
type f2(const char *p)\
{\
       return f1(&p);\
}

Definition at line 61 of file numlib.h.

#define NUMBUFSIZE   60

Definition at line 25 of file numlib.h.


Function Documentation

gid_t libmail_atogid_t ( const char *  )

Here is the caller graph for this function:

time_t libmail_atotime_t ( const char *  )

Here is the caller graph for this function:

uid_t libmail_atouid_t ( const char *  )

Here is the caller graph for this function:

void libmail_changegroup ( gid_t  )

Definition at line 23 of file changeuidgid.c.

{
       if ( setgid(gid))
       {
              perror("setgid");
              exit(1);
       }

#if HAVE_SETGROUPS
       if ( getuid() == 0 && setgroups(1, &gid) )
       {
              perror("setgroups");
              exit(1);
       }
#endif
}

Here is the caller graph for this function:

void libmail_changeuidgid ( uid_t  ,
gid_t   
)

Definition at line 40 of file changeuidgid.c.

{
       libmail_changegroup(gid);
       if ( setuid(uid))
       {
              perror("setuid");
              exit(1);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void libmail_changeusername ( const char *  ,
const gid_t *   
)

Definition at line 50 of file changeuidgid.c.

{
struct passwd *pw;
uid_t  changeuid;
gid_t  changegid;

/* uname might be a pointer returned from a previous called to getpw(),
** and libc has a problem getting it back.
*/
char   *p=malloc(strlen(uname)+1);

       if (!p)
       {
              perror("malloc");
              exit(1);
       }
       strcpy(p, uname);

       errno=ENOENT;
       if ((pw=getpwnam(p)) == 0)
       {
              free(p);
              perror("getpwnam");
              exit(1);
       }
       free(p);

       changeuid=pw->pw_uid;

       if ( !forcegrp )     forcegrp= &pw->pw_gid;

       changegid= *forcegrp;

       if ( setgid( changegid ))
       {
              perror("setgid");
              exit(1);
       }

#if HAVE_INITGROUPS
       if ( getuid() == 0 && initgroups(pw->pw_name, changegid) )
       {
              perror("initgroups");
              exit(1);
       }
#else
#if HAVE_SETGROUPS
       if ( getuid() == 0 && setgroups(1, &changegid) )
       {
              perror("setgroups");
              exit(1);
       }
#endif
#endif

       if (setuid(changeuid))
       {
              perror("setuid");
              exit(1);
       }
}

Here is the caller graph for this function:

char* libmail_str_dev_t ( dev_t  ,
char *   
)

Definition at line 13 of file strdevt.c.

{
       char   buf[NUMBUFSIZE];
       char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}
char* libmail_str_gid_t ( gid_t  ,
char *   
)

Definition at line 13 of file strgidt.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_ino_t ( ino_t  ,
char *   
)

Definition at line 13 of file strinot.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_int64_t ( int64_t  ,
char *   
)

Definition at line 38 of file strofft.c.

{
       char   buf[NUMBUFSIZE];
       char   *p=buf+sizeof(buf)-1;
       int    isneg=0;

       if (t < 0)
       {
              t= -t;
              isneg=1;
       }

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);

       if (isneg)
              *--p='-';

       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_off_t ( off_t  ,
char *   
)

Definition at line 13 of file strofft.c.

{
       char   buf[NUMBUFSIZE];
       char   *p=buf+sizeof(buf)-1;
       int    isneg=0;

       if (t < 0)
       {
              t= -t;
              isneg=1;
       }

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);

       if (isneg)
              *--p='-';

       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_pid_t ( pid_t  ,
char *   
)

Definition at line 13 of file strpidt.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_size_t ( size_t  ,
char *   
)

Definition at line 13 of file strsizet.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_sizekb ( unsigned  long,
char *   
)

Definition at line 27 of file strsize.c.

{
        /* If size is less than 1K bytes, display it as 0.xK */

        if (n < 1024)
        {
                strcpy(sizebuf, "0.");
                cat_n(sizebuf, (int)(10 * n / 1024 ));
                strcat(sizebuf, "K");
        }
        /* If size is less than 1 meg, display is as xK */

        else if (n < 1024 * 1024)
        {
                *sizebuf=0;
                cat_n(sizebuf, (unsigned long)(n+512)/1024);
                strcat(sizebuf, "K");
        }

        /* Otherwise, display in megabytes */

        else
        {
        unsigned long nm=(double)n / (1024.0 * 1024.0) * 10;

                *sizebuf=0;
                cat_n( sizebuf, nm / 10);
                strcat(sizebuf, ".");
                cat_n( sizebuf, nm % 10);
                strcat(sizebuf, "M");
        }

       return (sizebuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* libmail_str_time_t ( time_t  ,
char *   
)

Definition at line 13 of file strtimet.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_str_uid_t ( uid_t  ,
char *   
)

Definition at line 13 of file struidt.c.

{
char   buf[NUMBUFSIZE];
char   *p=buf+sizeof(buf)-1;

       *p=0;
       do
       {
              *--p= '0' + (t % 10);
              t=t / 10;
       } while(t);
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_strh_dev_t ( dev_t  ,
char *   
)

Definition at line 15 of file strhdevt.c.

{
char   buf[sizeof(t)*2+1];
char   *p=buf+sizeof(buf)-1;
unsigned i;

       *p=0;
       for (i=0; i<sizeof(t)*2; i++)
       {
              *--p= xdigit[t & 15];
              t=t / 16;
       }
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_strh_ino_t ( ino_t  ,
char *   
)

Definition at line 15 of file strhinot.c.

{
char   buf[sizeof(t)*2+1];
char   *p=buf+sizeof(buf)-1;
unsigned i;

       *p=0;
       for (i=0; i<sizeof(t)*2; i++)
       {
              *--p= xdigit[t & 15];
              t=t / 16;
       }
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

char* libmail_strh_pid_t ( pid_t  ,
char *   
)

Definition at line 15 of file strhpidt.c.

{
char   buf[sizeof(t)*2+1];
char   *p=buf+sizeof(buf)-1;
unsigned i;

       *p=0;
       for (i=0; i<sizeof(t)*2; i++)
       {
              *--p= xdigit[t & 15];
              t=t / 16;
       }
       return (strcpy(arg, p));
}
char* libmail_strh_time_t ( time_t  ,
char *   
)

Definition at line 15 of file strhtimet.c.

{
char   buf[sizeof(t)*2+1];
char   *p=buf+sizeof(buf)-1;
unsigned i;

       *p=0;
       for (i=0; i<sizeof(t)*2; i++)
       {
              *--p= xdigit[t & 15];
              t=t / 16;
       }
       return (strcpy(arg, p));
}

Here is the caller graph for this function:

gid_t libmail_strtogid_t ( const char **  )
time_t libmail_strtotime_t ( const char **  )

Here is the caller graph for this function:

uid_t libmail_strtouid_t ( const char **  )